Skip to content

Commit

Permalink
Merge pull request #115 from orkes-io/update_task_ref_v2
Browse files Browse the repository at this point in the history
Add client SDK support for update task by ref name
  • Loading branch information
v1r3n authored May 27, 2023
2 parents 2a94ed7 + 5e75b17 commit 9449dda
Show file tree
Hide file tree
Showing 30 changed files with 527 additions and 4,577 deletions.
25 changes: 24 additions & 1 deletion src/main/java/io/orkes/conductor/client/TaskClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,28 @@
package io.orkes.conductor.client;


import com.netflix.conductor.common.metadata.tasks.TaskResult;
import com.netflix.conductor.common.run.Workflow;

public class TaskClient extends com.netflix.conductor.client.http.TaskClient {}
public abstract class TaskClient extends com.netflix.conductor.client.http.TaskClient {

/**
* Update the task status and output based given workflow id and task reference name
* @param workflowId Workflow Id
* @param taskReferenceName Reference name of the task to be updated
* @param status Status of the task
* @param output Output for the task
*/
public abstract void updateTask(String workflowId, String taskReferenceName, TaskResult.Status status, Object output);

/**
* Update the task status and output based given workflow id and task reference name and return back the updated workflow status
* @param workflowId Workflow Id
* @param taskReferenceName Reference name of the task to be updated
* @param status Status of the task
* @param output Output for the task
* @return Status of the workflow after updating the task
*/
public abstract Workflow updateTaskSync(String workflowId, String taskReferenceName, TaskResult.Status status, Object output);

}
43 changes: 43 additions & 0 deletions src/main/java/io/orkes/conductor/client/http/OrkesTaskClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,27 @@
*/
package io.orkes.conductor.client.http;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import com.netflix.conductor.common.config.ObjectMapperProvider;
import com.netflix.conductor.common.metadata.tasks.PollData;
import com.netflix.conductor.common.metadata.tasks.Task;
import com.netflix.conductor.common.metadata.tasks.TaskExecLog;
import com.netflix.conductor.common.metadata.tasks.TaskResult;
import com.netflix.conductor.common.run.SearchResult;
import com.netflix.conductor.common.run.TaskSummary;
import com.netflix.conductor.common.run.Workflow;

import io.orkes.conductor.client.ApiClient;
import io.orkes.conductor.client.TaskClient;
import io.orkes.conductor.client.grpc.GrpcTaskClient;
import io.orkes.conductor.client.http.api.TaskResourceApi;

import com.fasterxml.jackson.databind.ObjectMapper;

public class OrkesTaskClient extends TaskClient implements AutoCloseable{

protected ApiClient apiClient;
Expand All @@ -36,6 +41,8 @@ public class OrkesTaskClient extends TaskClient implements AutoCloseable{

private GrpcTaskClient grpcTaskClient;

private ObjectMapper objectMapper = new ObjectMapperProvider().getObjectMapper();

public OrkesTaskClient(ApiClient apiClient) {
this.apiClient = apiClient;
this.taskResourceApi = new TaskResourceApi(apiClient);
Expand Down Expand Up @@ -93,6 +100,42 @@ public void updateTask(TaskResult taskResult) {
}
}


/**
* Update the task status and output based given workflow id and task reference name
* @param workflowId Workflow Id
* @param taskReferenceName Reference name of the task to be updated
* @param status Status of the task
* @param output Output for the task
*/
public void updateTask(String workflowId, String taskReferenceName, TaskResult.Status status, Object output) {
Map<String, Object> outputMap = new HashMap<>();
try {
outputMap = objectMapper.convertValue(output, Map.class);;
} catch (Exception e) {
outputMap.put("result", output);
}
taskResourceApi.updateTaskByRefName(outputMap, workflowId, taskReferenceName, status.toString());
}

/**
* Update the task status and output based given workflow id and task reference name and return back the updated workflow status
* @param workflowId Workflow Id
* @param taskReferenceName Reference name of the task to be updated
* @param status Status of the task
* @param output Output for the task
* @return Status of the workflow after updating the task
*/
public Workflow updateTaskSync(String workflowId, String taskReferenceName, TaskResult.Status status, Object output) {
Map<String, Object> outputMap = new HashMap<>();
try {
outputMap = objectMapper.convertValue(output, Map.class);;
} catch (Exception e) {
outputMap.put("result", output);
}
return taskResourceApi.updateTaskSync(outputMap, workflowId, taskReferenceName, status.toString());
}

@Override
public Optional<String> evaluateAndUploadLargePayload(
Map<String, Object> taskOutputData, String taskType) {
Expand Down
111 changes: 58 additions & 53 deletions src/main/java/io/orkes/conductor/client/http/api/TaskResourceApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.netflix.conductor.common.metadata.tasks.Task;
import com.netflix.conductor.common.metadata.tasks.TaskExecLog;
import com.netflix.conductor.common.metadata.tasks.TaskResult;
import com.netflix.conductor.common.run.Workflow;

import io.orkes.conductor.client.ApiClient;
import io.orkes.conductor.client.http.*;
Expand Down Expand Up @@ -1824,7 +1825,7 @@ private ApiResponse<Map<String, Integer>> sizeWithHttpInfo(List<String> taskType
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
*/
public com.squareup.okhttp.Call updateTaskCall(
private com.squareup.okhttp.Call updateTaskCall(
TaskResult taskResult,
final ProgressResponseBody.ProgressListener progressListener,
final ProgressRequestBody.ProgressRequestListener progressRequestListener)
Expand Down Expand Up @@ -1928,33 +1929,22 @@ private ApiResponse<String> updateTaskWithHttpInfo(TaskResult taskResult) throws
return apiClient.execute(call, localVarReturnType);
}

/**
* Build call for updateTask1
*
* @param body (required)
* @param workflowId (required)
* @param taskRefName (required)
* @param status (required)
* @param workerId (optional)
* @param progressListener Progress listener
* @param progressRequestListener Progress request listener
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
*/
public com.squareup.okhttp.Call updateTask1Call(
private com.squareup.okhttp.Call updateTaskByRefNameCall(
Map<String, Object> body,
String workflowId,
String taskRefName,
String status,
String workerId,
final ProgressResponseBody.ProgressListener progressListener,
final ProgressRequestBody.ProgressRequestListener progressRequestListener)
boolean sync)
throws ApiException {
Object localVarPostBody = body;

String path = "/tasks/{workflowId}/{taskRefName}/{status}";
if(sync) {
path += "/sync";
}
// create path and map variables
String localVarPath =
"/tasks/{workflowId}/{taskRefName}/{status}"
path
.replaceAll(
"\\{" + "workflowId" + "\\}",
apiClient.escapeString(workflowId.toString()))
Expand Down Expand Up @@ -1985,28 +1975,7 @@ public com.squareup.okhttp.Call updateTask1Call(
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
localVarHeaderParams.put("Content-Type", localVarContentType);

if (progressListener != null) {
apiClient
.getHttpClient()
.networkInterceptors()
.add(
new com.squareup.okhttp.Interceptor() {
@Override
public com.squareup.okhttp.Response intercept(
com.squareup.okhttp.Interceptor.Chain chain)
throws IOException {
com.squareup.okhttp.Response originalResponse =
chain.proceed(chain.request());
return originalResponse
.newBuilder()
.body(
new ProgressResponseBody(
originalResponse.body(),
progressListener))
.build();
}
});
}


String[] localVarAuthNames = new String[] {"api_key"};
return apiClient.buildCall(
Expand All @@ -2018,16 +1987,15 @@ public com.squareup.okhttp.Response intercept(
localVarHeaderParams,
localVarFormParams,
localVarAuthNames,
progressRequestListener);
null);
}

private com.squareup.okhttp.Call updateTask1ValidateBeforeCall(
Map<String, Object> body,
String workflowId,
String taskRefName,
String status,
final ProgressResponseBody.ProgressListener progressListener,
final ProgressRequestBody.ProgressRequestListener progressRequestListener)
boolean sync)
throws ApiException {
// verify the required parameter 'body' is set
if (body == null) {
Expand All @@ -2051,14 +2019,13 @@ private com.squareup.okhttp.Call updateTask1ValidateBeforeCall(
}

com.squareup.okhttp.Call call =
updateTask1Call(
updateTaskByRefNameCall(
body,
workflowId,
taskRefName,
status,
null,
progressListener,
progressRequestListener);
getIdentity(),
sync);
return call;
}

Expand All @@ -2073,10 +2040,42 @@ private com.squareup.okhttp.Call updateTask1ValidateBeforeCall(
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the
* response body
*/
@Deprecated
public String updateTask1(
Map<String, Object> body, String workflowId, String taskRefName, String status)
throws ApiException {
ApiResponse<String> resp = updateTask1WithHttpInfo(body, workflowId, taskRefName, status);
Type localVarReturnType = new TypeToken<String>() {}.getType();
ApiResponse<String> resp = updateTask1WithHttpInfo(body, workflowId, taskRefName, status, false, localVarReturnType);
return resp.getData();
}

/**
*
* @param output Task Output
* @param workflowId Workflow Id
* @param taskRefName Reference name of the task to be updated
* @param status Status
* @return Task Id
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response
*/
public String updateTaskByRefName(Map<String, Object> output, String workflowId, String taskRefName, String status) throws ApiException {
Type localVarReturnType = new TypeToken<String>() {}.getType();
ApiResponse<String> resp = updateTask1WithHttpInfo(output, workflowId, taskRefName, status, false, localVarReturnType);
return resp.getData();
}

/**
*
* @param output Task Output
* @param workflowId Workflow Id
* @param taskRefName Reference name of the task to be updated
* @param status Status
* @return Status of the workflow after updating the task
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response
*/
public Workflow updateTaskSync(Map<String, Object> output, String workflowId, String taskRefName, String status) throws ApiException {
Type localVarReturnType = new TypeToken<Workflow>() {}.getType();
ApiResponse<Workflow> resp = updateTask1WithHttpInfo(output, workflowId, taskRefName, status, true, localVarReturnType);
return resp.getData();
}

Expand All @@ -2091,12 +2090,18 @@ public String updateTask1(
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the
* response body
*/
private ApiResponse<String> updateTask1WithHttpInfo(
Map<String, Object> body, String workflowId, String taskRefName, String status)
private <T>ApiResponse<T> updateTask1WithHttpInfo(Map<String, Object> body, String workflowId, String taskRefName, String status, boolean sync, Type returnType)
throws ApiException {
com.squareup.okhttp.Call call =
updateTask1ValidateBeforeCall(body, workflowId, taskRefName, status, null, null);
Type localVarReturnType = new TypeToken<String>() {}.getType();
updateTask1ValidateBeforeCall(body, workflowId, taskRefName, status, sync);
return apiClient.execute(call, returnType);
}

private ApiResponse<Workflow> updateTaskSyncWithHttpInfo(Map<String, Object> body, String workflowId, String taskRefName, String status, boolean sync)
throws ApiException {
com.squareup.okhttp.Call call =
updateTask1ValidateBeforeCall(body, workflowId, taskRefName, status, sync);
Type localVarReturnType = new TypeToken<Workflow>() {}.getType();
return apiClient.execute(call, localVarReturnType);
}

Expand Down
Loading

0 comments on commit 9449dda

Please sign in to comment.