Search in sources :

Example 1 with ResourceNotFoundException

use of org.opensearch.ResourceNotFoundException in project OpenSearch by opensearch-project.

the class PercolateQueryBuilderTests method testIndexedDocumentDoesNotExist.

public void testIndexedDocumentDoesNotExist() throws IOException {
    indexedDocumentExists = false;
    PercolateQueryBuilder pqb = doCreateTestQueryBuilder(true);
    ResourceNotFoundException e = expectThrows(ResourceNotFoundException.class, () -> rewriteAndFetch(pqb, createShardContext()));
    String expectedString = "indexed document [" + indexedDocumentIndex + "/" + indexedDocumentId + "] couldn't be found";
    assertThat(e.getMessage(), equalTo(expectedString));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) ResourceNotFoundException(org.opensearch.ResourceNotFoundException)

Example 2 with ResourceNotFoundException

use of org.opensearch.ResourceNotFoundException in project OpenSearch by opensearch-project.

the class TransportGetComposableIndexTemplateAction method masterOperation.

@Override
protected void masterOperation(GetComposableIndexTemplateAction.Request request, ClusterState state, ActionListener<GetComposableIndexTemplateAction.Response> listener) {
    Map<String, ComposableIndexTemplate> allTemplates = state.metadata().templatesV2();
    // If we did not ask for a specific name, then we return all templates
    if (request.name() == null) {
        listener.onResponse(new GetComposableIndexTemplateAction.Response(allTemplates));
        return;
    }
    final Map<String, ComposableIndexTemplate> results = new HashMap<>();
    String name = request.name();
    if (Regex.isSimpleMatchPattern(name)) {
        for (Map.Entry<String, ComposableIndexTemplate> entry : allTemplates.entrySet()) {
            if (Regex.simpleMatch(name, entry.getKey())) {
                results.put(entry.getKey(), entry.getValue());
            }
        }
    } else if (allTemplates.containsKey(name)) {
        results.put(name, allTemplates.get(name));
    } else {
        throw new ResourceNotFoundException("index template matching [" + request.name() + "] not found");
    }
    listener.onResponse(new GetComposableIndexTemplateAction.Response(results));
}
Also used : ComposableIndexTemplate(org.opensearch.cluster.metadata.ComposableIndexTemplate) HashMap(java.util.HashMap) ResourceNotFoundException(org.opensearch.ResourceNotFoundException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with ResourceNotFoundException

use of org.opensearch.ResourceNotFoundException in project OpenSearch by opensearch-project.

the class TransportGetTaskAction method onGetFinishedTaskFromIndex.

/**
 * Called with the {@linkplain GetResponse} from loading the task from the results index. Called on the node that once had the task if
 * that node is part of the cluster or on the coordinating node if the node wasn't part of the cluster.
 */
void onGetFinishedTaskFromIndex(GetResponse response, ActionListener<GetTaskResponse> listener) throws IOException {
    if (false == response.isExists()) {
        listener.onFailure(new ResourceNotFoundException("task [{}] isn't running and hasn't stored its results", response.getId()));
        return;
    }
    if (response.isSourceEmpty()) {
        listener.onFailure(new OpenSearchException("Stored task status for [{}] didn't contain any source!", response.getId()));
        return;
    }
    try (XContentParser parser = XContentHelper.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, response.getSourceAsBytesRef())) {
        TaskResult result = TaskResult.PARSER.apply(parser, null);
        listener.onResponse(new GetTaskResponse(result));
    }
}
Also used : TaskResult(org.opensearch.tasks.TaskResult) OpenSearchException(org.opensearch.OpenSearchException) ResourceNotFoundException(org.opensearch.ResourceNotFoundException) XContentParser(org.opensearch.common.xcontent.XContentParser)

Example 4 with ResourceNotFoundException

use of org.opensearch.ResourceNotFoundException in project OpenSearch by opensearch-project.

the class TransportGetTaskAction method getFinishedTaskFromIndex.

/**
 * Send a {@link GetRequest} to the tasks index looking for a persisted copy of the task completed task. It'll only be found only if the
 * task's result was stored. Called on the node that once had the task if that node is still part of the cluster or on the
 * coordinating node if the node is no longer part of the cluster.
 */
void getFinishedTaskFromIndex(Task thisTask, GetTaskRequest request, ActionListener<GetTaskResponse> listener) {
    GetRequest get = new GetRequest(TaskResultsService.TASK_INDEX, request.getTaskId().toString());
    get.setParentTask(clusterService.localNode().getId(), thisTask.getId());
    client.get(get, ActionListener.wrap(r -> onGetFinishedTaskFromIndex(r, listener), e -> {
        if (ExceptionsHelper.unwrap(e, IndexNotFoundException.class) != null) {
            // We haven't yet created the index for the task results so it can't be found.
            listener.onFailure(new ResourceNotFoundException("task [{}] isn't running and hasn't stored its results", e, request.getTaskId()));
        } else {
            listener.onFailure(e);
        }
    }));
}
Also used : HandledTransportAction(org.opensearch.action.support.HandledTransportAction) AbstractRunnable(org.opensearch.common.util.concurrent.AbstractRunnable) ThreadPool(org.opensearch.threadpool.ThreadPool) OpenSearchException(org.opensearch.OpenSearchException) ResourceNotFoundException(org.opensearch.ResourceNotFoundException) XContentParser(org.opensearch.common.xcontent.XContentParser) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Inject(org.opensearch.common.inject.Inject) ActionListener(org.opensearch.action.ActionListener) GetResponse(org.opensearch.action.get.GetResponse) TaskResultsService(org.opensearch.tasks.TaskResultsService) Client(org.opensearch.client.Client) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) GetRequest(org.opensearch.action.get.GetRequest) LoggingDeprecationHandler(org.opensearch.common.xcontent.LoggingDeprecationHandler) TaskResult(org.opensearch.tasks.TaskResult) TransportRequestOptions(org.opensearch.transport.TransportRequestOptions) ExceptionsHelper(org.opensearch.ExceptionsHelper) TaskId(org.opensearch.tasks.TaskId) IOException(java.io.IOException) Task(org.opensearch.tasks.Task) TransportService(org.opensearch.transport.TransportService) XContentHelper(org.opensearch.common.xcontent.XContentHelper) ActionFilters(org.opensearch.action.support.ActionFilters) TaskInfo(org.opensearch.tasks.TaskInfo) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) TransportListTasksAction.waitForCompletionTimeout(org.opensearch.action.admin.cluster.node.tasks.list.TransportListTasksAction.waitForCompletionTimeout) ActionListenerResponseHandler(org.opensearch.action.ActionListenerResponseHandler) ClusterService(org.opensearch.cluster.service.ClusterService) OriginSettingClient(org.opensearch.client.OriginSettingClient) GetRequest(org.opensearch.action.get.GetRequest) ResourceNotFoundException(org.opensearch.ResourceNotFoundException)

Example 5 with ResourceNotFoundException

use of org.opensearch.ResourceNotFoundException in project OpenSearch by opensearch-project.

the class TransportGetTaskAction method runOnNodeWithTaskIfPossible.

/**
 * Executed on the coordinating node to forward execution of the remaining work to the node that matches that requested
 * {@link TaskId#getNodeId()}. If the node isn't in the cluster then this will just proceed to
 * {@link #getFinishedTaskFromIndex(Task, GetTaskRequest, ActionListener)} on this node.
 */
private void runOnNodeWithTaskIfPossible(Task thisTask, GetTaskRequest request, ActionListener<GetTaskResponse> listener) {
    TransportRequestOptions.Builder builder = TransportRequestOptions.builder();
    if (request.getTimeout() != null) {
        builder.withTimeout(request.getTimeout());
    }
    DiscoveryNode node = clusterService.state().nodes().get(request.getTaskId().getNodeId());
    if (node == null) {
        // Node is no longer part of the cluster! Try and look the task up from the results index.
        getFinishedTaskFromIndex(thisTask, request, ActionListener.wrap(listener::onResponse, e -> {
            if (e instanceof ResourceNotFoundException) {
                e = new ResourceNotFoundException("task [" + request.getTaskId() + "] belongs to the node [" + request.getTaskId().getNodeId() + "] which isn't part of the cluster and there is no record of the task", e);
            }
            listener.onFailure(e);
        }));
        return;
    }
    GetTaskRequest nodeRequest = request.nodeRequest(clusterService.localNode().getId(), thisTask.getId());
    transportService.sendRequest(node, GetTaskAction.NAME, nodeRequest, builder.build(), new ActionListenerResponseHandler<>(listener, GetTaskResponse::new, ThreadPool.Names.SAME));
}
Also used : HandledTransportAction(org.opensearch.action.support.HandledTransportAction) AbstractRunnable(org.opensearch.common.util.concurrent.AbstractRunnable) ThreadPool(org.opensearch.threadpool.ThreadPool) OpenSearchException(org.opensearch.OpenSearchException) ResourceNotFoundException(org.opensearch.ResourceNotFoundException) XContentParser(org.opensearch.common.xcontent.XContentParser) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Inject(org.opensearch.common.inject.Inject) ActionListener(org.opensearch.action.ActionListener) GetResponse(org.opensearch.action.get.GetResponse) TaskResultsService(org.opensearch.tasks.TaskResultsService) Client(org.opensearch.client.Client) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) GetRequest(org.opensearch.action.get.GetRequest) LoggingDeprecationHandler(org.opensearch.common.xcontent.LoggingDeprecationHandler) TaskResult(org.opensearch.tasks.TaskResult) TransportRequestOptions(org.opensearch.transport.TransportRequestOptions) ExceptionsHelper(org.opensearch.ExceptionsHelper) TaskId(org.opensearch.tasks.TaskId) IOException(java.io.IOException) Task(org.opensearch.tasks.Task) TransportService(org.opensearch.transport.TransportService) XContentHelper(org.opensearch.common.xcontent.XContentHelper) ActionFilters(org.opensearch.action.support.ActionFilters) TaskInfo(org.opensearch.tasks.TaskInfo) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) TransportListTasksAction.waitForCompletionTimeout(org.opensearch.action.admin.cluster.node.tasks.list.TransportListTasksAction.waitForCompletionTimeout) ActionListenerResponseHandler(org.opensearch.action.ActionListenerResponseHandler) ClusterService(org.opensearch.cluster.service.ClusterService) OriginSettingClient(org.opensearch.client.OriginSettingClient) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) TransportRequestOptions(org.opensearch.transport.TransportRequestOptions) ResourceNotFoundException(org.opensearch.ResourceNotFoundException)

Aggregations

ResourceNotFoundException (org.opensearch.ResourceNotFoundException)20 OpenSearchException (org.opensearch.OpenSearchException)8 IOException (java.io.IOException)6 XContentParser (org.opensearch.common.xcontent.XContentParser)6 HashMap (java.util.HashMap)5 GetResponse (org.opensearch.action.get.GetResponse)4 ClusterState (org.opensearch.cluster.ClusterState)4 BytesArray (org.opensearch.common.bytes.BytesArray)4 Map (java.util.Map)3 GetRequest (org.opensearch.action.get.GetRequest)3 DeletePipelineRequest (org.opensearch.action.ingest.DeletePipelineRequest)3 ClusterChangedEvent (org.opensearch.cluster.ClusterChangedEvent)3 ClusterName (org.opensearch.cluster.ClusterName)3 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)3 TaskResult (org.opensearch.tasks.TaskResult)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Objects (java.util.Objects)2