Search in sources :

Example 1 with WorkflowExecutionAlreadyStartedError

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

the class TestWorkflowService method startWorkflowExecutionImpl.

StartWorkflowExecutionResponse startWorkflowExecutionImpl(StartWorkflowExecutionRequest startRequest, Optional<TestWorkflowMutableState> parent) throws BadRequestError, WorkflowExecutionAlreadyStartedError, InternalServiceError {
    String requestWorkflowId = requireNotNull("WorkflowId", startRequest.getWorkflowId());
    String domain = requireNotNull("Domain", startRequest.getDomain());
    WorkflowId workflowId = new WorkflowId(domain, requestWorkflowId);
    TestWorkflowMutableState running;
    lock.lock();
    try {
        running = openExecutions.get(workflowId);
    } finally {
        lock.unlock();
    }
    if (running != null) {
        WorkflowExecutionAlreadyStartedError error = new WorkflowExecutionAlreadyStartedError();
        WorkflowExecution execution = running.getExecutionId().getExecution();
        error.setMessage(String.format("Workflow execution already running. WorkflowId: %s, " + "RunId: %s", execution.getWorkflowId(), execution.getRunId()));
        error.setRunId(execution.getRunId());
        error.setStartRequestId(startRequest.getRequestId());
        throw error;
    }
    return startWorkflowExecutionNoRunningCheck(startRequest, parent, workflowId);
}
Also used : WorkflowExecutionAlreadyStartedError(com.uber.cadence.WorkflowExecutionAlreadyStartedError) WorkflowExecution(com.uber.cadence.WorkflowExecution)

Example 2 with WorkflowExecutionAlreadyStartedError

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

the class WorkflowStubImpl method startWithOptions.

private WorkflowExecution startWithOptions(WorkflowOptions o, Object... args) {
    if (execution.get() != null) {
        throw new DuplicateWorkflowException(execution.get(), workflowType.get(), "Cannot reuse a stub instance to start more than one workflow execution. The stub " + "points to already started execution.");
    }
    StartWorkflowExecutionParameters p = new StartWorkflowExecutionParameters();
    p.setTaskStartToCloseTimeoutSeconds(o.getTaskStartToCloseTimeout().getSeconds());
    if (o.getWorkflowId() == null) {
        p.setWorkflowId(UUID.randomUUID().toString());
    } else {
        p.setWorkflowId(o.getWorkflowId());
    }
    p.setExecutionStartToCloseTimeoutSeconds(o.getExecutionStartToCloseTimeout().getSeconds());
    p.setInput(dataConverter.toData(args));
    p.setWorkflowType(new WorkflowType().setName(workflowType.get()));
    p.setTaskList(o.getTaskList());
    p.setChildPolicy(o.getChildPolicy());
    try {
        execution.set(genericClient.startWorkflow(p));
    } catch (WorkflowExecutionAlreadyStartedError e) {
        execution.set(new WorkflowExecution().setWorkflowId(p.getWorkflowId()).setRunId(e.getRunId()));
        WorkflowExecution execution = new WorkflowExecution().setWorkflowId(p.getWorkflowId()).setRunId(e.getRunId());
        throw new DuplicateWorkflowException(execution, workflowType.get(), e.getMessage());
    } catch (Exception e) {
        throw new WorkflowServiceException(execution.get(), workflowType, e);
    }
    return execution.get();
}
Also used : DuplicateWorkflowException(com.uber.cadence.client.DuplicateWorkflowException) WorkflowType(com.uber.cadence.WorkflowType) WorkflowExecutionAlreadyStartedError(com.uber.cadence.WorkflowExecutionAlreadyStartedError) StartWorkflowExecutionParameters(com.uber.cadence.internal.common.StartWorkflowExecutionParameters) WorkflowExecution(com.uber.cadence.WorkflowExecution) DuplicateWorkflowException(com.uber.cadence.client.DuplicateWorkflowException) TimeoutException(java.util.concurrent.TimeoutException) WorkflowFailureException(com.uber.cadence.client.WorkflowFailureException) WorkflowNotFoundException(com.uber.cadence.client.WorkflowNotFoundException) WorkflowQueryException(com.uber.cadence.client.WorkflowQueryException) WorkflowException(com.uber.cadence.client.WorkflowException) CancellationException(java.util.concurrent.CancellationException) CompletionException(java.util.concurrent.CompletionException) WorkflowExecutionFailedException(com.uber.cadence.internal.common.WorkflowExecutionFailedException) WorkflowServiceException(com.uber.cadence.client.WorkflowServiceException) WorkflowServiceException(com.uber.cadence.client.WorkflowServiceException)

Example 3 with WorkflowExecutionAlreadyStartedError

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

the class GenericWorkflowClientExternalImpl method startWorkflow.

@Override
public WorkflowExecution startWorkflow(StartWorkflowExecutionParameters startParameters) throws WorkflowExecutionAlreadyStartedError {
    StartWorkflowExecutionRequest request = new StartWorkflowExecutionRequest();
    request.setDomain(domain);
    request.setInput(startParameters.getInput());
    request.setExecutionStartToCloseTimeoutSeconds((int) startParameters.getExecutionStartToCloseTimeoutSeconds());
    request.setTaskStartToCloseTimeoutSeconds((int) startParameters.getTaskStartToCloseTimeoutSeconds());
    request.setWorkflowIdReusePolicy(startParameters.getWorkflowIdReusePolicy());
    String taskList = startParameters.getTaskList();
    if (taskList != null && !taskList.isEmpty()) {
        TaskList tl = new TaskList();
        tl.setName(taskList);
        request.setTaskList(tl);
    }
    String workflowId = startParameters.getWorkflowId();
    if (workflowId == null) {
        workflowId = UUID.randomUUID().toString();
    }
    request.setWorkflowId(workflowId);
    request.setWorkflowType(startParameters.getWorkflowType());
    // if(startParameters.getChildPolicy() != null) {
    // request.setChildPolicy(startParameters.getChildPolicy());
    // }
    StartWorkflowExecutionResponse result;
    try {
        result = service.StartWorkflowExecution(request);
    } catch (WorkflowExecutionAlreadyStartedError e) {
        throw e;
    } catch (TException e) {
        throw CheckedExceptionWrapper.wrap(e);
    }
    WorkflowExecution execution = new WorkflowExecution();
    execution.setRunId(result.getRunId());
    execution.setWorkflowId(request.getWorkflowId());
    return execution;
}
Also used : TException(org.apache.thrift.TException) TaskList(com.uber.cadence.TaskList) StartWorkflowExecutionResponse(com.uber.cadence.StartWorkflowExecutionResponse) WorkflowExecutionAlreadyStartedError(com.uber.cadence.WorkflowExecutionAlreadyStartedError) WorkflowExecution(com.uber.cadence.WorkflowExecution) StartWorkflowExecutionRequest(com.uber.cadence.StartWorkflowExecutionRequest)

Aggregations

WorkflowExecution (com.uber.cadence.WorkflowExecution)3 WorkflowExecutionAlreadyStartedError (com.uber.cadence.WorkflowExecutionAlreadyStartedError)3 StartWorkflowExecutionRequest (com.uber.cadence.StartWorkflowExecutionRequest)1 StartWorkflowExecutionResponse (com.uber.cadence.StartWorkflowExecutionResponse)1 TaskList (com.uber.cadence.TaskList)1 WorkflowType (com.uber.cadence.WorkflowType)1 DuplicateWorkflowException (com.uber.cadence.client.DuplicateWorkflowException)1 WorkflowException (com.uber.cadence.client.WorkflowException)1 WorkflowFailureException (com.uber.cadence.client.WorkflowFailureException)1 WorkflowNotFoundException (com.uber.cadence.client.WorkflowNotFoundException)1 WorkflowQueryException (com.uber.cadence.client.WorkflowQueryException)1 WorkflowServiceException (com.uber.cadence.client.WorkflowServiceException)1 StartWorkflowExecutionParameters (com.uber.cadence.internal.common.StartWorkflowExecutionParameters)1 WorkflowExecutionFailedException (com.uber.cadence.internal.common.WorkflowExecutionFailedException)1 CancellationException (java.util.concurrent.CancellationException)1 CompletionException (java.util.concurrent.CompletionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 TException (org.apache.thrift.TException)1