HDDS-373. Genconf tool must generate ozone-site.xml with sample values (#1025)

This commit is contained in:
dineshchitlangia 2019-07-01 11:58:47 -04:00 committed by Anu Engineer
parent 9df6275954
commit 1f75660350
4 changed files with 37 additions and 1 deletions

View File

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

View File

@ -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";
}

View File

@ -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();
}
}

View File

@ -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<Object> 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<OzoneConfiguration.Property> 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);
}
}
/**