Search in sources :

Example 11 with WorkflowExecutionAlreadyCompletedError

use of com.uber.cadence.WorkflowExecutionAlreadyCompletedError 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().setInitiatedEventId(parentChildInitiatedEventId.getAsLong()).setTimeoutType(TimeoutType.START_TO_CLOSE).setWorkflowType(startRequest.getWorkflowType()).setDomain(ctx.getDomain()).setWorkflowExecution(ctx.getExecution());
        parent.get().childWorkflowTimedOut(ctx.getExecutionId().getWorkflowId().getWorkflowId(), a);
    } catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) {
    // 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) WorkflowExecutionAlreadyCompletedError(com.uber.cadence.WorkflowExecutionAlreadyCompletedError) BadRequestError(com.uber.cadence.BadRequestError) ChildWorkflowExecutionTimedOutEventAttributes(com.uber.cadence.ChildWorkflowExecutionTimedOutEventAttributes)

Example 12 with WorkflowExecutionAlreadyCompletedError

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

the class TestWorkflowMutableStateImpl method startWorkflow.

@Override
public void startWorkflow(boolean continuedAsNew, Optional<SignalWorkflowExecutionRequest> signalWithStartSignal) throws InternalServiceError, BadRequestError {
    try {
        update(ctx -> {
            workflow.action(StateMachines.Action.START, ctx, startRequest, 0);
            if (signalWithStartSignal.isPresent()) {
                addExecutionSignaledEvent(ctx, signalWithStartSignal.get());
            }
            int backoffStartIntervalInSeconds = workflow.getData().backoffStartIntervalInSeconds;
            if (backoffStartIntervalInSeconds > 0) {
                ctx.addTimer(backoffStartIntervalInSeconds, () -> {
                    try {
                        update(ctx1 -> scheduleDecision(ctx1));
                    } catch (EntityNotExistsError e) {
                    // Expected as timers are not removed
                    } catch (Exception e) {
                        // Cannot fail to timer threads
                        log.error("Failure trying to add task for an delayed workflow retry", e);
                    }
                }, "delayedFirstDecision");
            } else {
                scheduleDecision(ctx);
            }
            int executionTimeoutTimerDelay = startRequest.getExecutionStartToCloseTimeoutSeconds();
            if (backoffStartIntervalInSeconds > 0) {
                executionTimeoutTimerDelay = executionTimeoutTimerDelay + backoffStartIntervalInSeconds;
            }
            ctx.addTimer(executionTimeoutTimerDelay, this::timeoutWorkflow, "workflow execution timeout");
        });
    } catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) {
        throw new InternalServiceError(Throwables.getStackTraceAsString(e));
    }
    if (!continuedAsNew && parent.isPresent()) {
        ChildWorkflowExecutionStartedEventAttributes a = new ChildWorkflowExecutionStartedEventAttributes().setInitiatedEventId(parentChildInitiatedEventId.getAsLong()).setWorkflowExecution(getExecutionId().getExecution()).setDomain(getExecutionId().getDomain()).setWorkflowType(startRequest.getWorkflowType());
        ForkJoinPool.commonPool().execute(() -> {
            try {
                parent.get().childWorkflowStarted(a);
            } catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) {
            // 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) 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 13 with WorkflowExecutionAlreadyCompletedError

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

the class WorkflowStubImpl method mapToWorkflowFailureException.

private <R> R mapToWorkflowFailureException(Exception failure, @SuppressWarnings("unused") Class<R> returnType) {
    failure = CheckedExceptionWrapper.unwrap(failure);
    Class<Throwable> detailsClass;
    if (failure instanceof WorkflowExecutionFailedException) {
        WorkflowExecutionFailedException executionFailed = (WorkflowExecutionFailedException) failure;
        try {
            @SuppressWarnings("unchecked") Class<Throwable> dc = (Class<Throwable>) Class.forName(executionFailed.getReason());
            detailsClass = dc;
        } catch (Exception e) {
            RuntimeException ee = new RuntimeException("Couldn't deserialize failure cause " + "as the reason field is expected to contain an exception class name", executionFailed);
            throw new WorkflowFailureException(execution.get(), workflowType, executionFailed.getDecisionTaskCompletedEventId(), ee);
        }
        Throwable cause = dataConverter.fromData(executionFailed.getDetails(), detailsClass, detailsClass);
        throw new WorkflowFailureException(execution.get(), workflowType, executionFailed.getDecisionTaskCompletedEventId(), cause);
    } else if (failure instanceof EntityNotExistsError) {
        throw new WorkflowNotFoundException(execution.get(), workflowType, failure.getMessage());
    } else if (failure instanceof WorkflowExecutionAlreadyCompletedError) {
        throw new WorkflowAlreadyCompletedException(execution.get(), workflowType, failure.getMessage());
    } else if (failure instanceof CancellationException) {
        throw (CancellationException) failure;
    } else if (failure instanceof WorkflowException) {
        throw (WorkflowException) failure;
    } else {
        throw new WorkflowServiceException(execution.get(), workflowType, failure);
    }
}
Also used : WorkflowExecutionFailedException(com.uber.cadence.internal.common.WorkflowExecutionFailedException) DataConverterException(com.uber.cadence.converter.DataConverterException) TimeoutException(java.util.concurrent.TimeoutException) CancellationException(java.util.concurrent.CancellationException) CompletionException(java.util.concurrent.CompletionException) WorkflowExecutionFailedException(com.uber.cadence.internal.common.WorkflowExecutionFailedException) CancellationException(java.util.concurrent.CancellationException) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) WorkflowExecutionAlreadyCompletedError(com.uber.cadence.WorkflowExecutionAlreadyCompletedError)

Example 14 with WorkflowExecutionAlreadyCompletedError

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

the class ActivityExecutionContextImpl method sendHeartbeatRequest.

private void sendHeartbeatRequest(Object details) throws TException {
    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()) {
            lastException = new ActivityCancelledException(task);
        } else {
            lastException = null;
        }
    } catch (EntityNotExistsError e) {
        lastException = new ActivityNotExistsException(task, e);
    } catch (WorkflowExecutionAlreadyCompletedError e) {
        throw new ActivityNotExistsException(task, e);
    } catch (BadRequestError e) {
        lastException = new ActivityCompletionFailureException(task, e);
    }
}
Also used : ActivityNotExistsException(com.uber.cadence.client.ActivityNotExistsException) 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) WorkflowExecutionAlreadyCompletedError(com.uber.cadence.WorkflowExecutionAlreadyCompletedError) BadRequestError(com.uber.cadence.BadRequestError)

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