use of org.opensearch.dataprepper.logstash.model.LogstashConfiguration in project data-prepper by opensearch-project.
the class LogstashMapperTest method mapPipeline_with_multiple_source_plugins_should_throw_exception_Test.
@Test
void mapPipeline_with_multiple_source_plugins_should_throw_exception_Test() {
LogstashConfiguration logstashConfiguration = TestDataProvider.sampleConfigurationWithMoreThanOnePlugin();
Exception exception = assertThrows(LogstashMappingException.class, () -> logstashMapper.mapPipeline(logstashConfiguration));
String expectedMessage = "More than 1 source plugins are not supported";
String actualMessage = exception.getMessage();
assertThat(actualMessage, equalTo(expectedMessage));
}
use of org.opensearch.dataprepper.logstash.model.LogstashConfiguration 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 org.opensearch.dataprepper.logstash.model.LogstashConfiguration in project data-prepper by opensearch-project.
the class ModelConvertingLogstashVisitorTest method visit_config_return_logstash_configuration_object_test.
@Test
void visit_config_return_logstash_configuration_object_test() {
given(configContextMock.plugin_section()).willReturn(Collections.singletonList(pluginSectionMock));
given(pluginSectionMock.plugin_type()).willReturn(pluginTypeContextMock);
given(pluginTypeContextMock.getText()).willReturn("input");
given(pluginSectionMock.branch_or_plugin()).willReturn(Collections.singletonList(branchOrPluginContextMock));
Mockito.doReturn(TestDataProvider.pluginWithOneArrayContextAttributeData()).when(logstashVisitor).visitBranch_or_plugin(branchOrPluginContextMock);
LogstashConfiguration actualLogstashConfiguration = (LogstashConfiguration) logstashVisitor.visitConfig(configContextMock);
LogstashConfiguration expectedLogstashConfiguration = TestDataProvider.configData();
assertThat(actualLogstashConfiguration.getPluginSection(LogstashPluginType.INPUT).size(), equalTo(expectedLogstashConfiguration.getPluginSection(LogstashPluginType.INPUT).size()));
Mockito.verify(logstashVisitor, Mockito.times(1)).visitPlugin_section(pluginSectionMock);
}
use of org.opensearch.dataprepper.logstash.model.LogstashConfiguration 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 org.opensearch.dataprepper.logstash.model.LogstashConfiguration 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