Skip to content

Commit

Permalink
- orkes-client: ApiClient will not be deprecated.
Browse files Browse the repository at this point in the history
- orkes-client: Added documentation to OrkesWorkflowClient.
- orkes-client: Removed ApiException (ConductorClientException should be used instead)
  • Loading branch information
jmigueprieto committed Oct 3, 2024
1 parent ba18cb6 commit 3a93794
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 99 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=4.0.0-alpha-SNAPSHOT
version=4.0.0-alpha1-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -61,7 +60,7 @@ public ApiClient(String rootUri) {
super(rootUri);
}

@Deprecated

public Call buildCall(
String path,
String method,
Expand Down Expand Up @@ -91,7 +90,6 @@ private List<Param> toParamList(List<Pair> pairList) {
* @param call An instance of the Call object
* @param callback ApiCallback&lt;T&gt;
*/
@Deprecated
public <T> void executeAsync(Call call, ApiCallback<T> callback) {
executeAsync(call, null, callback);
}
Expand All @@ -105,15 +103,14 @@ public <T> void executeAsync(Call call, ApiCallback<T> callback) {
* @param callback ApiCallback
*/
@SuppressWarnings("unchecked")
@Deprecated
public <T> void executeAsync(Call call, final Type returnType, final ApiCallback<T> 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;
}
Expand All @@ -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 <T> ApiResponse<T> execute(Call call) throws ApiException {
public <T> ApiResponse<T> execute(Call call) throws ConductorClientException {
return execute(call, null);
}

Expand All @@ -141,16 +137,15 @@ public <T> ApiResponse<T> 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 <T> ApiResponse<T> execute(Call call, Type returnType) throws ApiException {
public <T> ApiResponse<T> execute(Call call, Type returnType) {
try {
Response response = call.execute();
T data = handleResponse(response, returnType);
return new ApiResponse<T>(response.code(), response.headers().toMultimap(), data);
} catch (IOException e) {
throw new ApiException(e);
throw new ConductorClientException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -29,7 +30,7 @@ public interface ApiCallback<T> {
* @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<String, List<String>> responseHeaders);
void onFailure(ConductorClientException e, int statusCode, Map<String, List<String>> responseHeaders);

/**
* This is called when the API call succeeded.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*
* @param <T> The type of data that is deserialized from response body
*/
@Deprecated
public class ApiResponse<T> {
private final int statusCode;
private final Map<String, List<String>> headers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,67 +71,50 @@ public OrkesWorkflowClient(ConductorClient client, int executorThreadCount) {
}
}

@Deprecated
public CompletableFuture<WorkflowRun> 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<WorkflowRun> 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<WorkflowRun> executeWorkflow(StartWorkflowRequest request, List<String> 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<WorkflowRun> future = executeWorkflow(request, waitUntilTask);
return future.get(waitTimeout.get(ChronoUnit.MILLIS), TimeUnit.MILLISECONDS);
}

private CompletableFuture<WorkflowRun> executeWorkflowHttp(StartWorkflowRequest startWorkflowRequest, String waitUntilTask) {
CompletableFuture<WorkflowRun> 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<WorkflowRun> executeWorkflowHttp(StartWorkflowRequest startWorkflowRequest, String waitUntilTask, Integer waitForSeconds) {
CompletableFuture<WorkflowRun> 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);
Expand Down Expand Up @@ -234,4 +216,47 @@ public void close() {
executorService.shutdown();
}
}

private CompletableFuture<WorkflowRun> executeWorkflowHttp(StartWorkflowRequest startWorkflowRequest, String waitUntilTask) {
CompletableFuture<WorkflowRun> 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<WorkflowRun> executeWorkflowHttp(StartWorkflowRequest startWorkflowRequest, String waitUntilTask, Integer waitForSeconds) {
CompletableFuture<WorkflowRun> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3a93794

Please sign in to comment.