Search in sources :

Example 1 with Pipeline

use of org.elasticsearch.ingest.Pipeline in project elasticsearch by elastic.

the class SimulateExecutionServiceTests method testExecuteItem.

public void testExecuteItem() throws Exception {
    TestProcessor processor = new TestProcessor("processor_0", "mock", ingestDocument -> {
    });
    Pipeline pipeline = new Pipeline("_id", "_description", version, new CompoundProcessor(processor, processor));
    SimulateDocumentResult actualItemResponse = executionService.executeDocument(pipeline, ingestDocument, false);
    assertThat(processor.getInvokedCounter(), equalTo(2));
    assertThat(actualItemResponse, instanceOf(SimulateDocumentBaseResult.class));
    SimulateDocumentBaseResult simulateDocumentBaseResult = (SimulateDocumentBaseResult) actualItemResponse;
    assertThat(simulateDocumentBaseResult.getIngestDocument(), equalTo(ingestDocument));
    assertThat(simulateDocumentBaseResult.getFailure(), nullValue());
}
Also used : CompoundProcessor(org.elasticsearch.ingest.CompoundProcessor) TestProcessor(org.elasticsearch.ingest.TestProcessor) Pipeline(org.elasticsearch.ingest.Pipeline)

Example 2 with Pipeline

use of org.elasticsearch.ingest.Pipeline in project elasticsearch by elastic.

the class SimulateExecutionServiceTests method testExecuteItemWithFailure.

public void testExecuteItemWithFailure() throws Exception {
    TestProcessor processor = new TestProcessor(ingestDocument -> {
        throw new RuntimeException("processor failed");
    });
    Pipeline pipeline = new Pipeline("_id", "_description", version, new CompoundProcessor(processor, processor));
    SimulateDocumentResult actualItemResponse = executionService.executeDocument(pipeline, ingestDocument, false);
    assertThat(processor.getInvokedCounter(), equalTo(1));
    assertThat(actualItemResponse, instanceOf(SimulateDocumentBaseResult.class));
    SimulateDocumentBaseResult simulateDocumentBaseResult = (SimulateDocumentBaseResult) actualItemResponse;
    assertThat(simulateDocumentBaseResult.getIngestDocument(), nullValue());
    assertThat(simulateDocumentBaseResult.getFailure(), instanceOf(RuntimeException.class));
    Exception exception = simulateDocumentBaseResult.getFailure();
    assertThat(exception, instanceOf(ElasticsearchException.class));
    assertThat(exception.getMessage(), equalTo("java.lang.IllegalArgumentException: java.lang.RuntimeException: processor failed"));
}
Also used : CompoundProcessor(org.elasticsearch.ingest.CompoundProcessor) TestProcessor(org.elasticsearch.ingest.TestProcessor) ElasticsearchException(org.elasticsearch.ElasticsearchException) ElasticsearchException(org.elasticsearch.ElasticsearchException) Pipeline(org.elasticsearch.ingest.Pipeline)

Example 3 with Pipeline

use of org.elasticsearch.ingest.Pipeline in project elasticsearch by elastic.

the class SimulatePipelineRequest method parseWithPipelineId.

static Parsed parseWithPipelineId(String pipelineId, Map<String, Object> config, boolean verbose, PipelineStore pipelineStore) {
    if (pipelineId == null) {
        throw new IllegalArgumentException("param [pipeline] is null");
    }
    Pipeline pipeline = pipelineStore.get(pipelineId);
    if (pipeline == null) {
        throw new IllegalArgumentException("pipeline [" + pipelineId + "] does not exist");
    }
    List<IngestDocument> ingestDocumentList = parseDocs(config);
    return new Parsed(pipeline, ingestDocumentList, verbose);
}
Also used : IngestDocument(org.elasticsearch.ingest.IngestDocument) Pipeline(org.elasticsearch.ingest.Pipeline)

Example 4 with Pipeline

use of org.elasticsearch.ingest.Pipeline in project elasticsearch by elastic.

the class SimulatePipelineRequest method parse.

static Parsed parse(Map<String, Object> config, boolean verbose, PipelineStore pipelineStore) throws Exception {
    Map<String, Object> pipelineConfig = ConfigurationUtils.readMap(null, null, config, Fields.PIPELINE);
    Pipeline pipeline = PIPELINE_FACTORY.create(SIMULATED_PIPELINE_ID, pipelineConfig, pipelineStore.getProcessorFactories());
    List<IngestDocument> ingestDocumentList = parseDocs(config);
    return new Parsed(pipeline, ingestDocumentList, verbose);
}
Also used : IngestDocument(org.elasticsearch.ingest.IngestDocument) Pipeline(org.elasticsearch.ingest.Pipeline)

Example 5 with Pipeline

use of org.elasticsearch.ingest.Pipeline in project elasticsearch by elastic.

the class SimulateExecutionServiceTests method testExecuteVerboseItemExceptionWithIgnoreFailure.

public void testExecuteVerboseItemExceptionWithIgnoreFailure() throws Exception {
    RuntimeException exception = new RuntimeException("processor failed");
    TestProcessor testProcessor = new TestProcessor("processor_0", "mock", ingestDocument -> {
        throw exception;
    });
    CompoundProcessor processor = new CompoundProcessor(true, Collections.singletonList(testProcessor), Collections.emptyList());
    Pipeline pipeline = new Pipeline("_id", "_description", version, new CompoundProcessor(processor));
    SimulateDocumentResult actualItemResponse = executionService.executeDocument(pipeline, ingestDocument, true);
    assertThat(testProcessor.getInvokedCounter(), equalTo(1));
    assertThat(actualItemResponse, instanceOf(SimulateDocumentVerboseResult.class));
    SimulateDocumentVerboseResult simulateDocumentVerboseResult = (SimulateDocumentVerboseResult) actualItemResponse;
    assertThat(simulateDocumentVerboseResult.getProcessorResults().size(), equalTo(1));
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getProcessorTag(), equalTo("processor_0"));
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getFailure(), sameInstance(exception));
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument(), not(sameInstance(ingestDocument)));
    assertIngestDocument(simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument(), ingestDocument);
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument().getSourceAndMetadata(), not(sameInstance(ingestDocument.getSourceAndMetadata())));
}
Also used : CompoundProcessor(org.elasticsearch.ingest.CompoundProcessor) TestProcessor(org.elasticsearch.ingest.TestProcessor) Pipeline(org.elasticsearch.ingest.Pipeline)

Aggregations

Pipeline (org.elasticsearch.ingest.Pipeline)10 CompoundProcessor (org.elasticsearch.ingest.CompoundProcessor)8 TestProcessor (org.elasticsearch.ingest.TestProcessor)8 IngestDocument (org.elasticsearch.ingest.IngestDocument)4 IngestDocumentMatcher.assertIngestDocument (org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 PipelineStore (org.elasticsearch.ingest.PipelineStore)1 Before (org.junit.Before)1