use of com.amazon.dataprepper.model.configuration.PipelineModel 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 com.amazon.dataprepper.model.configuration.PipelineModel in project data-prepper by opensearch-project.
the class LogstashMapperTest method mapPipeline_with_no_plugins_should_return_pipeline_model_without_plugins_Test.
@Test
void mapPipeline_with_no_plugins_should_return_pipeline_model_without_plugins_Test() {
LogstashConfiguration logstashConfiguration = mock(LogstashConfiguration.class);
when(logstashConfiguration.getPluginSection(LogstashPluginType.INPUT)).thenReturn(Collections.emptyList());
when(logstashConfiguration.getPluginSection(LogstashPluginType.FILTER)).thenReturn(Collections.emptyList());
when(logstashConfiguration.getPluginSection(LogstashPluginType.OUTPUT)).thenReturn(Collections.emptyList());
PipelineModel actualPipelineModel = logstashMapper.mapPipeline(logstashConfiguration);
assertThat(actualPipelineModel.getSource(), equalTo(null));
assertThat(actualPipelineModel.getProcessors(), equalTo(Collections.emptyList()));
assertThat(actualPipelineModel.getSinks(), equalTo(Collections.emptyList()));
assertThat(actualPipelineModel.getReadBatchDelay(), equalTo(null));
assertThat(actualPipelineModel.getWorkers(), equalTo(null));
}
use of com.amazon.dataprepper.model.configuration.PipelineModel in project data-prepper by opensearch-project.
the class LogstashConfigConverter method convertLogstashConfigurationToPipeline.
public String convertLogstashConfigurationToPipeline(String logstashConfigurationPath, String outputDirectory) throws IOException {
final Path configurationFilePath = Paths.get(logstashConfigurationPath);
final String logstashConfigAsString = new String(Files.readAllBytes(configurationFilePath));
LogstashLexer lexer = new LogstashLexer(CharStreams.fromString(logstashConfigAsString));
CommonTokenStream tokens = new CommonTokenStream(lexer);
LogstashParser parser = new LogstashParser(tokens);
final ParseTree tree = parser.config();
ModelConvertingLogstashVisitor visitor = new ModelConvertingLogstashVisitor();
LogstashConfiguration logstashConfiguration = (LogstashConfiguration) visitor.visit(tree);
LogstashMapper logstashMapper = new LogstashMapper();
PipelineModel pipelineModel = logstashMapper.mapPipeline(logstashConfiguration);
PipelinesDataFlowModel pipelinesDataFlowModel = new PipelinesDataFlowModel(Collections.singletonMap("logstash-converted-pipeline", pipelineModel));
ObjectMapper mapper = new ObjectMapper(YAMLFactory.builder().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER).enable(YAMLGenerator.Feature.INDENT_ARRAYS_WITH_INDICATOR).enable(YAMLGenerator.Feature.USE_PLATFORM_LINE_BREAKS).disable(YAMLGenerator.Feature.SPLIT_LINES).enable(YAMLGenerator.Feature.LITERAL_BLOCK_STYLE).build());
final String confFileName = configurationFilePath.getFileName().toString();
final String yamlFileName = confFileName.substring(0, confFileName.lastIndexOf(".conf"));
final Path yamlFilePath = Paths.get(outputDirectory, yamlFileName + ".yaml");
mapper.writeValue(new File(String.valueOf(yamlFilePath)), pipelinesDataFlowModel);
return String.valueOf(yamlFilePath);
}
use of com.amazon.dataprepper.model.configuration.PipelineModel in project data-prepper by opensearch-project.
the class LogstashMapperTest method mapPipeline_returns_pipeline_model.
@Test
void mapPipeline_returns_pipeline_model() {
LogstashConfiguration logstashConfiguration = mock(LogstashConfiguration.class);
when(logstashConfiguration.getPluginSection(LogstashPluginType.INPUT)).thenReturn(Collections.singletonList(TestDataProvider.pluginData()));
PipelineModel actualPipelineModel = logstashMapper.mapPipeline(logstashConfiguration);
PipelineModel expectedPipelineModel = new PipelineModel(TestDataProvider.samplePluginModel(), null, null, null, null);
assertThat(actualPipelineModel.getSource().getPluginName(), equalTo(expectedPipelineModel.getSource().getPluginName()));
assertThat(actualPipelineModel.getSource().getPluginSettings(), equalTo(expectedPipelineModel.getSource().getPluginSettings()));
assertThat(actualPipelineModel.getReadBatchDelay(), equalTo(expectedPipelineModel.getReadBatchDelay()));
assertThat(actualPipelineModel.getWorkers(), equalTo(expectedPipelineModel.getWorkers()));
}
Aggregations