Search in sources :

Example 1 with Failure

use of io.temporal.api.failure.v1.Failure in project sdk-java by temporalio.

the class ActivityStateMachine method notifyCanceled.

private void notifyCanceled() {
    Failure canceledFailure = Failure.newBuilder().setSource(JAVA_SDK).setCanceledFailureInfo(CanceledFailureInfo.getDefaultInstance()).build();
    ActivityFailureInfo activityFailureInfo = ActivityFailureInfo.newBuilder().setActivityId(activityId).setActivityType(activityType).setIdentity("workflow").setScheduledEventId(getInitialCommandEventId()).setStartedEventId(startedCommandEventId).build();
    Failure failure = Failure.newBuilder().setActivityFailureInfo(activityFailureInfo).setCause(canceledFailure).setMessage("Activity canceled").build();
    completionCallback.apply(Optional.empty(), failure);
}
Also used : ActivityFailureInfo(io.temporal.api.failure.v1.ActivityFailureInfo) Failure(io.temporal.api.failure.v1.Failure)

Example 2 with Failure

use of io.temporal.api.failure.v1.Failure in project sdk-java by temporalio.

the class ActivityStateMachine method notifyCancellationFromEvent.

private void notifyCancellationFromEvent() {
    if (cancellationType == ActivityCancellationType.WAIT_CANCELLATION_COMPLETED) {
        ActivityTaskCanceledEventAttributes canceledAttr = currentEvent.getActivityTaskCanceledEventAttributes();
        Failure canceledFailure = Failure.newBuilder().setSource(JAVA_SDK).setCanceledFailureInfo(CanceledFailureInfo.newBuilder().setDetails(canceledAttr.getDetails())).build();
        ActivityFailureInfo failureInfo = ActivityFailureInfo.newBuilder().setActivityId(activityId).setActivityType(activityType).setScheduledEventId(canceledAttr.getScheduledEventId()).setStartedEventId(canceledAttr.getStartedEventId()).build();
        Failure failure = Failure.newBuilder().setActivityFailureInfo(failureInfo).setCause(canceledFailure).setMessage("Activity canceled").build();
        completionCallback.apply(Optional.empty(), failure);
    }
}
Also used : ActivityTaskCanceledEventAttributes(io.temporal.api.history.v1.ActivityTaskCanceledEventAttributes) ActivityFailureInfo(io.temporal.api.failure.v1.ActivityFailureInfo) Failure(io.temporal.api.failure.v1.Failure)

Example 3 with Failure

use of io.temporal.api.failure.v1.Failure in project sdk-java by temporalio.

the class TestWorkflowService method startWorkflowExecutionImpl.

StartWorkflowExecutionResponse startWorkflowExecutionImpl(StartWorkflowExecutionRequest startRequest, Duration backoffStartInterval, Optional<TestWorkflowMutableState> parent, OptionalLong parentChildInitiatedEventId, Optional<SignalWorkflowExecutionRequest> signalWithStartSignal) {
    String requestWorkflowId = requireNotNull("WorkflowId", startRequest.getWorkflowId());
    String namespace = requireNotNull("Namespace", startRequest.getNamespace());
    WorkflowId workflowId = new WorkflowId(namespace, requestWorkflowId);
    TestWorkflowMutableState existing;
    lock.lock();
    try {
        existing = executionsByWorkflowId.get(workflowId);
        if (existing != null) {
            WorkflowExecutionStatus status = existing.getWorkflowExecutionStatus();
            WorkflowIdReusePolicy policy = startRequest.getWorkflowIdReusePolicy();
            if (status == WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_RUNNING || policy == WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE) {
                return throwDuplicatedWorkflow(startRequest, existing);
            }
            if (policy == WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY && (status == WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_COMPLETED || status == WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_CONTINUED_AS_NEW)) {
                return throwDuplicatedWorkflow(startRequest, existing);
            }
        }
        Optional<TestServiceRetryState> retryState;
        Optional<Failure> lastFailure = Optional.empty();
        if (startRequest.hasRetryPolicy()) {
            Duration expirationInterval = ProtobufTimeUtils.toJavaDuration(startRequest.getWorkflowExecutionTimeout());
            retryState = newRetryStateLocked(startRequest.getRetryPolicy(), expirationInterval);
            if (retryState.isPresent()) {
                lastFailure = retryState.get().getPreviousRunFailure();
            }
        } else {
            retryState = Optional.empty();
        }
        return startWorkflowExecutionNoRunningCheckLocked(startRequest, UUID.randomUUID().toString(), Optional.empty(), retryState, backoffStartInterval, null, lastFailure, parent, parentChildInitiatedEventId, signalWithStartSignal, workflowId);
    } finally {
        lock.unlock();
    }
}
Also used : WorkflowExecutionStatus(io.temporal.api.enums.v1.WorkflowExecutionStatus) WorkflowIdReusePolicy(io.temporal.api.enums.v1.WorkflowIdReusePolicy) Duration(java.time.Duration) Failure(io.temporal.api.failure.v1.Failure) WorkflowExecutionAlreadyStartedFailure(io.temporal.api.errordetails.v1.WorkflowExecutionAlreadyStartedFailure)

Example 4 with Failure

use of io.temporal.api.failure.v1.Failure in project sdk-java by temporalio.

the class StateMachines method timeoutActivityTask.

private static State timeoutActivityTask(RequestContext ctx, ActivityTaskData data, TimeoutType timeoutType, long notUsed) {
    // ScheduleToStart (queue timeout) is not retryable. Instead of the retry, a customer should set
    // a larger ScheduleToStart timeout.
    RetryState retryState;
    if (timeoutType != TimeoutType.TIMEOUT_TYPE_SCHEDULE_TO_START) {
        retryState = attemptActivityRetry(ctx, Optional.empty(), data);
        if (retryState == RetryState.RETRY_STATE_IN_PROGRESS) {
            return INITIATED;
        }
    } else {
        retryState = RetryState.RETRY_STATE_NON_RETRYABLE_FAILURE;
    }
    Failure failure;
    if (timeoutType == TimeoutType.TIMEOUT_TYPE_HEARTBEAT || timeoutType == TimeoutType.TIMEOUT_TYPE_START_TO_CLOSE) {
        failure = newTimeoutFailure(TimeoutType.TIMEOUT_TYPE_SCHEDULE_TO_CLOSE, Optional.ofNullable(data.heartbeatDetails), Optional.of(newTimeoutFailure(timeoutType, Optional.empty(), Optional.empty())));
    } else {
        failure = newTimeoutFailure(timeoutType, Optional.ofNullable(data.heartbeatDetails), Optional.empty());
    }
    ActivityTaskTimedOutEventAttributes.Builder a = ActivityTaskTimedOutEventAttributes.newBuilder().setScheduledEventId(data.scheduledEventId).setRetryState(retryState).setStartedEventId(data.startedEventId).setFailure(failure);
    HistoryEvent event = HistoryEvent.newBuilder().setEventType(EventType.EVENT_TYPE_ACTIVITY_TASK_TIMED_OUT).setActivityTaskTimedOutEventAttributes(a).build();
    ctx.addEvent(event);
    return TIMED_OUT;
}
Also used : ActivityTaskTimedOutEventAttributes(io.temporal.api.history.v1.ActivityTaskTimedOutEventAttributes) HistoryEvent(io.temporal.api.history.v1.HistoryEvent) QueryFailedFailure(io.temporal.api.errordetails.v1.QueryFailedFailure) Failure(io.temporal.api.failure.v1.Failure) RetryState(io.temporal.api.enums.v1.RetryState)

Example 5 with Failure

use of io.temporal.api.failure.v1.Failure in project sdk-java by temporalio.

the class TestWorkflowService method continueAsNew.

/**
 * Creates next run of a workflow execution
 *
 * @return RunId
 */
public String continueAsNew(StartWorkflowExecutionRequest previousRunStartRequest, WorkflowExecutionContinuedAsNewEventAttributes a, Optional<TestServiceRetryState> retryState, String identity, ExecutionId executionId, Optional<TestWorkflowMutableState> parent, OptionalLong parentChildInitiatedEventId) {
    StartWorkflowExecutionRequest.Builder startRequestBuilder = StartWorkflowExecutionRequest.newBuilder().setRequestId(UUID.randomUUID().toString()).setWorkflowType(a.getWorkflowType()).setWorkflowRunTimeout(a.getWorkflowRunTimeout()).setWorkflowTaskTimeout(a.getWorkflowTaskTimeout()).setNamespace(executionId.getNamespace()).setTaskQueue(a.getTaskQueue()).setWorkflowId(executionId.getWorkflowId().getWorkflowId()).setWorkflowIdReusePolicy(previousRunStartRequest.getWorkflowIdReusePolicy()).setIdentity(identity).setCronSchedule(previousRunStartRequest.getCronSchedule());
    if (previousRunStartRequest.hasRetryPolicy()) {
        startRequestBuilder.setRetryPolicy(previousRunStartRequest.getRetryPolicy());
    }
    if (a.hasInput()) {
        startRequestBuilder.setInput(a.getInput());
    }
    if (a.hasHeader()) {
        startRequestBuilder.setHeader(a.getHeader());
    }
    StartWorkflowExecutionRequest startRequest = startRequestBuilder.build();
    lock.lock();
    Optional<Failure> lastFail = a.hasFailure() ? Optional.of(a.getFailure()) : retryState.flatMap(TestServiceRetryState::getPreviousRunFailure);
    try {
        StartWorkflowExecutionResponse response = startWorkflowExecutionNoRunningCheckLocked(startRequest, a.getNewExecutionRunId(), Optional.of(executionId.getExecution().getRunId()), retryState, ProtobufTimeUtils.toJavaDuration(a.getBackoffStartInterval()), a.getLastCompletionResult(), lastFail, parent, parentChildInitiatedEventId, Optional.empty(), executionId.getWorkflowId());
        return response.getRunId();
    } finally {
        lock.unlock();
    }
}
Also used : SignalWithStartWorkflowExecutionResponse(io.temporal.api.workflowservice.v1.SignalWithStartWorkflowExecutionResponse) StartWorkflowExecutionResponse(io.temporal.api.workflowservice.v1.StartWorkflowExecutionResponse) SignalWithStartWorkflowExecutionRequest(io.temporal.api.workflowservice.v1.SignalWithStartWorkflowExecutionRequest) StartWorkflowExecutionRequest(io.temporal.api.workflowservice.v1.StartWorkflowExecutionRequest) Failure(io.temporal.api.failure.v1.Failure) WorkflowExecutionAlreadyStartedFailure(io.temporal.api.errordetails.v1.WorkflowExecutionAlreadyStartedFailure)

Aggregations

Failure (io.temporal.api.failure.v1.Failure)32 Payloads (io.temporal.api.common.v1.Payloads)18 Command (io.temporal.api.command.v1.Command)17 EventType (io.temporal.api.enums.v1.EventType)17 DataConverter (io.temporal.common.converter.DataConverter)17 CommandType (io.temporal.api.enums.v1.CommandType)16 ActivityTaskTimedOutEventAttributes (io.temporal.api.history.v1.ActivityTaskTimedOutEventAttributes)16 HistoryEvent (io.temporal.api.history.v1.HistoryEvent)16 ArrayList (java.util.ArrayList)16 List (java.util.List)16 Optional (java.util.Optional)16 AfterClass (org.junit.AfterClass)16 Test (org.junit.Test)16 ScheduleActivityTaskCommandAttributes (io.temporal.api.command.v1.ScheduleActivityTaskCommandAttributes)15 ApplicationFailureInfo (io.temporal.api.failure.v1.ApplicationFailureInfo)15 ActivityTaskCanceledEventAttributes (io.temporal.api.history.v1.ActivityTaskCanceledEventAttributes)15 ActivityTaskFailedEventAttributes (io.temporal.api.history.v1.ActivityTaskFailedEventAttributes)15 ExecuteActivityParameters (io.temporal.internal.replay.ExecuteActivityParameters)15 Functions (io.temporal.workflow.Functions)15 ActivityCancellationType (io.temporal.activity.ActivityCancellationType)14