From 1f75660350b8af8fe27b88baa06af52d013bfca4 Mon Sep 17 00:00:00 2001 From: dineshchitlangia Date: Mon, 1 Jul 2019 11:58:47 -0400 Subject: [PATCH] HDDS-373. Genconf tool must generate ozone-site.xml with sample values (#1025) --- .../org/apache/hadoop/ozone/OzoneConfigKeys.java | 2 ++ .../org/apache/hadoop/ozone/OzoneConsts.java | 4 ++++ .../GenerateOzoneRequiredConfigurations.java | 16 +++++++++++++++- .../TestGenerateOzoneRequiredConfigurations.java | 16 ++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConfigKeys.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConfigKeys.java index b77cca35a8..98b3b56c77 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConfigKeys.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConfigKeys.java @@ -41,6 +41,8 @@ public final class OzoneConfigKeys { "dfs.container.ipc"; public static final int DFS_CONTAINER_IPC_PORT_DEFAULT = 9859; + public static final String OZONE_METADATA_DIRS = "ozone.metadata.dirs"; + /** * * When set to true, allocate a random free port for ozone container, diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java index 28f8907140..472cd799aa 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java @@ -299,4 +299,8 @@ private OzoneConsts() { // from OM leader to follower public static final String OM_RATIS_SNAPSHOT_BEFORE_DB_CHECKPOINT = "snapshotBeforeCheckpoint"; + + public static final String JAVA_TMP_DIR = "java.io.tmpdir"; + public static final String LOCALHOST = "localhost"; + } 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 c81ced3ca6..ae3a83b8f2 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,7 +21,10 @@ 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.hdds.scm.ScmConfigKeys; import org.apache.hadoop.ozone.OzoneConfigKeys; +import org.apache.hadoop.ozone.OzoneConsts; +import org.apache.hadoop.ozone.om.OMConfigKeys; import picocli.CommandLine.Command; import picocli.CommandLine.Parameters; import picocli.CommandLine.PicocliException; @@ -106,9 +109,19 @@ public static void generateConfigurations(String path) throws for (OzoneConfiguration.Property p : allProperties) { if (p.getTag() != null && p.getTag().contains("REQUIRED")) { - if(p.getName().equalsIgnoreCase(OzoneConfigKeys.OZONE_ENABLED)) { + if (p.getName().equalsIgnoreCase(OzoneConfigKeys.OZONE_ENABLED)) { p.setValue(String.valueOf(Boolean.TRUE)); + } else if (p.getName().equalsIgnoreCase( + OzoneConfigKeys.OZONE_METADATA_DIRS)) { + p.setValue(System.getProperty(OzoneConsts.JAVA_TMP_DIR)); + } else if (p.getName().equalsIgnoreCase( + OMConfigKeys.OZONE_OM_ADDRESS_KEY) + || p.getName().equalsIgnoreCase(ScmConfigKeys.OZONE_SCM_NAMES) + || p.getName().equalsIgnoreCase( + ScmConfigKeys.OZONE_SCM_CLIENT_ADDRESS_KEY)) { + p.setValue(OzoneConsts.LOCALHOST); } + requiredProperties.add(p); } } @@ -157,4 +170,5 @@ public static boolean canWrite(String path) { File file = new File(path); return file.canWrite(); } + } 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 ecb65f085b..9279d7f226 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 @@ -20,6 +20,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.RandomStringUtils; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.test.GenericTestUtils; import org.junit.After; import org.junit.AfterClass; @@ -39,6 +40,7 @@ import java.io.File; import java.io.IOException; import java.io.PrintStream; +import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -148,6 +150,7 @@ public List handleExecutionException(ExecutionException ex, /** * Tests a valid path and generates ozone-site.xml by calling * {@code GenerateOzoneRequiredConfigurations#generateConfigurations}. + * Further verifies that all properties have a default value. * * @throws Exception */ @@ -157,6 +160,19 @@ public void testGenerateConfigurations() throws Exception { String[] args = new String[]{tempPath.getAbsolutePath()}; execute(args, "ozone-site.xml has been generated at " + tempPath.getAbsolutePath()); + + //Fetch file generated by above line + URL url = new File(tempPath.getAbsolutePath() + "/ozone-site.xml") + .toURI().toURL(); + OzoneConfiguration oc = new OzoneConfiguration(); + List allProperties = + oc.readPropertyFromXml(url); + + //Asserts all properties have a non-empty value + for (OzoneConfiguration.Property p : allProperties) { + Assert.assertTrue( + p.getValue() != null && p.getValue().length() > 0); + } } /**