Search in sources :

Example 6 with EntityNotExistsError

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

the class WorkflowStubImpl method query.

@Override
public <R> R query(String queryType, Class<R> returnType, Object... args) {
    checkStarted();
    QueryWorkflowParameters p = new QueryWorkflowParameters();
    p.setInput(dataConverter.toData(args));
    p.setQueryType(queryType);
    p.setWorkflowId(execution.get().getWorkflowId());
    try {
        byte[] result = genericClient.queryWorkflow(p);
        return dataConverter.fromData(result, returnType);
    } catch (RuntimeException e) {
        Exception unwrapped = CheckedExceptionWrapper.unwrap(e);
        if (unwrapped instanceof EntityNotExistsError) {
            throw new WorkflowNotFoundException(execution.get(), workflowType, e.getMessage());
        }
        if (unwrapped instanceof QueryFailedError) {
            throw new WorkflowQueryException(execution.get(), unwrapped.getMessage());
        }
        if (unwrapped instanceof InternalServiceError) {
            throw new WorkflowServiceException(execution.get(), workflowType, unwrapped);
        }
        throw e;
    }
}
Also used : WorkflowNotFoundException(com.uber.cadence.client.WorkflowNotFoundException) InternalServiceError(com.uber.cadence.InternalServiceError) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) QueryFailedError(com.uber.cadence.QueryFailedError) QueryWorkflowParameters(com.uber.cadence.internal.replay.QueryWorkflowParameters) 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) WorkflowQueryException(com.uber.cadence.client.WorkflowQueryException) WorkflowServiceException(com.uber.cadence.client.WorkflowServiceException)

Example 7 with EntityNotExistsError

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

Example 8 with EntityNotExistsError

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

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

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

the class TestWorkflowMutableStateImpl method heartbeatActivityTask.

@Override
public RecordActivityTaskHeartbeatResponse heartbeatActivityTask(String activityId, RecordActivityTaskHeartbeatRequest request) throws InternalServiceError, EntityNotExistsError, BadRequestError {
    RecordActivityTaskHeartbeatResponse result = new RecordActivityTaskHeartbeatResponse();
    try {
        update(ctx -> {
            StateMachine<ActivityTaskData> activity = getActivity(activityId);
            activity.action(StateMachines.Action.UPDATE, ctx, request, 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 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) 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)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