Search in sources :

Example 11 with EntityNotExistsError

use of com.uber.cadence.EntityNotExistsError 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 12 with EntityNotExistsError

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

the class TestWorkflowService method PollForActivityTask.

@Override
public PollForActivityTaskResponse PollForActivityTask(PollForActivityTaskRequest pollRequest) throws BadRequestError, InternalServiceError, ServiceBusyError, TException {
    PollForActivityTaskResponse task;
    while (true) {
        try {
            task = store.pollForActivityTask(pollRequest);
        } catch (InterruptedException e) {
            return new PollForActivityTaskResponse();
        }
        ExecutionId executionId = new ExecutionId(pollRequest.getDomain(), task.getWorkflowExecution());
        TestWorkflowMutableState mutableState = getMutableState(executionId);
        try {
            mutableState.startActivityTask(task, pollRequest);
            return task;
        } catch (EntityNotExistsError e) {
            if (log.isDebugEnabled()) {
                log.debug("Skipping outdated activity task for " + executionId, e);
            }
        }
    }
}
Also used : PollForActivityTaskResponse(com.uber.cadence.PollForActivityTaskResponse) EntityNotExistsError(com.uber.cadence.EntityNotExistsError)

Example 13 with EntityNotExistsError

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

the class TestWorkflowService method PollForDecisionTask.

@Override
public PollForDecisionTaskResponse PollForDecisionTask(PollForDecisionTaskRequest pollRequest) throws BadRequestError, InternalServiceError, ServiceBusyError, TException {
    PollForDecisionTaskResponse task;
    try {
        task = store.pollForDecisionTask(pollRequest);
    } catch (InterruptedException e) {
        return new PollForDecisionTaskResponse();
    }
    ExecutionId executionId = new ExecutionId(pollRequest.getDomain(), task.getWorkflowExecution());
    TestWorkflowMutableState mutableState = getMutableState(executionId);
    try {
        mutableState.startDecisionTask(task, pollRequest);
        return task;
    } catch (EntityNotExistsError e) {
        if (log.isDebugEnabled()) {
            log.debug("Skipping outdated decision task for " + executionId, e);
        }
    // skip the task
    }
    return task;
}
Also used : PollForDecisionTaskResponse(com.uber.cadence.PollForDecisionTaskResponse) EntityNotExistsError(com.uber.cadence.EntityNotExistsError)

Example 14 with EntityNotExistsError

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

the class StateMachines method startDecisionTask.

private static void startDecisionTask(RequestContext ctx, DecisionTaskData data, PollForDecisionTaskRequest request, long notUsed) {
    DecisionTaskStartedEventAttributes a = new DecisionTaskStartedEventAttributes().setIdentity(request.getIdentity()).setScheduledEventId(data.scheduledEventId);
    HistoryEvent event = new HistoryEvent().setEventType(EventType.DecisionTaskStarted).setDecisionTaskStartedEventAttributes(a);
    long startedEventId = ctx.addEvent(event);
    ctx.onCommit((historySize) -> {
        data.decisionTask.setStartedEventId(startedEventId);
        DecisionTaskToken taskToken = new DecisionTaskToken(ctx.getExecutionId(), historySize);
        data.decisionTask.setTaskToken(taskToken.toBytes());
        GetWorkflowExecutionHistoryRequest getRequest = new GetWorkflowExecutionHistoryRequest().setDomain(request.getDomain()).setExecution(ctx.getExecution());
        List<HistoryEvent> events;
        try {
            events = data.store.getWorkflowExecutionHistory(ctx.getExecutionId(), getRequest).getHistory().getEvents();
        } catch (EntityNotExistsError entityNotExistsError) {
            throw new InternalServiceError(entityNotExistsError.toString());
        }
        data.decisionTask.setHistory(new History().setEvents(events));
        data.previousStartedEventId = startedEventId;
        data.attempt++;
    });
}
Also used : DecisionTaskStartedEventAttributes(com.uber.cadence.DecisionTaskStartedEventAttributes) GetWorkflowExecutionHistoryRequest(com.uber.cadence.GetWorkflowExecutionHistoryRequest) InternalServiceError(com.uber.cadence.InternalServiceError) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) HistoryEvent(com.uber.cadence.HistoryEvent) History(com.uber.cadence.History)

Example 15 with EntityNotExistsError

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

the class WorkflowStubImpl method mapToWorkflowFailureException.

private <R> R mapToWorkflowFailureException(Exception failure, Class<R> returnType) {
    failure = CheckedExceptionWrapper.unwrap(failure);
    Class<Throwable> detailsClass;
    if (failure instanceof WorkflowExecutionFailedException) {
        WorkflowExecutionFailedException executionFailed = (WorkflowExecutionFailedException) failure;
        try {
            @SuppressWarnings("unchecked") Class<Throwable> dc = (Class<Throwable>) Class.forName(executionFailed.getReason());
            detailsClass = dc;
        } catch (Exception e) {
            RuntimeException ee = new RuntimeException("Couldn't deserialize failure cause " + "as the reason field is expected to contain an exception class name", executionFailed);
            throw new WorkflowFailureException(execution.get(), workflowType, executionFailed.getDecisionTaskCompletedEventId(), ee);
        }
        Throwable cause = dataConverter.fromData(executionFailed.getDetails(), detailsClass);
        throw new WorkflowFailureException(execution.get(), workflowType, executionFailed.getDecisionTaskCompletedEventId(), cause);
    } else if (failure instanceof EntityNotExistsError) {
        throw new WorkflowNotFoundException(execution.get(), workflowType, failure.getMessage());
    } else if (failure instanceof CancellationException) {
        throw (CancellationException) failure;
    } else if (failure instanceof WorkflowException) {
        throw (WorkflowException) failure;
    } else {
        throw new WorkflowServiceException(execution.get(), workflowType, failure);
    }
}
Also used : WorkflowFailureException(com.uber.cadence.client.WorkflowFailureException) WorkflowNotFoundException(com.uber.cadence.client.WorkflowNotFoundException) DuplicateWorkflowException(com.uber.cadence.client.DuplicateWorkflowException) WorkflowException(com.uber.cadence.client.WorkflowException) WorkflowExecutionFailedException(com.uber.cadence.internal.common.WorkflowExecutionFailedException) 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) CancellationException(java.util.concurrent.CancellationException) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) WorkflowServiceException(com.uber.cadence.client.WorkflowServiceException)

Aggregations

EntityNotExistsError (com.uber.cadence.EntityNotExistsError)19 InternalServiceError (com.uber.cadence.InternalServiceError)10 BadRequestError (com.uber.cadence.BadRequestError)8 TException (org.apache.thrift.TException)7 ActivityCompletionFailureException (com.uber.cadence.client.ActivityCompletionFailureException)4 ActivityNotExistsException (com.uber.cadence.client.ActivityNotExistsException)4 RecordActivityTaskHeartbeatResponse (com.uber.cadence.RecordActivityTaskHeartbeatResponse)3 TimeoutException (java.util.concurrent.TimeoutException)3 GetWorkflowExecutionHistoryRequest (com.uber.cadence.GetWorkflowExecutionHistoryRequest)2 History (com.uber.cadence.History)2 HistoryEvent (com.uber.cadence.HistoryEvent)2 QueryFailedError (com.uber.cadence.QueryFailedError)2 RecordActivityTaskHeartbeatRequest (com.uber.cadence.RecordActivityTaskHeartbeatRequest)2 ActivityCancelledException (com.uber.cadence.client.ActivityCancelledException)2 DuplicateWorkflowException (com.uber.cadence.client.DuplicateWorkflowException)2 WorkflowException (com.uber.cadence.client.WorkflowException)2 WorkflowFailureException (com.uber.cadence.client.WorkflowFailureException)2 WorkflowNotFoundException (com.uber.cadence.client.WorkflowNotFoundException)2 WorkflowQueryException (com.uber.cadence.client.WorkflowQueryException)2 WorkflowServiceException (com.uber.cadence.client.WorkflowServiceException)2