Search in sources :

Example 1 with Processor

use of com.amazon.dataprepper.model.processor.Processor in project data-prepper by opensearch-project.

the class PrepperFactoryTests method testNewSingletonPrepperClassByNameThatExists.

/**
 * Tests if PrepperFactory is able to retrieve default Source plugins by name
 */
@Test
public void testNewSingletonPrepperClassByNameThatExists() {
    PrepperFactory.dangerousMethod_setPluginFunction((s, c) -> new NoOpPrepper());
    final PluginSetting noOpPrepperConfiguration = new PluginSetting("no-op", new HashMap<>());
    noOpPrepperConfiguration.setPipelineName(TEST_PIPELINE);
    final List<Processor> actualPrepperSets = PrepperFactory.newPreppers(noOpPrepperConfiguration);
    assertEquals(1, actualPrepperSets.size());
    final Processor actualPrepper = actualPrepperSets.get(0);
    final Processor expectedPrepper = new NoOpPrepper();
    assertThat(actualPrepper, notNullValue());
    assertThat(actualPrepper.getClass().getSimpleName(), is(equalTo(expectedPrepper.getClass().getSimpleName())));
}
Also used : Processor(com.amazon.dataprepper.model.processor.Processor) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Test(org.junit.jupiter.api.Test)

Example 2 with Processor

use of com.amazon.dataprepper.model.processor.Processor in project data-prepper by opensearch-project.

the class PrepperFactoryTests method testNewMultiInstancePrepperClassByNameThatExists.

@Test
public void testNewMultiInstancePrepperClassByNameThatExists() {
    final PluginSetting testPrepperConfiguration = new PluginSetting("test_prepper", new HashMap<>());
    testPrepperConfiguration.setProcessWorkers(2);
    testPrepperConfiguration.setPipelineName(TEST_PIPELINE);
    final List<Processor> actualPrepperSets = PrepperFactory.newPreppers(testPrepperConfiguration);
    assertEquals(2, actualPrepperSets.size());
    final Processor expectedPrepper = new TestPrepper(testPrepperConfiguration);
    assertThat(actualPrepperSets.get(0), notNullValue());
    assertThat(actualPrepperSets.get(0).getClass().getSimpleName(), is(equalTo(expectedPrepper.getClass().getSimpleName())));
    assertThat(actualPrepperSets.get(1), notNullValue());
    assertThat(actualPrepperSets.get(1).getClass().getSimpleName(), is(equalTo(expectedPrepper.getClass().getSimpleName())));
}
Also used : Processor(com.amazon.dataprepper.model.processor.Processor) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Test(org.junit.jupiter.api.Test)

Example 3 with Processor

use of com.amazon.dataprepper.model.processor.Processor in project data-prepper by opensearch-project.

the class ProcessWorker method run.

@Override
public void run() {
    try {
        do {
            final Map.Entry<Collection, CheckpointState> readResult = readBuffer.read(pipeline.getReadBatchTimeoutInMillis());
            Collection records = readResult.getKey();
            final CheckpointState checkpointState = readResult.getValue();
            // TODO Hacky way to avoid logging continuously - Will be removed as part of metrics implementation
            if (records.isEmpty()) {
                if (!isEmptyRecordsLogged) {
                    LOG.info(" {} Worker: No records received from buffer", pipeline.getName());
                    isEmptyRecordsLogged = true;
                }
            } else {
                LOG.info(" {} Worker: Processing {} records from buffer", pipeline.getName(), records.size());
            }
            // Should Empty list from buffer should be sent to the processors? For now sending as the Stateful processors expects it.
            for (final Processor processor : processors) {
                records = processor.execute(records);
            }
            if (!records.isEmpty()) {
                postToSink(records);
            }
            // Checkpoint the current batch read from the buffer after being processed by processors and sinks.
            readBuffer.checkpoint(checkpointState);
        } while (!shouldStop());
    } catch (final Exception e) {
        LOG.error("Encountered exception during pipeline {} processing", pipeline.getName(), e);
    }
}
Also used : Processor(com.amazon.dataprepper.model.processor.Processor) Collection(java.util.Collection) CheckpointState(com.amazon.dataprepper.model.CheckpointState) Map(java.util.Map)

Example 4 with Processor

use of com.amazon.dataprepper.model.processor.Processor in project data-prepper by opensearch-project.

the class PluginRepository method findPlugins.

private static void findPlugins() {
    final Reflections reflections = new Reflections(DEFAULT_PLUGINS_CLASSPATH);
    final Set<Class<?>> annotatedClasses = reflections.getTypesAnnotatedWith(DataPrepperPlugin.class);
    for (final Class<?> annotatedClass : annotatedClasses) {
        final DataPrepperPlugin dataPrepperPluginAnnotation = annotatedClass.getAnnotation(DataPrepperPlugin.class);
        final String pluginName = dataPrepperPluginAnnotation.name();
        final PluginType pluginType = extractPluginType(dataPrepperPluginAnnotation);
        switch(pluginType) {
            case SOURCE:
                SOURCES.put(pluginName, (Class<Source>) annotatedClass);
                break;
            case BUFFER:
                BUFFERS.put(pluginName, (Class<Buffer>) annotatedClass);
                break;
            case PREPPER:
                PROCESSORS.put(pluginName, (Class<Processor>) annotatedClass);
                break;
            case SINK:
                SINKS.put(pluginName, (Class<Sink>) annotatedClass);
                break;
        }
    }
}
Also used : Buffer(com.amazon.dataprepper.model.buffer.Buffer) Processor(com.amazon.dataprepper.model.processor.Processor) DataPrepperPlugin(com.amazon.dataprepper.model.annotations.DataPrepperPlugin) Sink(com.amazon.dataprepper.model.sink.Sink) PluginType(com.amazon.dataprepper.model.PluginType) Source(com.amazon.dataprepper.model.source.Source) Reflections(org.reflections.Reflections)

Aggregations

Processor (com.amazon.dataprepper.model.processor.Processor)4 PluginSetting (com.amazon.dataprepper.model.configuration.PluginSetting)2 Test (org.junit.jupiter.api.Test)2 CheckpointState (com.amazon.dataprepper.model.CheckpointState)1 PluginType (com.amazon.dataprepper.model.PluginType)1 DataPrepperPlugin (com.amazon.dataprepper.model.annotations.DataPrepperPlugin)1 Buffer (com.amazon.dataprepper.model.buffer.Buffer)1 Sink (com.amazon.dataprepper.model.sink.Sink)1 Source (com.amazon.dataprepper.model.source.Source)1 Collection (java.util.Collection)1 Map (java.util.Map)1 Reflections (org.reflections.Reflections)1