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