Search in sources :

Example 1 with WorkflowType

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

the class ReplayDecisionTaskHandler method createDecider.

private ReplayDecider createDecider(HistoryHelper historyHelper) throws Exception {
    PollForDecisionTaskResponse decisionTask = historyHelper.getDecisionTask();
    WorkflowType workflowType = decisionTask.getWorkflowType();
    DecisionsHelper decisionsHelper = new DecisionsHelper(decisionTask);
    ReplayWorkflow workflow = workflowFactory.getWorkflow(workflowType);
    return new ReplayDecider(domain, workflow, historyHelper, decisionsHelper);
}
Also used : WorkflowType(com.uber.cadence.WorkflowType) PollForDecisionTaskResponse(com.uber.cadence.PollForDecisionTaskResponse)

Example 2 with WorkflowType

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

the class SyncWorkflow method start.

@Override
public void start(HistoryEvent event, DecisionContext context) {
    WorkflowType workflowType = event.getWorkflowExecutionStartedEventAttributes().getWorkflowType();
    if (workflow == null) {
        throw new IllegalArgumentException("Unknown workflow type: " + workflowType);
    }
    SyncDecisionContext syncContext = new SyncDecisionContext(context, dataConverter);
    if (event.getEventType() != EventType.WorkflowExecutionStarted) {
        throw new IllegalArgumentException("first event is not WorkflowExecutionStarted, but " + event.getEventType());
    }
    workflowProc = new WorkflowRunnable(syncContext, workflow, event.getWorkflowExecutionStartedEventAttributes());
    runner = DeterministicRunner.newRunner(threadPool, syncContext, context::currentTimeMillis, workflowProc);
    syncContext.setRunner(runner);
}
Also used : WorkflowType(com.uber.cadence.WorkflowType)

Example 3 with WorkflowType

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

the class SyncDecisionContext method executeChildWorkflowOnce.

/**
 * @param executionResult promise that is set bu this method when child workflow is started.
 */
private Promise<byte[]> executeChildWorkflowOnce(String name, ChildWorkflowOptions options, byte[] input, CompletablePromise<WorkflowExecution> executionResult) {
    StartChildWorkflowExecutionParameters parameters = new StartChildWorkflowExecutionParameters.Builder().setWorkflowType(new WorkflowType().setName(name)).setWorkflowId(options.getWorkflowId()).setInput(input).setChildPolicy(options.getChildPolicy()).setExecutionStartToCloseTimeoutSeconds(options.getExecutionStartToCloseTimeout().getSeconds()).setDomain(options.getDomain()).setTaskList(options.getTaskList()).setTaskStartToCloseTimeoutSeconds(options.getTaskStartToCloseTimeout().getSeconds()).setWorkflowIdReusePolicy(options.getWorkflowIdReusePolicy()).build();
    CompletablePromise<byte[]> result = Workflow.newPromise();
    Consumer<Exception> cancellationCallback = context.startChildWorkflow(parameters, executionResult::complete, (output, failure) -> {
        if (failure != null) {
            runner.executeInWorkflowThread("child workflow failure callback", () -> result.completeExceptionally(mapChildWorkflowException(failure)));
        } else {
            runner.executeInWorkflowThread("child workflow completion callback", () -> result.complete(output));
        }
    });
    CancellationScope.current().getCancellationRequest().thenApply((reason) -> {
        cancellationCallback.accept(new CancellationException(reason));
        return null;
    });
    return result;
}
Also used : CancellationException(java.util.concurrent.CancellationException) WorkflowType(com.uber.cadence.WorkflowType) StartChildWorkflowExecutionParameters(com.uber.cadence.internal.replay.StartChildWorkflowExecutionParameters) ActivityTimeoutException(com.uber.cadence.workflow.ActivityTimeoutException) ChildWorkflowTaskFailedException(com.uber.cadence.internal.replay.ChildWorkflowTaskFailedException) ActivityTaskTimeoutException(com.uber.cadence.internal.replay.ActivityTaskTimeoutException) ActivityTaskFailedException(com.uber.cadence.internal.replay.ActivityTaskFailedException) ChildWorkflowFailureException(com.uber.cadence.workflow.ChildWorkflowFailureException) CancellationException(java.util.concurrent.CancellationException) ChildWorkflowException(com.uber.cadence.workflow.ChildWorkflowException) ActivityFailureException(com.uber.cadence.workflow.ActivityFailureException) SignalExternalWorkflowException(com.uber.cadence.workflow.SignalExternalWorkflowException) ActivityException(com.uber.cadence.workflow.ActivityException)

Example 4 with WorkflowType

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

the class WorkflowDecisionContext method handleStartChildWorkflowExecutionFailed.

void handleStartChildWorkflowExecutionFailed(HistoryEvent event) {
    StartChildWorkflowExecutionFailedEventAttributes attributes = event.getStartChildWorkflowExecutionFailedEventAttributes();
    String workflowId = attributes.getWorkflowId();
    if (decisions.handleStartChildWorkflowExecutionFailed(event)) {
        OpenChildWorkflowRequestInfo scheduled = scheduledExternalWorkflows.remove(workflowId);
        if (scheduled != null) {
            WorkflowExecution workflowExecution = new WorkflowExecution();
            workflowExecution.setWorkflowId(workflowId);
            WorkflowType workflowType = attributes.getWorkflowType();
            ChildWorkflowExecutionFailedCause cause = attributes.getCause();
            RuntimeException failure = new StartChildWorkflowFailedException(event.getEventId(), workflowExecution, workflowType, cause);
            BiConsumer<byte[], Exception> completionCallback = scheduled.getCompletionCallback();
            completionCallback.accept(null, failure);
        }
    }
}
Also used : WorkflowType(com.uber.cadence.WorkflowType) StartChildWorkflowFailedException(com.uber.cadence.workflow.StartChildWorkflowFailedException) WorkflowExecution(com.uber.cadence.WorkflowExecution) ChildWorkflowExecutionFailedCause(com.uber.cadence.ChildWorkflowExecutionFailedCause) StartChildWorkflowExecutionFailedEventAttributes(com.uber.cadence.StartChildWorkflowExecutionFailedEventAttributes) StartChildWorkflowFailedException(com.uber.cadence.workflow.StartChildWorkflowFailedException) ChildWorkflowTerminatedException(com.uber.cadence.workflow.ChildWorkflowTerminatedException) CancellationException(java.util.concurrent.CancellationException) ChildWorkflowTimedOutException(com.uber.cadence.workflow.ChildWorkflowTimedOutException) SignalExternalWorkflowException(com.uber.cadence.workflow.SignalExternalWorkflowException)

Example 5 with WorkflowType

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

the class WorkflowStubImpl method startWithOptions.

private WorkflowExecution startWithOptions(WorkflowOptions o, Object... args) {
    if (execution.get() != null) {
        throw new DuplicateWorkflowException(execution.get(), workflowType.get(), "Cannot reuse a stub instance to start more than one workflow execution. The stub " + "points to already started execution.");
    }
    StartWorkflowExecutionParameters p = new StartWorkflowExecutionParameters();
    p.setTaskStartToCloseTimeoutSeconds(o.getTaskStartToCloseTimeout().getSeconds());
    if (o.getWorkflowId() == null) {
        p.setWorkflowId(UUID.randomUUID().toString());
    } else {
        p.setWorkflowId(o.getWorkflowId());
    }
    p.setExecutionStartToCloseTimeoutSeconds(o.getExecutionStartToCloseTimeout().getSeconds());
    p.setInput(dataConverter.toData(args));
    p.setWorkflowType(new WorkflowType().setName(workflowType.get()));
    p.setTaskList(o.getTaskList());
    p.setChildPolicy(o.getChildPolicy());
    try {
        execution.set(genericClient.startWorkflow(p));
    } catch (WorkflowExecutionAlreadyStartedError e) {
        execution.set(new WorkflowExecution().setWorkflowId(p.getWorkflowId()).setRunId(e.getRunId()));
        WorkflowExecution execution = new WorkflowExecution().setWorkflowId(p.getWorkflowId()).setRunId(e.getRunId());
        throw new DuplicateWorkflowException(execution, workflowType.get(), e.getMessage());
    } catch (Exception e) {
        throw new WorkflowServiceException(execution.get(), workflowType, e);
    }
    return execution.get();
}
Also used : DuplicateWorkflowException(com.uber.cadence.client.DuplicateWorkflowException) WorkflowType(com.uber.cadence.WorkflowType) WorkflowExecutionAlreadyStartedError(com.uber.cadence.WorkflowExecutionAlreadyStartedError) StartWorkflowExecutionParameters(com.uber.cadence.internal.common.StartWorkflowExecutionParameters) WorkflowExecution(com.uber.cadence.WorkflowExecution) DuplicateWorkflowException(com.uber.cadence.client.DuplicateWorkflowException) TimeoutException(java.util.concurrent.TimeoutException) WorkflowFailureException(com.uber.cadence.client.WorkflowFailureException) WorkflowNotFoundException(com.uber.cadence.client.WorkflowNotFoundException) WorkflowQueryException(com.uber.cadence.client.WorkflowQueryException) WorkflowException(com.uber.cadence.client.WorkflowException) CancellationException(java.util.concurrent.CancellationException) CompletionException(java.util.concurrent.CompletionException) WorkflowExecutionFailedException(com.uber.cadence.internal.common.WorkflowExecutionFailedException) WorkflowServiceException(com.uber.cadence.client.WorkflowServiceException) WorkflowServiceException(com.uber.cadence.client.WorkflowServiceException)

Aggregations

WorkflowType (com.uber.cadence.WorkflowType)5 CancellationException (java.util.concurrent.CancellationException)3 WorkflowExecution (com.uber.cadence.WorkflowExecution)2 SignalExternalWorkflowException (com.uber.cadence.workflow.SignalExternalWorkflowException)2 ChildWorkflowExecutionFailedCause (com.uber.cadence.ChildWorkflowExecutionFailedCause)1 PollForDecisionTaskResponse (com.uber.cadence.PollForDecisionTaskResponse)1 StartChildWorkflowExecutionFailedEventAttributes (com.uber.cadence.StartChildWorkflowExecutionFailedEventAttributes)1 WorkflowExecutionAlreadyStartedError (com.uber.cadence.WorkflowExecutionAlreadyStartedError)1 DuplicateWorkflowException (com.uber.cadence.client.DuplicateWorkflowException)1 WorkflowException (com.uber.cadence.client.WorkflowException)1 WorkflowFailureException (com.uber.cadence.client.WorkflowFailureException)1 WorkflowNotFoundException (com.uber.cadence.client.WorkflowNotFoundException)1 WorkflowQueryException (com.uber.cadence.client.WorkflowQueryException)1 WorkflowServiceException (com.uber.cadence.client.WorkflowServiceException)1 StartWorkflowExecutionParameters (com.uber.cadence.internal.common.StartWorkflowExecutionParameters)1 WorkflowExecutionFailedException (com.uber.cadence.internal.common.WorkflowExecutionFailedException)1 ActivityTaskFailedException (com.uber.cadence.internal.replay.ActivityTaskFailedException)1 ActivityTaskTimeoutException (com.uber.cadence.internal.replay.ActivityTaskTimeoutException)1 ChildWorkflowTaskFailedException (com.uber.cadence.internal.replay.ChildWorkflowTaskFailedException)1 StartChildWorkflowExecutionParameters (com.uber.cadence.internal.replay.StartChildWorkflowExecutionParameters)1