Search in sources :

Example 6 with BadRequestError

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

the class TestWorkflowMutableStateImpl method startWorkflow.

@Override
public void startWorkflow() throws InternalServiceError, BadRequestError {
    try {
        update(ctx -> {
            workflow.action(StateMachines.Action.START, ctx, startRequest, 0);
            scheduleDecision(ctx);
            ctx.addTimer(startRequest.getExecutionStartToCloseTimeoutSeconds(), this::timeoutWorkflow);
        });
    } catch (EntityNotExistsError entityNotExistsError) {
        throw new InternalServiceError(Throwables.getStackTraceAsString(entityNotExistsError));
    }
    if (parent.isPresent()) {
        ChildWorkflowExecutionStartedEventAttributes a = new ChildWorkflowExecutionStartedEventAttributes().setWorkflowExecution(getExecutionId().getExecution()).setDomain(getExecutionId().getDomain()).setWorkflowType(startRequest.getWorkflowType());
        ForkJoinPool.commonPool().execute(() -> {
            try {
                parent.get().childWorkflowStarted(a);
            } catch (EntityNotExistsError entityNotExistsError) {
            // Not a problem. Parent might just close by now.
            } catch (BadRequestError | InternalServiceError e) {
                log.error("Failure reporting child completion", e);
            }
        });
    }
}
Also used : ChildWorkflowExecutionStartedEventAttributes(com.uber.cadence.ChildWorkflowExecutionStartedEventAttributes) InternalServiceError(com.uber.cadence.InternalServiceError) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) BadRequestError(com.uber.cadence.BadRequestError)

Example 7 with BadRequestError

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

the class TestWorkflowMutableStateImpl method reportWorkflowTimeoutToParent.

private void reportWorkflowTimeoutToParent(RequestContext ctx) {
    if (!parent.isPresent()) {
        return;
    }
    try {
        ChildWorkflowExecutionTimedOutEventAttributes a = new ChildWorkflowExecutionTimedOutEventAttributes().setTimeoutType(TimeoutType.START_TO_CLOSE).setWorkflowType(startRequest.getWorkflowType()).setDomain(ctx.getDomain()).setWorkflowExecution(ctx.getExecution());
        parent.get().childWorklfowTimedOut(ctx.getExecutionId().getWorkflowId().getWorkflowId(), a);
    } catch (EntityNotExistsError entityNotExistsError) {
    // Parent might already close
    } catch (BadRequestError | InternalServiceError e) {
        log.error("Failure reporting child timing out", e);
    }
}
Also used : InternalServiceError(com.uber.cadence.InternalServiceError) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) BadRequestError(com.uber.cadence.BadRequestError) ChildWorkflowExecutionTimedOutEventAttributes(com.uber.cadence.ChildWorkflowExecutionTimedOutEventAttributes)

Example 8 with BadRequestError

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

Aggregations

BadRequestError (com.uber.cadence.BadRequestError)8 EntityNotExistsError (com.uber.cadence.EntityNotExistsError)8 InternalServiceError (com.uber.cadence.InternalServiceError)7 TException (org.apache.thrift.TException)2 ChildWorkflowExecutionCanceledEventAttributes (com.uber.cadence.ChildWorkflowExecutionCanceledEventAttributes)1 ChildWorkflowExecutionCompletedEventAttributes (com.uber.cadence.ChildWorkflowExecutionCompletedEventAttributes)1 ChildWorkflowExecutionFailedEventAttributes (com.uber.cadence.ChildWorkflowExecutionFailedEventAttributes)1 ChildWorkflowExecutionStartedEventAttributes (com.uber.cadence.ChildWorkflowExecutionStartedEventAttributes)1 ChildWorkflowExecutionTimedOutEventAttributes (com.uber.cadence.ChildWorkflowExecutionTimedOutEventAttributes)1 Decision (com.uber.cadence.Decision)1 RecordActivityTaskHeartbeatRequest (com.uber.cadence.RecordActivityTaskHeartbeatRequest)1 RecordActivityTaskHeartbeatResponse (com.uber.cadence.RecordActivityTaskHeartbeatResponse)1 RespondDecisionTaskFailedRequest (com.uber.cadence.RespondDecisionTaskFailedRequest)1 StartChildWorkflowExecutionFailedEventAttributes (com.uber.cadence.StartChildWorkflowExecutionFailedEventAttributes)1 ActivityCancelledException (com.uber.cadence.client.ActivityCancelledException)1 ActivityCompletionFailureException (com.uber.cadence.client.ActivityCompletionFailureException)1 ActivityNotExistsException (com.uber.cadence.client.ActivityNotExistsException)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1