Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflow state update api #154

Merged
merged 5 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/main/java/io/orkes/conductor/client/WorkflowClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import io.orkes.conductor.client.http.ApiException;
import io.orkes.conductor.client.model.JumpWorkflowExecutionRequest;
import io.orkes.conductor.client.model.WorkflowStateUpdate;
import io.orkes.conductor.client.model.WorkflowStatus;
import io.orkes.conductor.common.model.WorkflowRun;

Expand Down Expand Up @@ -96,4 +97,19 @@ public abstract Map<String, List<Workflow>> getWorkflowsByNamesAndCorrelationIds
public abstract void jumpToTask(String workflowId, JumpWorkflowExecutionRequest jumpWorkflowExecutionRequest);

public abstract void upgradeRunningWorkflow(String workflowId, UpgradeWorkflowRequest body);

/**
*
* Update a runningw workflow by updating its variables or one of the scheduled task identified by task reference name
* @param workflowId Id of the workflow to be updated
* @param waitUntilTaskRefNames List of task reference names to wait for. The api call will wait for ANY of these tasks to be availble in workflow.
* @param waitForSeconds Maximum time to wait for. If the workflow does not complete or reach one of the tasks listed in waitUntilTaskRefNames by this time,
* the call will return with the current status of the workflow
* @param updateRequest Payload for updating state of workflow.
*
* @return
*/
public abstract WorkflowRun updateWorkflow(String workflowId, List<String> waitUntilTaskRefNames, Integer waitForSeconds,
WorkflowStateUpdate updateRequest);
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.*;

import org.apache.commons.lang.StringUtils;
import org.checkerframework.checker.units.qual.A;

import com.netflix.conductor.common.metadata.workflow.*;
import com.netflix.conductor.common.model.BulkResponse;
Expand All @@ -35,6 +37,7 @@
import io.orkes.conductor.client.http.api.WorkflowResourceApi;
import io.orkes.conductor.client.model.CorrelationIdsSearchRequest;
import io.orkes.conductor.client.model.JumpWorkflowExecutionRequest;
import io.orkes.conductor.client.model.WorkflowStateUpdate;
import io.orkes.conductor.client.model.WorkflowStatus;
import io.orkes.conductor.common.model.WorkflowRun;

Expand Down Expand Up @@ -352,6 +355,15 @@ public void upgradeRunningWorkflow(String workflowId, UpgradeWorkflowRequest upg
httpClient.upgradeRunningWorkflow(upgradeWorkflowRequest, workflowId);
}

@Override
public WorkflowRun updateWorkflow(String workflowId, List<String> waitUntilTaskRefNames, Integer waitForSeconds, WorkflowStateUpdate updateRequest) {
String joinedReferenceNames = "";
if (waitUntilTaskRefNames != null) {
joinedReferenceNames = String.join(",", waitUntilTaskRefNames);
}
return httpClient.updateWorkflowState(updateRequest, UUID.randomUUID().toString(), workflowId, joinedReferenceNames, waitForSeconds);
}

@Override
public void close() {
shutdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;
import java.util.Map;

import com.google.common.reflect.TypeToken;
import com.netflix.conductor.common.metadata.workflow.*;
import com.netflix.conductor.common.run.Workflow;
import com.netflix.conductor.common.run.WorkflowTestRequest;
Expand Down Expand Up @@ -4012,4 +4013,106 @@ public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Ch
return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
}



/**
* Update workflow and task status
* Updates the workflow variables, tasks and triggers evaluation.
* @param body (required)
* @param requestId (required)
* @param workflowId (required)
* @param waitUntilTaskRef (optional)
* @param waitForSeconds (optional, default to 10)
* @return WorkflowRun
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public WorkflowRun updateWorkflowState(WorkflowStateUpdate updateRequest, String requestId, String workflowId, String waitUntilTaskRef, Integer waitForSeconds) throws ApiException {
ApiResponse<WorkflowRun> resp = updateWorkflowAndTaskStateWithHttpInfo(updateRequest, requestId, workflowId, waitUntilTaskRef, waitForSeconds);
return resp.getData();
}

/**
* Update workflow and task status
* Updates the workflow variables, tasks and triggers evaluation.
* @param body (required)
* @param requestId (required)
* @param workflowId (required)
* @param waitUntilTaskRef (optional)
* @param waitForSeconds (optional, default to 10)
* @return ApiResponse&lt;WorkflowRun&gt;
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public ApiResponse<WorkflowRun> updateWorkflowAndTaskStateWithHttpInfo(WorkflowStateUpdate body, String requestId, String workflowId, String waitUntilTaskRef, Integer waitForSeconds) throws ApiException {
com.squareup.okhttp.Call call = updateWorkflowAndTaskStateValidateBeforeCall(body, requestId, workflowId, waitUntilTaskRef, waitForSeconds, null, null);
Type localVarReturnType = new TypeToken<WorkflowRun>(){}.getType();
return apiClient.execute(call, localVarReturnType);
}


public com.squareup.okhttp.Call updateWorkflowAndTaskStateCall(WorkflowStateUpdate body, String requestId, String workflowId, String waitUntilTaskRef, Integer waitForSeconds, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
Object localVarPostBody = body;

// create path and map variables
String localVarPath = "/workflow/{workflowId}/state"
.replaceAll("\\{" + "workflowId" + "\\}", apiClient.escapeString(workflowId.toString()));

List<Pair> localVarQueryParams = new ArrayList<Pair>();
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
if (requestId != null)
localVarQueryParams.addAll(apiClient.parameterToPair("requestId", requestId));
if (waitUntilTaskRef != null)
localVarQueryParams.addAll(apiClient.parameterToPair("waitUntilTaskRef", waitUntilTaskRef));
if (waitForSeconds != null)
localVarQueryParams.addAll(apiClient.parameterToPair("waitForSeconds", waitForSeconds));

Map<String, String> localVarHeaderParams = new HashMap<String, String>();

Map<String, Object> localVarFormParams = new HashMap<String, Object>();

final String[] localVarAccepts = {
"*/*"
};
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);

final String[] localVarContentTypes = {
"application/json"
};
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(localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
}

@SuppressWarnings("rawtypes")
private com.squareup.okhttp.Call updateWorkflowAndTaskStateValidateBeforeCall(WorkflowStateUpdate body, String requestId, String workflowId, String waitUntilTaskRef, Integer waitForSeconds, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
// verify the required parameter 'body' is set
if (body == null) {
throw new ApiException("Missing the required parameter 'body' when calling updateWorkflowAndTaskState(Async)");
}
// verify the required parameter 'requestId' is set
if (requestId == null) {
throw new ApiException("Missing the required parameter 'requestId' when calling updateWorkflowAndTaskState(Async)");
}
// verify the required parameter 'workflowId' is set
if (workflowId == null) {
throw new ApiException("Missing the required parameter 'workflowId' when calling updateWorkflowAndTaskState(Async)");
}

com.squareup.okhttp.Call call = updateWorkflowAndTaskStateCall(body, requestId, workflowId, waitUntilTaskRef, waitForSeconds, progressListener, progressRequestListener);
return call;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.orkes.conductor.client.model;

import java.util.Map;

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

import lombok.Data;

@Data
public class WorkflowStateUpdate {
private String taskReferenceName;
private Map<String, Object> variables;
private TaskResult taskResult;
}
Loading