-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimental cloud operations client (#2146)
Fixes #2059
- Loading branch information
Showing
11 changed files
with
520 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "temporal-serviceclient/src/main/proto"] | ||
path = temporal-serviceclient/src/main/proto | ||
url = https://github.com/temporalio/api.git | ||
[submodule "temporal-serviceclient/src/main/protocloud"] | ||
path = temporal-serviceclient/src/main/protocloud | ||
url = https://github.com/temporalio/api-cloud.git |
37 changes: 37 additions & 0 deletions
37
temporal-sdk/src/main/java/io/temporal/client/CloudOperationsClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this material except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.temporal.client; | ||
|
||
import io.temporal.common.Experimental; | ||
import io.temporal.serviceclient.CloudServiceStubs; | ||
|
||
/** Client to the Temporal Cloud operations service for performing cloud operations. */ | ||
@Experimental | ||
public interface CloudOperationsClient { | ||
@Experimental | ||
static CloudOperationsClient newInstance(CloudServiceStubs service) { | ||
return new CloudOperationsClientImpl(service); | ||
} | ||
|
||
/** Get the raw cloud service stubs. */ | ||
@Experimental | ||
CloudServiceStubs getCloudServiceStubs(); | ||
} |
36 changes: 36 additions & 0 deletions
36
temporal-sdk/src/main/java/io/temporal/client/CloudOperationsClientImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this material except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.temporal.client; | ||
|
||
import io.temporal.serviceclient.CloudServiceStubs; | ||
|
||
class CloudOperationsClientImpl implements CloudOperationsClient { | ||
private final CloudServiceStubs cloudServiceStubs; | ||
|
||
CloudOperationsClientImpl(CloudServiceStubs cloudServiceStubs) { | ||
this.cloudServiceStubs = cloudServiceStubs; | ||
} | ||
|
||
@Override | ||
public CloudServiceStubs getCloudServiceStubs() { | ||
return cloudServiceStubs; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
temporal-sdk/src/test/java/io/temporal/client/CloudOperationsClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this material except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.temporal.client; | ||
|
||
import io.temporal.api.cloud.cloudservice.v1.GetNamespaceRequest; | ||
import io.temporal.api.cloud.cloudservice.v1.GetNamespaceResponse; | ||
import io.temporal.serviceclient.CloudServiceStubs; | ||
import io.temporal.serviceclient.CloudServiceStubsOptions; | ||
import org.junit.Assert; | ||
import org.junit.Assume; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class CloudOperationsClientTest { | ||
private String namespace; | ||
private String apiKey; | ||
private String apiVersion; | ||
|
||
@Before | ||
public void checkCloudEnvVars() { | ||
namespace = System.getenv("TEMPORAL_CLIENT_CLOUD_NAMESPACE"); | ||
apiKey = System.getenv("TEMPORAL_CLIENT_CLOUD_API_KEY"); | ||
apiVersion = System.getenv("TEMPORAL_CLIENT_CLOUD_API_VERSION"); | ||
Assume.assumeTrue( | ||
"Cloud environment variables not present", namespace != null && apiKey != null); | ||
} | ||
|
||
@Test | ||
public void simpleCall() { | ||
CloudOperationsClient client = | ||
CloudOperationsClient.newInstance( | ||
CloudServiceStubs.newServiceStubs( | ||
CloudServiceStubsOptions.newBuilder() | ||
.addApiKey(() -> apiKey) | ||
.setVersion(apiVersion) | ||
.build())); | ||
// Do simple get namespace call | ||
GetNamespaceResponse resp = | ||
client | ||
.getCloudServiceStubs() | ||
.blockingStub() | ||
.getNamespace(GetNamespaceRequest.newBuilder().setNamespace(namespace).build()); | ||
Assert.assertEquals(namespace, resp.getNamespace().getNamespace()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
temporal-serviceclient/src/main/java/io/temporal/serviceclient/CloudServiceStubs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this material except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.temporal.serviceclient; | ||
|
||
import static io.temporal.internal.WorkflowThreadMarker.enforceNonWorkflowThread; | ||
|
||
import io.temporal.api.cloud.cloudservice.v1.CloudServiceGrpc; | ||
import io.temporal.internal.WorkflowThreadMarker; | ||
|
||
/** | ||
* Initializes and holds gRPC blocking and future stubs. | ||
* | ||
* <p>WARNING: The cloud service is currently experimental. | ||
*/ | ||
public interface CloudServiceStubs | ||
extends ServiceStubs< | ||
CloudServiceGrpc.CloudServiceBlockingStub, CloudServiceGrpc.CloudServiceFutureStub> { | ||
String HEALTH_CHECK_SERVICE_NAME = "temporal.api.cloud.cloudservice.v1.CloudService"; | ||
|
||
/** Creates CloudService gRPC stubs pointed on to Temporal Cloud. */ | ||
static CloudServiceStubs newCloudServiceStubs() { | ||
return newServiceStubs(CloudServiceStubsOptions.getDefaultInstance()); | ||
} | ||
|
||
/** | ||
* Creates CloudService gRPC stubs<br> | ||
* This method creates stubs with lazy connectivity, connection is not performed during the | ||
* creation time and happens on the first request. | ||
* | ||
* @param options stub options to use | ||
*/ | ||
static CloudServiceStubs newServiceStubs(CloudServiceStubsOptions options) { | ||
enforceNonWorkflowThread(); | ||
return WorkflowThreadMarker.protectFromWorkflowThread( | ||
new CloudServiceStubsImpl(options), CloudServiceStubs.class); | ||
} | ||
} |
Oops, something went wrong.