Search in sources :

Example 1 with QueryWorkflowResponse

use of com.uber.cadence.QueryWorkflowResponse in project cadence-client by uber-java.

the class TestWorkflowMutableStateImpl method completeQuery.

@Override
public void completeQuery(QueryId queryId, RespondQueryTaskCompletedRequest completeRequest) throws EntityNotExistsError {
    CompletableFuture<QueryWorkflowResponse> result = queries.get(queryId.getQueryId());
    if (result == null) {
        throw new EntityNotExistsError("Unknown query id: " + queryId.getQueryId());
    }
    if (completeRequest.getCompletedType() == QueryTaskCompletedType.COMPLETED) {
        QueryWorkflowResponse response = new QueryWorkflowResponse().setQueryResult(completeRequest.getQueryResult());
        result.complete(response);
    } else {
        QueryFailedError error = new QueryFailedError().setMessage(completeRequest.getErrorMessage());
        result.completeExceptionally(error);
    }
}
Also used : QueryWorkflowResponse(com.uber.cadence.QueryWorkflowResponse) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) QueryFailedError(com.uber.cadence.QueryFailedError)

Example 2 with QueryWorkflowResponse

use of com.uber.cadence.QueryWorkflowResponse in project cadence-client by uber-java.

the class TestWorkflowMutableStateImpl method query.

@Override
public QueryWorkflowResponse query(QueryWorkflowRequest queryRequest) throws TException {
    QueryId queryId = new QueryId(executionId);
    PollForDecisionTaskResponse task = new PollForDecisionTaskResponse().setTaskToken(queryId.toBytes()).setWorkflowExecution(executionId.getExecution()).setWorkflowType(startRequest.getWorkflowType()).setQuery(queryRequest.getQuery());
    TaskListId taskListId = new TaskListId(queryRequest.getDomain(), startRequest.getTaskList().getName());
    store.sendQueryTask(executionId, taskListId, task);
    CompletableFuture<QueryWorkflowResponse> result = new CompletableFuture<>();
    queries.put(queryId.getQueryId(), result);
    try {
        return result.get();
    } catch (InterruptedException e) {
        return new QueryWorkflowResponse();
    } catch (ExecutionException e) {
        Throwable cause = e.getCause();
        if (cause instanceof TException) {
            throw (TException) cause;
        }
        throw new InternalServiceError(Throwables.getStackTraceAsString(cause));
    }
}
Also used : TException(org.apache.thrift.TException) CompletableFuture(java.util.concurrent.CompletableFuture) QueryWorkflowResponse(com.uber.cadence.QueryWorkflowResponse) TaskListId(com.uber.cadence.internal.testservice.TestWorkflowStore.TaskListId) PollForDecisionTaskResponse(com.uber.cadence.PollForDecisionTaskResponse) InternalServiceError(com.uber.cadence.InternalServiceError) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with QueryWorkflowResponse

use of com.uber.cadence.QueryWorkflowResponse in project cadence-client by uber-java.

the class GenericWorkflowClientExternalImpl method queryWorkflow.

@Override
public byte[] queryWorkflow(QueryWorkflowParameters queryParameters) {
    QueryWorkflowRequest request = new QueryWorkflowRequest();
    request.setDomain(domain);
    WorkflowExecution execution = new WorkflowExecution();
    execution.setWorkflowId(queryParameters.getWorkflowId()).setRunId(queryParameters.getRunId());
    request.setExecution(execution);
    WorkflowQuery query = new WorkflowQuery();
    query.setQueryArgs(queryParameters.getInput());
    query.setQueryType(queryParameters.getQueryType());
    request.setQuery(query);
    try {
        QueryWorkflowResponse response = service.QueryWorkflow(request);
        return response.getQueryResult();
    } catch (TException e) {
        throw CheckedExceptionWrapper.wrap(e);
    }
}
Also used : TException(org.apache.thrift.TException) WorkflowQuery(com.uber.cadence.WorkflowQuery) QueryWorkflowResponse(com.uber.cadence.QueryWorkflowResponse) WorkflowExecution(com.uber.cadence.WorkflowExecution) QueryWorkflowRequest(com.uber.cadence.QueryWorkflowRequest)

Aggregations

QueryWorkflowResponse (com.uber.cadence.QueryWorkflowResponse)3 TException (org.apache.thrift.TException)2 EntityNotExistsError (com.uber.cadence.EntityNotExistsError)1 InternalServiceError (com.uber.cadence.InternalServiceError)1 PollForDecisionTaskResponse (com.uber.cadence.PollForDecisionTaskResponse)1 QueryFailedError (com.uber.cadence.QueryFailedError)1 QueryWorkflowRequest (com.uber.cadence.QueryWorkflowRequest)1 WorkflowExecution (com.uber.cadence.WorkflowExecution)1 WorkflowQuery (com.uber.cadence.WorkflowQuery)1 TaskListId (com.uber.cadence.internal.testservice.TestWorkflowStore.TaskListId)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1