Search in sources :

Example 1 with LogstashMappingException

use of org.opensearch.dataprepper.logstash.exception.LogstashMappingException in project data-prepper by opensearch-project.

the class LogstashPluginMapper method mapPlugin.

public List<PluginModel> mapPlugin(LogstashPlugin logstashPlugin) {
    final String mappingResourceName = logstashPlugin.getPluginName() + ".mapping.yaml";
    final InputStream inputStream = this.getClass().getResourceAsStream(mappingResourceName);
    if (inputStream == null) {
        throw new LogstashMappingException("Unable to find mapping resource " + mappingResourceName);
    }
    LogstashMappingModel logstashMappingModel;
    try {
        logstashMappingModel = objectMapper.readValue(inputStream, LogstashMappingModel.class);
    } catch (IOException ex) {
        throw new LogstashMappingException("Unable to parse mapping file " + mappingResourceName, ex);
    }
    if (logstashMappingModel.getCustomPluginMapperClass() != null) {
        final LogstashPluginAttributesMapper mapper = pluginMapperProvider.getAttributesMapper(logstashMappingModel);
        return mapper.mapAttributes(logstashPlugin.getAttributes(), logstashMappingModel);
    }
    if (logstashMappingModel.getPluginName() == null) {
        throw new LogstashMappingException("The mapping file " + mappingResourceName + " has a null value for 'pluginName'.");
    }
    final LogstashPluginAttributesMapper pluginAttributesMapper = pluginMapperProvider.getAttributesMapper(logstashMappingModel);
    final List<PluginModel> pluginModels = pluginAttributesMapper.mapAttributes(logstashPlugin.getAttributes(), logstashMappingModel);
    return pluginModels;
}
Also used : PluginModel(com.amazon.dataprepper.model.configuration.PluginModel) InputStream(java.io.InputStream) LogstashMappingException(org.opensearch.dataprepper.logstash.exception.LogstashMappingException) IOException(java.io.IOException)

Example 2 with LogstashMappingException

use of org.opensearch.dataprepper.logstash.exception.LogstashMappingException in project data-prepper by opensearch-project.

the class LogstashMapper method mapPipeline.

public PipelineModel mapPipeline(LogstashConfiguration logstashConfiguration) {
    List<PluginModel> sourcePluginModels = mapPluginSection(logstashConfiguration, LogstashPluginType.INPUT);
    PluginModel sourcePlugin = null;
    if (sourcePluginModels.size() > 1)
        throw new LogstashMappingException("More than 1 source plugins are not supported");
    else if (sourcePluginModels.size() == 1)
        sourcePlugin = sourcePluginModels.get(0);
    List<PluginModel> prepperPluginModels = mapPluginSection(logstashConfiguration, LogstashPluginType.FILTER);
    List<PluginModel> sinkPluginModels = mapPluginSection(logstashConfiguration, LogstashPluginType.OUTPUT);
    return new PipelineModel(sourcePlugin, prepperPluginModels, sinkPluginModels, null, null);
}
Also used : PluginModel(com.amazon.dataprepper.model.configuration.PluginModel) LogstashMappingException(org.opensearch.dataprepper.logstash.exception.LogstashMappingException) PipelineModel(com.amazon.dataprepper.model.configuration.PipelineModel)

Example 3 with LogstashMappingException

use of org.opensearch.dataprepper.logstash.exception.LogstashMappingException in project data-prepper by opensearch-project.

the class AttributesMapperCreator method createMapperClass.

LogstashPluginAttributesMapper createMapperClass(final String attributesMapperClassName) {
    final Class<?> attributesMapperClass;
    try {
        attributesMapperClass = Class.forName(attributesMapperClassName);
    } catch (final ClassNotFoundException ex) {
        throw new LogstashMappingException("Unable to find Mapper class with name of " + attributesMapperClassName, ex);
    }
    if (!LogstashPluginAttributesMapper.class.isAssignableFrom(attributesMapperClass)) {
        throw new LogstashMappingException("The provided mapping class does not implement " + LogstashPluginAttributesMapper.class);
    }
    try {
        final Constructor<?> defaultConstructor = attributesMapperClass.getDeclaredConstructor();
        final Object instance = defaultConstructor.newInstance();
        return (LogstashPluginAttributesMapper) instance;
    } catch (final Exception ex) {
        throw new LogstashMappingException("Unable to create Mapper class with name of " + attributesMapperClassName, ex);
    }
}
Also used : LogstashMappingException(org.opensearch.dataprepper.logstash.exception.LogstashMappingException) LogstashMappingException(org.opensearch.dataprepper.logstash.exception.LogstashMappingException)

Aggregations

LogstashMappingException (org.opensearch.dataprepper.logstash.exception.LogstashMappingException)3 PluginModel (com.amazon.dataprepper.model.configuration.PluginModel)2 PipelineModel (com.amazon.dataprepper.model.configuration.PipelineModel)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1