Search in sources :

Example 16 with EntityNotExistsError

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

the class WorkflowExecutionUtils method getInstanceCloseEvent.

/**
 * Returns an instance closing event, potentially waiting for workflow to complete.
 */
public static HistoryEvent getInstanceCloseEvent(IWorkflowService service, String domain, WorkflowExecution workflowExecution, long timeout, TimeUnit unit) throws TimeoutException, EntityNotExistsError {
    byte[] pageToken = null;
    GetWorkflowExecutionHistoryResponse response;
    // TODO: Interrupt service long poll call on timeout and on interrupt
    long start = System.currentTimeMillis();
    HistoryEvent event;
    do {
        GetWorkflowExecutionHistoryRequest r = new GetWorkflowExecutionHistoryRequest();
        r.setDomain(domain);
        r.setExecution(workflowExecution);
        r.setHistoryEventFilterType(HistoryEventFilterType.CLOSE_EVENT);
        r.setNextPageToken(pageToken);
        try {
            response = Retryer.retryWithResult(retryParameters, () -> service.GetWorkflowExecutionHistory(r));
        } catch (EntityNotExistsError e) {
            throw e;
        } catch (TException e) {
            throw CheckedExceptionWrapper.wrap(e);
        }
        if (timeout != 0 && System.currentTimeMillis() - start > unit.toMillis(timeout)) {
            throw new TimeoutException("WorkflowId=" + workflowExecution.getWorkflowId() + ", runId=" + workflowExecution.getRunId() + ", timeout=" + timeout + ", unit=" + unit);
        }
        pageToken = response.getNextPageToken();
        History history = response.getHistory();
        if (history != null && history.getEvents().size() > 0) {
            event = history.getEvents().get(0);
            if (!isWorkflowExecutionCompletedEvent(event)) {
                throw new RuntimeException("Last history event is not completion event: " + event);
            }
            // Workflow called continueAsNew. Start polling the new generation with new runId.
            if (event.getEventType() == EventType.WorkflowExecutionContinuedAsNew) {
                pageToken = null;
                workflowExecution = new WorkflowExecution().setWorkflowId(workflowExecution.getWorkflowId()).setRunId(event.getWorkflowExecutionContinuedAsNewEventAttributes().getNewExecutionRunId());
                continue;
            }
            break;
        }
    } while (true);
    return event;
}
Also used : TException(org.apache.thrift.TException) GetWorkflowExecutionHistoryRequest(com.uber.cadence.GetWorkflowExecutionHistoryRequest) WorkflowExecution(com.uber.cadence.WorkflowExecution) GetWorkflowExecutionHistoryResponse(com.uber.cadence.GetWorkflowExecutionHistoryResponse) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) HistoryEvent(com.uber.cadence.HistoryEvent) History(com.uber.cadence.History) TimeoutException(java.util.concurrent.TimeoutException)

Example 17 with EntityNotExistsError

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

the class ManualActivityCompletionClientImpl method fail.

@Override
public void fail(Throwable failure) {
    if (failure == null) {
        throw new IllegalArgumentException("null failure");
    }
    // When converting failures reason is class name, details are serialized exception.
    if (taskToken != null) {
        RespondActivityTaskFailedRequest request = new RespondActivityTaskFailedRequest();
        request.setReason(failure.getClass().getName());
        request.setDetails(dataConverter.toData(failure));
        request.setTaskToken(taskToken);
        try {
            service.RespondActivityTaskFailed(request);
        } catch (EntityNotExistsError e) {
            throw new ActivityNotExistsException(e);
        } catch (TException e) {
            throw new ActivityCompletionFailureException(e);
        }
    } else {
        RespondActivityTaskFailedByIDRequest request = new RespondActivityTaskFailedByIDRequest();
        request.setReason(failure.getClass().getName());
        request.setDetails(dataConverter.toData(failure));
        request.setDomain(domain);
        request.setWorkflowID(execution.getWorkflowId());
        request.setRunID(execution.getRunId());
        try {
            service.RespondActivityTaskFailedByID(request);
        } catch (EntityNotExistsError e) {
            throw new ActivityNotExistsException(e);
        } catch (TException e) {
            throw new ActivityCompletionFailureException(activityId, e);
        }
    }
}
Also used : ActivityNotExistsException(com.uber.cadence.client.ActivityNotExistsException) TException(org.apache.thrift.TException) RespondActivityTaskFailedByIDRequest(com.uber.cadence.RespondActivityTaskFailedByIDRequest) ActivityCompletionFailureException(com.uber.cadence.client.ActivityCompletionFailureException) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) RespondActivityTaskFailedRequest(com.uber.cadence.RespondActivityTaskFailedRequest)

Example 18 with EntityNotExistsError

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

the class ManualActivityCompletionClientImpl method complete.

@Override
public void complete(Object result) {
    if (taskToken != null) {
        RespondActivityTaskCompletedRequest request = new RespondActivityTaskCompletedRequest();
        byte[] convertedResult = dataConverter.toData(result);
        request.setResult(convertedResult);
        request.setTaskToken(taskToken);
        try {
            service.RespondActivityTaskCompleted(request);
        } catch (EntityNotExistsError e) {
            throw new ActivityNotExistsException(e);
        } catch (TException e) {
            throw new ActivityCompletionFailureException(e);
        }
    } else {
        if (activityId == null) {
            throw new IllegalArgumentException("Either activity id or task token are required");
        }
        RespondActivityTaskCompletedByIDRequest request = new RespondActivityTaskCompletedByIDRequest();
        request.setActivityID(activityId);
        byte[] convertedResult = dataConverter.toData(result);
        request.setResult(convertedResult);
        request.setDomain(domain);
        request.setWorkflowID(execution.getWorkflowId());
        request.setRunID(execution.getRunId());
        try {
            service.RespondActivityTaskCompletedByID(request);
        } catch (EntityNotExistsError e) {
            throw new ActivityNotExistsException(e);
        } catch (TException e) {
            throw new ActivityCompletionFailureException(activityId, e);
        }
    }
}
Also used : ActivityNotExistsException(com.uber.cadence.client.ActivityNotExistsException) TException(org.apache.thrift.TException) RespondActivityTaskCompletedByIDRequest(com.uber.cadence.RespondActivityTaskCompletedByIDRequest) RespondActivityTaskCompletedRequest(com.uber.cadence.RespondActivityTaskCompletedRequest) ActivityCompletionFailureException(com.uber.cadence.client.ActivityCompletionFailureException) EntityNotExistsError(com.uber.cadence.EntityNotExistsError)

Example 19 with EntityNotExistsError

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

the class ManualActivityCompletionClientImpl method recordHeartbeat.

@Override
public void recordHeartbeat(Object details) throws CancellationException {
    if (taskToken != null) {
        RecordActivityTaskHeartbeatRequest request = new RecordActivityTaskHeartbeatRequest();
        request.setDetails(dataConverter.toData(details));
        request.setTaskToken(taskToken);
        RecordActivityTaskHeartbeatResponse status = null;
        try {
            status = service.RecordActivityTaskHeartbeat(request);
            if (status.isCancelRequested()) {
                throw new ActivityCancelledException();
            }
        } catch (EntityNotExistsError e) {
            throw new ActivityNotExistsException(e);
        } catch (TException e) {
            throw new ActivityCompletionFailureException(e);
        }
    } else {
        throw new UnsupportedOperationException("Heartbeating by id is not implemented by Cadence service yet.");
    }
}
Also used : ActivityNotExistsException(com.uber.cadence.client.ActivityNotExistsException) TException(org.apache.thrift.TException) ActivityCancelledException(com.uber.cadence.client.ActivityCancelledException) RecordActivityTaskHeartbeatResponse(com.uber.cadence.RecordActivityTaskHeartbeatResponse) ActivityCompletionFailureException(com.uber.cadence.client.ActivityCompletionFailureException) RecordActivityTaskHeartbeatRequest(com.uber.cadence.RecordActivityTaskHeartbeatRequest) EntityNotExistsError(com.uber.cadence.EntityNotExistsError)

Aggregations

EntityNotExistsError (com.uber.cadence.EntityNotExistsError)19 InternalServiceError (com.uber.cadence.InternalServiceError)10 BadRequestError (com.uber.cadence.BadRequestError)8 TException (org.apache.thrift.TException)7 ActivityCompletionFailureException (com.uber.cadence.client.ActivityCompletionFailureException)4 ActivityNotExistsException (com.uber.cadence.client.ActivityNotExistsException)4 RecordActivityTaskHeartbeatResponse (com.uber.cadence.RecordActivityTaskHeartbeatResponse)3 TimeoutException (java.util.concurrent.TimeoutException)3 GetWorkflowExecutionHistoryRequest (com.uber.cadence.GetWorkflowExecutionHistoryRequest)2 History (com.uber.cadence.History)2 HistoryEvent (com.uber.cadence.HistoryEvent)2 QueryFailedError (com.uber.cadence.QueryFailedError)2 RecordActivityTaskHeartbeatRequest (com.uber.cadence.RecordActivityTaskHeartbeatRequest)2 ActivityCancelledException (com.uber.cadence.client.ActivityCancelledException)2 DuplicateWorkflowException (com.uber.cadence.client.DuplicateWorkflowException)2 WorkflowException (com.uber.cadence.client.WorkflowException)2 WorkflowFailureException (com.uber.cadence.client.WorkflowFailureException)2 WorkflowNotFoundException (com.uber.cadence.client.WorkflowNotFoundException)2 WorkflowQueryException (com.uber.cadence.client.WorkflowQueryException)2 WorkflowServiceException (com.uber.cadence.client.WorkflowServiceException)2