Search in sources :

Example 6 with InternalServiceError

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

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

the class TestWorkflowMutableStateImpl method query.

@Override
public QueryWorkflowResponse query(QueryWorkflowRequest queryRequest) throws TException {
    QueryId queryId = new QueryId(executionId);
    PollForDecisionTaskResponse task = new PollForDecisionTaskResponse().setTaskToken(queryId.toBytes()).setWorkflowExecution(executionId.getExecution()).setWorkflowType(startRequest.getWorkflowType()).setQuery(queryRequest.getQuery());
    TaskListId taskListId = new TaskListId(queryRequest.getDomain(), startRequest.getTaskList().getName());
    store.sendQueryTask(executionId, taskListId, task);
    CompletableFuture<QueryWorkflowResponse> result = new CompletableFuture<>();
    queries.put(queryId.getQueryId(), result);
    try {
        return result.get();
    } catch (InterruptedException e) {
        return new QueryWorkflowResponse();
    } catch (ExecutionException e) {
        Throwable cause = e.getCause();
        if (cause instanceof TException) {
            throw (TException) cause;
        }
        throw new InternalServiceError(Throwables.getStackTraceAsString(cause));
    }
}
Also used : TException(org.apache.thrift.TException) CompletableFuture(java.util.concurrent.CompletableFuture) QueryWorkflowResponse(com.uber.cadence.QueryWorkflowResponse) TaskListId(com.uber.cadence.internal.testservice.TestWorkflowStore.TaskListId) PollForDecisionTaskResponse(com.uber.cadence.PollForDecisionTaskResponse) InternalServiceError(com.uber.cadence.InternalServiceError) ExecutionException(java.util.concurrent.ExecutionException)

Example 8 with InternalServiceError

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

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

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

Aggregations

InternalServiceError (com.uber.cadence.InternalServiceError)17 EntityNotExistsError (com.uber.cadence.EntityNotExistsError)10 IOException (java.io.IOException)8 BadRequestError (com.uber.cadence.BadRequestError)7 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 DataInputStream (java.io.DataInputStream)3 DataOutputStream (java.io.DataOutputStream)3 ExecutionException (java.util.concurrent.ExecutionException)3 TException (org.apache.thrift.TException)3 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 DecisionTaskStartedEventAttributes (com.uber.cadence.DecisionTaskStartedEventAttributes)1 GetWorkflowExecutionHistoryRequest (com.uber.cadence.GetWorkflowExecutionHistoryRequest)1 History (com.uber.cadence.History)1 HistoryEvent (com.uber.cadence.HistoryEvent)1