[GitHub] kasakrisz commented on a change in pull request #53: AMBARI-23456. Generate markdown docs from internal annotations.

2018-12-03 Thread GitBox
kasakrisz commented on a change in pull request #53: AMBARI-23456. Generate 
markdown docs from internal annotations.
URL: https://github.com/apache/ambari-logsearch/pull/53#discussion_r238528708
 
 

 ##
 File path: 
ambari-logsearch-docs/src/main/java/org/apache/ambari/logsearch/doc/LogSearchMarkdownGenerator.java
 ##
 @@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ambari.logsearch.doc;
+
+import com.google.common.collect.ImmutableList;
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import org.apache.ambari.logsearch.config.api.LogSearchPropertyDescription;
+import org.apache.ambari.logsearch.config.api.ShipperConfigElementDescription;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.io.FileUtils;
+import org.reflections.Reflections;
+import org.reflections.scanners.FieldAnnotationsScanner;
+import org.reflections.scanners.MethodAnnotationsScanner;
+import org.springframework.core.io.ClassPathResource;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.StringWriter;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.nio.charset.Charset;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+public class LogSearchMarkdownGenerator {
+
+  private static final String TOP_LEVEL_SECTIONS = "topLevelSections";
+  private static final String INPUT_CONFIG_SECTION = "inputConfigSection";
+  private static final String FILTER_CONFIG_SECTION = "filterConfigSection";
+  private static final String POST_MAP_VALUES_SECTION = "postMapValuesSection";
+  private static final String LOGSEARCH_PROPERTIES_TEMPLATE_KEY = 
"logsearchProperties";
+  private static final String LOGFEEDER_PROPERTIES_TEMPLATE_KEY = 
"logfeederProperties";
+
+  private static final String OUTPUT_DIR_OPTION = "output-dir";
+
+  private static final String LOGSEARCH_PACKAGE = 
"org.apache.ambari.logsearch";
+  private static final String LOGFEEDER_PACKAGE = 
"org.apache.ambari.logfeeder";
+  private static final String CONFIG_API_PACKAGE = 
"org.apache.ambari.logsearch.config.json.model.inputconfig.impl";
+
+  private static final String TEMPLATES_FOLDER = "templates";
+
+  private static final String LOGSEARCH_PROPERTIES = "logsearch.properties";
+  private static final String LOGSEARCH_PROPERTIES_MARKDOWN_TEMPLATE_FILE = 
"logsearch_properties.md.ftl";
+  private static final String LOGSEARCH_PROPERTIES_MARKDOWN_OUTPUT = 
"logsearch_properties.md";
+
+  private static final String LOGFEEDER_PROPERTIES = "logfeeder.properties";
+  private static final String LOGFEEDER_PROPERTIES_MARKDOWN_TEMPLATE_FILE = 
"logfeeder_properties.md.ftl";
+  private static final String LOGFEEDER_PROPERTIES_MARKDOWN_OUTPUT = 
"logfeeder_properties.md";
+
+  private static final String SHIPPER_CONFIGURATIONS_MARKDOWN_TEMPLATE_FILE = 
"shipper_configurations.md.ftl";
+  private static final String SHIPPER_CONFIGURATIONS_MARKDOWN_OUTPUT = 
"shipper_configurations.md";
+
+
+  public static void main(String[] args) {
+try {
+  Options options = new Options();
+  options.addOption(Option.builder()
+.desc("Output folder of the markdowns")
+.longOpt(OUTPUT_DIR_OPTION)
+.hasArg()
+.required()
+.type(String.class)
+.build());
+  CommandLineParser parser = new DefaultParser();
+  CommandLine cmdLine = parser.parse(options, args);
+
+  String outputDir = cmdLine.getOptionValue(OUTPUT_DIR_OPTION);
+  File outputFileDir = new File(outputDir);
+  if (!outputFileDir.exists() || !outputFileDir.isDirectory()) {
+throw new FileNotFoundException(String.format("Directory '%s' does not 
exist", outputDir));
+  }
+
+  final Map> propertyDescriptions = 
new ConcurrentHashMap<>();
+  

[GitHub] kasakrisz commented on a change in pull request #53: AMBARI-23456. Generate markdown docs from internal annotations.

2018-12-03 Thread GitBox
kasakrisz commented on a change in pull request #53: AMBARI-23456. Generate 
markdown docs from internal annotations.
URL: https://github.com/apache/ambari-logsearch/pull/53#discussion_r238527060
 
 

 ##
 File path: 
ambari-logsearch-docs/src/main/java/org/apache/ambari/logsearch/doc/LogSearchMarkdownGenerator.java
 ##
 @@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ambari.logsearch.doc;
+
+import com.google.common.collect.ImmutableList;
 
 Review comment:
   You can use `java.util.Collections.unmodifiableList` instead of 
`com.google.common.collect.ImmutableList`


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] kasakrisz commented on a change in pull request #53: AMBARI-23456. Generate markdown docs from internal annotations.

2018-12-03 Thread GitBox
kasakrisz commented on a change in pull request #53: AMBARI-23456. Generate 
markdown docs from internal annotations.
URL: https://github.com/apache/ambari-logsearch/pull/53#discussion_r238526407
 
 

 ##
 File path: 
ambari-logsearch-docs/src/main/java/org/apache/ambari/logsearch/doc/AbstractDescriptionData.java
 ##
 @@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ambari.logsearch.doc;
+
+public abstract class AbstractDescriptionData {
+
+  private final String description;
+  private final String defaultValue;
+  private final String examples;
+
+  public AbstractDescriptionData(String description, String defaultStr, 
String[] examplesArr) {
+this.description = description;
+examples = generateExamplesString(examplesArr);
+defaultValue = generateDefaultValue(defaultStr);
+  }
+
+  protected String generateDefaultValue(String defaultValue) {
+if (defaultValue == null || defaultValue.length() == 0) {
+  return "`EMPTY`";
+} else {
+  return defaultValue;
+}
+  }
+
+  protected String generateExamplesString(String[] examples) {
+if (examples == null) {
+  return "";
+} else {
+  final StringBuilder stringBuilder = new StringBuilder();
+  if(examples.length > 0){
+stringBuilder.append("");
+for( String example : examples){
+  stringBuilder.append("").append("`").append(example).append("`");
 
 Review comment:
   Is an `append("")` missing from the end?


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] kasakrisz commented on a change in pull request #53: AMBARI-23456. Generate markdown docs from internal annotations.

2018-12-03 Thread GitBox
kasakrisz commented on a change in pull request #53: AMBARI-23456. Generate 
markdown docs from internal annotations.
URL: https://github.com/apache/ambari-logsearch/pull/53#discussion_r238529400
 
 

 ##
 File path: 
ambari-logsearch-docs/src/main/java/org/apache/ambari/logsearch/doc/LogSearchMarkdownGenerator.java
 ##
 @@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ambari.logsearch.doc;
+
+import com.google.common.collect.ImmutableList;
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import org.apache.ambari.logsearch.config.api.LogSearchPropertyDescription;
+import org.apache.ambari.logsearch.config.api.ShipperConfigElementDescription;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.io.FileUtils;
+import org.reflections.Reflections;
+import org.reflections.scanners.FieldAnnotationsScanner;
+import org.reflections.scanners.MethodAnnotationsScanner;
+import org.springframework.core.io.ClassPathResource;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.StringWriter;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.nio.charset.Charset;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+public class LogSearchMarkdownGenerator {
+
+  private static final String TOP_LEVEL_SECTIONS = "topLevelSections";
+  private static final String INPUT_CONFIG_SECTION = "inputConfigSection";
+  private static final String FILTER_CONFIG_SECTION = "filterConfigSection";
+  private static final String POST_MAP_VALUES_SECTION = "postMapValuesSection";
+  private static final String LOGSEARCH_PROPERTIES_TEMPLATE_KEY = 
"logsearchProperties";
+  private static final String LOGFEEDER_PROPERTIES_TEMPLATE_KEY = 
"logfeederProperties";
+
+  private static final String OUTPUT_DIR_OPTION = "output-dir";
+
+  private static final String LOGSEARCH_PACKAGE = 
"org.apache.ambari.logsearch";
+  private static final String LOGFEEDER_PACKAGE = 
"org.apache.ambari.logfeeder";
+  private static final String CONFIG_API_PACKAGE = 
"org.apache.ambari.logsearch.config.json.model.inputconfig.impl";
+
+  private static final String TEMPLATES_FOLDER = "templates";
+
+  private static final String LOGSEARCH_PROPERTIES = "logsearch.properties";
+  private static final String LOGSEARCH_PROPERTIES_MARKDOWN_TEMPLATE_FILE = 
"logsearch_properties.md.ftl";
+  private static final String LOGSEARCH_PROPERTIES_MARKDOWN_OUTPUT = 
"logsearch_properties.md";
+
+  private static final String LOGFEEDER_PROPERTIES = "logfeeder.properties";
+  private static final String LOGFEEDER_PROPERTIES_MARKDOWN_TEMPLATE_FILE = 
"logfeeder_properties.md.ftl";
+  private static final String LOGFEEDER_PROPERTIES_MARKDOWN_OUTPUT = 
"logfeeder_properties.md";
+
+  private static final String SHIPPER_CONFIGURATIONS_MARKDOWN_TEMPLATE_FILE = 
"shipper_configurations.md.ftl";
+  private static final String SHIPPER_CONFIGURATIONS_MARKDOWN_OUTPUT = 
"shipper_configurations.md";
+
+
+  public static void main(String[] args) {
+try {
+  Options options = new Options();
+  options.addOption(Option.builder()
+.desc("Output folder of the markdowns")
+.longOpt(OUTPUT_DIR_OPTION)
+.hasArg()
+.required()
+.type(String.class)
+.build());
+  CommandLineParser parser = new DefaultParser();
+  CommandLine cmdLine = parser.parse(options, args);
+
+  String outputDir = cmdLine.getOptionValue(OUTPUT_DIR_OPTION);
+  File outputFileDir = new File(outputDir);
+  if (!outputFileDir.exists() || !outputFileDir.isDirectory()) {
+throw new FileNotFoundException(String.format("Directory '%s' does not 
exist", outputDir));
+  }
+
+  final Map> propertyDescriptions = 
new ConcurrentHashMap<>();
+