Search in sources :

Example 1 with Source

use of com.amazon.dataprepper.model.source.Source in project data-prepper by opensearch-project.

the class SourceFactoryTests method testSourceClassByName.

/**
 * Tests if SourceFactory is able to retrieve default Source plugins by name
 */
@Test
public void testSourceClassByName() {
    final PluginSetting stdInSourceConfiguration = new PluginSetting("stdin", new HashMap<>());
    stdInSourceConfiguration.setPipelineName(TEST_PIPELINE);
    final Source actualSource = SourceFactory.newSource(stdInSourceConfiguration);
    final Source expectedSource = new StdInSource(500, TEST_PIPELINE);
    assertThat(actualSource, notNullValue());
    assertThat(actualSource.getClass().getSimpleName(), is(equalTo(expectedSource.getClass().getSimpleName())));
}
Also used : PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Source(com.amazon.dataprepper.model.source.Source) Test(org.junit.Test)

Example 2 with Source

use of com.amazon.dataprepper.model.source.Source in project data-prepper by opensearch-project.

the class PluginFactoryTests method testNoMandatoryConstructor.

@Test
public void testNoMandatoryConstructor() {
    final PluginSetting testPluginSettings = new PluginSetting("junit-test", new HashMap<>());
    final Class<Source> clazz = PluginRepository.getSourceClass(testPluginSettings.getName());
    assertNotNull(clazz);
    try {
        PluginFactory.newPlugin(testPluginSettings, clazz);
    } catch (PluginException e) {
        assertTrue("Incorrect exception or exception message was thrown", e.getMessage().startsWith("Data Prepper plugin requires a constructor with PluginSetting parameter; Plugin " + "ConstructorLessComponent with name junit-test is missing such constructor."));
    }
}
Also used : PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Source(com.amazon.dataprepper.model.source.Source) Test(org.junit.Test)

Example 3 with Source

use of com.amazon.dataprepper.model.source.Source 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 4 with Source

use of com.amazon.dataprepper.model.source.Source 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

Source (com.amazon.dataprepper.model.source.Source)4 PluginSetting (com.amazon.dataprepper.model.configuration.PluginSetting)3 Buffer (com.amazon.dataprepper.model.buffer.Buffer)2 Sink (com.amazon.dataprepper.model.sink.Sink)2 Test (org.junit.Test)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 Reflections (org.reflections.Reflections)1