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);
}
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());
}
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());
}
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;
}
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());
}
}
Aggregations