Search in sources :

Example 21 with WorkflowExecution

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

the class WorkflowDecisionContext method handleChildWorkflowExecutionCompleted.

void handleChildWorkflowExecutionCompleted(HistoryEvent event) {
    ChildWorkflowExecutionCompletedEventAttributes attributes = event.getChildWorkflowExecutionCompletedEventAttributes();
    WorkflowExecution execution = attributes.getWorkflowExecution();
    String workflowId = execution.getWorkflowId();
    if (decisions.handleChildWorkflowExecutionClosed(workflowId)) {
        OpenChildWorkflowRequestInfo scheduled = scheduledExternalWorkflows.remove(workflowId);
        if (scheduled != null) {
            BiConsumer<byte[], Exception> completionCallback = scheduled.getCompletionCallback();
            byte[] result = attributes.getResult();
            completionCallback.accept(result, null);
        }
    }
}
Also used : WorkflowExecution(com.uber.cadence.WorkflowExecution) ChildWorkflowExecutionCompletedEventAttributes(com.uber.cadence.ChildWorkflowExecutionCompletedEventAttributes) 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 22 with WorkflowExecution

use of com.uber.cadence.WorkflowExecution 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 23 with WorkflowExecution

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

the class WorkflowDecisionContext method handleChildWorkflowExecutionFailed.

void handleChildWorkflowExecutionFailed(HistoryEvent event) {
    ChildWorkflowExecutionFailedEventAttributes attributes = event.getChildWorkflowExecutionFailedEventAttributes();
    WorkflowExecution execution = attributes.getWorkflowExecution();
    String workflowId = execution.getWorkflowId();
    if (decisions.handleChildWorkflowExecutionClosed(workflowId)) {
        OpenChildWorkflowRequestInfo scheduled = scheduledExternalWorkflows.remove(workflowId);
        if (scheduled != null) {
            String reason = attributes.getReason();
            byte[] details = attributes.getDetails();
            RuntimeException failure = new ChildWorkflowTaskFailedException(event.getEventId(), execution, attributes.getWorkflowType(), reason, details);
            BiConsumer<byte[], Exception> completionCallback = scheduled.getCompletionCallback();
            completionCallback.accept(null, failure);
        }
    }
}
Also used : WorkflowExecution(com.uber.cadence.WorkflowExecution) StartChildWorkflowExecutionFailedEventAttributes(com.uber.cadence.StartChildWorkflowExecutionFailedEventAttributes) ChildWorkflowExecutionFailedEventAttributes(com.uber.cadence.ChildWorkflowExecutionFailedEventAttributes) 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 24 with WorkflowExecution

use of com.uber.cadence.WorkflowExecution 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)

Example 25 with WorkflowExecution

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

the class WorkflowDecisionContext method handleSignalExternalWorkflowExecutionFailed.

void handleSignalExternalWorkflowExecutionFailed(HistoryEvent event) {
    SignalExternalWorkflowExecutionFailedEventAttributes attributes = event.getSignalExternalWorkflowExecutionFailedEventAttributes();
    String signalId = new String(attributes.getControl(), StandardCharsets.UTF_8);
    if (decisions.handleSignalExternalWorkflowExecutionFailed(signalId)) {
        OpenRequestInfo<Void, Void> signalContextAndResult = scheduledSignals.remove(signalId);
        if (signalContextAndResult != null) {
            WorkflowExecution signaledExecution = new WorkflowExecution();
            signaledExecution.setWorkflowId(attributes.getWorkflowExecution().getWorkflowId());
            signaledExecution.setRunId(attributes.getWorkflowExecution().getRunId());
            RuntimeException failure = new SignalExternalWorkflowException(event.getEventId(), signaledExecution, attributes.getCause());
            signalContextAndResult.getCompletionCallback().accept(null, failure);
        }
    }
}
Also used : SignalExternalWorkflowException(com.uber.cadence.workflow.SignalExternalWorkflowException) SignalExternalWorkflowExecutionFailedEventAttributes(com.uber.cadence.SignalExternalWorkflowExecutionFailedEventAttributes) WorkflowExecution(com.uber.cadence.WorkflowExecution)

Aggregations

WorkflowExecution (com.uber.cadence.WorkflowExecution)30 CancellationException (java.util.concurrent.CancellationException)11 SignalExternalWorkflowException (com.uber.cadence.workflow.SignalExternalWorkflowException)8 ChildWorkflowTerminatedException (com.uber.cadence.workflow.ChildWorkflowTerminatedException)7 ChildWorkflowTimedOutException (com.uber.cadence.workflow.ChildWorkflowTimedOutException)7 StartChildWorkflowFailedException (com.uber.cadence.workflow.StartChildWorkflowFailedException)7 HistoryEvent (com.uber.cadence.HistoryEvent)6 Test (org.junit.Test)6 TimeoutException (java.util.concurrent.TimeoutException)5 TException (org.apache.thrift.TException)5 WorkflowStub (com.uber.cadence.client.WorkflowStub)4 GetWorkflowExecutionHistoryRequest (com.uber.cadence.GetWorkflowExecutionHistoryRequest)3 History (com.uber.cadence.History)3 StartChildWorkflowExecutionFailedEventAttributes (com.uber.cadence.StartChildWorkflowExecutionFailedEventAttributes)3 WorkflowExecutionAlreadyStartedError (com.uber.cadence.WorkflowExecutionAlreadyStartedError)3 WorkflowType (com.uber.cadence.WorkflowType)3 DeterministicRunnerTest (com.uber.cadence.internal.sync.DeterministicRunnerTest)3 ChildWorkflowExecutionCanceledEventAttributes (com.uber.cadence.ChildWorkflowExecutionCanceledEventAttributes)2 ChildWorkflowExecutionCompletedEventAttributes (com.uber.cadence.ChildWorkflowExecutionCompletedEventAttributes)2 ChildWorkflowExecutionFailedCause (com.uber.cadence.ChildWorkflowExecutionFailedCause)2