Search in sources :

Example 26 with HistoryEvent

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

the class WorkflowWorker method queryWorkflowExecution.

public byte[] queryWorkflowExecution(WorkflowExecution execution, String queryType, byte[] args) throws Exception {
    Iterator<HistoryEvent> history = WorkflowExecutionUtils.getHistory(service, domain, execution);
    DecisionTaskWithHistoryIterator historyIterator = new ReplayDecisionTaskWithHistoryIterator(execution, history);
    WorkflowQuery query = new WorkflowQuery();
    query.setQueryType(queryType).setQueryArgs(args);
    historyIterator.getDecisionTask().setQuery(query);
    DecisionTaskHandler.Result result = handler.handleDecisionTask(historyIterator);
    if (result.getQueryCompleted() != null) {
        RespondQueryTaskCompletedRequest r = result.getQueryCompleted();
        return r.getQueryResult();
    }
    throw new RuntimeException("Query returned wrong response: " + result);
}
Also used : WorkflowQuery(com.uber.cadence.WorkflowQuery) RespondQueryTaskCompletedRequest(com.uber.cadence.RespondQueryTaskCompletedRequest) HistoryEvent(com.uber.cadence.HistoryEvent)

Example 27 with HistoryEvent

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

the class TestWorkflowMutableStateImpl method processCancelTimer.

private void processCancelTimer(RequestContext ctx, CancelTimerDecisionAttributes d, long decisionTaskCompletedId) throws InternalServiceError {
    String timerId = d.getTimerId();
    StateMachine<TimerData> timer = timers.get(timerId);
    if (timer == null) {
        CancelTimerFailedEventAttributes failedAttr = new CancelTimerFailedEventAttributes().setTimerId(timerId).setCause("TIMER_ID_UNKNOWN").setDecisionTaskCompletedEventId(decisionTaskCompletedId);
        HistoryEvent cancellationFailed = new HistoryEvent().setEventType(EventType.CancelTimerFailed).setCancelTimerFailedEventAttributes(failedAttr);
        ctx.addEvent(cancellationFailed);
        return;
    }
    timer.action(StateMachines.Action.CANCEL, ctx, d, decisionTaskCompletedId);
    timers.remove(timerId);
}
Also used : TimerData(com.uber.cadence.internal.testservice.StateMachines.TimerData) CancelTimerFailedEventAttributes(com.uber.cadence.CancelTimerFailedEventAttributes) HistoryEvent(com.uber.cadence.HistoryEvent)

Example 28 with HistoryEvent

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

the class TestWorkflowMutableStateImpl method processRequestCancelActivityTask.

private void processRequestCancelActivityTask(RequestContext ctx, RequestCancelActivityTaskDecisionAttributes a, long decisionTaskCompletedId) throws InternalServiceError {
    String activityId = a.getActivityId();
    StateMachine<?> activity = activities.get(activityId);
    if (activity == null) {
        RequestCancelActivityTaskFailedEventAttributes failedAttr = new RequestCancelActivityTaskFailedEventAttributes().setActivityId(activityId).setCause("ACTIVITY_ID_UNKNOWN").setDecisionTaskCompletedEventId(decisionTaskCompletedId);
        HistoryEvent cancellationFailed = new HistoryEvent().setEventType(EventType.RequestCancelActivityTaskFailed).setRequestCancelActivityTaskFailedEventAttributes(failedAttr);
        ctx.addEvent(cancellationFailed);
        return;
    }
    State beforeState = activity.getState();
    activity.action(StateMachines.Action.REQUEST_CANCELLATION, ctx, a, decisionTaskCompletedId);
    if (beforeState == StateMachines.State.INITIATED) {
        activity.action(StateMachines.Action.CANCEL, ctx, null, 0);
        activities.remove(activityId);
        ctx.setNeedDecision(true);
    }
}
Also used : State(com.uber.cadence.internal.testservice.StateMachines.State) HistoryEvent(com.uber.cadence.HistoryEvent) RequestCancelActivityTaskFailedEventAttributes(com.uber.cadence.RequestCancelActivityTaskFailedEventAttributes)

Example 29 with HistoryEvent

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

the class TestWorkflowMutableStateImpl method processContinueAsNewWorkflowExecution.

private void processContinueAsNewWorkflowExecution(RequestContext ctx, ContinueAsNewWorkflowExecutionDecisionAttributes d, long decisionTaskCompletedId, String identity) throws InternalServiceError, BadRequestError {
    workflow.action(Action.CONTINUE_AS_NEW, ctx, d, decisionTaskCompletedId);
    HistoryEvent event = ctx.getEvents().get(ctx.getEvents().size() - 1);
    String runId = service.continueAsNew(startRequest, event.getWorkflowExecutionContinuedAsNewEventAttributes(), identity, getExecutionId(), parent);
    event.getWorkflowExecutionContinuedAsNewEventAttributes().setNewExecutionRunId(runId);
}
Also used : HistoryEvent(com.uber.cadence.HistoryEvent)

Example 30 with HistoryEvent

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

the class TestWorkflowStoreImpl method getWorkflowExecutionHistory.

@Override
public GetWorkflowExecutionHistoryResponse getWorkflowExecutionHistory(ExecutionId executionId, GetWorkflowExecutionHistoryRequest getRequest) throws EntityNotExistsError {
    HistoryStore history;
    // Used to eliminate the race condition on waitForNewEvents
    long expectedNextEventId;
    lock.lock();
    try {
        history = getHistoryStore(executionId);
        if (!getRequest.isWaitForNewEvent() && getRequest.getHistoryEventFilterType() != HistoryEventFilterType.CLOSE_EVENT) {
            List<HistoryEvent> events = history.getEventsLocked();
            // Copy the list as it is mutable. Individual events assumed immutable.
            ArrayList<HistoryEvent> eventsCopy = new ArrayList<>(events);
            return new GetWorkflowExecutionHistoryResponse().setHistory(new History().setEvents(eventsCopy));
        }
        expectedNextEventId = history.getNextEventIdLocked();
    } finally {
        lock.unlock();
    }
    List<HistoryEvent> events = history.waitForNewEvents(expectedNextEventId, getRequest.getHistoryEventFilterType());
    GetWorkflowExecutionHistoryResponse result = new GetWorkflowExecutionHistoryResponse();
    if (events != null) {
        result.setHistory(new History().setEvents(events));
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) GetWorkflowExecutionHistoryResponse(com.uber.cadence.GetWorkflowExecutionHistoryResponse) HistoryEvent(com.uber.cadence.HistoryEvent) History(com.uber.cadence.History)

Aggregations

HistoryEvent (com.uber.cadence.HistoryEvent)49 History (com.uber.cadence.History)5 WorkflowExecution (com.uber.cadence.WorkflowExecution)5 GetWorkflowExecutionHistoryRequest (com.uber.cadence.GetWorkflowExecutionHistoryRequest)4 GetWorkflowExecutionHistoryResponse (com.uber.cadence.GetWorkflowExecutionHistoryResponse)3 SignalExternalWorkflowExecutionInitiatedEventAttributes (com.uber.cadence.SignalExternalWorkflowExecutionInitiatedEventAttributes)3 ActivityTaskCompletedEventAttributes (com.uber.cadence.ActivityTaskCompletedEventAttributes)2 ActivityTaskFailedEventAttributes (com.uber.cadence.ActivityTaskFailedEventAttributes)2 ChildWorkflowExecutionTimedOutEventAttributes (com.uber.cadence.ChildWorkflowExecutionTimedOutEventAttributes)2 EntityNotExistsError (com.uber.cadence.EntityNotExistsError)2 PollForActivityTaskResponse (com.uber.cadence.PollForActivityTaskResponse)2 PollForDecisionTaskResponse (com.uber.cadence.PollForDecisionTaskResponse)2 SignalExternalWorkflowExecutionFailedEventAttributes (com.uber.cadence.SignalExternalWorkflowExecutionFailedEventAttributes)2 StartChildWorkflowExecutionInitiatedEventAttributes (com.uber.cadence.StartChildWorkflowExecutionInitiatedEventAttributes)2 StartWorkflowExecutionRequest (com.uber.cadence.StartWorkflowExecutionRequest)2 WorkflowExecutionContinuedAsNewEventAttributes (com.uber.cadence.WorkflowExecutionContinuedAsNewEventAttributes)2 WorkflowExecutionSignaledEventAttributes (com.uber.cadence.WorkflowExecutionSignaledEventAttributes)2 WorkflowExecutionStartedEventAttributes (com.uber.cadence.WorkflowExecutionStartedEventAttributes)2 TaskListId (com.uber.cadence.internal.testservice.TestWorkflowStore.TaskListId)2 ArrayList (java.util.ArrayList)2