Search in sources :

Example 1 with Buffer

use of com.amazon.dataprepper.model.buffer.Buffer in project data-prepper by opensearch-project.

the class PipelineParser method buildPipelineFromConfiguration.

private void buildPipelineFromConfiguration(final String pipelineName, final Map<String, PipelineConfiguration> pipelineConfigurationMap, final Map<String, Pipeline> pipelineMap) {
    final PipelineConfiguration pipelineConfiguration = pipelineConfigurationMap.get(pipelineName);
    LOG.info("Building pipeline [{}] from provided configuration", pipelineName);
    try {
        final PluginSetting sourceSetting = pipelineConfiguration.getSourcePluginSetting();
        final Optional<Source> pipelineSource = getSourceIfPipelineType(pipelineName, sourceSetting, pipelineMap, pipelineConfigurationMap);
        final Source source = pipelineSource.orElseGet(() -> pluginFactory.loadPlugin(Source.class, sourceSetting));
        LOG.info("Building buffer for the pipeline [{}]", pipelineName);
        final Buffer buffer = pluginFactory.loadPlugin(Buffer.class, pipelineConfiguration.getBufferPluginSetting());
        LOG.info("Building processors for the pipeline [{}]", pipelineName);
        final int processorThreads = pipelineConfiguration.getWorkers();
        final List<List<Processor>> processorSets = pipelineConfiguration.getProcessorPluginSettings().stream().map(this::newProcessor).collect(Collectors.toList());
        final int readBatchDelay = pipelineConfiguration.getReadBatchDelay();
        LOG.info("Building sinks for the pipeline [{}]", pipelineName);
        final List<Sink> sinks = pipelineConfiguration.getSinkPluginSettings().stream().map(this::buildSinkOrConnector).collect(Collectors.toList());
        final Pipeline pipeline = new Pipeline(pipelineName, source, buffer, processorSets, sinks, processorThreads, readBatchDelay);
        pipelineMap.put(pipelineName, pipeline);
    } catch (Exception ex) {
        // If pipeline construction errors out, we will skip that pipeline and proceed
        LOG.error("Construction of pipeline components failed, skipping building of pipeline [{}] and its connected " + "pipelines", pipelineName, ex);
        processRemoveIfRequired(pipelineName, pipelineConfigurationMap, pipelineMap);
    }
}
Also used : Buffer(com.amazon.dataprepper.model.buffer.Buffer) Sink(com.amazon.dataprepper.model.sink.Sink) List(java.util.List) PipelineConfiguration(com.amazon.dataprepper.parser.model.PipelineConfiguration) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Source(com.amazon.dataprepper.model.source.Source) NoPluginFoundException(com.amazon.dataprepper.model.plugin.NoPluginFoundException) IOException(java.io.IOException) Pipeline(com.amazon.dataprepper.pipeline.Pipeline)

Example 2 with Buffer

use of com.amazon.dataprepper.model.buffer.Buffer 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)

Example 3 with Buffer

use of com.amazon.dataprepper.model.buffer.Buffer in project data-prepper by opensearch-project.

the class BufferFactoryTests method testNewBufferClassByNameThatExists.

/**
 * Tests if BufferFactory is able to retrieve default Source plugins by name
 */
@Test
public void testNewBufferClassByNameThatExists() {
    final PluginSetting pluginSetting = new PluginSetting("test_buffer", new HashMap<>());
    final Buffer testBuffer = BufferFactory.newBuffer(pluginSetting);
    final Buffer expectedBuffer = new TestBuffer(pluginSetting);
    assertThat(testBuffer, notNullValue());
    assertThat(testBuffer.getClass().getSimpleName(), is(equalTo(expectedBuffer.getClass().getSimpleName())));
}
Also used : Buffer(com.amazon.dataprepper.model.buffer.Buffer) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Test(org.junit.Test)

Aggregations

Buffer (com.amazon.dataprepper.model.buffer.Buffer)3 PluginSetting (com.amazon.dataprepper.model.configuration.PluginSetting)2 Sink (com.amazon.dataprepper.model.sink.Sink)2 Source (com.amazon.dataprepper.model.source.Source)2 PluginType (com.amazon.dataprepper.model.PluginType)1 DataPrepperPlugin (com.amazon.dataprepper.model.annotations.DataPrepperPlugin)1 NoPluginFoundException (com.amazon.dataprepper.model.plugin.NoPluginFoundException)1 Processor (com.amazon.dataprepper.model.processor.Processor)1 PipelineConfiguration (com.amazon.dataprepper.parser.model.PipelineConfiguration)1 Pipeline (com.amazon.dataprepper.pipeline.Pipeline)1 IOException (java.io.IOException)1 List (java.util.List)1 Test (org.junit.Test)1 Reflections (org.reflections.Reflections)1