Skip to content

Commit

Permalink
Updated configConverter and removed the tests
Browse files Browse the repository at this point in the history
Signed-off-by: Asif Sohail Mohammed <[email protected]>
  • Loading branch information
asifsmohammed committed Nov 12, 2021
1 parent e594b87 commit 219a8c1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.opensearch.dataprepper.logstash.parser;
package org.opensearch.dataprepper.logstash;

import com.amazon.dataprepper.model.configuration.PipelineModel;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -7,14 +7,14 @@
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
import org.opensearch.dataprepper.logstash.LogstashLexer;
import org.opensearch.dataprepper.logstash.LogstashParser;
import org.opensearch.dataprepper.logstash.mapping.LogstashMapper;
import org.opensearch.dataprepper.logstash.model.LogstashConfiguration;
import org.opensearch.dataprepper.logstash.parser.LogstashVisitor;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.Map;
Expand All @@ -26,19 +26,20 @@
*/
public class LogstashConfigConverter {
public String convertLogstashConfigurationToPipeline(String logstashConfigurationPath, String outputDirectory) throws IOException {
final String logstashConfigAsString = new String(Files.readAllBytes(Paths.get(logstashConfigurationPath)));
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);
ParseTree tree = parser.config();

LogstashVisitor visitor = new LogstashVisitor();
org.opensearch.dataprepper.logstash.parser.LogstashVisitor visitor = new LogstashVisitor();
LogstashConfiguration logstashConfiguration = (LogstashConfiguration) visitor.visit(tree);

LogstashMapper logstashMapper = new LogstashMapper();
PipelineModel pipelineModel = logstashMapper.mapPipeline(logstashConfiguration);
Map<String, Object> pipeline = Collections.singletonMap("log-pipeline", pipelineModel);
Map<String, Object> pipeline = Collections.singletonMap("logstash-converted-pipeline", pipelineModel);

YAMLFactory factory = new YAMLFactory();
factory.disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER);
Expand All @@ -48,9 +49,13 @@ public String convertLogstashConfigurationToPipeline(String logstashConfiguratio

ObjectMapper mapper = new ObjectMapper(factory);

String yamlFilePath = outputDirectory + "logstash.yaml";
mapper.writeValue(new File(yamlFilePath), pipeline);
String confFileName = configurationFilePath.getFileName().toString();
String yamlFileName = confFileName.substring(0, confFileName.lastIndexOf("."));

return yamlFilePath;
Path yamlFilePath = Paths.get(outputDirectory , yamlFileName + ".yaml");

mapper.writeValue(new File(String.valueOf(yamlFilePath)), pipeline);

return String.valueOf(yamlFilePath);
}
}

This file was deleted.

This file was deleted.

0 comments on commit 219a8c1

Please sign in to comment.