HDFS-11725. Ozone: Revise create container CLI specification and implementation. Contributed by Weiwei Yang
This commit is contained in:
parent
b581cde542
commit
3158f479d3
|
@ -35,7 +35,9 @@ import static org.apache.hadoop.ozone.scm.cli.SCMCLI.HELP_OP;
|
|||
public class CreateContainerHandler extends OzoneCommandHandler {
|
||||
|
||||
public static final String CONTAINER_CREATE = "create";
|
||||
public static final String PIPELINE_ID = "p";
|
||||
public static final String OPT_CONTAINER_NAME = "c";
|
||||
// TODO Support an optional -p <pipelineID> option to create
|
||||
// container on given datanodes.
|
||||
|
||||
public CreateContainerHandler(ScmClient scmClient) {
|
||||
super(scmClient);
|
||||
|
@ -46,25 +48,23 @@ public class CreateContainerHandler extends OzoneCommandHandler {
|
|||
if (!cmd.hasOption(CONTAINER_CREATE)) {
|
||||
throw new IOException("Expecting container create");
|
||||
}
|
||||
// TODO requires pipeline id (instead of optional as in the design) for now
|
||||
if (!cmd.hasOption(PIPELINE_ID)) {
|
||||
if (!cmd.hasOption(OPT_CONTAINER_NAME)) {
|
||||
displayHelp();
|
||||
if (!cmd.hasOption(HELP_OP)) {
|
||||
throw new IOException("Expecting container ID");
|
||||
throw new IOException("Expecting container name");
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
String pipelineID = cmd.getOptionValue(PIPELINE_ID);
|
||||
String containerName = cmd.getOptionValue(OPT_CONTAINER_NAME);
|
||||
|
||||
logOut("Creating container : %s.", pipelineID);
|
||||
getScmClient().createContainer(pipelineID);
|
||||
logOut("Creating container : %s.", containerName);
|
||||
getScmClient().createContainer(containerName);
|
||||
logOut("Container created.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayHelp() {
|
||||
// TODO : may need to change this if we decide to make -p optional later
|
||||
Options options = new Options();
|
||||
addOptions(options);
|
||||
HelpFormatter helpFormatter = new HelpFormatter();
|
||||
|
@ -73,7 +73,8 @@ public class CreateContainerHandler extends OzoneCommandHandler {
|
|||
}
|
||||
|
||||
public static void addOptions(Options options) {
|
||||
Option pipelineID = new Option(PIPELINE_ID, true, "Specify pipeline ID");
|
||||
options.addOption(pipelineID);
|
||||
Option containerNameOpt = new Option(OPT_CONTAINER_NAME,
|
||||
true, "Specify container name");
|
||||
options.addOption(containerNameOpt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,9 +113,8 @@ public class TestSCMCli {
|
|||
assertTrue(ioe.getMessage().contains(
|
||||
"Specified key does not exist. key : " + containerName));
|
||||
}
|
||||
String[] args = {"-container", "-create", "-p", containerName};
|
||||
String[] args = {"-container", "-create", "-c", containerName};
|
||||
assertEquals(ResultCode.SUCCESS, cli.run(args));
|
||||
Thread.sleep(3000);
|
||||
Pipeline container = scm.getContainer(containerName);
|
||||
assertNotNull(container);
|
||||
assertEquals(containerName, container.getContainerName());
|
||||
|
@ -226,7 +225,7 @@ public class TestSCMCli {
|
|||
String expected2 =
|
||||
"usage: hdfs scm -container -create <option>\n" +
|
||||
"where <option> is\n" +
|
||||
" -p <arg> Specify pipeline ID\n";
|
||||
" -c <arg> Specify container name\n";
|
||||
assertEquals(expected2, testContent.toString());
|
||||
System.setOut(init);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue