From 3a937941a6b4edbdf92cee57dc893a201234d125 Mon Sep 17 00:00:00 2001 From: Miguel Prieto Date: Thu, 3 Oct 2024 15:14:58 -0400 Subject: [PATCH 1/2] - orkes-client: ApiClient will not be deprecated. - orkes-client: Added documentation to OrkesWorkflowClient. - orkes-client: Removed ApiException (ConductorClientException should be used instead) --- .../java/conductor-java-sdk/gradle.properties | 2 +- .../io/orkes/conductor/client/ApiClient.java | 23 ++-- .../conductor/client/http/ApiCallback.java | 5 +- .../conductor/client/http/ApiException.java | 35 ------ .../conductor/client/http/ApiResponse.java | 1 - .../client/http/OrkesWorkflowClient.java | 113 +++++++++++------- .../io/orkes/conductor/client/http/Pair.java | 1 - .../model/event/QueueConfiguration.java | 1 - 8 files changed, 82 insertions(+), 99 deletions(-) delete mode 100644 conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/ApiException.java diff --git a/conductor-clients/java/conductor-java-sdk/gradle.properties b/conductor-clients/java/conductor-java-sdk/gradle.properties index 2cf0dd1ea..a1b6e67b4 100644 --- a/conductor-clients/java/conductor-java-sdk/gradle.properties +++ b/conductor-clients/java/conductor-java-sdk/gradle.properties @@ -1 +1 @@ -version=4.0.0-alpha-SNAPSHOT +version=4.0.0-alpha1-SNAPSHOT diff --git a/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/ApiClient.java b/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/ApiClient.java index c41edf348..015db0254 100644 --- a/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/ApiClient.java +++ b/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/ApiClient.java @@ -22,11 +22,11 @@ import org.jetbrains.annotations.NotNull; +import com.netflix.conductor.client.exception.ConductorClientException; import com.netflix.conductor.client.http.ConductorClient; import com.netflix.conductor.client.http.Param; import io.orkes.conductor.client.http.ApiCallback; -import io.orkes.conductor.client.http.ApiException; import io.orkes.conductor.client.http.ApiResponse; import io.orkes.conductor.client.http.OrkesAuthentication; import io.orkes.conductor.client.http.Pair; @@ -41,7 +41,6 @@ * This class exists to maintain backward compatibility and facilitate the migration for * users of orkes-conductor-client v2. */ -@Deprecated public final class ApiClient extends ConductorClient { public ApiClient(String rootUri, String keyId, String secret) { @@ -61,7 +60,7 @@ public ApiClient(String rootUri) { super(rootUri); } - @Deprecated + public Call buildCall( String path, String method, @@ -91,7 +90,6 @@ private List toParamList(List pairList) { * @param call An instance of the Call object * @param callback ApiCallback<T> */ - @Deprecated public void executeAsync(Call call, ApiCallback callback) { executeAsync(call, null, callback); } @@ -105,15 +103,14 @@ public void executeAsync(Call call, ApiCallback callback) { * @param callback ApiCallback */ @SuppressWarnings("unchecked") - @Deprecated public void executeAsync(Call call, final Type returnType, final ApiCallback callback) { call.enqueue(new Callback() { @Override - public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { + public void onResponse(@NotNull Call call, @NotNull Response response) { T result; try { result = (T) handleResponse(response, returnType); - } catch (ApiException e) { + } catch (ConductorClientException e) { callback.onFailure(e, response.code(), response.headers().toMultimap()); return; } @@ -123,13 +120,12 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - callback.onFailure(new ApiException(e), 0, null); + callback.onFailure(new ConductorClientException(e), 0, null); } }); } - @Deprecated - public ApiResponse execute(Call call) throws ApiException { + public ApiResponse execute(Call call) throws ConductorClientException { return execute(call, null); } @@ -141,16 +137,15 @@ public ApiResponse execute(Call call) throws ApiException { * @param call Call * @return ApiResponse object containing response status, headers and data, which is a Java * object deserialized from response body and would be null when returnType is null. - * @throws ApiException If fail to execute the call + * @throws ConductorClientException If fail to execute the call */ - @Deprecated - public ApiResponse execute(Call call, Type returnType) throws ApiException { + public ApiResponse execute(Call call, Type returnType) { try { Response response = call.execute(); T data = handleResponse(response, returnType); return new ApiResponse(response.code(), response.headers().toMultimap(), data); } catch (IOException e) { - throw new ApiException(e); + throw new ConductorClientException(e); } } diff --git a/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/ApiCallback.java b/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/ApiCallback.java index 1c02618e9..2cbd474c0 100644 --- a/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/ApiCallback.java +++ b/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/ApiCallback.java @@ -15,7 +15,8 @@ import java.util.List; import java.util.Map; -@Deprecated +import com.netflix.conductor.client.exception.ConductorClientException; + /** * Callback for asynchronous API call. * @@ -29,7 +30,7 @@ public interface ApiCallback { * @param statusCode Status code of the response if available, otherwise it would be 0 * @param responseHeaders Headers of the response if available, otherwise it would be null */ - void onFailure(ApiException e, int statusCode, Map> responseHeaders); + void onFailure(ConductorClientException e, int statusCode, Map> responseHeaders); /** * This is called when the API call succeeded. diff --git a/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/ApiException.java b/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/ApiException.java deleted file mode 100644 index 951ebf5ff..000000000 --- a/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/ApiException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2024 Conductor Authors. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 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.orkes.conductor.client.http; - -import com.netflix.conductor.client.exception.ConductorClientException; - - -/** - * This class exists to maintain backward compatibility and facilitate the migration - * for users of orkes-conductor-client v2. - */ -@Deprecated -public class ApiException extends ConductorClientException { - - public ApiException() { - } - - public ApiException(Throwable throwable) { - super(throwable); - } - - public ApiException(String message) { - super(message); - } -} diff --git a/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/ApiResponse.java b/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/ApiResponse.java index 18c194e69..7473e3a10 100644 --- a/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/ApiResponse.java +++ b/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/ApiResponse.java @@ -23,7 +23,6 @@ * * @param The type of data that is deserialized from response body */ -@Deprecated public class ApiResponse { private final int statusCode; private final Map> headers; diff --git a/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/OrkesWorkflowClient.java b/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/OrkesWorkflowClient.java index c12498dca..1c12ebc95 100644 --- a/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/OrkesWorkflowClient.java +++ b/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/OrkesWorkflowClient.java @@ -42,7 +42,6 @@ import io.orkes.conductor.client.model.WorkflowStateUpdate; import io.orkes.conductor.client.model.WorkflowStatus; -//TODO should this extend or not WorkflowClient? public class OrkesWorkflowClient implements AutoCloseable { private final WorkflowResource workflowResource; @@ -72,67 +71,50 @@ public OrkesWorkflowClient(ConductorClient client, int executorThreadCount) { } } + @Deprecated public CompletableFuture executeWorkflow(StartWorkflowRequest request, String waitUntilTask) { return executeWorkflowHttp(request, waitUntilTask); } + /** + * Synchronously executes a workflow + * @param request workflow execution request + * @param waitUntilTask waits until workflow has reached this task. + * Useful for executing it synchronously until this task and then continuing asynchronous execution + * @param waitForSeconds maximum amount of time to wait before returning + * @return WorkflowRun + */ public CompletableFuture executeWorkflow(StartWorkflowRequest request, String waitUntilTask, Integer waitForSeconds) { return executeWorkflowHttp(request, waitUntilTask, waitForSeconds); } + /** + * Synchronously executes a workflow + * @param request workflow execution request + * @param waitUntilTasks waits until workflow has reached one of these tasks. + * Useful for executing it synchronously until this task and then continuing asynchronous execution + * Useful when workflow has multiple branches to wait for any of the branches to reach the task + * @param waitForSeconds maximum amount of time to wait before returning + * @return WorkflowRun + */ public CompletableFuture executeWorkflow(StartWorkflowRequest request, List waitUntilTasks, Integer waitForSeconds) { String waitUntilTask = String.join(",", waitUntilTasks); return executeWorkflowHttp(request, waitUntilTask, waitForSeconds); } + /** + * Synchronously executes a workflow + * @param request workflow execution request + * @param waitUntilTask waits until workflow has reached one of these tasks. + * Useful for executing it synchronously until this task and then continuing asynchronous execution + * @param waitTimeout maximum amount of time to wait before returning + * @return WorkflowRun + */ public WorkflowRun executeWorkflow(StartWorkflowRequest request, String waitUntilTask, Duration waitTimeout) throws ExecutionException, InterruptedException, TimeoutException { CompletableFuture future = executeWorkflow(request, waitUntilTask); return future.get(waitTimeout.get(ChronoUnit.MILLIS), TimeUnit.MILLISECONDS); } - private CompletableFuture executeWorkflowHttp(StartWorkflowRequest startWorkflowRequest, String waitUntilTask) { - CompletableFuture future = new CompletableFuture<>(); - String requestId = UUID.randomUUID().toString(); - executorService.submit( - () -> { - try { - WorkflowRun response = workflowResource.executeWorkflow( - startWorkflowRequest, - startWorkflowRequest.getName(), - startWorkflowRequest.getVersion(), - waitUntilTask, - requestId); - future.complete(response); - } catch (Throwable t) { - future.completeExceptionally(t); - } - }); - - return future; - } - - private CompletableFuture executeWorkflowHttp(StartWorkflowRequest startWorkflowRequest, String waitUntilTask, Integer waitForSeconds) { - CompletableFuture future = new CompletableFuture<>(); - String requestId = UUID.randomUUID().toString(); - executorService.submit( - () -> { - try { - WorkflowRun response = workflowResource.executeWorkflow( - startWorkflowRequest, - startWorkflowRequest.getName(), - startWorkflowRequest.getVersion(), - waitUntilTask, - requestId, - waitForSeconds); - future.complete(response); - } catch (Throwable t) { - future.completeExceptionally(t); - } - }); - - return future; - } - public void terminateWorkflowWithFailure(String workflowId, String reason, boolean triggerFailureWorkflow) { Validate.notBlank(workflowId, "workflow id cannot be blank"); workflowResource.terminateWithAReason(workflowId, reason, triggerFailureWorkflow); @@ -234,4 +216,47 @@ public void close() { executorService.shutdown(); } } + + private CompletableFuture executeWorkflowHttp(StartWorkflowRequest startWorkflowRequest, String waitUntilTask) { + CompletableFuture future = new CompletableFuture<>(); + String requestId = UUID.randomUUID().toString(); + executorService.submit( + () -> { + try { + WorkflowRun response = workflowResource.executeWorkflow( + startWorkflowRequest, + startWorkflowRequest.getName(), + startWorkflowRequest.getVersion(), + waitUntilTask, + requestId); + future.complete(response); + } catch (Throwable t) { + future.completeExceptionally(t); + } + }); + + return future; + } + + private CompletableFuture executeWorkflowHttp(StartWorkflowRequest startWorkflowRequest, String waitUntilTask, Integer waitForSeconds) { + CompletableFuture future = new CompletableFuture<>(); + String requestId = UUID.randomUUID().toString(); + executorService.submit( + () -> { + try { + WorkflowRun response = workflowResource.executeWorkflow( + startWorkflowRequest, + startWorkflowRequest.getName(), + startWorkflowRequest.getVersion(), + waitUntilTask, + requestId, + waitForSeconds); + future.complete(response); + } catch (Throwable t) { + future.completeExceptionally(t); + } + }); + + return future; + } } diff --git a/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/Pair.java b/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/Pair.java index d5074585a..429e72cdd 100644 --- a/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/Pair.java +++ b/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/Pair.java @@ -16,7 +16,6 @@ * This class exists to maintain backward compatibility and facilitate the migration for * users of orkes-conductor-client v2. */ -@Deprecated public class Pair { private String name = ""; private String value = ""; diff --git a/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/model/event/QueueConfiguration.java b/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/model/event/QueueConfiguration.java index 4200fbd82..b74062c79 100644 --- a/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/model/event/QueueConfiguration.java +++ b/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/model/event/QueueConfiguration.java @@ -51,7 +51,6 @@ public String getQueueName() { return this.queueName; } - //FIXME why? explain me why? @Deprecated public String getConfiguration() throws Exception { if (this.consumer == null) { From b7c95c461e414426c405bf64125048f861b0f11b Mon Sep 17 00:00:00 2001 From: Miguel Prieto Date: Fri, 4 Oct 2024 10:25:23 -0400 Subject: [PATCH 2/2] - Cleanup + refactoring: allow ConductorClient builder extension - Changes in orkes client module --- .../client/http/ConductorClient.java | 128 +++++++----------- .../io/orkes/conductor/client/ApiClient.java | 33 +++-- .../conductor/client/util/ClientTestUtil.java | 6 +- 3 files changed, 73 insertions(+), 94 deletions(-) diff --git a/conductor-clients/java/conductor-java-sdk/conductor-client/src/main/java/com/netflix/conductor/client/http/ConductorClient.java b/conductor-clients/java/conductor-java-sdk/conductor-client/src/main/java/com/netflix/conductor/client/http/ConductorClient.java index 6a0af40f2..9cf7a7d21 100644 --- a/conductor-clients/java/conductor-java-sdk/conductor-client/src/main/java/com/netflix/conductor/client/http/ConductorClient.java +++ b/conductor-clients/java/conductor-java-sdk/conductor-client/src/main/java/com/netflix/conductor/client/http/ConductorClient.java @@ -74,38 +74,38 @@ public class ConductorClient { private final KeyManager[] keyManagers; private final List headerSuppliers; - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new Builder<>(); } @SneakyThrows - protected ConductorClient(Builder builder) { + protected ConductorClient(Builder builder) { builder.validateAndAssignDefaults(); final OkHttpClient.Builder okHttpBuilder = builder.okHttpClientBuilder; this.objectMapper = builder.objectMapperSupplier.get(); - this.basePath = builder.basePath(); - this.verifyingSsl = builder.verifyingSsl(); - this.sslCaCert = builder.sslCaCert(); - this.keyManagers = builder.keyManagers(); + this.basePath = builder.basePath; + this.verifyingSsl = builder.verifyingSsl; + this.sslCaCert = builder.sslCaCert; + this.keyManagers = builder.keyManagers; this.headerSuppliers = builder.headerSupplier(); - if (builder.connectTimeout() > -1) { - okHttpBuilder.connectTimeout(builder.connectTimeout(), TimeUnit.MILLISECONDS); + if (builder.connectTimeout > -1) { + okHttpBuilder.connectTimeout(builder.connectTimeout, TimeUnit.MILLISECONDS); } - if (builder.readTimeout() > -1) { - okHttpBuilder.readTimeout(builder.readTimeout(), TimeUnit.MILLISECONDS); + if (builder.readTimeout > -1) { + okHttpBuilder.readTimeout(builder.readTimeout, TimeUnit.MILLISECONDS); } - if (builder.writeTimeout() > -1) { - okHttpBuilder.writeTimeout(builder.writeTimeout(), TimeUnit.MILLISECONDS); + if (builder.writeTimeout > -1) { + okHttpBuilder.writeTimeout(builder.writeTimeout, TimeUnit.MILLISECONDS); } - if (builder.getProxy() != null) { - okHttpBuilder.proxy(builder.getProxy()); + if (builder.proxy != null) { + okHttpBuilder.proxy(builder.proxy); } - ConnectionPoolConfig connectionPoolConfig = builder.getConnectionPoolConfig(); + ConnectionPoolConfig connectionPoolConfig = builder.connectionPoolConfig; if (connectionPoolConfig != null) { okHttpBuilder.connectionPool(new ConnectionPool( connectionPoolConfig.getMaxIdleConnections(), @@ -125,11 +125,11 @@ protected ConductorClient(Builder builder) { } public ConductorClient() { - this(new Builder()); + this(new Builder<>()); } public ConductorClient(String basePath) { - this(new Builder().basePath(basePath)); + this(new Builder<>().basePath(basePath)); } public String getBasePath() { @@ -433,7 +433,7 @@ private ConductorClientResponse execute(Call call, Type returnType) { } } - public static class Builder { + public static class Builder> { private final OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder(); private String basePath = "http://localhost:8080/api"; private boolean verifyingSsl = true; @@ -447,85 +447,54 @@ public static class Builder { private Supplier objectMapperSupplier = () -> new ObjectMapperProvider().getObjectMapper(); private final List headerSuppliers = new ArrayList<>(); - public String basePath() { - return basePath; + protected T self() { + //noinspection unchecked + return (T) this; } - public Builder basePath(String basePath) { + public T basePath(String basePath) { this.basePath = basePath; - return this; - } - - public boolean verifyingSsl() { - return verifyingSsl; + return self(); } - public Builder verifyingSsl(boolean verifyingSsl) { + public T verifyingSsl(boolean verifyingSsl) { this.verifyingSsl = verifyingSsl; - return this; - } - - public InputStream sslCaCert() { - return sslCaCert; + return self(); } - public Builder sslCaCert(InputStream sslCaCert) { + public T sslCaCert(InputStream sslCaCert) { this.sslCaCert = sslCaCert; - return this; + return self(); } - public KeyManager[] keyManagers() { - return keyManagers; - } - - public Builder keyManagers(KeyManager[] keyManagers) { + public T keyManagers(KeyManager[] keyManagers) { this.keyManagers = keyManagers; - return this; - } - - public long connectTimeout() { - return connectTimeout; + return self(); } - public Builder connectTimeout(long connectTimeout) { + public T connectTimeout(long connectTimeout) { this.connectTimeout = connectTimeout; - return this; + return self(); } - public long readTimeout() { - return readTimeout; - } - - public Builder readTimeout(long readTimeout) { + public T readTimeout(long readTimeout) { this.readTimeout = readTimeout; - return this; + return self(); } - public long writeTimeout() { - return writeTimeout; - } - - public Builder writeTimeout(long writeTimeout) { + public T writeTimeout(long writeTimeout) { this.writeTimeout = writeTimeout; - return this; + return self(); } - public Builder proxy(Proxy proxy) { + public T proxy(Proxy proxy) { this.proxy = proxy; - return this; + return self(); } - public ConnectionPoolConfig getConnectionPoolConfig() { - return this.connectionPoolConfig; - } - - public Builder connectionPoolConfig(ConnectionPoolConfig config) { + public T connectionPoolConfig(ConnectionPoolConfig config) { this.connectionPoolConfig = config; - return this; - } - - Proxy getProxy() { - return proxy; + return self(); } /** @@ -534,9 +503,9 @@ Proxy getProxy() { * @param configurer * @return */ - public Builder configureOkHttp(Consumer configurer) { + public T configureOkHttp(Consumer configurer) { configurer.accept(this.okHttpClientBuilder); - return this; + return self(); } /** @@ -545,17 +514,17 @@ public Builder configureOkHttp(Consumer configurer) { * @param objectMapperSupplier * @return */ - public Builder objectMapperSupplier(Supplier objectMapperSupplier) { + public T objectMapperSupplier(Supplier objectMapperSupplier) { this.objectMapperSupplier = objectMapperSupplier; - return this; + return self(); } - public Builder addHeaderSupplier(HeaderSupplier headerSupplier) { + public T addHeaderSupplier(HeaderSupplier headerSupplier) { this.headerSuppliers.add(headerSupplier); - return this; + return self(); } - public List headerSupplier() { + protected List headerSupplier() { return headerSuppliers; } @@ -563,7 +532,7 @@ public ConductorClient build() { return new ConductorClient(this); } - void validateAndAssignDefaults() { + protected void validateAndAssignDefaults() { if (StringUtils.isBlank(basePath)) { throw new IllegalArgumentException("basePath cannot be blank"); } @@ -571,7 +540,6 @@ void validateAndAssignDefaults() { if (basePath.endsWith("/")) { basePath = basePath.substring(0, basePath.length() - 1); } - } } } diff --git a/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/ApiClient.java b/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/ApiClient.java index 015db0254..c7b8d449d 100644 --- a/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/ApiClient.java +++ b/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/ApiClient.java @@ -17,7 +17,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.function.Consumer; import java.util.stream.Collectors; import org.jetbrains.annotations.NotNull; @@ -33,7 +32,6 @@ import okhttp3.Call; import okhttp3.Callback; -import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -44,22 +42,18 @@ public final class ApiClient extends ConductorClient { public ApiClient(String rootUri, String keyId, String secret) { - super(ConductorClient.builder() + this(ApiClient.builder() .basePath(rootUri) - .addHeaderSupplier(new OrkesAuthentication(keyId, secret))); - } - - public ApiClient(String rootUri, String keyId, String secret, Consumer configurer) { - super(ConductorClient.builder() - .basePath(rootUri) - .configureOkHttp(configurer) - .addHeaderSupplier(new OrkesAuthentication(keyId, secret))); + .credentials(keyId, secret)); } public ApiClient(String rootUri) { super(rootUri); } + private ApiClient(ApiClientBuilder builder) { + super(builder); + } public Call buildCall( String path, @@ -149,4 +143,21 @@ public ApiResponse execute(Call call, Type returnType) { } } + public static ApiClientBuilder builder() { + return new ApiClientBuilder(); + } + + public static class ApiClientBuilder extends Builder { + + public ApiClientBuilder credentials(String key, String secret) { + this.addHeaderSupplier(new OrkesAuthentication(key, secret)); + return this; + } + + @Override + public ApiClient build() { + return new ApiClient(this); + } + } + } diff --git a/conductor-clients/java/conductor-java-sdk/tests/src/test/java/io/orkes/conductor/client/util/ClientTestUtil.java b/conductor-clients/java/conductor-java-sdk/tests/src/test/java/io/orkes/conductor/client/util/ClientTestUtil.java index bcd735932..3eed57749 100644 --- a/conductor-clients/java/conductor-java-sdk/tests/src/test/java/io/orkes/conductor/client/util/ClientTestUtil.java +++ b/conductor-clients/java/conductor-java-sdk/tests/src/test/java/io/orkes/conductor/client/util/ClientTestUtil.java @@ -16,8 +16,8 @@ import com.netflix.conductor.client.http.ConductorClient; +import io.orkes.conductor.client.ApiClient; import io.orkes.conductor.client.OrkesClients; -import io.orkes.conductor.client.http.OrkesAuthentication; public class ClientTestUtil { private static final String ENV_ROOT_URI = "CONDUCTOR_SERVER_URL"; @@ -41,9 +41,9 @@ public static ConductorClient getClient() { String keySecret = getEnv(ENV_SECRET); Assertions.assertNotNull(keySecret, ENV_SECRET + " env not set"); - return ConductorClient.builder() + return ApiClient.builder() .basePath(basePath) - .addHeaderSupplier(new OrkesAuthentication(keyId, keySecret)) + .credentials(keyId, keySecret) .readTimeout(30_000) .connectTimeout(30_000) .writeTimeout(30_000)