Search in sources :

Example 6 with WorkflowExecutionAlreadyCompletedError

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

the class ManualActivityCompletionClientImpl method complete.

@Override
public void complete(Object result) {
    if (taskToken != null) {
        RespondActivityTaskCompletedRequest request = new RespondActivityTaskCompletedRequest();
        byte[] convertedResult = dataConverter.toData(result);
        request.setResult(convertedResult);
        request.setTaskToken(taskToken);
        try {
            RpcRetryer.retry(() -> service.RespondActivityTaskCompleted(request));
            metricsScope.counter(MetricsType.ACTIVITY_TASK_COMPLETED_COUNTER).inc(1);
        } catch (EntityNotExistsError e) {
            throw new ActivityNotExistsException(e);
        } catch (WorkflowExecutionAlreadyCompletedError e) {
            throw new ActivityNotExistsException(e);
        } catch (TException e) {
            throw new ActivityCompletionFailureException(e);
        }
    } else {
        if (activityId == null) {
            throw new IllegalArgumentException("Either activity id or task token are required");
        }
        RespondActivityTaskCompletedByIDRequest request = new RespondActivityTaskCompletedByIDRequest();
        request.setActivityID(activityId);
        byte[] convertedResult = dataConverter.toData(result);
        request.setResult(convertedResult);
        request.setDomain(domain);
        request.setWorkflowID(execution.getWorkflowId());
        request.setRunID(execution.getRunId());
        try {
            service.RespondActivityTaskCompletedByID(request);
            metricsScope.counter(MetricsType.ACTIVITY_TASK_COMPLETED_BY_ID_COUNTER).inc(1);
        } catch (EntityNotExistsError e) {
            throw new ActivityNotExistsException(e);
        } catch (WorkflowExecutionAlreadyCompletedError e) {
            throw new ActivityNotExistsException(e);
        } catch (TException e) {
            throw new ActivityCompletionFailureException(activityId, e);
        }
    }
}
Also used : ActivityNotExistsException(com.uber.cadence.client.ActivityNotExistsException) TException(org.apache.thrift.TException) RespondActivityTaskCompletedByIDRequest(com.uber.cadence.RespondActivityTaskCompletedByIDRequest) RespondActivityTaskCompletedRequest(com.uber.cadence.RespondActivityTaskCompletedRequest) ActivityCompletionFailureException(com.uber.cadence.client.ActivityCompletionFailureException) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) WorkflowExecutionAlreadyCompletedError(com.uber.cadence.WorkflowExecutionAlreadyCompletedError)

Example 7 with WorkflowExecutionAlreadyCompletedError

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

the class ManualActivityCompletionClientImpl method fail.

@Override
public void fail(Throwable failure) {
    if (failure == null) {
        throw new IllegalArgumentException("null failure");
    }
    // When converting failures reason is class name, details are serialized exception.
    if (taskToken != null) {
        RespondActivityTaskFailedRequest request = new RespondActivityTaskFailedRequest();
        request.setReason(failure.getClass().getName());
        request.setDetails(dataConverter.toData(failure));
        request.setTaskToken(taskToken);
        try {
            RpcRetryer.retry(() -> service.RespondActivityTaskFailed(request));
            metricsScope.counter(MetricsType.ACTIVITY_TASK_FAILED_COUNTER).inc(1);
        } catch (EntityNotExistsError e) {
            throw new ActivityNotExistsException(e);
        } catch (WorkflowExecutionAlreadyCompletedError e) {
            throw new ActivityNotExistsException(e);
        } catch (TException e) {
            throw new ActivityCompletionFailureException(e);
        }
    } else {
        RespondActivityTaskFailedByIDRequest request = new RespondActivityTaskFailedByIDRequest();
        request.setReason(failure.getClass().getName());
        request.setDetails(dataConverter.toData(failure));
        request.setDomain(domain);
        request.setWorkflowID(execution.getWorkflowId());
        request.setRunID(execution.getRunId());
        try {
            RpcRetryer.retry(() -> service.RespondActivityTaskFailedByID(request));
            metricsScope.counter(MetricsType.ACTIVITY_TASK_FAILED_BY_ID_COUNTER).inc(1);
        } catch (EntityNotExistsError e) {
            throw new ActivityNotExistsException(e);
        } catch (WorkflowExecutionAlreadyCompletedError e) {
            throw new ActivityNotExistsException(e);
        } catch (TException e) {
            throw new ActivityCompletionFailureException(activityId, e);
        }
    }
}
Also used : ActivityNotExistsException(com.uber.cadence.client.ActivityNotExistsException) TException(org.apache.thrift.TException) RespondActivityTaskFailedByIDRequest(com.uber.cadence.RespondActivityTaskFailedByIDRequest) ActivityCompletionFailureException(com.uber.cadence.client.ActivityCompletionFailureException) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) WorkflowExecutionAlreadyCompletedError(com.uber.cadence.WorkflowExecutionAlreadyCompletedError) RespondActivityTaskFailedRequest(com.uber.cadence.RespondActivityTaskFailedRequest)

Example 8 with WorkflowExecutionAlreadyCompletedError

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

the class ManualActivityCompletionClientImpl method recordHeartbeat.

@Override
public void recordHeartbeat(Object details) throws CancellationException {
    if (taskToken != null) {
        RecordActivityTaskHeartbeatRequest request = new RecordActivityTaskHeartbeatRequest();
        request.setDetails(dataConverter.toData(details));
        request.setTaskToken(taskToken);
        RecordActivityTaskHeartbeatResponse status = null;
        try {
            status = service.RecordActivityTaskHeartbeat(request);
            if (status.isCancelRequested()) {
                throw new ActivityCancelledException();
            }
        } catch (EntityNotExistsError e) {
            throw new ActivityNotExistsException(e);
        } catch (WorkflowExecutionAlreadyCompletedError e) {
            throw new ActivityNotExistsException(e);
        } catch (TException e) {
            throw new ActivityCompletionFailureException(e);
        }
    } else {
        throw new UnsupportedOperationException("Heartbeating by id is not implemented by Cadence service yet.");
    }
}
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) WorkflowExecutionAlreadyCompletedError(com.uber.cadence.WorkflowExecutionAlreadyCompletedError)

Example 9 with WorkflowExecutionAlreadyCompletedError

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

the class TestWorkflowMutableStateImpl method processCancelWorkflowExecution.

private void processCancelWorkflowExecution(RequestContext ctx, CancelWorkflowExecutionDecisionAttributes d, long decisionTaskCompletedId) throws InternalServiceError, BadRequestError {
    workflow.action(StateMachines.Action.CANCEL, ctx, d, decisionTaskCompletedId);
    if (parent.isPresent()) {
        // unlocked by the parent
        ctx.lockTimer();
        ChildWorkflowExecutionCanceledEventAttributes a = new ChildWorkflowExecutionCanceledEventAttributes().setInitiatedEventId(parentChildInitiatedEventId.getAsLong()).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 | WorkflowExecutionAlreadyCompletedError e) {
            // 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) WorkflowExecutionAlreadyCompletedError(com.uber.cadence.WorkflowExecutionAlreadyCompletedError) BadRequestError(com.uber.cadence.BadRequestError) ChildWorkflowExecutionCanceledEventAttributes(com.uber.cadence.ChildWorkflowExecutionCanceledEventAttributes)

Example 10 with WorkflowExecutionAlreadyCompletedError

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

the class TestWorkflowMutableStateImpl method addActivityRetryTimer.

private void addActivityRetryTimer(RequestContext ctx, StateMachine<ActivityTaskData> activity) {
    ActivityTaskData data = activity.getData();
    int attempt = data.retryState.getAttempt();
    ctx.addTimer(data.nextBackoffIntervalSeconds, () -> {
        // Timers are not removed, so skip if it is not for this attempt.
        if (activity.getState() != State.INITIATED && data.retryState.getAttempt() != attempt) {
            return;
        }
        selfAdvancingTimer.lockTimeSkipping("activityRetryTimer " + activity.getData().scheduledEvent.getActivityId());
        boolean unlockTimer = false;
        try {
            update(ctx1 -> ctx1.addActivityTask(data.activityTask));
        } catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) {
            unlockTimer = true;
        // Expected as timers are not removed
        } catch (Exception e) {
            unlockTimer = true;
            // Cannot fail to timer threads
            log.error("Failure trying to add task for an activity retry", e);
        } finally {
            if (unlockTimer) {
                // Allow time skipping when waiting for an activity retry
                selfAdvancingTimer.unlockTimeSkipping("activityRetryTimer " + activity.getData().scheduledEvent.getActivityId());
            }
        }
    }, "Activity Retry");
}
Also used : EntityNotExistsError(com.uber.cadence.EntityNotExistsError) WorkflowExecutionAlreadyCompletedError(com.uber.cadence.WorkflowExecutionAlreadyCompletedError) 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)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