Are there plans to develop an SDK API for managing (list/create/delete) Nexus endpoints?
It’s preferable to manage endpoints programmatically like we do with namespaces.
Thanks.
Are there plans to develop an SDK API for managing (list/create/delete) Nexus endpoints?
It’s preferable to manage endpoints programmatically like we do with namespaces.
Thanks.
It should be available via operator service, see cli code for reference:
@tihomir Thanks! Didn’t know about the Operator service, maybe because I use the Java SDK.
Anyway, even with the Go code, the Java solution wasn’t real obvious. Here’s a Java code snippet for creating a Nexus endpoint that may save others some time.
public void addNexusEndpoint(String targetNamespace, String targetTaskQueue) {
WorkflowServiceStubsOptions stubOptions = WorkflowServiceStubsOptions.newBuilder()
.setTarget(String.format("%s:%d", getTemporalHost(), getTemporalPort()))
.build();
OperatorServiceStubs operatorService = OperatorServiceStubs.newServiceStubs(
OperatorServiceStubsOptions.newBuilder()
.setChannel(stubOptions.getChannel())
.validateAndBuildWithDefaults());
String endPointName = targetNamespace + "-endpoint";
if (!nexusEndpointExists(operatorService, endPointName)) {
CreateNexusEndpointRequest request = CreateNexusEndpointRequest.newBuilder()
.setSpec(EndpointSpec.newBuilder()
.setName(endPointName)
.setTarget(EndpointTarget.newBuilder()
.setWorker(EndpointTarget.Worker.newBuilder()
.setNamespace(targetNamespace)
.setTaskQueue(targetTaskQueue)
.build())
.build())
.build())
.build();
CreateNexusEndpointResponse response = operatorService.blockingStub().createNexusEndpoint(request);
logger.info("Added Nexus endpoint {}, response: {}", endPointName, response.toString());
} else {
logger.info("Nexus endpoint {} already exists", endPointName);
}
operatorService.shutdown();
}
private boolean nexusEndpointExists(OperatorServiceStubs operatorService, String endPointName) {
ListNexusEndpointsRequest req = ListNexusEndpointsRequest.newBuilder().build();
ListNexusEndpointsResponse response = operatorService.blockingStub().listNexusEndpoints(req);
final boolean[] rv = {false};
response.getEndpointsList().forEach(endpoint -> {
if (endpoint.getSpec().getName().equals(endPointName)) {
rv[0] = true;
}
});
return rv[0];
}