Documentation around search workflows/executions (java-sdk)

Hi

I am looking for documentation, java doc and usage around workflow search - describe/list/query workflows/workflowExecutions.
for example queryWorkflow, QueryWorkflowRequest…
It would be very useful, if you can add a section in here https://docs.temporal.io/docs/java-sdk-overview with pointers to further docs like java doc and usage.

Thanks in Advance!

1 Like

Hi
Any help is appreciated.
Basically using java-sdk, i want to see workflow execution history.
Are are they any doc/code samples around this?

Thanks

We don’t have specific Java samples at this point. List queries are done through gRPC stub:

    WorkflowServiceStubs service = WorkflowServiceStubs.newInstance(...);
     ListOpenWorkflowExecutionsRequest listRequest =
          ListOpenWorkflowExecutionsRequest.newBuilder()
              .setNamespace(testEnvironment.getNamespace())
              .build();
      ListOpenWorkflowExecutionsResponse listResponse =
              service
              .blockingStub()
              .listOpenWorkflowExecutions(listRequest);

The service supports all the other gRPC APIs like DescribeWorkflowExecution.

For queries see HelloQuery sample.

Thank you for responding.

I am trying to use

            ListWorkflowExecutionsRequest request = ListWorkflowExecutionsRequest
                            .newBuilder()
                            .setQuery("WorkflowType='TestWorkflow'")
                            .setNamespace("test-ns")
                            .build();
                        ListWorkflowExecutionsResponse response = service.blockingStub()
                            .listWorkflowExecutions(request);

I am testing locally against the docker container (docker-compose-mysql.yml)

It gives the response INVALID_ARGUMENT: Operation not support. Please use on ElasticSearch
I am using mysql without elastic search.
I would like to know which api supports getting workflows given a workflowType and a namespace, in this case(no elastic search).

Only ListOpenWorkflowExecutions and ListClosedWorkflowExecutions APIs are supported without ElasticSearch.

Is there a way to get only open/closed workflow executions for a given workflowType ?

Yes, both ListOpenWorkflowExecutions and ListClosedWorkflowExecutions accept WorkflowTypeFilter as a parameter.

Cool that was helpful.

ListClosedWorkflowExecutionsRequest
                .newBuilder()
                .setTypeFilter(WorkflowTypeFilter.newBuilder().setName(workflowType).build())
                .setNamespace("test-ns")
                .build();
1 Like

Further questions:

  1. Please confirm
    listOpenWorkflowExecutions - returns all which has status Running
    listClosedWorkflowExecutions - returns all which has status != Running

io.temporal.api.enums.v1.WorkflowExecutionStatus is my reference
WORKFLOW_EXECUTION_STATUS_UNSPECIFIED(0),
WORKFLOW_EXECUTION_STATUS_RUNNING(1),
WORKFLOW_EXECUTION_STATUS_COMPLETED(2),
WORKFLOW_EXECUTION_STATUS_FAILED(3),
WORKFLOW_EXECUTION_STATUS_CANCELED(4),
WORKFLOW_EXECUTION_STATUS_TERMINATED(5),
WORKFLOW_EXECUTION_STATUS_CONTINUED_AS_NEW(6),
WORKFLOW_EXECUTION_STATUS_TIMED_OUT(7),
UNRECOGNIZED(-1);

  1. For listClosedWorkflowExecutions, could we further filter by status ?
  1. Yes, you are correct.
  2. I believe you should be able to. But please test this as not all filter combinations are supported.

Thank you for clarifying

Hi Maxim

I am trying to add custom queryMethod to a workflow.
Which API (sdk-java) can i use to call this queryMethod on closed and open workflows?

Thanks

The standard way to call the query method on the stub created through the Client. There is no API difference when querying closed and open workflows. See HelloQuery sample as a reference.

For listClosedWorkflowExecutions/describe/getWorkflowExecutionHistory, this is how I called the apis

WorkflowServiceStubs service = WorkflowServiceStubs.newInstance();
 WorkflowExecution execution = WorkflowExecution
        .newBuilder()
        .setWorkflowId(workflowId)
        .build();
    GetWorkflowExecutionHistoryRequest request = GetWorkflowExecutionHistoryRequest
        .newBuilder()
        .setNamespace("ns-test")
        .setExecution(execution)
        .build();
    GetWorkflowExecutionHistoryResponse response = service.blockingStub()
        .getWorkflowExecutionHistory(request);

Is there a similar way to call the query method ?

I’m not sure I understand your question. Is the approach from the HelloQuery not working for you?

i want to know how to call the custom query method if i have just the workflowId and runId

MyWorkflow workflow = client.newWorkflowStub(MyWorkflow.class, <workflowId>);
System.out.println(workflow.myQuery());

yes thats what is given in HelloQuery sample.

I wanted to know if there is a way to call the custom query method if i have just the workflowId and runId

Do you mean when you don’t have the class definition? You can use an untyped stub:

  WorkflowStub workflow = Workflow.newUntypedWorkflowStub(
      "<workflowId>",  Optional.of("<runId>"), Optional.empty());
  <ResultClass> result =  workflow.query("<queryType>", <ResultClass>.class);

Yes. Thanku.
That worked fine on workflows which are running.
But on completed workflows it throws error and I had reported it sometime back - Custom query on a terminated workflow returns error - #2 by maxim

Any updates on the issue?