Search in sources :

Example 1 with WorkflowExecutionAlreadyCompletedError

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

the class WorkflowServiceTChannel method measureRemoteCallWithTags.

private <T> T measureRemoteCallWithTags(String scopeName, RemoteCall<T> call, Map<String, String> tags) throws TException {
    Scope scope = options.getMetricsScope().subScope(scopeName);
    if (tags != null) {
        scope = scope.tagged(tags);
    }
    scope.counter(MetricsType.CADENCE_REQUEST).inc(1);
    Stopwatch sw = scope.timer(MetricsType.CADENCE_LATENCY).start();
    try {
        T resp = call.apply();
        sw.stop();
        return resp;
    } catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError | BadRequestError | DomainAlreadyExistsError | WorkflowExecutionAlreadyStartedError | QueryFailedError e) {
        sw.stop();
        scope.counter(MetricsType.CADENCE_INVALID_REQUEST).inc(1);
        throw e;
    } catch (TException e) {
        sw.stop();
        scope.counter(MetricsType.CADENCE_ERROR).inc(1);
        throw e;
    }
}
Also used : TException(org.apache.thrift.TException) Scope(com.uber.m3.tally.Scope) DomainAlreadyExistsError(com.uber.cadence.DomainAlreadyExistsError) Stopwatch(com.uber.m3.tally.Stopwatch) WorkflowExecutionAlreadyStartedError(com.uber.cadence.WorkflowExecutionAlreadyStartedError) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) WorkflowExecutionAlreadyCompletedError(com.uber.cadence.WorkflowExecutionAlreadyCompletedError) QueryFailedError(com.uber.cadence.QueryFailedError) BadRequestError(com.uber.cadence.BadRequestError)

Example 2 with WorkflowExecutionAlreadyCompletedError

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

the class TestWorkflowMutableStateImpl method processFailWorkflowExecution.

private void processFailWorkflowExecution(RequestContext ctx, FailWorkflowExecutionDecisionAttributes d, long decisionTaskCompletedId, String identity) throws InternalServiceError, BadRequestError {
    WorkflowData data = workflow.getData();
    if (data.retryState.isPresent()) {
        RetryState rs = data.retryState.get();
        int backoffIntervalSeconds = rs.getBackoffIntervalInSeconds(d.getReason(), store.currentTimeMillis());
        if (backoffIntervalSeconds > 0) {
            ContinueAsNewWorkflowExecutionDecisionAttributes continueAsNewAttr = new ContinueAsNewWorkflowExecutionDecisionAttributes().setInput(startRequest.getInput()).setWorkflowType(startRequest.getWorkflowType()).setExecutionStartToCloseTimeoutSeconds(startRequest.getExecutionStartToCloseTimeoutSeconds()).setTaskStartToCloseTimeoutSeconds(startRequest.getTaskStartToCloseTimeoutSeconds()).setTaskList(startRequest.getTaskList()).setBackoffStartIntervalInSeconds(backoffIntervalSeconds).setRetryPolicy(startRequest.getRetryPolicy());
            workflow.action(Action.CONTINUE_AS_NEW, ctx, continueAsNewAttr, decisionTaskCompletedId);
            HistoryEvent event = ctx.getEvents().get(ctx.getEvents().size() - 1);
            WorkflowExecutionContinuedAsNewEventAttributes continuedAsNewEventAttributes = event.getWorkflowExecutionContinuedAsNewEventAttributes();
            Optional<RetryState> continuedRetryState = Optional.of(rs.getNextAttempt());
            String runId = service.continueAsNew(startRequest, continuedAsNewEventAttributes, continuedRetryState, identity, getExecutionId(), parent, parentChildInitiatedEventId);
            continuedAsNewEventAttributes.setNewExecutionRunId(runId);
            return;
        }
    }
    if (!Strings.isNullOrEmpty(data.cronSchedule)) {
        startNewCronRun(ctx, decisionTaskCompletedId, identity, data, data.lastCompletionResult);
        return;
    }
    workflow.action(StateMachines.Action.FAIL, ctx, d, decisionTaskCompletedId);
    if (parent.isPresent()) {
        // unlocked by the parent
        ctx.lockTimer();
        ChildWorkflowExecutionFailedEventAttributes a = new ChildWorkflowExecutionFailedEventAttributes().setInitiatedEventId(parentChildInitiatedEventId.getAsLong()).setDetails(d.getDetails()).setReason(d.getReason()).setWorkflowType(startRequest.getWorkflowType()).setDomain(ctx.getDomain()).setWorkflowExecution(ctx.getExecution());
        ForkJoinPool.commonPool().execute(() -> {
            try {
                parent.get().childWorkflowFailed(ctx.getExecutionId().getWorkflowId().getWorkflowId(), a);
            } catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) {
            // Parent might already close
            } catch (BadRequestError | InternalServiceError e) {
                log.error("Failure reporting child completion", e);
            }
        });
    }
}
Also used : InternalServiceError(com.uber.cadence.InternalServiceError) HistoryEvent(com.uber.cadence.HistoryEvent) BadRequestError(com.uber.cadence.BadRequestError) ChildWorkflowData(com.uber.cadence.internal.testservice.StateMachines.ChildWorkflowData) WorkflowData(com.uber.cadence.internal.testservice.StateMachines.WorkflowData) ContinueAsNewWorkflowExecutionDecisionAttributes(com.uber.cadence.ContinueAsNewWorkflowExecutionDecisionAttributes) StartChildWorkflowExecutionFailedEventAttributes(com.uber.cadence.StartChildWorkflowExecutionFailedEventAttributes) ChildWorkflowExecutionFailedEventAttributes(com.uber.cadence.ChildWorkflowExecutionFailedEventAttributes) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) WorkflowExecutionAlreadyCompletedError(com.uber.cadence.WorkflowExecutionAlreadyCompletedError) WorkflowExecutionContinuedAsNewEventAttributes(com.uber.cadence.WorkflowExecutionContinuedAsNewEventAttributes)

Example 3 with WorkflowExecutionAlreadyCompletedError

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

the class TestWorkflowMutableStateImpl method processCompleteWorkflowExecution.

private void processCompleteWorkflowExecution(RequestContext ctx, CompleteWorkflowExecutionDecisionAttributes d, long decisionTaskCompletedId, String identity) throws InternalServiceError, BadRequestError {
    WorkflowData data = workflow.getData();
    if (!Strings.isNullOrEmpty(data.cronSchedule)) {
        startNewCronRun(ctx, decisionTaskCompletedId, identity, data, d.getResult());
        return;
    }
    workflow.action(StateMachines.Action.COMPLETE, ctx, d, decisionTaskCompletedId);
    if (parent.isPresent()) {
        // unlocked by the parent
        ctx.lockTimer();
        ChildWorkflowExecutionCompletedEventAttributes a = new ChildWorkflowExecutionCompletedEventAttributes().setInitiatedEventId(parentChildInitiatedEventId.getAsLong()).setResult(d.getResult()).setDomain(ctx.getDomain()).setWorkflowExecution(ctx.getExecution()).setWorkflowType(startRequest.getWorkflowType());
        ForkJoinPool.commonPool().execute(() -> {
            try {
                parent.get().childWorkflowCompleted(ctx.getExecutionId().getWorkflowId().getWorkflowId(), a);
            } catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) {
            // Parent might already close
            } catch (BadRequestError | InternalServiceError e) {
                log.error("Failure reporting child completion", e);
            }
        });
    }
}
Also used : InternalServiceError(com.uber.cadence.InternalServiceError) ChildWorkflowExecutionCompletedEventAttributes(com.uber.cadence.ChildWorkflowExecutionCompletedEventAttributes) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) WorkflowExecutionAlreadyCompletedError(com.uber.cadence.WorkflowExecutionAlreadyCompletedError) BadRequestError(com.uber.cadence.BadRequestError) ChildWorkflowData(com.uber.cadence.internal.testservice.StateMachines.ChildWorkflowData) WorkflowData(com.uber.cadence.internal.testservice.StateMachines.WorkflowData)

Example 4 with WorkflowExecutionAlreadyCompletedError

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

the class TestWorkflowMutableStateImpl method update.

private void update(boolean completeDecisionUpdate, UpdateProcedure updater, String caller) throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, BadRequestError {
    String callerInfo = "Decision Update from " + caller;
    lock.lock();
    LockHandle lockHandle = selfAdvancingTimer.lockTimeSkipping(callerInfo);
    try {
        checkCompleted();
        boolean concurrentDecision = !completeDecisionUpdate && (decision != null && decision.getState() == StateMachines.State.STARTED);
        RequestContext ctx = new RequestContext(clock, this, nextEventId);
        updater.apply(ctx);
        setPendingQueries(ctx);
        if (concurrentDecision && workflow.getState() != State.TIMED_OUT) {
            concurrentToDecision.add(ctx);
            ctx.fireCallbacks(0);
            store.applyTimersAndLocks(ctx);
        } else {
            nextEventId = ctx.commitChanges(store);
        }
    } catch (InternalServiceError | EntityNotExistsError | WorkflowExecutionAlreadyCompletedError | BadRequestError e) {
        throw e;
    } catch (Exception e) {
        throw new InternalServiceError(Throwables.getStackTraceAsString(e));
    } finally {
        lockHandle.unlock();
        lock.unlock();
    }
}
Also used : InternalServiceError(com.uber.cadence.InternalServiceError) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) WorkflowExecutionAlreadyCompletedError(com.uber.cadence.WorkflowExecutionAlreadyCompletedError) BadRequestError(com.uber.cadence.BadRequestError) TException(org.apache.thrift.TException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with WorkflowExecutionAlreadyCompletedError

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

the class TestWorkflowMutableStateImpl method heartbeatActivityTask.

@Override
public RecordActivityTaskHeartbeatResponse heartbeatActivityTask(String activityId, byte[] details) throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError {
    RecordActivityTaskHeartbeatResponse result = new RecordActivityTaskHeartbeatResponse();
    try {
        update(ctx -> {
            StateMachine<ActivityTaskData> activity = getActivity(activityId);
            activity.action(StateMachines.Action.UPDATE, ctx, details, 0);
            if (activity.getState() == StateMachines.State.CANCELLATION_REQUESTED) {
                result.setCancelRequested(true);
            }
            ActivityTaskData data = activity.getData();
            data.lastHeartbeatTime = clock.getAsLong();
            int startToCloseTimeout = data.scheduledEvent.getStartToCloseTimeoutSeconds();
            int heartbeatTimeout = data.scheduledEvent.getHeartbeatTimeoutSeconds();
            updateHeartbeatTimer(ctx, activityId, activity, startToCloseTimeout, heartbeatTimeout);
        });
    } catch (InternalServiceError | EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) {
        throw e;
    } catch (Exception e) {
        throw new InternalServiceError(Throwables.getStackTraceAsString(e));
    }
    return result;
}
Also used : RecordActivityTaskHeartbeatResponse(com.uber.cadence.RecordActivityTaskHeartbeatResponse) InternalServiceError(com.uber.cadence.InternalServiceError) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) WorkflowExecutionAlreadyCompletedError(com.uber.cadence.WorkflowExecutionAlreadyCompletedError) ActivityTaskData(com.uber.cadence.internal.testservice.StateMachines.ActivityTaskData) TException(org.apache.thrift.TException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

EntityNotExistsError (com.uber.cadence.EntityNotExistsError)14 WorkflowExecutionAlreadyCompletedError (com.uber.cadence.WorkflowExecutionAlreadyCompletedError)14 BadRequestError (com.uber.cadence.BadRequestError)8 TException (org.apache.thrift.TException)8 InternalServiceError (com.uber.cadence.InternalServiceError)7 ActivityCompletionFailureException (com.uber.cadence.client.ActivityCompletionFailureException)4 ActivityNotExistsException (com.uber.cadence.client.ActivityNotExistsException)4 IOException (java.io.IOException)4 ExecutionException (java.util.concurrent.ExecutionException)4 RecordActivityTaskHeartbeatResponse (com.uber.cadence.RecordActivityTaskHeartbeatResponse)3 RecordActivityTaskHeartbeatRequest (com.uber.cadence.RecordActivityTaskHeartbeatRequest)2 ActivityCancelledException (com.uber.cadence.client.ActivityCancelledException)2 ActivityTaskData (com.uber.cadence.internal.testservice.StateMachines.ActivityTaskData)2 ChildWorkflowData (com.uber.cadence.internal.testservice.StateMachines.ChildWorkflowData)2 WorkflowData (com.uber.cadence.internal.testservice.StateMachines.WorkflowData)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