Skip to content

Commit

Permalink
updated javadoc for public classes
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 1, 2021
1 parent e56cf3e commit ecee63a
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* Grammar file for parsing Logstash configurations
*/

grammar Logstash;

@header {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.opensearch.dataprepper.logstash.exception;

/**
* Exception for Logtsash converter
* Exception for Logstash converter
*
* @since 1.2
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -30,22 +30,22 @@ public class LogstashVisitor extends LogstashBaseVisitor {
private final Map<String, Object> 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)
.build();
}

@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;
Expand All @@ -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);
Expand All @@ -69,23 +69,23 @@ 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");
}
}

@Override
public Object visitPlugin(LogstashParser.PluginContext ctx) {
String pluginName = ctx.name().getText();
public Object visitPlugin(LogstashParser.PluginContext pluginContext) {
String pluginName = pluginContext.name().getText();
List<LogstashAttribute> 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()
Expand All @@ -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()
Expand All @@ -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<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit ecee63a

Please sign in to comment.