use of com.uber.cadence.EntityNotExistsError 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();
}
}
use of com.uber.cadence.EntityNotExistsError in project cadence-client by uber-java.
the class TestWorkflowService method PollForActivityTask.
@Override
public PollForActivityTaskResponse PollForActivityTask(PollForActivityTaskRequest pollRequest) throws BadRequestError, InternalServiceError, ServiceBusyError, TException {
PollForActivityTaskResponse task;
while (true) {
try {
task = store.pollForActivityTask(pollRequest);
} catch (InterruptedException e) {
return new PollForActivityTaskResponse();
}
ExecutionId executionId = new ExecutionId(pollRequest.getDomain(), task.getWorkflowExecution());
TestWorkflowMutableState mutableState = getMutableState(executionId);
try {
mutableState.startActivityTask(task, pollRequest);
return task;
} catch (EntityNotExistsError e) {
if (log.isDebugEnabled()) {
log.debug("Skipping outdated activity task for " + executionId, e);
}
}
}
}
use of com.uber.cadence.EntityNotExistsError in project cadence-client by uber-java.
the class TestWorkflowService method PollForDecisionTask.
@Override
public PollForDecisionTaskResponse PollForDecisionTask(PollForDecisionTaskRequest pollRequest) throws BadRequestError, InternalServiceError, ServiceBusyError, TException {
PollForDecisionTaskResponse task;
try {
task = store.pollForDecisionTask(pollRequest);
} catch (InterruptedException e) {
return new PollForDecisionTaskResponse();
}
ExecutionId executionId = new ExecutionId(pollRequest.getDomain(), task.getWorkflowExecution());
TestWorkflowMutableState mutableState = getMutableState(executionId);
try {
mutableState.startDecisionTask(task, pollRequest);
return task;
} catch (EntityNotExistsError e) {
if (log.isDebugEnabled()) {
log.debug("Skipping outdated decision task for " + executionId, e);
}
// skip the task
}
return task;
}
use of com.uber.cadence.EntityNotExistsError 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++;
});
}
use of com.uber.cadence.EntityNotExistsError in project cadence-client by uber-java.
the class WorkflowStubImpl method mapToWorkflowFailureException.
private <R> R mapToWorkflowFailureException(Exception failure, Class<R> returnType) {
failure = CheckedExceptionWrapper.unwrap(failure);
Class<Throwable> detailsClass;
if (failure instanceof WorkflowExecutionFailedException) {
WorkflowExecutionFailedException executionFailed = (WorkflowExecutionFailedException) failure;
try {
@SuppressWarnings("unchecked") Class<Throwable> dc = (Class<Throwable>) Class.forName(executionFailed.getReason());
detailsClass = dc;
} catch (Exception e) {
RuntimeException ee = new RuntimeException("Couldn't deserialize failure cause " + "as the reason field is expected to contain an exception class name", executionFailed);
throw new WorkflowFailureException(execution.get(), workflowType, executionFailed.getDecisionTaskCompletedEventId(), ee);
}
Throwable cause = dataConverter.fromData(executionFailed.getDetails(), detailsClass);
throw new WorkflowFailureException(execution.get(), workflowType, executionFailed.getDecisionTaskCompletedEventId(), cause);
} else if (failure instanceof EntityNotExistsError) {
throw new WorkflowNotFoundException(execution.get(), workflowType, failure.getMessage());
} else if (failure instanceof CancellationException) {
throw (CancellationException) failure;
} else if (failure instanceof WorkflowException) {
throw (WorkflowException) failure;
} else {
throw new WorkflowServiceException(execution.get(), workflowType, failure);
}
}
Aggregations