Search in sources :

Example 6 with CompoundProcessor

use of org.elasticsearch.ingest.CompoundProcessor 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 7 with CompoundProcessor

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

the class SimulateExecutionService method executeDocument.

SimulateDocumentResult executeDocument(Pipeline pipeline, IngestDocument ingestDocument, boolean verbose) {
    if (verbose) {
        List<SimulateProcessorResult> processorResultList = new ArrayList<>();
        CompoundProcessor verbosePipelineProcessor = decorate(pipeline.getCompoundProcessor(), processorResultList);
        try {
            verbosePipelineProcessor.execute(ingestDocument);
            return new SimulateDocumentVerboseResult(processorResultList);
        } catch (Exception e) {
            return new SimulateDocumentVerboseResult(processorResultList);
        }
    } else {
        try {
            pipeline.execute(ingestDocument);
            return new SimulateDocumentBaseResult(ingestDocument);
        } catch (Exception e) {
            return new SimulateDocumentBaseResult(e);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) CompoundProcessor(org.elasticsearch.ingest.CompoundProcessor)

Example 8 with CompoundProcessor

use of org.elasticsearch.ingest.CompoundProcessor 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)

Example 9 with CompoundProcessor

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

the class SimulateExecutionServiceTests method testExecuteVerboseItemWithoutExceptionAndWithIgnoreFailure.

public void testExecuteVerboseItemWithoutExceptionAndWithIgnoreFailure() throws Exception {
    TestProcessor testProcessor = new TestProcessor("processor_0", "mock", ingestDocument -> {
    });
    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(), nullValue());
    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)

Example 10 with CompoundProcessor

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

the class SimulateExecutionServiceTests method testExecuteVerboseItem.

public void testExecuteVerboseItem() throws Exception {
    TestProcessor processor = new TestProcessor("test-id", "mock", ingestDocument -> {
    });
    Pipeline pipeline = new Pipeline("_id", "_description", version, new CompoundProcessor(processor, processor));
    SimulateDocumentResult actualItemResponse = executionService.executeDocument(pipeline, ingestDocument, true);
    assertThat(processor.getInvokedCounter(), equalTo(2));
    assertThat(actualItemResponse, instanceOf(SimulateDocumentVerboseResult.class));
    SimulateDocumentVerboseResult simulateDocumentVerboseResult = (SimulateDocumentVerboseResult) actualItemResponse;
    assertThat(simulateDocumentVerboseResult.getProcessorResults().size(), equalTo(2));
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getProcessorTag(), equalTo("test-id"));
    IngestDocument firstProcessorIngestDocument = simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument();
    assertThat(firstProcessorIngestDocument, not(sameInstance(this.ingestDocument)));
    assertIngestDocument(firstProcessorIngestDocument, this.ingestDocument);
    assertThat(firstProcessorIngestDocument.getSourceAndMetadata(), not(sameInstance(this.ingestDocument.getSourceAndMetadata())));
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getFailure(), nullValue());
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getProcessorTag(), equalTo("test-id"));
    IngestDocument secondProcessorIngestDocument = simulateDocumentVerboseResult.getProcessorResults().get(1).getIngestDocument();
    assertThat(secondProcessorIngestDocument, not(sameInstance(this.ingestDocument)));
    assertIngestDocument(secondProcessorIngestDocument, this.ingestDocument);
    assertThat(secondProcessorIngestDocument.getSourceAndMetadata(), not(sameInstance(this.ingestDocument.getSourceAndMetadata())));
    assertThat(secondProcessorIngestDocument.getSourceAndMetadata(), not(sameInstance(firstProcessorIngestDocument.getSourceAndMetadata())));
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getFailure(), nullValue());
}
Also used : CompoundProcessor(org.elasticsearch.ingest.CompoundProcessor) TestProcessor(org.elasticsearch.ingest.TestProcessor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument) Pipeline(org.elasticsearch.ingest.Pipeline)

Aggregations

CompoundProcessor (org.elasticsearch.ingest.CompoundProcessor)15 TestProcessor (org.elasticsearch.ingest.TestProcessor)13 Pipeline (org.elasticsearch.ingest.Pipeline)8 ArrayList (java.util.ArrayList)4 IngestDocument (org.elasticsearch.ingest.IngestDocument)4 Processor (org.elasticsearch.ingest.Processor)3 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Locale (java.util.Locale)2 Map (java.util.Map)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 IngestDocumentMatcher.assertIngestDocument (org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument)2 TemplateService (org.elasticsearch.ingest.TemplateService)2 TestTemplateService (org.elasticsearch.ingest.TestTemplateService)2 ESTestCase (org.elasticsearch.test.ESTestCase)2 Matchers.equalTo (org.hamcrest.Matchers.equalTo)2 PipelineStore (org.elasticsearch.ingest.PipelineStore)1 Before (org.junit.Before)1