Search in sources :

Example 1 with Payloads

use of io.temporal.api.common.v1.Payloads in project sdk-java by temporalio.

the class ReplayWorkflowRunTaskHandler method executeQueries.

private void executeQueries(Map<String, WorkflowQuery> queries) {
    for (Map.Entry<String, WorkflowQuery> entry : queries.entrySet()) {
        WorkflowQuery query = entry.getValue();
        try {
            Optional<Payloads> queryResult = replayWorkflowExecutor.query(query);
            WorkflowQueryResult.Builder result = WorkflowQueryResult.newBuilder().setResultType(QueryResultType.QUERY_RESULT_TYPE_ANSWERED);
            if (queryResult.isPresent()) {
                result.setAnswer(queryResult.get());
            }
            queryResults.put(entry.getKey(), result.build());
        } catch (Exception e) {
            String stackTrace = Throwables.getStackTraceAsString(e);
            queryResults.put(entry.getKey(), WorkflowQueryResult.newBuilder().setResultType(QueryResultType.QUERY_RESULT_TYPE_FAILED).setErrorMessage(e.toString() + "\n" + stackTrace).build());
        }
    }
}
Also used : WorkflowQuery(io.temporal.api.query.v1.WorkflowQuery) WorkflowQueryResult(io.temporal.api.query.v1.WorkflowQueryResult) HashMap(java.util.HashMap) Map(java.util.Map) Payloads(io.temporal.api.common.v1.Payloads)

Example 2 with Payloads

use of io.temporal.api.common.v1.Payloads in project sdk-java by temporalio.

the class ActivityStateMachine method notifyCompleted.

private void notifyCompleted() {
    ActivityTaskCompletedEventAttributes completedAttr = currentEvent.getActivityTaskCompletedEventAttributes();
    Optional<Payloads> result = completedAttr.hasResult() ? Optional.of(completedAttr.getResult()) : Optional.empty();
    completionCallback.apply(result, null);
}
Also used : ActivityTaskCompletedEventAttributes(io.temporal.api.history.v1.ActivityTaskCompletedEventAttributes) Payloads(io.temporal.api.common.v1.Payloads)

Example 3 with Payloads

use of io.temporal.api.common.v1.Payloads in project sdk-java by temporalio.

the class ChildWorkflowStateMachine method notifyCompleted.

private void notifyCompleted() {
    ChildWorkflowExecutionCompletedEventAttributes attributes = currentEvent.getChildWorkflowExecutionCompletedEventAttributes();
    Optional<Payloads> result = attributes.hasResult() ? Optional.of(attributes.getResult()) : Optional.empty();
    completionCallback.apply(result, null);
}
Also used : ChildWorkflowExecutionCompletedEventAttributes(io.temporal.api.history.v1.ChildWorkflowExecutionCompletedEventAttributes) Payloads(io.temporal.api.common.v1.Payloads)

Example 4 with Payloads

use of io.temporal.api.common.v1.Payloads in project sdk-java by temporalio.

the class WorkflowExecutionUtils method getResultFromCloseEvent.

public static Optional<Payloads> getResultFromCloseEvent(WorkflowExecution workflowExecution, Optional<String> workflowType, HistoryEvent closeEvent, DataConverter converter) {
    if (closeEvent == null) {
        throw new IllegalStateException("Workflow is still running");
    }
    switch(closeEvent.getEventType()) {
        case EVENT_TYPE_WORKFLOW_EXECUTION_COMPLETED:
            WorkflowExecutionCompletedEventAttributes completedEventAttributes = closeEvent.getWorkflowExecutionCompletedEventAttributes();
            if (completedEventAttributes.hasResult()) {
                return Optional.of(completedEventAttributes.getResult());
            }
            return Optional.empty();
        case EVENT_TYPE_WORKFLOW_EXECUTION_CANCELED:
            String message = null;
            WorkflowExecutionCanceledEventAttributes attributes = closeEvent.getWorkflowExecutionCanceledEventAttributes();
            Optional<Payloads> details = attributes.hasDetails() ? Optional.of(attributes.getDetails()) : Optional.empty();
            throw new WorkflowFailedException(workflowExecution, workflowType.orElse(null), 0, RetryState.RETRY_STATE_NON_RETRYABLE_FAILURE, new CanceledFailure("Workflow canceled", new EncodedValues(details, converter), null));
        case EVENT_TYPE_WORKFLOW_EXECUTION_FAILED:
            WorkflowExecutionFailedEventAttributes failed = closeEvent.getWorkflowExecutionFailedEventAttributes();
            throw new WorkflowExecutionFailedException(failed.getFailure(), failed.getWorkflowTaskCompletedEventId(), failed.getRetryState());
        case EVENT_TYPE_WORKFLOW_EXECUTION_TERMINATED:
            WorkflowExecutionTerminatedEventAttributes terminated = closeEvent.getWorkflowExecutionTerminatedEventAttributes();
            throw new WorkflowFailedException(workflowExecution, workflowType.orElse(null), 0, RetryState.RETRY_STATE_NON_RETRYABLE_FAILURE, new TerminatedFailure(terminated.getReason(), null));
        case EVENT_TYPE_WORKFLOW_EXECUTION_TIMED_OUT:
            WorkflowExecutionTimedOutEventAttributes timedOut = closeEvent.getWorkflowExecutionTimedOutEventAttributes();
            throw new WorkflowFailedException(workflowExecution, workflowType.orElse(null), 0, timedOut.getRetryState(), new TimeoutFailure(null, null, TimeoutType.TIMEOUT_TYPE_START_TO_CLOSE));
        default:
            throw new RuntimeException("Workflow end state is not completed: " + WorkflowExecutionUtils.prettyPrintObject(closeEvent));
    }
}
Also used : WorkflowExecutionFailedEventAttributes(io.temporal.api.history.v1.WorkflowExecutionFailedEventAttributes) WorkflowExecutionCanceledEventAttributes(io.temporal.api.history.v1.WorkflowExecutionCanceledEventAttributes) CanceledFailure(io.temporal.failure.CanceledFailure) EncodedValues(io.temporal.common.converter.EncodedValues) WorkflowExecutionTimedOutEventAttributes(io.temporal.api.history.v1.WorkflowExecutionTimedOutEventAttributes) WorkflowFailedException(io.temporal.client.WorkflowFailedException) TimeoutFailure(io.temporal.failure.TimeoutFailure) WorkflowExecutionCompletedEventAttributes(io.temporal.api.history.v1.WorkflowExecutionCompletedEventAttributes) WorkflowExecutionTerminatedEventAttributes(io.temporal.api.history.v1.WorkflowExecutionTerminatedEventAttributes) TerminatedFailure(io.temporal.failure.TerminatedFailure) Payloads(io.temporal.api.common.v1.Payloads)

Example 5 with Payloads

use of io.temporal.api.common.v1.Payloads in project sdk-java by temporalio.

the class ReplayWorkflowExecutor method handleWorkflowExecutionSignaled.

public void handleWorkflowExecutionSignaled(HistoryEvent event) {
    WorkflowExecutionSignaledEventAttributes signalAttributes = event.getWorkflowExecutionSignaledEventAttributes();
    if (completed) {
        throw new IllegalStateException("Signal received after workflow is closed.");
    }
    Optional<Payloads> input = signalAttributes.hasInput() ? Optional.of(signalAttributes.getInput()) : Optional.empty();
    this.workflow.handleSignal(signalAttributes.getSignalName(), input, event.getEventId());
}
Also used : WorkflowExecutionSignaledEventAttributes(io.temporal.api.history.v1.WorkflowExecutionSignaledEventAttributes) Payloads(io.temporal.api.common.v1.Payloads)

Aggregations

Payloads (io.temporal.api.common.v1.Payloads)47 Test (org.junit.Test)31 HistoryEvent (io.temporal.api.history.v1.HistoryEvent)21 ArrayList (java.util.ArrayList)19 Failure (io.temporal.api.failure.v1.Failure)18 List (java.util.List)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 Functions (io.temporal.workflow.Functions)16 Optional (java.util.Optional)16 AfterClass (org.junit.AfterClass)16 ScheduleActivityTaskCommandAttributes (io.temporal.api.command.v1.ScheduleActivityTaskCommandAttributes)15 ActivityTaskCanceledEventAttributes (io.temporal.api.history.v1.ActivityTaskCanceledEventAttributes)15 ActivityTaskCompletedEventAttributes (io.temporal.api.history.v1.ActivityTaskCompletedEventAttributes)15 WorkflowExecutionSignaledEventAttributes (io.temporal.api.history.v1.WorkflowExecutionSignaledEventAttributes)15 ExecuteActivityParameters (io.temporal.internal.replay.ExecuteActivityParameters)15 ActivityCancellationType (io.temporal.activity.ActivityCancellationType)14 TimeoutType (io.temporal.api.enums.v1.TimeoutType)14