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<String, List<PropertyDescriptionData>> propertyDescriptions = 
new ConcurrentHashMap<>();
+      final List<String> configPackagesToScan = 
ImmutableList.of(LOGSEARCH_PACKAGE, LOGFEEDER_PACKAGE);
+      fillPropertyDescriptions(propertyDescriptions, configPackagesToScan);
+      System.out.println(String.format("Number of logsearch.properties 
configuration descriptors found: %d", 
propertyDescriptions.get(LOGSEARCH_PROPERTIES).size()));
+      System.out.println(String.format("Number of logfeeder.properties 
configuration descriptors found: %d", 
propertyDescriptions.get(LOGFEEDER_PROPERTIES).size()));
+
+      final Map<String, List<ShipperConfigDescriptionData>> 
shipperConfigDescriptionMap = new HashMap<>();
 
 Review comment:
   Why don't you use a class with the right property names instead of 
`Map<String, List<ShipperConfigDescriptionData>>` ? Like:
   ```
   class ShipperConfigDescription {
     private List<ShipperConfigDescriptionData> topLevelSections;
     private List<ShipperConfigDescriptionData> inputConfigSections;
   ...
   }
   ```
   
   and instead of
   ``` 
   void fillShipperConfigDescriptions(...)
   ```
   return
   ```
   ShipperConfigDescription collectShipperConfigDescriptions(...)
   ```

----------------------------------------------------------------
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

Reply via email to