Search in sources :

Example 6 with PutPipelineRequest

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

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

the class PipelineStoreTests method testValidate.

public void testValidate() throws Exception {
    PutPipelineRequest putRequest = new PutPipelineRequest("_id", new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\", \"tag\": \"tag1\"}}," + "{\"remove\" : {\"field\": \"_field\", \"tag\": \"tag2\"}}]}"), XContentType.JSON);
    DiscoveryNode node1 = new DiscoveryNode("_node_id1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    DiscoveryNode node2 = new DiscoveryNode("_node_id2", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    Map<DiscoveryNode, IngestInfo> ingestInfos = new HashMap<>();
    ingestInfos.put(node1, new IngestInfo(Arrays.asList(new ProcessorInfo("set"), new ProcessorInfo("remove"))));
    ingestInfos.put(node2, new IngestInfo(Arrays.asList(new ProcessorInfo("set"))));
    ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class, () -> store.validatePipeline(ingestInfos, putRequest));
    assertEquals("Processor type [remove] is not installed on node [" + node2 + "]", e.getMessage());
    assertEquals("remove", e.getHeader("processor_type").get(0));
    assertEquals("tag2", e.getHeader("processor_tag").get(0));
    ingestInfos.put(node2, new IngestInfo(Arrays.asList(new ProcessorInfo("set"), new ProcessorInfo("remove"))));
    store.validatePipeline(ingestInfos, putRequest);
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) HashMap(java.util.HashMap) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException) PutPipelineRequest(org.elasticsearch.action.ingest.PutPipelineRequest)

Example 8 with PutPipelineRequest

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

the class PipelineStoreTests method testPut.

public void testPut() {
    String id = "_id";
    Pipeline pipeline = store.get(id);
    assertThat(pipeline, nullValue());
    ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build();
    // add a new pipeline:
    PutPipelineRequest putRequest = new PutPipelineRequest(id, new BytesArray("{\"processors\": []}"), 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(0));
    // overwrite existing pipeline:
    putRequest = new PutPipelineRequest(id, new BytesArray("{\"processors\": [], \"description\": \"_description\"}"), XContentType.JSON);
    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(), equalTo("_description"));
    assertThat(pipeline.getProcessors().size(), equalTo(0));
}
Also used : 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 PutPipelineRequest

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

the class PipelineStoreTests method testPutWithErrorResponse.

public void testPutWithErrorResponse() {
    String id = "_id";
    Pipeline pipeline = store.get(id);
    assertThat(pipeline, nullValue());
    ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build();
    PutPipelineRequest putRequest = new PutPipelineRequest(id, new BytesArray("{\"description\": \"empty processors\"}"), XContentType.JSON);
    ClusterState previousClusterState = clusterState;
    clusterState = store.innerPut(putRequest, clusterState);
    try {
        store.innerUpdatePipelines(previousClusterState, clusterState);
        fail("should fail");
    } catch (ElasticsearchParseException e) {
        assertThat(e.getMessage(), equalTo("[processors] required property is missing"));
    }
    pipeline = store.get(id);
    assertThat(pipeline, nullValue());
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) BytesArray(org.elasticsearch.common.bytes.BytesArray) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException) ClusterName(org.elasticsearch.cluster.ClusterName) PutPipelineRequest(org.elasticsearch.action.ingest.PutPipelineRequest)

Aggregations

PutPipelineRequest (org.elasticsearch.action.ingest.PutPipelineRequest)9 BytesArray (org.elasticsearch.common.bytes.BytesArray)5 ElasticsearchParseException (org.elasticsearch.ElasticsearchParseException)4 BytesReference (org.elasticsearch.common.bytes.BytesReference)4 ClusterName (org.elasticsearch.cluster.ClusterName)3 ClusterState (org.elasticsearch.cluster.ClusterState)3 DeletePipelineRequest (org.elasticsearch.action.ingest.DeletePipelineRequest)2 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 ResourceNotFoundException (org.elasticsearch.ResourceNotFoundException)1 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)1 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)1 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)1 IndexRequest (org.elasticsearch.action.index.IndexRequest)1 IndexResponse (org.elasticsearch.action.index.IndexResponse)1 GetPipelineRequest (org.elasticsearch.action.ingest.GetPipelineRequest)1 GetPipelineResponse (org.elasticsearch.action.ingest.GetPipelineResponse)1