Search in sources :

Example 6 with DeletePipelineRequest

use of org.elasticsearch.action.ingest.DeletePipelineRequest 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 DeletePipelineRequest

use of org.elasticsearch.action.ingest.DeletePipelineRequest in project elasticsearch by elastic.

the class RestDeletePipelineAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
    DeletePipelineRequest request = new DeletePipelineRequest(restRequest.param("id"));
    request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout()));
    request.timeout(restRequest.paramAsTime("timeout", request.timeout()));
    return channel -> client.admin().cluster().deletePipeline(request, new AcknowledgedRestListener<>(channel));
}
Also used : DeletePipelineRequest(org.elasticsearch.action.ingest.DeletePipelineRequest) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Settings(org.elasticsearch.common.settings.Settings) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) DeletePipelineRequest(org.elasticsearch.action.ingest.DeletePipelineRequest) RestController(org.elasticsearch.rest.RestController) AcknowledgedRestListener(org.elasticsearch.rest.action.AcknowledgedRestListener)

Example 8 with DeletePipelineRequest

use of org.elasticsearch.action.ingest.DeletePipelineRequest in project elasticsearch by elastic.

the class PipelineStoreTests method testCrud.

public void testCrud() throws Exception {
    String id = "_id";
    Pipeline pipeline = store.get(id);
    assertThat(pipeline, nullValue());
    // Start empty
    ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build();
    PutPipelineRequest putRequest = new PutPipelineRequest(id, new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}"), XContentType.JSON);
    ClusterState previousClusterState = clusterState;
    clusterState = store.innerPut(putRequest, clusterState);
    store.innerUpdatePipelines(previousClusterState, clusterState);
    pipeline = store.get(id);
    assertThat(pipeline, notNullValue());
    assertThat(pipeline.getId(), equalTo(id));
    assertThat(pipeline.getDescription(), nullValue());
    assertThat(pipeline.getProcessors().size(), equalTo(1));
    assertThat(pipeline.getProcessors().get(0).getType(), equalTo("set"));
    DeletePipelineRequest deleteRequest = new DeletePipelineRequest(id);
    previousClusterState = clusterState;
    clusterState = store.innerDelete(deleteRequest, clusterState);
    store.innerUpdatePipelines(previousClusterState, clusterState);
    pipeline = store.get(id);
    assertThat(pipeline, nullValue());
}
Also used : DeletePipelineRequest(org.elasticsearch.action.ingest.DeletePipelineRequest) ClusterState(org.elasticsearch.cluster.ClusterState) BytesArray(org.elasticsearch.common.bytes.BytesArray) ClusterName(org.elasticsearch.cluster.ClusterName) PutPipelineRequest(org.elasticsearch.action.ingest.PutPipelineRequest)

Example 9 with DeletePipelineRequest

use of org.elasticsearch.action.ingest.DeletePipelineRequest in project elasticsearch by elastic.

the class CancelTests method testUpdateByQueryCancel.

public void testUpdateByQueryCancel() throws Exception {
    BytesReference pipeline = new BytesArray("{\n" + "  \"description\" : \"sets processed to true\",\n" + "  \"processors\" : [ {\n" + "      \"test\" : {}\n" + "  } ]\n" + "}");
    assertAcked(client().admin().cluster().preparePutPipeline("set-processed", pipeline, XContentType.JSON).get());
    testCancel(UpdateByQueryAction.NAME, updateByQuery().setPipeline("set-processed").source(INDEX), (response, total, modified) -> {
        assertThat(response, matcher().updated(modified).reasonCancelled(equalTo("by user request")));
        assertHitCount(client().prepareSearch(INDEX).setSize(0).setQuery(termQuery("processed", true)).get(), modified);
    }, equalTo("update-by-query [" + INDEX + "]"));
    assertAcked(client().admin().cluster().deletePipeline(new DeletePipelineRequest("set-processed")).get());
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) DeletePipelineRequest(org.elasticsearch.action.ingest.DeletePipelineRequest) BytesArray(org.elasticsearch.common.bytes.BytesArray)

Aggregations

DeletePipelineRequest (org.elasticsearch.action.ingest.DeletePipelineRequest)9 BytesArray (org.elasticsearch.common.bytes.BytesArray)7 ClusterName (org.elasticsearch.cluster.ClusterName)4 ClusterState (org.elasticsearch.cluster.ClusterState)4 BytesReference (org.elasticsearch.common.bytes.BytesReference)4 ResourceNotFoundException (org.elasticsearch.ResourceNotFoundException)3 HashMap (java.util.HashMap)2 GetPipelineResponse (org.elasticsearch.action.ingest.GetPipelineResponse)2 PutPipelineRequest (org.elasticsearch.action.ingest.PutPipelineRequest)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 CreateSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)1 RestoreSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)1 GetStoredScriptResponse (org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptResponse)1 GetIndexTemplatesResponse (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse)1 GetPipelineRequest (org.elasticsearch.action.ingest.GetPipelineRequest)1 WritePipelineResponse (org.elasticsearch.action.ingest.WritePipelineResponse)1 Client (org.elasticsearch.client.Client)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 Settings (org.elasticsearch.common.settings.Settings)1