Search in sources :

Example 6 with Decision

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

the class TestWorkflowMutableStateImpl method completeDecisionTask.

@Override
public void completeDecisionTask(int historySize, RespondDecisionTaskCompletedRequest request) throws InternalServiceError, EntityNotExistsError, BadRequestError {
    List<Decision> decisions = request.getDecisions();
    completeDecisionUpdate(ctx -> {
        if (ctx.getInitialEventId() != historySize) {
            throw new BadRequestError("Expired decision: expectedHistorySize=" + historySize + "," + " actualHistorySize=" + ctx.getInitialEventId());
        }
        long decisionTaskCompletedId = ctx.getNextEventId() - 1;
        // workflow
        if (!concurrentToDecision.isEmpty() && hasCompleteDecision(request.getDecisions())) {
            RespondDecisionTaskFailedRequest failedRequest = new RespondDecisionTaskFailedRequest().setCause(DecisionTaskFailedCause.UNHANDLED_DECISION).setIdentity(request.getIdentity());
            decision.action(Action.FAIL, ctx, failedRequest, decisionTaskCompletedId);
            for (RequestContext deferredCtx : this.concurrentToDecision) {
                ctx.add(deferredCtx);
            }
            this.concurrentToDecision.clear();
            scheduleDecision(ctx);
            return;
        }
        if (decision == null) {
            throw new EntityNotExistsError("No outstanding decision");
        }
        decision.action(StateMachines.Action.COMPLETE, ctx, request, 0);
        for (Decision d : decisions) {
            processDecision(ctx, d, request.getIdentity(), decisionTaskCompletedId);
        }
        for (RequestContext deferredCtx : this.concurrentToDecision) {
            ctx.add(deferredCtx);
        }
        this.decision = null;
        boolean completed = workflow.getState() == StateMachines.State.COMPLETED || workflow.getState() == StateMachines.State.FAILED || workflow.getState() == StateMachines.State.CANCELED;
        if (!completed && (ctx.isNeedDecision() || !this.concurrentToDecision.isEmpty())) {
            scheduleDecision(ctx);
        }
        this.concurrentToDecision.clear();
        ctx.unlockTimer();
    });
    lock.lock();
    try {
        {
            if (decision != null && decision.getState() != StateMachines.State.INITIATED) {
                throw new InternalServiceError("non null decision after the completion: " + decision.getState());
            }
        }
    } finally {
        lock.unlock();
    }
}
Also used : RespondDecisionTaskFailedRequest(com.uber.cadence.RespondDecisionTaskFailedRequest) InternalServiceError(com.uber.cadence.InternalServiceError) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) BadRequestError(com.uber.cadence.BadRequestError) Decision(com.uber.cadence.Decision)

Example 7 with Decision

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

the class SignalDecisionStateMachine method createSignalExternalWorkflowExecutionDecision.

private Decision createSignalExternalWorkflowExecutionDecision() {
    Decision decision = new Decision();
    decision.setSignalExternalWorkflowExecutionDecisionAttributes(attributes);
    decision.setDecisionType(DecisionType.SignalExternalWorkflowExecution);
    return decision;
}
Also used : Decision(com.uber.cadence.Decision)

Example 8 with Decision

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

the class TimerDecisionStateMachine method createStartTimerDecision.

private Decision createStartTimerDecision() {
    Decision decision = new Decision();
    decision.setStartTimerDecisionAttributes(attributes);
    decision.setDecisionType(DecisionType.StartTimer);
    return decision;
}
Also used : Decision(com.uber.cadence.Decision)

Example 9 with Decision

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

the class DecisionsHelper method cancelWorkflowExecution.

/**
 * @return <code>false</code> means that cancel failed, <code>true</code> that
 *     CancelWorkflowExecution was created.
 */
void cancelWorkflowExecution() {
    Decision decision = new Decision();
    CancelWorkflowExecutionDecisionAttributes cancel = new CancelWorkflowExecutionDecisionAttributes();
    cancel.setDetails((byte[]) null);
    decision.setCancelWorkflowExecutionDecisionAttributes(cancel);
    decision.setDecisionType(DecisionType.CancelWorkflowExecution);
    DecisionId decisionId = new DecisionId(DecisionTarget.SELF, null);
    addDecision(decisionId, new CompleteWorkflowStateMachine(decisionId, decision));
}
Also used : CancelWorkflowExecutionDecisionAttributes(com.uber.cadence.CancelWorkflowExecutionDecisionAttributes) Decision(com.uber.cadence.Decision)

Example 10 with Decision

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

the class DecisionsHelper method getDecisions.

List<Decision> getDecisions() {
    List<Decision> result = new ArrayList<>(MAXIMUM_DECISIONS_PER_COMPLETION + 1);
    for (DecisionStateMachine decisionStateMachine : decisions.values()) {
        Decision decision = decisionStateMachine.getDecision();
        if (decision != null) {
            result.add(decision);
        }
    }
    // Include FORCE_IMMEDIATE_DECISION timer only if there are more then 100 events
    int size = result.size();
    if (size > MAXIMUM_DECISIONS_PER_COMPLETION && !isCompletionEvent(result.get(MAXIMUM_DECISIONS_PER_COMPLETION - 2))) {
        result = result.subList(0, MAXIMUM_DECISIONS_PER_COMPLETION - 1);
        StartTimerDecisionAttributes attributes = new StartTimerDecisionAttributes();
        attributes.setStartToFireTimeoutSeconds(0);
        attributes.setTimerId(FORCE_IMMEDIATE_DECISION_TIMER);
        Decision d = new Decision();
        d.setStartTimerDecisionAttributes(attributes);
        d.setDecisionType(DecisionType.StartTimer);
        result.add(d);
    }
    return result;
}
Also used : StartTimerDecisionAttributes(com.uber.cadence.StartTimerDecisionAttributes) ArrayList(java.util.ArrayList) Decision(com.uber.cadence.Decision)

Aggregations

Decision (com.uber.cadence.Decision)15 BadRequestError (com.uber.cadence.BadRequestError)1 CancelTimerDecisionAttributes (com.uber.cadence.CancelTimerDecisionAttributes)1 CancelWorkflowExecutionDecisionAttributes (com.uber.cadence.CancelWorkflowExecutionDecisionAttributes)1 ChildWorkflowExecutionStartedEventAttributes (com.uber.cadence.ChildWorkflowExecutionStartedEventAttributes)1 CompleteWorkflowExecutionDecisionAttributes (com.uber.cadence.CompleteWorkflowExecutionDecisionAttributes)1 ContinueAsNewWorkflowExecutionDecisionAttributes (com.uber.cadence.ContinueAsNewWorkflowExecutionDecisionAttributes)1 EntityNotExistsError (com.uber.cadence.EntityNotExistsError)1 FailWorkflowExecutionDecisionAttributes (com.uber.cadence.FailWorkflowExecutionDecisionAttributes)1 InternalServiceError (com.uber.cadence.InternalServiceError)1 PollForDecisionTaskResponse (com.uber.cadence.PollForDecisionTaskResponse)1 RequestCancelActivityTaskDecisionAttributes (com.uber.cadence.RequestCancelActivityTaskDecisionAttributes)1 RequestCancelExternalWorkflowExecutionDecisionAttributes (com.uber.cadence.RequestCancelExternalWorkflowExecutionDecisionAttributes)1 RespondDecisionTaskCompletedRequest (com.uber.cadence.RespondDecisionTaskCompletedRequest)1 RespondDecisionTaskFailedRequest (com.uber.cadence.RespondDecisionTaskFailedRequest)1 RespondQueryTaskCompletedRequest (com.uber.cadence.RespondQueryTaskCompletedRequest)1 StartTimerDecisionAttributes (com.uber.cadence.StartTimerDecisionAttributes)1 TaskList (com.uber.cadence.TaskList)1 WorkflowExecution (com.uber.cadence.WorkflowExecution)1 WorkflowExecutionStartedEventAttributes (com.uber.cadence.WorkflowExecutionStartedEventAttributes)1