Search in sources :

Example 1 with DataPrepperPlugin

use of com.amazon.dataprepper.model.annotations.DataPrepperPlugin in project data-prepper by opensearch-project.

the class ClasspathPluginProvider method scanForPlugins.

private Map<String, Map<Class<?>, Class<?>>> scanForPlugins() {
    final Set<Class<?>> dataPrepperPluginClasses = reflections.getTypesAnnotatedWith(DataPrepperPlugin.class);
    final Map<String, Map<Class<?>, Class<?>>> pluginsMap = new HashMap<>(dataPrepperPluginClasses.size());
    for (final Class<?> concretePluginClass : dataPrepperPluginClasses) {
        final DataPrepperPlugin dataPrepperPluginAnnotation = concretePluginClass.getAnnotation(DataPrepperPlugin.class);
        final String pluginName = dataPrepperPluginAnnotation.name();
        Class<?> supportedType = dataPrepperPluginAnnotation.pluginType();
        if (supportedType.equals(Void.class)) {
            supportedType = dataPrepperPluginAnnotation.type().pluginClass();
        }
        final Map<Class<?>, Class<?>> supportTypeToPluginTypeMap = pluginsMap.computeIfAbsent(pluginName, k -> new HashMap<>());
        supportTypeToPluginTypeMap.put(supportedType, concretePluginClass);
    }
    return pluginsMap;
}
Also used : DataPrepperPlugin(com.amazon.dataprepper.model.annotations.DataPrepperPlugin) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with DataPrepperPlugin

use of com.amazon.dataprepper.model.annotations.DataPrepperPlugin in project data-prepper by opensearch-project.

the class DefaultPluginFactory method getConstructionContext.

private <T> PluginArgumentsContext getConstructionContext(final PluginSetting pluginSetting, final Class<? extends T> pluginClass) {
    final DataPrepperPlugin pluginAnnotation = pluginClass.getAnnotation(DataPrepperPlugin.class);
    final Class<?> pluginConfigurationType = pluginAnnotation.pluginConfigurationType();
    final Object configuration = pluginConfigurationConverter.convert(pluginConfigurationType, pluginSetting);
    return new PluginArgumentsContext.Builder().withPluginSetting(pluginSetting).withPluginConfiguration(configuration).withPluginFactory(this).withBeanFactory(pluginBeanFactoryProvider.get()).build();
}
Also used : DataPrepperPlugin(com.amazon.dataprepper.model.annotations.DataPrepperPlugin)

Example 3 with DataPrepperPlugin

use of com.amazon.dataprepper.model.annotations.DataPrepperPlugin 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

DataPrepperPlugin (com.amazon.dataprepper.model.annotations.DataPrepperPlugin)3 PluginType (com.amazon.dataprepper.model.PluginType)1 Buffer (com.amazon.dataprepper.model.buffer.Buffer)1 Processor (com.amazon.dataprepper.model.processor.Processor)1 Sink (com.amazon.dataprepper.model.sink.Sink)1 Source (com.amazon.dataprepper.model.source.Source)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Reflections (org.reflections.Reflections)1