Search in sources :

Example 16 with InternalServiceError

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

the class ExecutionId method fromBytes.

static ExecutionId fromBytes(byte[] serialized) throws InternalServiceError {
    ByteArrayInputStream bin = new ByteArrayInputStream(serialized);
    DataInputStream in = new DataInputStream(bin);
    try {
        return readFromBytes(in);
    } 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)

Example 17 with InternalServiceError

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

the class StateMachines method startDecisionTask.

private static void startDecisionTask(RequestContext ctx, DecisionTaskData data, PollForDecisionTaskRequest request, long notUsed) {
    DecisionTaskStartedEventAttributes a = new DecisionTaskStartedEventAttributes().setIdentity(request.getIdentity()).setScheduledEventId(data.scheduledEventId);
    HistoryEvent event = new HistoryEvent().setEventType(EventType.DecisionTaskStarted).setDecisionTaskStartedEventAttributes(a);
    long startedEventId = ctx.addEvent(event);
    ctx.onCommit((historySize) -> {
        data.decisionTask.setStartedEventId(startedEventId);
        DecisionTaskToken taskToken = new DecisionTaskToken(ctx.getExecutionId(), historySize);
        data.decisionTask.setTaskToken(taskToken.toBytes());
        GetWorkflowExecutionHistoryRequest getRequest = new GetWorkflowExecutionHistoryRequest().setDomain(request.getDomain()).setExecution(ctx.getExecution());
        List<HistoryEvent> events;
        try {
            events = data.store.getWorkflowExecutionHistory(ctx.getExecutionId(), getRequest).getHistory().getEvents();
        } catch (EntityNotExistsError entityNotExistsError) {
            throw new InternalServiceError(entityNotExistsError.toString());
        }
        data.decisionTask.setHistory(new History().setEvents(events));
        data.previousStartedEventId = startedEventId;
        data.attempt++;
    });
}
Also used : DecisionTaskStartedEventAttributes(com.uber.cadence.DecisionTaskStartedEventAttributes) GetWorkflowExecutionHistoryRequest(com.uber.cadence.GetWorkflowExecutionHistoryRequest) InternalServiceError(com.uber.cadence.InternalServiceError) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) HistoryEvent(com.uber.cadence.HistoryEvent) History(com.uber.cadence.History)

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