HDDS-621. ozone genconf improvements. Contributed by Dinesh Chitlangia.

(cherry picked from commit c456d6b3a5061b99141869f07dc1820ec96b7a67)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/69cf9e66
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/69cf9e66
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/69cf9e66

Branch: refs/heads/ozone-0.3
Commit: 69cf9e66e27fb5c9f757370c6b8e24aaabf0a92a
Parents: 4aa4936
Author: Arpit Agarwal <[email protected]>
Authored: Fri Oct 19 11:36:36 2018 -0700
Committer: Arpit Agarwal <[email protected]>
Committed: Fri Oct 19 11:36:41 2018 -0700

----------------------------------------------------------------------
 hadoop-ozone/docs/content/Settings.md           |  4 +--
 .../GenerateOzoneRequiredConfigurations.java    | 26 ++++++++++++++------
 ...TestGenerateOzoneRequiredConfigurations.java | 19 ++++++++++++++
 3 files changed, 40 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/69cf9e66/hadoop-ozone/docs/content/Settings.md
----------------------------------------------------------------------
diff --git a/hadoop-ozone/docs/content/Settings.md 
b/hadoop-ozone/docs/content/Settings.md
index 5c9bb41..b02816b 100644
--- a/hadoop-ozone/docs/content/Settings.md
+++ b/hadoop-ozone/docs/content/Settings.md
@@ -56,9 +56,9 @@ the specified path (directory).
 ozone genconf <path>
 {{< /highlight >}}
 
-Let us look at the settings inside the generated file (ozone-site.xml)  and
+Let us look at the settings inside the generated file (ozone-site.xml) and
 how they control ozone. Once the right values are defined, this file
-needs to be copied to ```ozone directory/etc/Hadoop```.
+needs to be copied to ```ozone directory/etc/hadoop```.
 
 
 * **ozone.enabled** This is the most critical setting for ozone.

http://git-wip-us.apache.org/repos/asf/hadoop/blob/69cf9e66/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/genconf/GenerateOzoneRequiredConfigurations.java
----------------------------------------------------------------------
diff --git 
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/genconf/GenerateOzoneRequiredConfigurations.java
 
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/genconf/GenerateOzoneRequiredConfigurations.java
index 5d27838..c81ced3 100644
--- 
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/genconf/GenerateOzoneRequiredConfigurations.java
+++ 
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/genconf/GenerateOzoneRequiredConfigurations.java
@@ -21,6 +21,7 @@ package org.apache.hadoop.ozone.genconf;
 import org.apache.hadoop.hdds.cli.GenericCli;
 import org.apache.hadoop.hdds.cli.HddsVersionProvider;
 import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.OzoneConfigKeys;
 import picocli.CommandLine.Command;
 import picocli.CommandLine.Parameters;
 import picocli.CommandLine.PicocliException;
@@ -29,6 +30,7 @@ import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
 import java.io.File;
+import java.io.IOException;
 import java.net.URL;
 import java.nio.file.Files;
 import java.nio.file.InvalidPathException;
@@ -79,7 +81,7 @@ public final class GenerateOzoneRequiredConfigurations 
extends GenericCli {
    * @throws JAXBException
    */
   public static void generateConfigurations(String path) throws
-      PicocliException, JAXBException {
+      PicocliException, JAXBException, IOException {
 
     if (!isValidPath(path)) {
       throw new PicocliException("Invalid directory path.");
@@ -104,6 +106,9 @@ public final class GenerateOzoneRequiredConfigurations 
extends GenericCli {
 
     for (OzoneConfiguration.Property p : allProperties) {
       if (p.getTag() != null && p.getTag().contains("REQUIRED")) {
+        if(p.getName().equalsIgnoreCase(OzoneConfigKeys.OZONE_ENABLED)) {
+          p.setValue(String.valueOf(Boolean.TRUE));
+        }
         requiredProperties.add(p);
       }
     }
@@ -112,13 +117,20 @@ public final class GenerateOzoneRequiredConfigurations 
extends GenericCli {
         new OzoneConfiguration.XMLConfiguration();
     requiredConfig.setProperties(requiredProperties);
 
-    JAXBContext context =
-        JAXBContext.newInstance(OzoneConfiguration.XMLConfiguration.class);
-    Marshaller m = context.createMarshaller();
-    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
-    m.marshal(requiredConfig, new File(path, "ozone-site.xml"));
+    File output = new File(path, "ozone-site.xml");
+    if(output.createNewFile()){
+      JAXBContext context =
+          JAXBContext.newInstance(OzoneConfiguration.XMLConfiguration.class);
+      Marshaller m = context.createMarshaller();
+      m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+      m.marshal(requiredConfig, output);
+
+      System.out.println("ozone-site.xml has been generated at " + path);
+    } else {
+      System.out.printf("ozone-site.xml already exists at %s and " +
+          "will not be overwritten%n", path);
+    }
 
-    System.out.println("ozone-site.xml has been generated at " + path);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hadoop/blob/69cf9e66/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/genconf/TestGenerateOzoneRequiredConfigurations.java
----------------------------------------------------------------------
diff --git 
a/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/genconf/TestGenerateOzoneRequiredConfigurations.java
 
b/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/genconf/TestGenerateOzoneRequiredConfigurations.java
index 0fab185..ecb65f0 100644
--- 
a/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/genconf/TestGenerateOzoneRequiredConfigurations.java
+++ 
b/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/genconf/TestGenerateOzoneRequiredConfigurations.java
@@ -160,6 +160,25 @@ public class TestGenerateOzoneRequiredConfigurations {
   }
 
   /**
+   * Generates ozone-site.xml at specified path.
+   * Verify that it does not overwrite if file already exists in path.
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testDoesNotOverwrite() throws Exception {
+    File tempPath = getRandomTempDir();
+    String[] args = new String[]{tempPath.getAbsolutePath()};
+    execute(args, "ozone-site.xml has been generated at " +
+        tempPath.getAbsolutePath());
+
+    //attempt overwrite
+    execute(args, "ozone-site.xml already exists at " +
+            tempPath.getAbsolutePath() + " and will not be overwritten");
+
+  }
+
+  /**
    * Test to avoid generating ozone-site.xml when insufficient permission.
    * @throws Exception
    */


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to