Search in sources :

Example 1 with EntityNotExistsError

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

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

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

the class TestWorkflowMutableStateImpl method completeQuery.

@Override
public void completeQuery(QueryId queryId, RespondQueryTaskCompletedRequest completeRequest) throws EntityNotExistsError {
    CompletableFuture<QueryWorkflowResponse> result = queries.get(queryId.getQueryId());
    if (result == null) {
        throw new EntityNotExistsError("Unknown query id: " + queryId.getQueryId());
    }
    if (completeRequest.getCompletedType() == QueryTaskCompletedType.COMPLETED) {
        QueryWorkflowResponse response = new QueryWorkflowResponse().setQueryResult(completeRequest.getQueryResult());
        result.complete(response);
    } else {
        QueryFailedError error = new QueryFailedError().setMessage(completeRequest.getErrorMessage());
        result.completeExceptionally(error);
    }
}
Also used : QueryWorkflowResponse(com.uber.cadence.QueryWorkflowResponse) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) QueryFailedError(com.uber.cadence.QueryFailedError)

Example 4 with EntityNotExistsError

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

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

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