HDDS-621. ozone genconf improvements. Contributed by Dinesh Chitlangia.
This commit is contained in:
parent
dc27408043
commit
c456d6b3a5
@ -58,7 +58,7 @@ ozone genconf <path>
|
||||
|
||||
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.
|
||||
|
@ -21,6 +21,7 @@
|
||||
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.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 Void call() throws Exception {
|
||||
* @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 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)) {
|
||||
p.setValue(String.valueOf(Boolean.TRUE));
|
||||
}
|
||||
requiredProperties.add(p);
|
||||
}
|
||||
}
|
||||
@ -112,13 +117,20 @@ public static void generateConfigurations(String path) throws
|
||||
new OzoneConfiguration.XMLConfiguration();
|
||||
requiredConfig.setProperties(requiredProperties);
|
||||
|
||||
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, new File(path, "ozone-site.xml"));
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -159,6 +159,25 @@ public void testGenerateConfigurations() throws Exception {
|
||||
tempPath.getAbsolutePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
Loading…
Reference in New Issue
Block a user