Search in sources :

Example 1 with WorkflowExecutionStartedEventAttributes

use of io.temporal.api.history.v1.WorkflowExecutionStartedEventAttributes in project sdk-java by temporalio.

the class WorkflowContext method getContinuedExecutionRunId.

Optional<String> getContinuedExecutionRunId() {
    WorkflowExecutionStartedEventAttributes attributes = getWorkflowStartedEventAttributes();
    String runId = attributes.getContinuedExecutionRunId();
    return runId.isEmpty() ? Optional.empty() : Optional.of(runId);
}
Also used : WorkflowExecutionStartedEventAttributes(io.temporal.api.history.v1.WorkflowExecutionStartedEventAttributes)

Example 2 with WorkflowExecutionStartedEventAttributes

use of io.temporal.api.history.v1.WorkflowExecutionStartedEventAttributes in project sdk-java by temporalio.

the class WorkflowReplayer method getQueueName.

private static String getQueueName(WorkflowExecutionHistory history) {
    WorkflowExecutionStartedEventAttributes attr = history.getEvents().get(0).getWorkflowExecutionStartedEventAttributes();
    TaskQueue taskQueue = attr.getTaskQueue();
    return taskQueue.getName();
}
Also used : TaskQueue(io.temporal.api.taskqueue.v1.TaskQueue) WorkflowExecutionStartedEventAttributes(io.temporal.api.history.v1.WorkflowExecutionStartedEventAttributes)

Example 3 with WorkflowExecutionStartedEventAttributes

use of io.temporal.api.history.v1.WorkflowExecutionStartedEventAttributes in project sdk-java by temporalio.

the class SyncWorkflow method start.

@Override
public void start(HistoryEvent event, ReplayWorkflowContext context) {
    if (event.getEventType() != EventType.EVENT_TYPE_WORKFLOW_EXECUTION_STARTED || !event.hasWorkflowExecutionStartedEventAttributes()) {
        throw new IllegalArgumentException("first event is not WorkflowExecutionStarted, but " + event.getEventType());
    }
    WorkflowExecutionStartedEventAttributes startEvent = event.getWorkflowExecutionStartedEventAttributes();
    WorkflowType workflowType = startEvent.getWorkflowType();
    if (workflow == null) {
        throw new IllegalArgumentException("Unknown workflow type: " + workflowType);
    }
    Optional<Payloads> result = startEvent.hasLastCompletionResult() ? Optional.of(startEvent.getLastCompletionResult()) : Optional.empty();
    Optional<Failure> lastFailure = startEvent.hasContinuedFailure() ? Optional.of(startEvent.getContinuedFailure()) : Optional.empty();
    SyncWorkflowContext syncContext = new SyncWorkflowContext(context, workflowImplementationOptions, dataConverter, contextPropagators, result, lastFailure);
    workflowProc = new WorkflowExecuteRunnable(syncContext, workflow, startEvent, workflowImplementationOptions);
    // The following order is ensured by this code and DeterministicRunner implementation:
    // 1. workflow.initialize
    // 2. signal handler (if signalWithStart was called)
    // 3. main workflow method
    runner = DeterministicRunner.newRunner(threadPool, syncContext, () -> {
        workflow.initialize();
        WorkflowInternal.newWorkflowMethodThread(() -> workflowProc.run(), workflowMethodThreadNameStrategy.createThreadName(context.getWorkflowExecution())).start();
    }, cache);
}
Also used : WorkflowType(io.temporal.api.common.v1.WorkflowType) WorkflowExecutionStartedEventAttributes(io.temporal.api.history.v1.WorkflowExecutionStartedEventAttributes) Failure(io.temporal.api.failure.v1.Failure) Payloads(io.temporal.api.common.v1.Payloads)

Example 4 with WorkflowExecutionStartedEventAttributes

use of io.temporal.api.history.v1.WorkflowExecutionStartedEventAttributes in project sdk-java by temporalio.

the class QueryReplayHelper method queryWorkflowExecution.

private Optional<Payloads> queryWorkflowExecution(String queryType, Optional<Payloads> args, WorkflowExecutionHistory history, ByteString nextPageToken) throws Exception {
    WorkflowQuery.Builder query = WorkflowQuery.newBuilder().setQueryType(queryType);
    args.ifPresent(query::setQueryArgs);
    PollWorkflowTaskQueueResponse.Builder task = PollWorkflowTaskQueueResponse.newBuilder().setWorkflowExecution(history.getWorkflowExecution()).setStartedEventId(Long.MAX_VALUE).setPreviousStartedEventId(Long.MAX_VALUE).setNextPageToken(nextPageToken).setQuery(query);
    List<HistoryEvent> events = history.getEvents();
    HistoryEvent startedEvent = events.get(0);
    if (!startedEvent.hasWorkflowExecutionStartedEventAttributes()) {
        throw new IllegalStateException("First event of the history is not WorkflowExecutionStarted: " + startedEvent);
    }
    WorkflowExecutionStartedEventAttributes started = startedEvent.getWorkflowExecutionStartedEventAttributes();
    WorkflowType workflowType = started.getWorkflowType();
    task.setWorkflowType(workflowType);
    task.setHistory(History.newBuilder().addAllEvents(events));
    WorkflowTaskHandler.Result result = handler.handleWorkflowTask(task.build());
    if (result.getQueryCompleted() != null) {
        RespondQueryTaskCompletedRequest r = result.getQueryCompleted();
        if (!r.getErrorMessage().isEmpty()) {
            throw new RuntimeException("query failure for " + history.getWorkflowExecution() + ", queryType=" + queryType + ", args=" + args + ", error=" + r.getErrorMessage());
        }
        if (r.hasQueryResult()) {
            return Optional.of(r.getQueryResult());
        } else {
            return Optional.empty();
        }
    }
    throw new RuntimeException("Query returned wrong response: " + result);
}
Also used : WorkflowQuery(io.temporal.api.query.v1.WorkflowQuery) WorkflowExecutionStartedEventAttributes(io.temporal.api.history.v1.WorkflowExecutionStartedEventAttributes) HistoryEvent(io.temporal.api.history.v1.HistoryEvent) PollWorkflowTaskQueueResponse(io.temporal.api.workflowservice.v1.PollWorkflowTaskQueueResponse) RespondQueryTaskCompletedRequest(io.temporal.api.workflowservice.v1.RespondQueryTaskCompletedRequest) WorkflowType(io.temporal.api.common.v1.WorkflowType)

Example 5 with WorkflowExecutionStartedEventAttributes

use of io.temporal.api.history.v1.WorkflowExecutionStartedEventAttributes in project sdk-java by temporalio.

the class WorkflowContextTest method TestMergeSearchAttributes.

@Test
public void TestMergeSearchAttributes() {
    WorkflowExecutionStartedEventAttributes startAttr = WorkflowExecutionStartedEventAttributes.getDefaultInstance();
    WorkflowContext workflowContext = new WorkflowContext("namespace", null, startAttr, 0, null);
    DataConverter converter = DataConverter.getDefaultInstance();
    Map<String, Payload> indexedFields = new HashMap<>();
    indexedFields.put("CustomKeywordField", converter.toPayload("key").get());
    SearchAttributes searchAttributes = SearchAttributes.newBuilder().putAllIndexedFields(indexedFields).build();
    workflowContext.mergeSearchAttributes(searchAttributes);
    assertEquals("key", SearchAttributesUtil.getValueFromSearchAttributes(workflowContext.getSearchAttributes(), "CustomKeywordField", String.class));
}
Also used : HashMap(java.util.HashMap) SearchAttributes(io.temporal.api.common.v1.SearchAttributes) Payload(io.temporal.api.common.v1.Payload) WorkflowExecutionStartedEventAttributes(io.temporal.api.history.v1.WorkflowExecutionStartedEventAttributes) DataConverter(io.temporal.common.converter.DataConverter) Test(org.junit.Test)

Aggregations

WorkflowExecutionStartedEventAttributes (io.temporal.api.history.v1.WorkflowExecutionStartedEventAttributes)5 WorkflowType (io.temporal.api.common.v1.WorkflowType)2 Payload (io.temporal.api.common.v1.Payload)1 Payloads (io.temporal.api.common.v1.Payloads)1 SearchAttributes (io.temporal.api.common.v1.SearchAttributes)1 Failure (io.temporal.api.failure.v1.Failure)1 HistoryEvent (io.temporal.api.history.v1.HistoryEvent)1 WorkflowQuery (io.temporal.api.query.v1.WorkflowQuery)1 TaskQueue (io.temporal.api.taskqueue.v1.TaskQueue)1 PollWorkflowTaskQueueResponse (io.temporal.api.workflowservice.v1.PollWorkflowTaskQueueResponse)1 RespondQueryTaskCompletedRequest (io.temporal.api.workflowservice.v1.RespondQueryTaskCompletedRequest)1 DataConverter (io.temporal.common.converter.DataConverter)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1