From ecee63a11b675c385a7fe9ad91bb33d9a78d294f Mon Sep 17 00:00:00 2001 From: Asif Sohail Mohammed Date: Mon, 1 Nov 2021 14:56:22 -0400 Subject: [PATCH] updated javadoc for public classes Signed-off-by: Asif Sohail Mohammed --- .../src/main/antlr/Logstash.g4 | 4 + .../LogstashConfigurationException.java | 2 +- .../exception/LogstashGrammarException.java | 2 +- .../exception/LogstashParsingException.java | 3 +- .../logstash/parser/LogstashVisitor.java | 83 ++++++++++--------- .../logstash/parser/TestDataProvider.java | 1 - 6 files changed, 51 insertions(+), 44 deletions(-) diff --git a/data-prepper-logstash-configuration/src/main/antlr/Logstash.g4 b/data-prepper-logstash-configuration/src/main/antlr/Logstash.g4 index a3d169ac6d..eb22d50c31 100644 --- a/data-prepper-logstash-configuration/src/main/antlr/Logstash.g4 +++ b/data-prepper-logstash-configuration/src/main/antlr/Logstash.g4 @@ -1,3 +1,7 @@ +/* +* Grammar file for parsing Logstash configurations +*/ + grammar Logstash; @header { diff --git a/data-prepper-logstash-configuration/src/main/java/org/opensearch/dataprepper/logstash/exception/LogstashConfigurationException.java b/data-prepper-logstash-configuration/src/main/java/org/opensearch/dataprepper/logstash/exception/LogstashConfigurationException.java index 0292b964b1..f72dae0b47 100644 --- a/data-prepper-logstash-configuration/src/main/java/org/opensearch/dataprepper/logstash/exception/LogstashConfigurationException.java +++ b/data-prepper-logstash-configuration/src/main/java/org/opensearch/dataprepper/logstash/exception/LogstashConfigurationException.java @@ -1,7 +1,7 @@ package org.opensearch.dataprepper.logstash.exception; /** - * Exception for Logtsash converter + * Exception for Logstash converter * * @since 1.2 */ diff --git a/data-prepper-logstash-configuration/src/main/java/org/opensearch/dataprepper/logstash/exception/LogstashGrammarException.java b/data-prepper-logstash-configuration/src/main/java/org/opensearch/dataprepper/logstash/exception/LogstashGrammarException.java index 5dad010ab2..3f66e0306e 100644 --- a/data-prepper-logstash-configuration/src/main/java/org/opensearch/dataprepper/logstash/exception/LogstashGrammarException.java +++ b/data-prepper-logstash-configuration/src/main/java/org/opensearch/dataprepper/logstash/exception/LogstashGrammarException.java @@ -1,7 +1,7 @@ package org.opensearch.dataprepper.logstash.exception; /** - * Exception for ANTLR failures + * Exception thrown when ANTLR fails to parse the Logstash configuration * * @since 1.2 */ diff --git a/data-prepper-logstash-configuration/src/main/java/org/opensearch/dataprepper/logstash/exception/LogstashParsingException.java b/data-prepper-logstash-configuration/src/main/java/org/opensearch/dataprepper/logstash/exception/LogstashParsingException.java index 7bb1dcb03f..7c49bafcb3 100644 --- a/data-prepper-logstash-configuration/src/main/java/org/opensearch/dataprepper/logstash/exception/LogstashParsingException.java +++ b/data-prepper-logstash-configuration/src/main/java/org/opensearch/dataprepper/logstash/exception/LogstashParsingException.java @@ -1,7 +1,8 @@ package org.opensearch.dataprepper.logstash.exception; /** - * Exception for visitor when it's unable to convert into Logstash models + * Exception thrown when {@link org.opensearch.dataprepper.logstash.parser.LogstashVisitor} is unable to convert + * Logstash configuration into Logstash model objects * * @since 1.2 */ diff --git a/data-prepper-logstash-configuration/src/main/java/org/opensearch/dataprepper/logstash/parser/LogstashVisitor.java b/data-prepper-logstash-configuration/src/main/java/org/opensearch/dataprepper/logstash/parser/LogstashVisitor.java index b75f0c397e..dfc2d59161 100644 --- a/data-prepper-logstash-configuration/src/main/java/org/opensearch/dataprepper/logstash/parser/LogstashVisitor.java +++ b/data-prepper-logstash-configuration/src/main/java/org/opensearch/dataprepper/logstash/parser/LogstashVisitor.java @@ -17,7 +17,7 @@ import java.util.ArrayList; /** - * Class to populate Logstash configuration model POJO's using ANTLR + * Class to populate Logstash configuration model objects using ANTLR * * @since 1.2 */ @@ -30,9 +30,9 @@ public class LogstashVisitor extends LogstashBaseVisitor { private final Map hashEntries = new LinkedHashMap<>(); @Override - public Object visitConfig(LogstashParser.ConfigContext ctx) { - for(int i = 0; i < ctx.plugin_section().size(); i++) { - visitPlugin_section(ctx.plugin_section().get(i)); + public Object visitConfig(LogstashParser.ConfigContext configContext) { + for(int i = 0; i < configContext.plugin_section().size(); i++) { + visitPlugin_section(configContext.plugin_section().get(i)); } return LogstashConfiguration.builder() .pluginSections(pluginSections) @@ -40,12 +40,12 @@ public Object visitConfig(LogstashParser.ConfigContext ctx) { } @Override - public Object visitPlugin_section(LogstashParser.Plugin_sectionContext ctx) { + public Object visitPlugin_section(LogstashParser.Plugin_sectionContext pluginSectionContext) { LogstashPluginType logstashPluginType; logstashPluginList = new LinkedList<>(); - switch (ctx.plugin_type().getText()) { + switch (pluginSectionContext.plugin_type().getText()) { case "input": logstashPluginType = LogstashPluginType.INPUT; break; @@ -59,8 +59,8 @@ public Object visitPlugin_section(LogstashParser.Plugin_sectionContext ctx) { throw new LogstashParsingException("only input, filter and output plugin sections are supported."); } - for (int i = 0; i < ctx.branch_or_plugin().size(); i++) { - logstashPluginList.add((LogstashPlugin) visitBranch_or_plugin(ctx.branch_or_plugin().get(i))); + for (int i = 0; i < pluginSectionContext.branch_or_plugin().size(); i++) { + logstashPluginList.add((LogstashPlugin) visitBranch_or_plugin(pluginSectionContext.branch_or_plugin().get(i))); } pluginSections.put(logstashPluginType, logstashPluginList); @@ -69,10 +69,10 @@ public Object visitPlugin_section(LogstashParser.Plugin_sectionContext ctx) { } @Override - public Object visitBranch_or_plugin(LogstashParser.Branch_or_pluginContext ctx) { + public Object visitBranch_or_plugin(LogstashParser.Branch_or_pluginContext branchOrPluginContext) { - if (ctx.getChild(0) instanceof LogstashParser.PluginContext) { - return visitPlugin(ctx.plugin()); + if (branchOrPluginContext.getChild(0) instanceof LogstashParser.PluginContext) { + return visitPlugin(branchOrPluginContext.plugin()); } else { throw new LogstashParsingException("conditionals are not supported"); @@ -80,12 +80,12 @@ public Object visitBranch_or_plugin(LogstashParser.Branch_or_pluginContext ctx) } @Override - public Object visitPlugin(LogstashParser.PluginContext ctx) { - String pluginName = ctx.name().getText(); + public Object visitPlugin(LogstashParser.PluginContext pluginContext) { + String pluginName = pluginContext.name().getText(); List logstashAttributeList = new ArrayList<>(); - for (int i = 0; i < ctx.attributes().attribute().size(); i++) { - logstashAttributeList.add((LogstashAttribute) visitAttribute(ctx.attributes().attribute().get(i))); + for (int i = 0; i < pluginContext.attributes().attribute().size(); i++) { + logstashAttributeList.add((LogstashAttribute) visitAttribute(pluginContext.attributes().attribute().get(i))); } return LogstashPlugin.builder() @@ -95,33 +95,36 @@ public Object visitPlugin(LogstashParser.PluginContext ctx) { } @Override - public Object visitAttribute(LogstashParser.AttributeContext ctx) { + public Object visitAttribute(LogstashParser.AttributeContext attributeContext) { LogstashValueType logstashValueType = null; Object value = null; - if (ctx.value().getChild(0) instanceof LogstashParser.ArrayContext) { + if (attributeContext.value().getChild(0) instanceof LogstashParser.ArrayContext) { logstashValueType = LogstashValueType.ARRAY; - value = visitArray(ctx.value().array()); + value = visitArray(attributeContext.value().array()); } - else if (ctx.value().getChild(0) instanceof LogstashParser.HashContext) { + else if (attributeContext.value().getChild(0) instanceof LogstashParser.HashContext) { logstashValueType = LogstashValueType.HASH; - value = visitHash(ctx.value().hash()); + value = visitHash(attributeContext.value().hash()); } - else if (ctx.value().getChild(0) instanceof LogstashParser.PluginContext) { + else if (attributeContext.value().getChild(0) instanceof LogstashParser.PluginContext) { throw new LogstashParsingException("plugins are not supported in attribute"); } - else if (ctx.value().NUMBER() != null && ctx.value().getText().equals(ctx.value().NUMBER().toString())) { + else if (attributeContext.value().NUMBER() != null && + attributeContext.value().getText().equals(attributeContext.value().NUMBER().toString())) { logstashValueType = LogstashValueType.NUMBER; - value = Double.valueOf(ctx.value().getText()); + value = Double.valueOf(attributeContext.value().getText()); } - else if (ctx.value().BAREWORD() != null && ctx.value().getText().equals(ctx.value().BAREWORD().toString())) { + else if (attributeContext.value().BAREWORD() != null && + attributeContext.value().getText().equals(attributeContext.value().BAREWORD().toString())) { logstashValueType = LogstashValueType.BAREWORD; - value = ctx.value().getText(); + value = attributeContext.value().getText(); } - else if (ctx.value().STRING() != null && ctx.value().getText().equals(ctx.value().STRING().toString())) { + else if (attributeContext.value().STRING() != null && + attributeContext.value().getText().equals(attributeContext.value().STRING().toString())) { logstashValueType = LogstashValueType.STRING; - value = ctx.value().getText().replaceAll("^\"|\"$|^'|'$", ""); + value = attributeContext.value().getText().replaceAll("^\"|\"$|^'|'$", ""); } LogstashAttributeValue logstashAttributeValue = LogstashAttributeValue.builder() @@ -130,41 +133,41 @@ else if (ctx.value().STRING() != null && ctx.value().getText().equals(ctx.value( .build(); return LogstashAttribute.builder() - .attributeName(ctx.name().getText()) + .attributeName(attributeContext.name().getText()) .attributeValue(logstashAttributeValue) .build(); } @Override - public Object visitArray(LogstashParser.ArrayContext ctx) { + public Object visitArray(LogstashParser.ArrayContext arrayContext) { List values = new LinkedList<>(); - for(int i = 0; i < ctx.value().size(); i++) - values.add(ctx.value().get(i).getText() ); + for(int i = 0; i < arrayContext.value().size(); i++) + values.add(arrayContext.value().get(i).getText() ); return values; } @Override - public Object visitHash(LogstashParser.HashContext ctx) { - return visitHashentries(ctx.hashentries()); + public Object visitHash(LogstashParser.HashContext hashContext) { + return visitHashentries(hashContext.hashentries()); } @Override - public Object visitHashentries(LogstashParser.HashentriesContext ctx) { - for (int i = 0; i < ctx.hashentry().size(); i++) { - visitHashentry((ctx.hashentry().get(i))); + public Object visitHashentries(LogstashParser.HashentriesContext hashentriesContext) { + for (int i = 0; i < hashentriesContext.hashentry().size(); i++) { + visitHashentry((hashentriesContext.hashentry().get(i))); } return hashEntries; } @Override - public Object visitHashentry(LogstashParser.HashentryContext ctx) { + public Object visitHashentry(LogstashParser.HashentryContext hashentryContext) { - if (ctx.value().getChild(0) instanceof LogstashParser.ArrayContext) - hashEntries.put(ctx.hashname().getText(), visitArray(ctx.value().array())); + if (hashentryContext.value().getChild(0) instanceof LogstashParser.ArrayContext) + hashEntries.put(hashentryContext.hashname().getText(), visitArray(hashentryContext.value().array())); else - hashEntries.put(ctx.hashname().getText(), ctx.value().getText()); + hashEntries.put(hashentryContext.hashname().getText(), hashentryContext.value().getText()); return hashEntries; } diff --git a/data-prepper-logstash-configuration/src/test/java/org/opensearch/dataprepper/logstash/parser/TestDataProvider.java b/data-prepper-logstash-configuration/src/test/java/org/opensearch/dataprepper/logstash/parser/TestDataProvider.java index 35fe0c40e0..bc6217053b 100644 --- a/data-prepper-logstash-configuration/src/test/java/org/opensearch/dataprepper/logstash/parser/TestDataProvider.java +++ b/data-prepper-logstash-configuration/src/test/java/org/opensearch/dataprepper/logstash/parser/TestDataProvider.java @@ -23,7 +23,6 @@ public class TestDataProvider { static final String RANDOM_STRING_2 = UUID.randomUUID().toString(); static final String RANDOM_VALUE = String.valueOf(new Random().nextInt(1000)); - // data public static LogstashConfiguration configData() { return LogstashConfiguration.builder().pluginSections(pluginSectionData()).build(); }