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);
}
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();
}
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);
}
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);
}
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));
}
Aggregations