use of org.opensearch.ml.common.transport.task.MLTaskGetResponse in project ml-commons by opensearch-project.
the class GetTaskTransportAction method doExecute.
@Override
protected void doExecute(Task task, ActionRequest request, ActionListener<MLTaskGetResponse> actionListener) {
MLTaskGetRequest mlTaskGetRequest = MLTaskGetRequest.fromActionRequest(request);
String taskId = mlTaskGetRequest.getTaskId();
GetRequest getRequest = new GetRequest(ML_TASK_INDEX).id(taskId);
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) {
client.get(getRequest, ActionListener.wrap(r -> {
log.info("Completed Get Task Request, id:{}", taskId);
if (r != null && r.isExists()) {
try (XContentParser parser = createXContentParserFromRegistry(xContentRegistry, r.getSourceAsBytesRef())) {
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser);
MLTask mlTask = MLTask.parse(parser);
actionListener.onResponse(MLTaskGetResponse.builder().mlTask(mlTask).build());
} catch (Exception e) {
log.error("Failed to parse ml task" + r.getId(), e);
actionListener.onFailure(e);
}
} else {
actionListener.onFailure(new MLResourceNotFoundException("Fail to find task"));
}
}, e -> {
if (e instanceof IndexNotFoundException) {
actionListener.onFailure(new MLResourceNotFoundException("Fail to find task"));
} else {
log.error("Failed to get ML task " + taskId, e);
actionListener.onFailure(e);
}
}));
} catch (Exception e) {
log.error("Failed to get ML task " + taskId, e);
actionListener.onFailure(e);
}
}
Aggregations