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;
}
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);
}
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);
}
}
Aggregations