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);
}
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);
}
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);
}
}
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);
}
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;
}
Aggregations