Search in sources :

Example 1 with PutPipelineRequest

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

the class IngestClientIT method testPutPipeline.

public void testPutPipeline() throws IOException {
    String id = "some_pipeline_id";
    XContentBuilder pipelineBuilder = buildRandomXContentPipeline();
    PutPipelineRequest request = new PutPipelineRequest(id, BytesReference.bytes(pipelineBuilder), pipelineBuilder.contentType());
    AcknowledgedResponse putPipelineResponse = execute(request, highLevelClient().ingest()::putPipeline, highLevelClient().ingest()::putPipelineAsync);
    assertTrue(putPipelineResponse.isAcknowledged());
}
Also used : AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) PutPipelineRequest(org.opensearch.action.ingest.PutPipelineRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 2 with PutPipelineRequest

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

the class OpenSearchRestHighLevelClientTestCase method createPipeline.

protected static void createPipeline(String pipelineId) throws IOException {
    XContentBuilder builder = buildRandomXContentPipeline();
    createPipeline(new PutPipelineRequest(pipelineId, BytesReference.bytes(builder), builder.contentType()));
}
Also used : PutPipelineRequest(org.opensearch.action.ingest.PutPipelineRequest) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 3 with PutPipelineRequest

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

the class OpenSearchRestHighLevelClientTestCase method createFieldAddingPipleine.

protected static void createFieldAddingPipleine(String id, String fieldName, String value) throws IOException {
    XContentBuilder pipeline = jsonBuilder().startObject().startArray("processors").startObject().startObject("set").field("field", fieldName).field("value", value).endObject().endObject().endArray().endObject();
    createPipeline(new PutPipelineRequest(id, BytesReference.bytes(pipeline), XContentType.JSON));
}
Also used : PutPipelineRequest(org.opensearch.action.ingest.PutPipelineRequest) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 4 with PutPipelineRequest

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

the class GeoIpProcessorNonIngestNodeIT method testLazyLoading.

/**
 * This test shows that we do not load the geo-IP databases on non-ingest nodes, and only load on ingest nodes on first use.
 *
 * @throws IOException if an I/O exception occurs building the JSON
 */
public void testLazyLoading() throws IOException {
    assumeFalse("https://github.com/elastic/elasticsearch/issues/37342", Constants.WINDOWS);
    final BytesReference bytes;
    try (XContentBuilder builder = JsonXContent.contentBuilder()) {
        builder.startObject();
        {
            builder.field("description", "test");
            builder.startArray("processors");
            {
                builder.startObject();
                {
                    builder.startObject("geoip");
                    {
                        builder.field("field", "ip");
                        builder.field("target_field", "ip-city");
                        builder.field("database_file", "GeoLite2-City.mmdb");
                    }
                    builder.endObject();
                }
                builder.endObject();
                builder.startObject();
                {
                    builder.startObject("geoip");
                    {
                        builder.field("field", "ip");
                        builder.field("target_field", "ip-country");
                        builder.field("database_file", "GeoLite2-Country.mmdb");
                    }
                    builder.endObject();
                }
                builder.endObject();
                builder.startObject();
                {
                    builder.startObject("geoip");
                    {
                        builder.field("field", "ip");
                        builder.field("target_field", "ip-asn");
                        builder.field("database_file", "GeoLite2-ASN.mmdb");
                    }
                    builder.endObject();
                }
                builder.endObject();
            }
            builder.endArray();
        }
        builder.endObject();
        bytes = BytesReference.bytes(builder);
    }
    assertAcked(client().admin().cluster().putPipeline(new PutPipelineRequest("geoip", bytes, XContentType.JSON)).actionGet());
    // the geo-IP databases should not be loaded on any nodes as they are all non-ingest nodes
    Arrays.stream(internalCluster().getNodeNames()).forEach(node -> assertDatabaseLoadStatus(node, false));
    // start an ingest node
    final String ingestNode = internalCluster().startNode(NodeRoles.ingestNode());
    internalCluster().getInstance(IngestService.class, ingestNode);
    // the geo-IP database should not be loaded yet as we have no indexed any documents using a pipeline that has a geo-IP processor
    assertDatabaseLoadStatus(ingestNode, false);
    final IndexRequest indexRequest = new IndexRequest("index");
    indexRequest.setPipeline("geoip");
    indexRequest.source(Collections.singletonMap("ip", "1.1.1.1"));
    final IndexResponse indexResponse = client().index(indexRequest).actionGet();
    assertThat(indexResponse.status(), equalTo(RestStatus.CREATED));
    // now the geo-IP database should be loaded on the ingest node
    assertDatabaseLoadStatus(ingestNode, true);
    // the geo-IP database should still not be loaded on the non-ingest nodes
    Arrays.stream(internalCluster().getNodeNames()).filter(node -> node.equals(ingestNode) == false).forEach(node -> assertDatabaseLoadStatus(node, false));
}
Also used : BytesReference(org.opensearch.common.bytes.BytesReference) Arrays(java.util.Arrays) BytesReference(org.opensearch.common.bytes.BytesReference) IndexResponse(org.opensearch.action.index.IndexResponse) PutPipelineRequest(org.opensearch.action.ingest.PutPipelineRequest) StreamsUtils(org.opensearch.test.StreamsUtils) ByteArrayInputStream(java.io.ByteArrayInputStream) Path(java.nio.file.Path) NodeRoles(org.opensearch.test.NodeRoles) OpenSearchAssertions.assertAcked(org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked) Setting(org.opensearch.common.settings.Setting) IngestService(org.opensearch.ingest.IngestService) Files(java.nio.file.Files) Collection(java.util.Collection) Settings(org.opensearch.common.settings.Settings) IOException(java.io.IOException) RestStatus(org.opensearch.rest.RestStatus) Plugin(org.opensearch.plugins.Plugin) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) Constants(org.apache.lucene.util.Constants) NodeRoles.nonIngestNode(org.opensearch.test.NodeRoles.nonIngestNode) Matchers.equalTo(org.hamcrest.Matchers.equalTo) JsonXContent(org.opensearch.common.xcontent.json.JsonXContent) XContentType(org.opensearch.common.xcontent.XContentType) IndexRequest(org.opensearch.action.index.IndexRequest) OpenSearchIntegTestCase(org.opensearch.test.OpenSearchIntegTestCase) Collections(java.util.Collections) IndexResponse(org.opensearch.action.index.IndexResponse) PutPipelineRequest(org.opensearch.action.ingest.PutPipelineRequest) IndexRequest(org.opensearch.action.index.IndexRequest) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 5 with PutPipelineRequest

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

the class BulkIntegrationIT method createSamplePipeline.

private void createSamplePipeline(String pipelineId) throws IOException, ExecutionException, InterruptedException {
    XContentBuilder pipeline = jsonBuilder().startObject().startArray("processors").startObject().startObject("test").endObject().endObject().endArray().endObject();
    AcknowledgedResponse acknowledgedResponse = client().admin().cluster().putPipeline(new PutPipelineRequest(pipelineId, BytesReference.bytes(pipeline), XContentType.JSON)).get();
    assertTrue(acknowledgedResponse.isAcknowledged());
}
Also used : AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) PutPipelineRequest(org.opensearch.action.ingest.PutPipelineRequest) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Aggregations

PutPipelineRequest (org.opensearch.action.ingest.PutPipelineRequest)45 BytesArray (org.opensearch.common.bytes.BytesArray)29 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)20 OpenSearchParseException (org.opensearch.OpenSearchParseException)19 IndexRequest (org.opensearch.action.index.IndexRequest)19 ClusterChangedEvent (org.opensearch.cluster.ClusterChangedEvent)19 ClusterName (org.opensearch.cluster.ClusterName)19 ClusterState (org.opensearch.cluster.ClusterState)19 Settings (org.opensearch.common.settings.Settings)19 Mockito.anyString (org.mockito.Mockito.anyString)18 HashMap (java.util.HashMap)16 ResourceNotFoundException (org.opensearch.ResourceNotFoundException)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 BulkRequest (org.opensearch.action.bulk.BulkRequest)15 DeletePipelineRequest (org.opensearch.action.ingest.DeletePipelineRequest)15 XContentType (org.opensearch.common.xcontent.XContentType)14 List (java.util.List)13 BiConsumer (java.util.function.BiConsumer)13 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)13 Arrays (java.util.Arrays)12