Search in sources :

Example 1 with GetPipelineRequest

use of org.opensearch.action.ingest.GetPipelineRequest in project OpenSearch by opensearch-project.

the class IngestRequestConverters method getPipeline.

static Request getPipeline(GetPipelineRequest getPipelineRequest) {
    String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_ingest/pipeline").addCommaSeparatedPathParts(getPipelineRequest.getIds()).build();
    Request request = new Request(HttpGet.METHOD_NAME, endpoint);
    RequestConverters.Params parameters = new RequestConverters.Params();
    parameters.withMasterTimeout(getPipelineRequest.masterNodeTimeout());
    request.addParameters(parameters.asMap());
    return request;
}
Also used : DeletePipelineRequest(org.opensearch.action.ingest.DeletePipelineRequest) SimulatePipelineRequest(org.opensearch.action.ingest.SimulatePipelineRequest) GetPipelineRequest(org.opensearch.action.ingest.GetPipelineRequest) PutPipelineRequest(org.opensearch.action.ingest.PutPipelineRequest)

Example 2 with GetPipelineRequest

use of org.opensearch.action.ingest.GetPipelineRequest in project OpenSearch by opensearch-project.

the class IngestRequestConvertersTests method testGetPipeline.

public void testGetPipeline() {
    String pipelineId = "some_pipeline_id";
    Map<String, String> expectedParams = new HashMap<>();
    GetPipelineRequest request = new GetPipelineRequest("some_pipeline_id");
    RequestConvertersTests.setRandomMasterTimeout(request, expectedParams);
    Request expectedRequest = IngestRequestConverters.getPipeline(request);
    StringJoiner endpoint = new StringJoiner("/", "/", "");
    endpoint.add("_ingest/pipeline");
    endpoint.add(pipelineId);
    Assert.assertEquals(endpoint.toString(), expectedRequest.getEndpoint());
    Assert.assertEquals(HttpGet.METHOD_NAME, expectedRequest.getMethod());
    Assert.assertEquals(expectedParams, expectedRequest.getParameters());
}
Also used : GetPipelineRequest(org.opensearch.action.ingest.GetPipelineRequest) HashMap(java.util.HashMap) DeletePipelineRequest(org.opensearch.action.ingest.DeletePipelineRequest) AcknowledgedRequest(org.opensearch.action.support.master.AcknowledgedRequest) PutPipelineRequest(org.opensearch.action.ingest.PutPipelineRequest) SimulatePipelineRequest(org.opensearch.action.ingest.SimulatePipelineRequest) GetPipelineRequest(org.opensearch.action.ingest.GetPipelineRequest) StringJoiner(java.util.StringJoiner)

Example 3 with GetPipelineRequest

use of org.opensearch.action.ingest.GetPipelineRequest in project OpenSearch by opensearch-project.

the class IngestClientIT method testGetNonexistentPipeline.

public void testGetNonexistentPipeline() throws IOException {
    String id = "nonexistent_pipeline_id";
    GetPipelineRequest request = new GetPipelineRequest(id);
    GetPipelineResponse response = execute(request, highLevelClient().ingest()::getPipeline, highLevelClient().ingest()::getPipelineAsync);
    assertFalse(response.isFound());
}
Also used : GetPipelineRequest(org.opensearch.action.ingest.GetPipelineRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) GetPipelineResponse(org.opensearch.action.ingest.GetPipelineResponse)

Example 4 with GetPipelineRequest

use of org.opensearch.action.ingest.GetPipelineRequest in project OpenSearch by opensearch-project.

the class IngestClientIT method test.

public void test() throws Exception {
    BytesReference source = BytesReference.bytes(jsonBuilder().startObject().field("description", "my_pipeline").startArray("processors").startObject().startObject("test").endObject().endObject().endArray().endObject());
    PutPipelineRequest putPipelineRequest = new PutPipelineRequest("_id", source, XContentType.JSON);
    client().admin().cluster().putPipeline(putPipelineRequest).get();
    GetPipelineRequest getPipelineRequest = new GetPipelineRequest("_id");
    GetPipelineResponse getResponse = client().admin().cluster().getPipeline(getPipelineRequest).get();
    assertThat(getResponse.isFound(), is(true));
    assertThat(getResponse.pipelines().size(), equalTo(1));
    assertThat(getResponse.pipelines().get(0).getId(), equalTo("_id"));
    client().prepareIndex("test").setId("1").setPipeline("_id").setSource("field", "value", "fail", false).get();
    Map<String, Object> doc = client().prepareGet("test", "1").get().getSourceAsMap();
    assertThat(doc.get("field"), equalTo("value"));
    assertThat(doc.get("processed"), equalTo(true));
    client().prepareBulk().add(client().prepareIndex("test").setId("2").setSource("field", "value2", "fail", false).setPipeline("_id")).get();
    doc = client().prepareGet("test", "2").get().getSourceAsMap();
    assertThat(doc.get("field"), equalTo("value2"));
    assertThat(doc.get("processed"), equalTo(true));
    DeletePipelineRequest deletePipelineRequest = new DeletePipelineRequest("_id");
    AcknowledgedResponse response = client().admin().cluster().deletePipeline(deletePipelineRequest).get();
    assertThat(response.isAcknowledged(), is(true));
    getResponse = client().admin().cluster().prepareGetPipeline("_id").get();
    assertThat(getResponse.isFound(), is(false));
    assertThat(getResponse.pipelines().size(), equalTo(0));
}
Also used : BytesReference(org.opensearch.common.bytes.BytesReference) DeletePipelineRequest(org.opensearch.action.ingest.DeletePipelineRequest) GetPipelineRequest(org.opensearch.action.ingest.GetPipelineRequest) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) PutPipelineRequest(org.opensearch.action.ingest.PutPipelineRequest) GetPipelineResponse(org.opensearch.action.ingest.GetPipelineResponse)

Example 5 with GetPipelineRequest

use of org.opensearch.action.ingest.GetPipelineRequest in project OpenSearch by opensearch-project.

the class IngestClientIT method testGetPipeline.

public void testGetPipeline() throws IOException {
    String id = "some_pipeline_id";
    XContentBuilder pipelineBuilder = buildRandomXContentPipeline();
    {
        PutPipelineRequest request = new PutPipelineRequest(id, BytesReference.bytes(pipelineBuilder), pipelineBuilder.contentType());
        createPipeline(request);
    }
    GetPipelineRequest request = new GetPipelineRequest(id);
    GetPipelineResponse response = execute(request, highLevelClient().ingest()::getPipeline, highLevelClient().ingest()::getPipelineAsync);
    assertTrue(response.isFound());
    assertEquals(response.pipelines().get(0).getId(), id);
    PipelineConfiguration expectedConfig = new PipelineConfiguration(id, BytesReference.bytes(pipelineBuilder), pipelineBuilder.contentType());
    assertEquals(expectedConfig.getConfigAsMap(), response.pipelines().get(0).getConfigAsMap());
}
Also used : GetPipelineRequest(org.opensearch.action.ingest.GetPipelineRequest) PutPipelineRequest(org.opensearch.action.ingest.PutPipelineRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) PipelineConfiguration(org.opensearch.ingest.PipelineConfiguration) GetPipelineResponse(org.opensearch.action.ingest.GetPipelineResponse) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Aggregations

GetPipelineRequest (org.opensearch.action.ingest.GetPipelineRequest)6 PutPipelineRequest (org.opensearch.action.ingest.PutPipelineRequest)4 DeletePipelineRequest (org.opensearch.action.ingest.DeletePipelineRequest)3 GetPipelineResponse (org.opensearch.action.ingest.GetPipelineResponse)3 Matchers.containsString (org.hamcrest.Matchers.containsString)2 SimulatePipelineRequest (org.opensearch.action.ingest.SimulatePipelineRequest)2 IOException (java.io.IOException)1 Arrays.asList (java.util.Arrays.asList)1 Collections.unmodifiableList (java.util.Collections.unmodifiableList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 StringJoiner (java.util.StringJoiner)1 AcknowledgedRequest (org.opensearch.action.support.master.AcknowledgedRequest)1 AcknowledgedResponse (org.opensearch.action.support.master.AcknowledgedResponse)1 NodeClient (org.opensearch.client.node.NodeClient)1 Strings (org.opensearch.common.Strings)1 BytesReference (org.opensearch.common.bytes.BytesReference)1 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)1 PipelineConfiguration (org.opensearch.ingest.PipelineConfiguration)1 BaseRestHandler (org.opensearch.rest.BaseRestHandler)1