Search in sources :

Example 1 with ResourceNotFoundException

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

the class PercolateQueryBuilder method doRewrite.

@Override
protected QueryBuilder doRewrite(QueryRewriteContext queryShardContext) throws IOException {
    if (document != null) {
        return this;
    }
    GetRequest getRequest = new GetRequest(indexedDocumentIndex, indexedDocumentType, indexedDocumentId);
    getRequest.preference("_local");
    getRequest.routing(indexedDocumentRouting);
    getRequest.preference(indexedDocumentPreference);
    if (indexedDocumentVersion != null) {
        getRequest.version(indexedDocumentVersion);
    }
    GetResponse getResponse = queryShardContext.getClient().get(getRequest).actionGet();
    if (getResponse.isExists() == false) {
        throw new ResourceNotFoundException("indexed document [{}/{}/{}] couldn't be found", indexedDocumentIndex, indexedDocumentType, indexedDocumentId);
    }
    if (getResponse.isSourceEmpty()) {
        throw new IllegalArgumentException("indexed document [" + indexedDocumentIndex + "/" + indexedDocumentType + "/" + indexedDocumentId + "] source disabled");
    }
    final BytesReference source = getResponse.getSourceAsBytesRef();
    return new PercolateQueryBuilder(field, documentType, source, XContentFactory.xContentType(source));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) GetRequest(org.elasticsearch.action.get.GetRequest) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) GetResponse(org.elasticsearch.action.get.GetResponse)

Example 2 with ResourceNotFoundException

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

the class PipelineStoreTests method testDeleteUsingWildcard.

public void testDeleteUsingWildcard() {
    HashMap<String, PipelineConfiguration> pipelines = new HashMap<>();
    BytesArray definition = new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}");
    pipelines.put("p1", new PipelineConfiguration("p1", definition, XContentType.JSON));
    pipelines.put("p2", new PipelineConfiguration("p2", definition, XContentType.JSON));
    pipelines.put("q1", new PipelineConfiguration("q1", definition, XContentType.JSON));
    IngestMetadata ingestMetadata = new IngestMetadata(pipelines);
    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("p1"), notNullValue());
    assertThat(store.get("p2"), notNullValue());
    assertThat(store.get("q1"), notNullValue());
    // Delete pipeline matching wildcard
    DeletePipelineRequest deleteRequest = new DeletePipelineRequest("p*");
    previousClusterState = clusterState;
    clusterState = store.innerDelete(deleteRequest, clusterState);
    store.innerUpdatePipelines(previousClusterState, clusterState);
    assertThat(store.get("p1"), nullValue());
    assertThat(store.get("p2"), nullValue());
    assertThat(store.get("q1"), notNullValue());
    // Exception if we used name which does not exist
    try {
        store.innerDelete(new DeletePipelineRequest("unknown"), clusterState);
        fail("exception expected");
    } catch (ResourceNotFoundException e) {
        assertThat(e.getMessage(), equalTo("pipeline [unknown] is missing"));
    }
    // match all wildcard works on last remaining pipeline
    DeletePipelineRequest matchAllDeleteRequest = new DeletePipelineRequest("*");
    previousClusterState = clusterState;
    clusterState = store.innerDelete(matchAllDeleteRequest, clusterState);
    store.innerUpdatePipelines(previousClusterState, clusterState);
    assertThat(store.get("p1"), nullValue());
    assertThat(store.get("p2"), nullValue());
    assertThat(store.get("q1"), nullValue());
    // match all wildcard does not throw exception if none match
    store.innerDelete(matchAllDeleteRequest, clusterState);
}
Also used : DeletePipelineRequest(org.elasticsearch.action.ingest.DeletePipelineRequest) ClusterState(org.elasticsearch.cluster.ClusterState) BytesArray(org.elasticsearch.common.bytes.BytesArray) HashMap(java.util.HashMap) ClusterName(org.elasticsearch.cluster.ClusterName) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException)

Example 3 with ResourceNotFoundException

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

the class PipelineStoreTests method testDeleteWithExistingUnmatchedPipelines.

public void testDeleteWithExistingUnmatchedPipelines() {
    HashMap<String, PipelineConfiguration> pipelines = new HashMap<>();
    BytesArray definition = new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}");
    pipelines.put("p1", new PipelineConfiguration("p1", definition, XContentType.JSON));
    IngestMetadata ingestMetadata = new IngestMetadata(pipelines);
    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("p1"), notNullValue());
    DeletePipelineRequest deleteRequest = new DeletePipelineRequest("z*");
    try {
        store.innerDelete(deleteRequest, clusterState);
        fail("exception expected");
    } catch (ResourceNotFoundException e) {
        assertThat(e.getMessage(), equalTo("pipeline [z*] is missing"));
    }
}
Also used : DeletePipelineRequest(org.elasticsearch.action.ingest.DeletePipelineRequest) ClusterState(org.elasticsearch.cluster.ClusterState) BytesArray(org.elasticsearch.common.bytes.BytesArray) HashMap(java.util.HashMap) ClusterName(org.elasticsearch.cluster.ClusterName) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException)

Example 4 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 5 with ResourceNotFoundException

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

the class TasksIT method expectNotFound.

private ResourceNotFoundException expectNotFound(ThrowingRunnable r) {
    Exception e = expectThrows(Exception.class, r);
    ResourceNotFoundException notFound = (ResourceNotFoundException) ExceptionsHelper.unwrap(e, ResourceNotFoundException.class);
    if (notFound == null)
        throw new RuntimeException("Expected ResourceNotFoundException", e);
    return notFound;
}
Also used : ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) FailedNodeException(org.elasticsearch.action.FailedNodeException) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) ReceiveTimeoutTransportException(org.elasticsearch.transport.ReceiveTimeoutTransportException) ElasticsearchTimeoutException(org.elasticsearch.ElasticsearchTimeoutException) IOException(java.io.IOException) BrokenBarrierException(java.util.concurrent.BrokenBarrierException)

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