Search in sources :

Example 11 with InternalServiceError

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

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

Example 13 with InternalServiceError

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

the class TestWorkflowMutableStateImpl method completeDecisionTask.

@Override
public void completeDecisionTask(int historySize, RespondDecisionTaskCompletedRequest request) throws InternalServiceError, EntityNotExistsError, BadRequestError {
    List<Decision> decisions = request.getDecisions();
    completeDecisionUpdate(ctx -> {
        if (ctx.getInitialEventId() != historySize) {
            throw new BadRequestError("Expired decision: expectedHistorySize=" + historySize + "," + " actualHistorySize=" + ctx.getInitialEventId());
        }
        long decisionTaskCompletedId = ctx.getNextEventId() - 1;
        // workflow
        if (!concurrentToDecision.isEmpty() && hasCompleteDecision(request.getDecisions())) {
            RespondDecisionTaskFailedRequest failedRequest = new RespondDecisionTaskFailedRequest().setCause(DecisionTaskFailedCause.UNHANDLED_DECISION).setIdentity(request.getIdentity());
            decision.action(Action.FAIL, ctx, failedRequest, decisionTaskCompletedId);
            for (RequestContext deferredCtx : this.concurrentToDecision) {
                ctx.add(deferredCtx);
            }
            this.concurrentToDecision.clear();
            scheduleDecision(ctx);
            return;
        }
        if (decision == null) {
            throw new EntityNotExistsError("No outstanding decision");
        }
        decision.action(StateMachines.Action.COMPLETE, ctx, request, 0);
        for (Decision d : decisions) {
            processDecision(ctx, d, request.getIdentity(), decisionTaskCompletedId);
        }
        for (RequestContext deferredCtx : this.concurrentToDecision) {
            ctx.add(deferredCtx);
        }
        this.decision = null;
        boolean completed = workflow.getState() == StateMachines.State.COMPLETED || workflow.getState() == StateMachines.State.FAILED || workflow.getState() == StateMachines.State.CANCELED;
        if (!completed && (ctx.isNeedDecision() || !this.concurrentToDecision.isEmpty())) {
            scheduleDecision(ctx);
        }
        this.concurrentToDecision.clear();
        ctx.unlockTimer();
    });
    lock.lock();
    try {
        {
            if (decision != null && decision.getState() != StateMachines.State.INITIATED) {
                throw new InternalServiceError("non null decision after the completion: " + decision.getState());
            }
        }
    } finally {
        lock.unlock();
    }
}
Also used : RespondDecisionTaskFailedRequest(com.uber.cadence.RespondDecisionTaskFailedRequest) InternalServiceError(com.uber.cadence.InternalServiceError) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) BadRequestError(com.uber.cadence.BadRequestError) Decision(com.uber.cadence.Decision)

Example 14 with InternalServiceError

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

the class ActivityId method toBytes.

/**
 * Used for task tokens.
 */
public byte[] toBytes() throws InternalServiceError {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(bout);
    try {
        out.writeUTF(executionId.getDomain());
        WorkflowExecution execution = executionId.getExecution();
        out.writeUTF(execution.getWorkflowId());
        out.writeUTF(execution.getRunId());
        out.writeUTF(id);
        return bout.toByteArray();
    } catch (IOException e) {
        throw new InternalServiceError(Throwables.getStackTraceAsString(e));
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) WorkflowExecution(com.uber.cadence.WorkflowExecution) InternalServiceError(com.uber.cadence.InternalServiceError) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 15 with InternalServiceError

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

the class DecisionTaskToken method fromBytes.

static DecisionTaskToken fromBytes(byte[] serialized) throws InternalServiceError {
    ByteArrayInputStream bin = new ByteArrayInputStream(serialized);
    DataInputStream in = new DataInputStream(bin);
    try {
        ExecutionId executionId = ExecutionId.readFromBytes(in);
        int historySize = in.readInt();
        return new DecisionTaskToken(executionId, historySize);
    } catch (IOException e) {
        throw new InternalServiceError(Throwables.getStackTraceAsString(e));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InternalServiceError(com.uber.cadence.InternalServiceError) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

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