Search in sources :

Example 6 with ResourceNotFoundException

use of org.elasticsearch.ResourceNotFoundException in project elasticsearch by elastic.

the class PipelineStoreTests method testDelete.

public void testDelete() {
    PipelineConfiguration config = new PipelineConfiguration("_id", new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}"), XContentType.JSON);
    IngestMetadata ingestMetadata = new IngestMetadata(Collections.singletonMap("_id", config));
    ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build();
    ClusterState previousClusterState = clusterState;
    clusterState = ClusterState.builder(clusterState).metaData(MetaData.builder().putCustom(IngestMetadata.TYPE, ingestMetadata)).build();
    store.innerUpdatePipelines(previousClusterState, clusterState);
    assertThat(store.get("_id"), notNullValue());
    // Delete pipeline:
    DeletePipelineRequest deleteRequest = new DeletePipelineRequest("_id");
    previousClusterState = clusterState;
    clusterState = store.innerDelete(deleteRequest, clusterState);
    store.innerUpdatePipelines(previousClusterState, clusterState);
    assertThat(store.get("_id"), nullValue());
    // Delete existing pipeline:
    try {
        store.innerDelete(deleteRequest, clusterState);
        fail("exception expected");
    } catch (ResourceNotFoundException e) {
        assertThat(e.getMessage(), equalTo("pipeline [_id] is missing"));
    }
}
Also used : DeletePipelineRequest(org.elasticsearch.action.ingest.DeletePipelineRequest) ClusterState(org.elasticsearch.cluster.ClusterState) BytesArray(org.elasticsearch.common.bytes.BytesArray) ClusterName(org.elasticsearch.cluster.ClusterName) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException)

Example 7 with ResourceNotFoundException

use of org.elasticsearch.ResourceNotFoundException in project elasticsearch by elastic.

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());
    }
    builder.withCompress(false);
    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 TransportResponseHandler<GetTaskResponse>() {

        @Override
        public GetTaskResponse newInstance() {
            return new GetTaskResponse();
        }

        @Override
        public void handleResponse(GetTaskResponse response) {
            listener.onResponse(response);
        }

        @Override
        public void handleException(TransportException exp) {
            listener.onFailure(exp);
        }

        @Override
        public String executor() {
            return ThreadPool.Names.SAME;
        }
    });
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException) GetResponse(org.elasticsearch.action.get.GetResponse) ClusterService(org.elasticsearch.cluster.service.ClusterService) TaskId(org.elasticsearch.tasks.TaskId) Inject(org.elasticsearch.common.inject.Inject) XContentHelper(org.elasticsearch.common.xcontent.XContentHelper) TaskResult(org.elasticsearch.tasks.TaskResult) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) HandledTransportAction(org.elasticsearch.action.support.HandledTransportAction) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) TaskResultsService(org.elasticsearch.tasks.TaskResultsService) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TransportService(org.elasticsearch.transport.TransportService) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) TaskInfo(org.elasticsearch.tasks.TaskInfo) GetRequest(org.elasticsearch.action.get.GetRequest) ActionFilters(org.elasticsearch.action.support.ActionFilters) Client(org.elasticsearch.client.Client) IOException(java.io.IOException) XContentParser(org.elasticsearch.common.xcontent.XContentParser) ExceptionsHelper(org.elasticsearch.ExceptionsHelper) AbstractRunnable(org.elasticsearch.common.util.concurrent.AbstractRunnable) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) TransportListTasksAction.waitForCompletionTimeout(org.elasticsearch.action.admin.cluster.node.tasks.list.TransportListTasksAction.waitForCompletionTimeout) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Task(org.elasticsearch.tasks.Task) TransportException(org.elasticsearch.transport.TransportException) ActionListener(org.elasticsearch.action.ActionListener) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) TransportException(org.elasticsearch.transport.TransportException)

Example 8 with ResourceNotFoundException

use of org.elasticsearch.ResourceNotFoundException in project elasticsearch by elastic.

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, TaskResultsService.TASK_TYPE, request.getTaskId().toString());
    get.setParentTask(clusterService.localNode().getId(), thisTask.getId());
    client.get(get, new ActionListener<GetResponse>() {

        @Override
        public void onResponse(GetResponse getResponse) {
            try {
                onGetFinishedTaskFromIndex(getResponse, listener);
            } catch (Exception e) {
                listener.onFailure(e);
            }
        }

        @Override
        public void onFailure(Exception 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 : GetRequest(org.elasticsearch.action.get.GetRequest) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) GetResponse(org.elasticsearch.action.get.GetResponse) ElasticsearchException(org.elasticsearch.ElasticsearchException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) IOException(java.io.IOException) TransportException(org.elasticsearch.transport.TransportException)

Example 9 with ResourceNotFoundException

use of org.elasticsearch.ResourceNotFoundException in project elasticsearch by elastic.

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 ElasticsearchException("Stored task status for [{}] didn't contain any source!", response.getId()));
        return;
    }
    try (XContentParser parser = XContentHelper.createParser(xContentRegistry, response.getSourceAsBytesRef())) {
        TaskResult result = TaskResult.PARSER.apply(parser, null);
        listener.onResponse(new GetTaskResponse(result));
    }
}
Also used : TaskResult(org.elasticsearch.tasks.TaskResult) ElasticsearchException(org.elasticsearch.ElasticsearchException) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 10 with ResourceNotFoundException

use of org.elasticsearch.ResourceNotFoundException in project elasticsearch by elastic.

the class ScriptServiceTests method testDeleteScript.

public void testDeleteScript() throws Exception {
    ScriptMetaData scriptMetaData = ScriptMetaData.putStoredScript(null, "_id", StoredScriptSource.parse("_lang", new BytesArray("{\"script\":\"abc\"}"), XContentType.JSON));
    scriptMetaData = ScriptMetaData.deleteStoredScript(scriptMetaData, "_id", "_lang");
    assertNotNull(scriptMetaData);
    assertNull(scriptMetaData.getStoredScript("_id", "_lang"));
    ScriptMetaData errorMetaData = scriptMetaData;
    ResourceNotFoundException e = expectThrows(ResourceNotFoundException.class, () -> {
        ScriptMetaData.deleteStoredScript(errorMetaData, "_id", "_lang");
    });
    assertEquals("stored script [_id] using lang [_lang] does not exist and cannot be deleted", e.getMessage());
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException)

Aggregations

ResourceNotFoundException (org.elasticsearch.ResourceNotFoundException)12 IOException (java.io.IOException)4 ElasticsearchException (org.elasticsearch.ElasticsearchException)4 BytesArray (org.elasticsearch.common.bytes.BytesArray)4 GetRequest (org.elasticsearch.action.get.GetRequest)3 GetResponse (org.elasticsearch.action.get.GetResponse)3 DeletePipelineRequest (org.elasticsearch.action.ingest.DeletePipelineRequest)3 ClusterName (org.elasticsearch.cluster.ClusterName)3 ClusterState (org.elasticsearch.cluster.ClusterState)3 XContentParser (org.elasticsearch.common.xcontent.XContentParser)3 HashMap (java.util.HashMap)2 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)2 TaskResult (org.elasticsearch.tasks.TaskResult)2 TransportException (org.elasticsearch.transport.TransportException)2 FileNotFoundException (java.io.FileNotFoundException)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 ElasticsearchStatusException (org.elasticsearch.ElasticsearchStatusException)1 ElasticsearchTimeoutException (org.elasticsearch.ElasticsearchTimeoutException)1 ExceptionsHelper (org.elasticsearch.ExceptionsHelper)1 ResourceAlreadyExistsException (org.elasticsearch.ResourceAlreadyExistsException)1