Search in sources :

Example 1 with PipelineConfiguration

use of org.opensearch.ingest.PipelineConfiguration in project OpenSearch by opensearch-project.

the class GetPipelineResponse method fromXContent.

/**
 * @param parser the parser for the XContent that contains the serialized GetPipelineResponse.
 * @return an instance of GetPipelineResponse read from the parser
 * @throws IOException If the parsing fails
 */
public static GetPipelineResponse fromXContent(XContentParser parser) throws IOException {
    ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser);
    List<PipelineConfiguration> pipelines = new ArrayList<>();
    while (parser.nextToken().equals(Token.FIELD_NAME)) {
        String pipelineId = parser.currentName();
        parser.nextToken();
        try (XContentBuilder contentBuilder = XContentBuilder.builder(parser.contentType().xContent())) {
            contentBuilder.generator().copyCurrentStructure(parser);
            PipelineConfiguration pipeline = new PipelineConfiguration(pipelineId, BytesReference.bytes(contentBuilder), contentBuilder.contentType());
            pipelines.add(pipeline);
        }
    }
    ensureExpectedToken(XContentParser.Token.END_OBJECT, parser.currentToken(), parser);
    return new GetPipelineResponse(pipelines);
}
Also used : ArrayList(java.util.ArrayList) PipelineConfiguration(org.opensearch.ingest.PipelineConfiguration) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 2 with PipelineConfiguration

use of org.opensearch.ingest.PipelineConfiguration in project OpenSearch by opensearch-project.

the class GetPipelineResponseTests method createRandomPipeline.

private PipelineConfiguration createRandomPipeline(String pipelineId) throws IOException {
    String field = "field_" + randomInt();
    String value = "value_" + randomInt();
    XContentBuilder builder = getRandomXContentBuilder();
    builder.startObject();
    // We only use a single SetProcessor here in each pipeline to test.
    // Since the contents are returned as a configMap anyway this does not matter for fromXContent
    builder.startObject("set");
    builder.field("field", field);
    builder.field("value", value);
    builder.endObject();
    builder.endObject();
    return new PipelineConfiguration(pipelineId, BytesReference.bytes(builder), builder.contentType());
}
Also used : PipelineConfiguration(org.opensearch.ingest.PipelineConfiguration) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 3 with PipelineConfiguration

use of org.opensearch.ingest.PipelineConfiguration 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)

Example 4 with PipelineConfiguration

use of org.opensearch.ingest.PipelineConfiguration in project OpenSearch by opensearch-project.

the class GetPipelineResponse method toXContent.

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject();
    for (PipelineConfiguration pipeline : pipelines) {
        builder.field(pipeline.getId(), pipeline.getConfigAsMap());
    }
    builder.endObject();
    return builder;
}
Also used : PipelineConfiguration(org.opensearch.ingest.PipelineConfiguration)

Example 5 with PipelineConfiguration

use of org.opensearch.ingest.PipelineConfiguration in project OpenSearch by opensearch-project.

the class GetPipelineResponseTests method testXContentDeserialization.

public void testXContentDeserialization() throws IOException {
    Map<String, PipelineConfiguration> pipelinesMap = createPipelineConfigMap();
    GetPipelineResponse response = new GetPipelineResponse(new ArrayList<>(pipelinesMap.values()));
    XContentBuilder builder = response.toXContent(getRandomXContentBuilder(), ToXContent.EMPTY_PARAMS);
    XContentParser parser = builder.generator().contentType().xContent().createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, BytesReference.bytes(builder).streamInput());
    GetPipelineResponse parsedResponse = GetPipelineResponse.fromXContent(parser);
    List<PipelineConfiguration> actualPipelines = response.pipelines();
    List<PipelineConfiguration> parsedPipelines = parsedResponse.pipelines();
    assertEquals(actualPipelines.size(), parsedPipelines.size());
    for (PipelineConfiguration pipeline : parsedPipelines) {
        assertTrue(pipelinesMap.containsKey(pipeline.getId()));
        assertEquals(pipelinesMap.get(pipeline.getId()).getConfigAsMap(), pipeline.getConfigAsMap());
    }
}
Also used : PipelineConfiguration(org.opensearch.ingest.PipelineConfiguration) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) XContentParser(org.opensearch.common.xcontent.XContentParser)

Aggregations

PipelineConfiguration (org.opensearch.ingest.PipelineConfiguration)6 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)4 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 GetPipelineRequest (org.opensearch.action.ingest.GetPipelineRequest)1 GetPipelineResponse (org.opensearch.action.ingest.GetPipelineResponse)1 PutPipelineRequest (org.opensearch.action.ingest.PutPipelineRequest)1 XContentParser (org.opensearch.common.xcontent.XContentParser)1