Search in sources :

Example 1 with BadRequestError

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

the class ActivityExecutionContextImpl method recordActivityHeartbeat.

/**
 * @throws CancellationException
 * @see ActivityExecutionContext#recordActivityHeartbeat(Object)
 */
@Override
public void recordActivityHeartbeat(Object details) throws ActivityCompletionException {
    // TODO: call service with the specified minimal interval (through @ActivityExecutionOptions)
    // allowing more frequent calls of this method.
    RecordActivityTaskHeartbeatRequest r = new RecordActivityTaskHeartbeatRequest();
    r.setTaskToken(task.getTaskToken());
    byte[] serialized = dataConverter.toData(details);
    r.setDetails(serialized);
    RecordActivityTaskHeartbeatResponse status;
    try {
        status = service.RecordActivityTaskHeartbeat(r);
        if (status.isCancelRequested()) {
            throw new ActivityCancelledException(task);
        }
    } catch (EntityNotExistsError e) {
        throw new ActivityNotExistsException(task, e);
    } catch (BadRequestError e) {
        throw new ActivityCompletionFailureException(task, e);
    } catch (TException e) {
        log.warn("Failure heartbeating on activityID=" + task.getActivityId() + " of Workflow=" + task.getWorkflowExecution(), e);
    // Not rethrowing to not fail activity implementation on intermittent connection or Cadence errors.
    }
}
Also used : ActivityNotExistsException(com.uber.cadence.client.ActivityNotExistsException) TException(org.apache.thrift.TException) ActivityCancelledException(com.uber.cadence.client.ActivityCancelledException) RecordActivityTaskHeartbeatResponse(com.uber.cadence.RecordActivityTaskHeartbeatResponse) ActivityCompletionFailureException(com.uber.cadence.client.ActivityCompletionFailureException) RecordActivityTaskHeartbeatRequest(com.uber.cadence.RecordActivityTaskHeartbeatRequest) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) BadRequestError(com.uber.cadence.BadRequestError)

Example 2 with BadRequestError

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

the class TestWorkflowMutableStateImpl method processCompleteWorkflowExecution.

private void processCompleteWorkflowExecution(RequestContext ctx, CompleteWorkflowExecutionDecisionAttributes d, long decisionTaskCompletedId) throws InternalServiceError {
    workflow.action(StateMachines.Action.COMPLETE, ctx, d, decisionTaskCompletedId);
    if (parent.isPresent()) {
        // unlocked by the parent
        ctx.lockTimer();
        ChildWorkflowExecutionCompletedEventAttributes a = new ChildWorkflowExecutionCompletedEventAttributes().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 entityNotExistsError) {
            // 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) BadRequestError(com.uber.cadence.BadRequestError)

Example 3 with BadRequestError

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

the class TestWorkflowMutableStateImpl method update.

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

Example 4 with BadRequestError

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

the class TestWorkflowMutableStateImpl method processFailWorkflowExecution.

private void processFailWorkflowExecution(RequestContext ctx, FailWorkflowExecutionDecisionAttributes d, long decisionTaskCompletedId) throws InternalServiceError {
    workflow.action(StateMachines.Action.FAIL, ctx, d, decisionTaskCompletedId);
    if (parent.isPresent()) {
        // unlocked by the parent
        ctx.lockTimer();
        ChildWorkflowExecutionFailedEventAttributes a = new ChildWorkflowExecutionFailedEventAttributes().setDetails(d.getDetails()).setReason(d.getReason()).setWorkflowType(startRequest.getWorkflowType()).setDomain(ctx.getDomain()).setWorkflowExecution(ctx.getExecution());
        ForkJoinPool.commonPool().execute(() -> {
            try {
                parent.get().childWorklfowFailed(ctx.getExecutionId().getWorkflowId().getWorkflowId(), a);
            } catch (EntityNotExistsError entityNotExistsError) {
            // Parent might already close
            } catch (BadRequestError | InternalServiceError e) {
                log.error("Failure reporting child completion", e);
            }
        });
    }
}
Also used : InternalServiceError(com.uber.cadence.InternalServiceError) StartChildWorkflowExecutionFailedEventAttributes(com.uber.cadence.StartChildWorkflowExecutionFailedEventAttributes) ChildWorkflowExecutionFailedEventAttributes(com.uber.cadence.ChildWorkflowExecutionFailedEventAttributes) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) BadRequestError(com.uber.cadence.BadRequestError)

Example 5 with BadRequestError

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

the class TestWorkflowMutableStateImpl method processCancelWorkflowExecution.

private void processCancelWorkflowExecution(RequestContext ctx, CancelWorkflowExecutionDecisionAttributes d, long decisionTaskCompletedId) throws InternalServiceError {
    workflow.action(StateMachines.Action.CANCEL, ctx, d, decisionTaskCompletedId);
    if (parent.isPresent()) {
        // unlocked by the parent
        ctx.lockTimer();
        ChildWorkflowExecutionCanceledEventAttributes a = new ChildWorkflowExecutionCanceledEventAttributes().setDetails(d.getDetails()).setDomain(ctx.getDomain()).setWorkflowExecution(ctx.getExecution()).setWorkflowType(startRequest.getWorkflowType());
        ForkJoinPool.commonPool().execute(() -> {
            try {
                parent.get().childWorkflowCanceled(ctx.getExecutionId().getWorkflowId().getWorkflowId(), a);
            } catch (EntityNotExistsError entityNotExistsError) {
            // Parent might already close
            } catch (BadRequestError | InternalServiceError e) {
                log.error("Failure reporting child completion", e);
            }
        });
    }
}
Also used : InternalServiceError(com.uber.cadence.InternalServiceError) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) BadRequestError(com.uber.cadence.BadRequestError) ChildWorkflowExecutionCanceledEventAttributes(com.uber.cadence.ChildWorkflowExecutionCanceledEventAttributes)

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