Search in sources :

Example 1 with StartWorkflowExecutionRequest

use of com.uber.cadence.StartWorkflowExecutionRequest in project cadence-client by uber-java.

the class StateMachines method continueAsNewWorkflow.

private static void continueAsNewWorkflow(RequestContext ctx, WorkflowData data, ContinueAsNewWorkflowExecutionDecisionAttributes d, long decisionTaskCompletedEventId) {
    StartWorkflowExecutionRequest sr = ctx.getWorkflowMutableState().getStartRequest();
    WorkflowExecutionContinuedAsNewEventAttributes a = new WorkflowExecutionContinuedAsNewEventAttributes();
    a.setInput(d.getInput());
    if (d.isSetExecutionStartToCloseTimeoutSeconds()) {
        a.setExecutionStartToCloseTimeoutSeconds(d.getExecutionStartToCloseTimeoutSeconds());
    } else {
        a.setExecutionStartToCloseTimeoutSeconds(sr.getExecutionStartToCloseTimeoutSeconds());
    }
    if (d.isSetTaskList()) {
        a.setTaskList(d.getTaskList());
    } else {
        a.setTaskList(sr.getTaskList());
    }
    if (d.isSetWorkflowType()) {
        a.setWorkflowType(d.getWorkflowType());
    } else {
        a.setWorkflowType(sr.getWorkflowType());
    }
    if (d.isSetTaskStartToCloseTimeoutSeconds()) {
        a.setTaskStartToCloseTimeoutSeconds(d.getTaskStartToCloseTimeoutSeconds());
    } else {
        a.setTaskStartToCloseTimeoutSeconds(sr.getTaskStartToCloseTimeoutSeconds());
    }
    a.setDecisionTaskCompletedEventId(decisionTaskCompletedEventId);
    HistoryEvent event = new HistoryEvent().setEventType(EventType.WorkflowExecutionContinuedAsNew).setWorkflowExecutionContinuedAsNewEventAttributes(a);
    ctx.addEvent(event);
}
Also used : StartWorkflowExecutionRequest(com.uber.cadence.StartWorkflowExecutionRequest) WorkflowExecutionContinuedAsNewEventAttributes(com.uber.cadence.WorkflowExecutionContinuedAsNewEventAttributes) HistoryEvent(com.uber.cadence.HistoryEvent)

Example 2 with StartWorkflowExecutionRequest

use of com.uber.cadence.StartWorkflowExecutionRequest in project cadence-client by uber-java.

the class StateMachines method initiateChildWorkflow.

private static void initiateChildWorkflow(RequestContext ctx, ChildWorkflowData data, StartChildWorkflowExecutionDecisionAttributes d, long decisionTaskCompletedEventId) {
    StartChildWorkflowExecutionInitiatedEventAttributes a = new StartChildWorkflowExecutionInitiatedEventAttributes().setControl(d.getControl()).setInput(d.getInput()).setChildPolicy(d.getChildPolicy()).setDecisionTaskCompletedEventId(decisionTaskCompletedEventId).setDomain(d.getDomain() == null ? ctx.getDomain() : d.getDomain()).setExecutionStartToCloseTimeoutSeconds(d.getExecutionStartToCloseTimeoutSeconds()).setTaskStartToCloseTimeoutSeconds(d.getTaskStartToCloseTimeoutSeconds()).setTaskList(d.getTaskList()).setWorkflowId(d.getWorkflowId()).setWorkflowIdReusePolicy(d.getWorkflowIdReusePolicy()).setWorkflowType(d.getWorkflowType());
    HistoryEvent event = new HistoryEvent().setEventType(EventType.StartChildWorkflowExecutionInitiated).setStartChildWorkflowExecutionInitiatedEventAttributes(a);
    long initiatedEventId = ctx.addEvent(event);
    ctx.onCommit((historySize) -> {
        data.initiatedEventId = initiatedEventId;
        data.initiatedEvent = a;
        StartWorkflowExecutionRequest startChild = new StartWorkflowExecutionRequest().setInput(d.getInput()).setDomain(d.getDomain() == null ? ctx.getDomain() : d.getDomain()).setExecutionStartToCloseTimeoutSeconds(d.getExecutionStartToCloseTimeoutSeconds()).setTaskStartToCloseTimeoutSeconds(d.getTaskStartToCloseTimeoutSeconds()).setTaskList(d.getTaskList()).setWorkflowId(d.getWorkflowId()).setWorkflowIdReusePolicy(d.getWorkflowIdReusePolicy()).setWorkflowType(d.getWorkflowType());
        addStartChildTask(ctx, data, initiatedEventId, startChild);
    });
}
Also used : StartChildWorkflowExecutionInitiatedEventAttributes(com.uber.cadence.StartChildWorkflowExecutionInitiatedEventAttributes) HistoryEvent(com.uber.cadence.HistoryEvent) StartWorkflowExecutionRequest(com.uber.cadence.StartWorkflowExecutionRequest)

Example 3 with StartWorkflowExecutionRequest

use of com.uber.cadence.StartWorkflowExecutionRequest in project cadence-client by uber-java.

the class TestWorkflowService method continueAsNew.

/**
 * Creates next run of a workflow execution
 *
 * @return RunId
 */
public String continueAsNew(StartWorkflowExecutionRequest previousRunStartRequest, WorkflowExecutionContinuedAsNewEventAttributes a, String identity, ExecutionId executionId, Optional<TestWorkflowMutableState> parent) throws InternalServiceError, BadRequestError {
    StartWorkflowExecutionRequest startRequest = new StartWorkflowExecutionRequest().setInput(a.getInput()).setWorkflowType(a.getWorkflowType()).setExecutionStartToCloseTimeoutSeconds(a.getExecutionStartToCloseTimeoutSeconds()).setTaskStartToCloseTimeoutSeconds(a.getTaskStartToCloseTimeoutSeconds()).setDomain(executionId.getDomain()).setTaskList(a.getTaskList()).setWorkflowId(executionId.getWorkflowId().getWorkflowId()).setWorkflowIdReusePolicy(previousRunStartRequest.getWorkflowIdReusePolicy()).setIdentity(identity);
    StartWorkflowExecutionResponse response = startWorkflowExecutionNoRunningCheck(startRequest, parent, executionId.getWorkflowId());
    return response.getRunId();
}
Also used : StartWorkflowExecutionResponse(com.uber.cadence.StartWorkflowExecutionResponse) StartWorkflowExecutionRequest(com.uber.cadence.StartWorkflowExecutionRequest)

Example 4 with StartWorkflowExecutionRequest

use of com.uber.cadence.StartWorkflowExecutionRequest in project cadence-client by uber-java.

the class GenericWorkflowClientExternalImpl method startWorkflow.

@Override
public WorkflowExecution startWorkflow(StartWorkflowExecutionParameters startParameters) throws WorkflowExecutionAlreadyStartedError {
    StartWorkflowExecutionRequest request = new StartWorkflowExecutionRequest();
    request.setDomain(domain);
    request.setInput(startParameters.getInput());
    request.setExecutionStartToCloseTimeoutSeconds((int) startParameters.getExecutionStartToCloseTimeoutSeconds());
    request.setTaskStartToCloseTimeoutSeconds((int) startParameters.getTaskStartToCloseTimeoutSeconds());
    request.setWorkflowIdReusePolicy(startParameters.getWorkflowIdReusePolicy());
    String taskList = startParameters.getTaskList();
    if (taskList != null && !taskList.isEmpty()) {
        TaskList tl = new TaskList();
        tl.setName(taskList);
        request.setTaskList(tl);
    }
    String workflowId = startParameters.getWorkflowId();
    if (workflowId == null) {
        workflowId = UUID.randomUUID().toString();
    }
    request.setWorkflowId(workflowId);
    request.setWorkflowType(startParameters.getWorkflowType());
    // if(startParameters.getChildPolicy() != null) {
    // request.setChildPolicy(startParameters.getChildPolicy());
    // }
    StartWorkflowExecutionResponse result;
    try {
        result = service.StartWorkflowExecution(request);
    } catch (WorkflowExecutionAlreadyStartedError e) {
        throw e;
    } catch (TException e) {
        throw CheckedExceptionWrapper.wrap(e);
    }
    WorkflowExecution execution = new WorkflowExecution();
    execution.setRunId(result.getRunId());
    execution.setWorkflowId(request.getWorkflowId());
    return execution;
}
Also used : TException(org.apache.thrift.TException) TaskList(com.uber.cadence.TaskList) StartWorkflowExecutionResponse(com.uber.cadence.StartWorkflowExecutionResponse) WorkflowExecutionAlreadyStartedError(com.uber.cadence.WorkflowExecutionAlreadyStartedError) WorkflowExecution(com.uber.cadence.WorkflowExecution) StartWorkflowExecutionRequest(com.uber.cadence.StartWorkflowExecutionRequest)

Aggregations

StartWorkflowExecutionRequest (com.uber.cadence.StartWorkflowExecutionRequest)4 HistoryEvent (com.uber.cadence.HistoryEvent)2 StartWorkflowExecutionResponse (com.uber.cadence.StartWorkflowExecutionResponse)2 StartChildWorkflowExecutionInitiatedEventAttributes (com.uber.cadence.StartChildWorkflowExecutionInitiatedEventAttributes)1 TaskList (com.uber.cadence.TaskList)1 WorkflowExecution (com.uber.cadence.WorkflowExecution)1 WorkflowExecutionAlreadyStartedError (com.uber.cadence.WorkflowExecutionAlreadyStartedError)1 WorkflowExecutionContinuedAsNewEventAttributes (com.uber.cadence.WorkflowExecutionContinuedAsNewEventAttributes)1 TException (org.apache.thrift.TException)1