Search in sources :

Example 1 with SearchAttributes

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

the class SyncWorkflowContext method upsertSearchAttributes.

@Override
public void upsertSearchAttributes(Map<String, Object> searchAttributes) {
    if (searchAttributes.isEmpty()) {
        throw new IllegalArgumentException("Empty search attributes");
    }
    SearchAttributes attr = InternalUtils.convertMapToSearchAttributes(searchAttributes);
    context.upsertSearchAttributes(attr);
}
Also used : SearchAttributes(io.temporal.api.common.v1.SearchAttributes)

Example 2 with SearchAttributes

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

the class SyncWorkflowContext method continueAsNew.

@Override
public void continueAsNew(ContinueAsNewInput input) {
    ContinueAsNewWorkflowExecutionCommandAttributes.Builder attributes = ContinueAsNewWorkflowExecutionCommandAttributes.newBuilder();
    String workflowType = input.getWorkflowType();
    if (workflowType != null) {
        attributes.setWorkflowType(WorkflowType.newBuilder().setName(workflowType));
    }
    @Nullable ContinueAsNewOptions options = input.getOptions();
    if (options != null) {
        if (options.getWorkflowRunTimeout() != null) {
            attributes.setWorkflowRunTimeout(ProtobufTimeUtils.toProtoDuration(options.getWorkflowRunTimeout()));
        }
        if (options.getWorkflowTaskTimeout() != null) {
            attributes.setWorkflowTaskTimeout(ProtobufTimeUtils.toProtoDuration(options.getWorkflowTaskTimeout()));
        }
        if (!options.getTaskQueue().isEmpty()) {
            attributes.setTaskQueue(TaskQueue.newBuilder().setName(options.getTaskQueue()));
        }
        Map<String, Object> searchAttributes = options.getSearchAttributes();
        if (searchAttributes != null) {
            attributes.setSearchAttributes(SearchAttributes.newBuilder().putAllIndexedFields(intoPayloadMap(DataConverter.getDefaultInstance(), searchAttributes)));
        }
        Map<String, Object> memo = options.getMemo();
        if (memo != null) {
            attributes.setMemo(Memo.newBuilder().putAllFields(intoPayloadMap(getDataConverter(), memo)));
        }
    }
    List<ContextPropagator> propagators = options != null && options.getContextPropagators() != null ? options.getContextPropagators() : this.contextPropagators;
    io.temporal.api.common.v1.Header grpcHeader = toHeaderGrpc(input.getHeader(), extractContextsAndConvertToBytes(propagators));
    attributes.setHeader(grpcHeader);
    Optional<Payloads> payloads = getDataConverter().toPayloads(input.getArgs());
    payloads.ifPresent(attributes::setInput);
    context.continueAsNewOnCompletion(attributes.build());
    WorkflowThread.exit(null);
}
Also used : ContinueAsNewOptions(io.temporal.workflow.ContinueAsNewOptions) ContinueAsNewWorkflowExecutionCommandAttributes(io.temporal.api.command.v1.ContinueAsNewWorkflowExecutionCommandAttributes) ContextPropagator(io.temporal.common.context.ContextPropagator) Nullable(javax.annotation.Nullable) Payloads(io.temporal.api.common.v1.Payloads)

Example 3 with SearchAttributes

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

the class SearchAttributesUtilTest method TestGetValueFromSearchAttributes.

@Test
public void TestGetValueFromSearchAttributes() {
    assertEquals(null, SearchAttributesUtil.getValueFromSearchAttributes(null, "key", String.class));
    assertEquals(null, SearchAttributesUtil.getValueFromSearchAttributes(SearchAttributes.getDefaultInstance(), "", String.class));
    Map<String, Object> attr = new HashMap<>();
    String stringVal = "keyword";
    attr.put("CustomKeywordField", stringVal);
    Integer intVal = 1;
    attr.put("CustomIntField", intVal);
    Double doubleVal = 1.0;
    attr.put("CustomDoubleField", doubleVal);
    Boolean boolVal = Boolean.TRUE;
    attr.put("CustomBooleanField", boolVal);
    SearchAttributes searchAttributes = InternalUtils.convertMapToSearchAttributes(attr);
    assertEquals(stringVal, SearchAttributesUtil.getValueFromSearchAttributes(searchAttributes, "CustomKeywordField", String.class));
    assertEquals(intVal, SearchAttributesUtil.getValueFromSearchAttributes(searchAttributes, "CustomIntField", Integer.class));
    assertEquals(doubleVal, SearchAttributesUtil.getValueFromSearchAttributes(searchAttributes, "CustomDoubleField", Double.class));
    assertEquals(boolVal, SearchAttributesUtil.getValueFromSearchAttributes(searchAttributes, "CustomBooleanField", Boolean.class));
}
Also used : HashMap(java.util.HashMap) SearchAttributes(io.temporal.api.common.v1.SearchAttributes) Test(org.junit.Test)

Example 4 with SearchAttributes

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

the class SearchAttributesUtilTest method TestGetValueFromSearchAttributesRepeated.

@Test
public void TestGetValueFromSearchAttributesRepeated() {
    Map<String, Object> attr = new HashMap<>();
    String stringVal = "keyword";
    attr.put("CustomKeywordField", stringVal);
    SearchAttributes searchAttributes = InternalUtils.convertMapToSearchAttributes(attr);
    assertEquals(stringVal, SearchAttributesUtil.getValueFromSearchAttributes(searchAttributes, "CustomKeywordField", String.class));
    assertEquals(stringVal, SearchAttributesUtil.getValueFromSearchAttributes(searchAttributes, "CustomKeywordField", String.class));
}
Also used : HashMap(java.util.HashMap) SearchAttributes(io.temporal.api.common.v1.SearchAttributes) Test(org.junit.Test)

Example 5 with SearchAttributes

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

the class InternalUtils method convertMapToSearchAttributes.

public static SearchAttributes convertMapToSearchAttributes(Map<String, Object> searchAttributes) {
    DataConverter converter = DataConverter.getDefaultInstance();
    Map<String, Payload> mapOfByteBuffer = new HashMap<>();
    searchAttributes.forEach((key, value) -> mapOfByteBuffer.put(key, converter.toPayload(value).get()));
    return SearchAttributes.newBuilder().putAllIndexedFields(mapOfByteBuffer).build();
}
Also used : HashMap(java.util.HashMap) Payload(io.temporal.api.common.v1.Payload) DataConverter(io.temporal.common.converter.DataConverter)

Aggregations

SearchAttributes (io.temporal.api.common.v1.SearchAttributes)8 HashMap (java.util.HashMap)6 Test (org.junit.Test)6 Payload (io.temporal.api.common.v1.Payload)4 DataConverter (io.temporal.common.converter.DataConverter)4 WorkflowExecution (io.temporal.api.common.v1.WorkflowExecution)2 WorkflowOptions (io.temporal.client.WorkflowOptions)2 ByteString (com.google.protobuf.ByteString)1 NoopScope (com.uber.m3.tally.NoopScope)1 ContinueAsNewWorkflowExecutionCommandAttributes (io.temporal.api.command.v1.ContinueAsNewWorkflowExecutionCommandAttributes)1 Payloads (io.temporal.api.common.v1.Payloads)1 HistoryEvent (io.temporal.api.history.v1.HistoryEvent)1 WorkflowExecutionStartedEventAttributes (io.temporal.api.history.v1.WorkflowExecutionStartedEventAttributes)1 DescribeWorkflowExecutionRequest (io.temporal.api.workflowservice.v1.DescribeWorkflowExecutionRequest)1 DescribeWorkflowExecutionResponse (io.temporal.api.workflowservice.v1.DescribeWorkflowExecutionResponse)1 GetWorkflowExecutionHistoryResponse (io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse)1 WorkflowClient (io.temporal.client.WorkflowClient)1 ContextPropagator (io.temporal.common.context.ContextPropagator)1 WorkflowServiceStubs (io.temporal.serviceclient.WorkflowServiceStubs)1 Worker (io.temporal.worker.Worker)1