|
@@ -19,6 +19,7 @@ package org.apache.hadoop.registry.cli;
|
|
|
|
|
|
import static org.apache.hadoop.registry.client.binding.RegistryTypeUtils.*;
|
|
import static org.apache.hadoop.registry.client.binding.RegistryTypeUtils.*;
|
|
|
|
|
|
|
|
+import java.io.Closeable;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.PrintStream;
|
|
import java.io.PrintStream;
|
|
import java.net.URI;
|
|
import java.net.URI;
|
|
@@ -34,12 +35,14 @@ import org.apache.commons.cli.Option;
|
|
import org.apache.commons.cli.OptionBuilder;
|
|
import org.apache.commons.cli.OptionBuilder;
|
|
import org.apache.commons.cli.Options;
|
|
import org.apache.commons.cli.Options;
|
|
import org.apache.commons.cli.ParseException;
|
|
import org.apache.commons.cli.ParseException;
|
|
|
|
+import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configured;
|
|
import org.apache.hadoop.conf.Configured;
|
|
import org.apache.hadoop.fs.PathNotFoundException;
|
|
import org.apache.hadoop.fs.PathNotFoundException;
|
|
import org.apache.hadoop.security.AccessControlException;
|
|
import org.apache.hadoop.security.AccessControlException;
|
|
|
|
+import org.apache.hadoop.service.ServiceOperations;
|
|
|
|
+import org.apache.hadoop.util.ExitUtil;
|
|
import org.apache.hadoop.util.Tool;
|
|
import org.apache.hadoop.util.Tool;
|
|
import org.apache.hadoop.util.ToolRunner;
|
|
import org.apache.hadoop.util.ToolRunner;
|
|
-import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
|
|
import org.apache.hadoop.registry.client.api.BindFlags;
|
|
import org.apache.hadoop.registry.client.api.BindFlags;
|
|
import org.apache.hadoop.registry.client.api.RegistryOperations;
|
|
import org.apache.hadoop.registry.client.api.RegistryOperations;
|
|
import org.apache.hadoop.registry.client.api.RegistryOperationsFactory;
|
|
import org.apache.hadoop.registry.client.api.RegistryOperationsFactory;
|
|
@@ -54,41 +57,76 @@ import org.apache.hadoop.registry.client.types.ServiceRecord;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
-public class RegistryCli extends Configured implements Tool {
|
|
|
|
|
|
+/**
|
|
|
|
+ * Command line for registry operations.
|
|
|
|
+ */
|
|
|
|
+public class RegistryCli extends Configured implements Tool, Closeable {
|
|
private static final Logger LOG =
|
|
private static final Logger LOG =
|
|
LoggerFactory.getLogger(RegistryCli.class);
|
|
LoggerFactory.getLogger(RegistryCli.class);
|
|
- protected final PrintStream sysout;
|
|
|
|
- protected final PrintStream syserr;
|
|
|
|
|
|
+ protected final PrintStream sysout;
|
|
|
|
+ protected final PrintStream syserr;
|
|
|
|
|
|
|
|
|
|
- private RegistryOperations registry;
|
|
|
|
|
|
+ private RegistryOperations registry;
|
|
|
|
|
|
- static final String LS_USAGE = "ls pathName";
|
|
|
|
- static final String RESOLVE_USAGE = "resolve pathName";
|
|
|
|
- static final String BIND_USAGE =
|
|
|
|
|
|
+ private static final String LS_USAGE = "ls pathName";
|
|
|
|
+ private static final String RESOLVE_USAGE = "resolve pathName";
|
|
|
|
+ private static final String BIND_USAGE =
|
|
"bind -inet -api apiName -p portNumber -h hostName pathName" + "\n"
|
|
"bind -inet -api apiName -p portNumber -h hostName pathName" + "\n"
|
|
+ "bind -webui uriString -api apiName pathName" + "\n"
|
|
+ "bind -webui uriString -api apiName pathName" + "\n"
|
|
+ "bind -rest uriString -api apiName pathName";
|
|
+ "bind -rest uriString -api apiName pathName";
|
|
- static final String MKNODE_USAGE = "mknode directoryName";
|
|
|
|
- static final String RM_USAGE = "rm pathName";
|
|
|
|
- static final String USAGE =
|
|
|
|
|
|
+ private static final String MKNODE_USAGE = "mknode directoryName";
|
|
|
|
+ private static final String RM_USAGE = "rm pathName";
|
|
|
|
+ private static final String USAGE =
|
|
"\n" + LS_USAGE + "\n" + RESOLVE_USAGE + "\n" + BIND_USAGE + "\n" +
|
|
"\n" + LS_USAGE + "\n" + RESOLVE_USAGE + "\n" + BIND_USAGE + "\n" +
|
|
MKNODE_USAGE + "\n" + RM_USAGE;
|
|
MKNODE_USAGE + "\n" + RM_USAGE;
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
- public RegistryCli(PrintStream sysout, PrintStream syserr) {
|
|
|
|
- super(new YarnConfiguration());
|
|
|
|
|
|
+ public RegistryCli(PrintStream sysout, PrintStream syserr) {
|
|
|
|
+ Configuration conf = new Configuration();
|
|
|
|
+ super.setConf(conf);
|
|
|
|
+ registry = RegistryOperationsFactory.createInstance(conf);
|
|
|
|
+ registry.start();
|
|
this.sysout = sysout;
|
|
this.sysout = sysout;
|
|
this.syserr = syserr;
|
|
this.syserr = syserr;
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ public RegistryCli(RegistryOperations reg,
|
|
|
|
+ Configuration conf,
|
|
|
|
+ PrintStream sysout,
|
|
|
|
+ PrintStream syserr) {
|
|
|
|
+ super(conf);
|
|
|
|
+ Preconditions.checkArgument(reg != null, "Null registry");
|
|
|
|
+ registry = reg;
|
|
|
|
+ this.sysout = sysout;
|
|
|
|
+ this.syserr = syserr;
|
|
|
|
+ }
|
|
|
|
|
|
@SuppressWarnings("UseOfSystemOutOrSystemErr")
|
|
@SuppressWarnings("UseOfSystemOutOrSystemErr")
|
|
public static void main(String[] args) throws Exception {
|
|
public static void main(String[] args) throws Exception {
|
|
- RegistryCli cli = new RegistryCli(System.out, System.err);
|
|
|
|
- int res = ToolRunner.run(cli, args);
|
|
|
|
- System.exit(res);
|
|
|
|
|
|
+ int res = -1;
|
|
|
|
+ try (RegistryCli cli = new RegistryCli(System.out, System.err)) {
|
|
|
|
+ res = ToolRunner.run(cli, args);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ ExitUtil.terminate(res, e);
|
|
|
|
+ }
|
|
|
|
+ ExitUtil.terminate(res);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Close the object by stopping the registry.
|
|
|
|
+ * <p>
|
|
|
|
+ * <i>Important:</i>
|
|
|
|
+ * <p>
|
|
|
|
+ * After this call is made, no operations may be made of this
|
|
|
|
+ * object, <i>or of a YARN registry instance used when constructing
|
|
|
|
+ * this object. </i>
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public void close() throws IOException {
|
|
|
|
+ ServiceOperations.stopQuietly(registry);
|
|
|
|
+ registry = null;
|
|
}
|
|
}
|
|
|
|
|
|
private int usageError(String err, String usage) {
|
|
private int usageError(String err, String usage) {
|
|
@@ -104,146 +142,151 @@ public class RegistryCli extends Configured implements Tool {
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public int run(String[] args) throws Exception {
|
|
public int run(String[] args) throws Exception {
|
|
Preconditions.checkArgument(getConf() != null, "null configuration");
|
|
Preconditions.checkArgument(getConf() != null, "null configuration");
|
|
- registry = RegistryOperationsFactory.createInstance(
|
|
|
|
- new YarnConfiguration(getConf()));
|
|
|
|
- registry.start();
|
|
|
|
if (args.length > 0) {
|
|
if (args.length > 0) {
|
|
- if (args[0].equals("ls")) {
|
|
|
|
- return ls(args);
|
|
|
|
- } else if (args[0].equals("resolve")) {
|
|
|
|
- return resolve(args);
|
|
|
|
- } else if (args[0].equals("bind")) {
|
|
|
|
- return bind(args);
|
|
|
|
- } else if (args[0].equals("mknode")) {
|
|
|
|
- return mknode(args);
|
|
|
|
- } else if (args[0].equals("rm")) {
|
|
|
|
- return rm(args);
|
|
|
|
|
|
+ switch (args[0]) {
|
|
|
|
+ case "ls":
|
|
|
|
+ return ls(args);
|
|
|
|
+ case "resolve":
|
|
|
|
+ return resolve(args);
|
|
|
|
+ case "bind":
|
|
|
|
+ return bind(args);
|
|
|
|
+ case "mknode":
|
|
|
|
+ return mknode(args);
|
|
|
|
+ case "rm":
|
|
|
|
+ return rm(args);
|
|
|
|
+ default:
|
|
|
|
+ return usageError("Invalid command: " + args[0], USAGE);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return usageError("Invalid command: " + args[0], USAGE);
|
|
|
|
|
|
+ return usageError("No command arg passed.", USAGE);
|
|
}
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
- public int ls(String [] args) {
|
|
|
|
-
|
|
|
|
- Options lsOption = new Options();
|
|
|
|
- CommandLineParser parser = new GnuParser();
|
|
|
|
- try {
|
|
|
|
- CommandLine line = parser.parse(lsOption, args);
|
|
|
|
-
|
|
|
|
- List<String> argsList = line.getArgList();
|
|
|
|
- if (argsList.size() != 2) {
|
|
|
|
- return usageError("ls requires exactly one path argument", LS_USAGE);
|
|
|
|
- }
|
|
|
|
- if (!validatePath(argsList.get(1)))
|
|
|
|
- return -1;
|
|
|
|
-
|
|
|
|
- try {
|
|
|
|
- List<String> children = registry.list(argsList.get(1));
|
|
|
|
|
|
+ public int ls(String[] args) {
|
|
|
|
+
|
|
|
|
+ Options lsOption = new Options();
|
|
|
|
+ CommandLineParser parser = new GnuParser();
|
|
|
|
+ try {
|
|
|
|
+ CommandLine line = parser.parse(lsOption, args);
|
|
|
|
+
|
|
|
|
+ List<String> argsList = line.getArgList();
|
|
|
|
+ if (argsList.size() != 2) {
|
|
|
|
+ return usageError("ls requires exactly one path argument", LS_USAGE);
|
|
|
|
+ }
|
|
|
|
+ if (!validatePath(argsList.get(1))) {
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ List<String> children = registry.list(argsList.get(1));
|
|
for (String child : children) {
|
|
for (String child : children) {
|
|
sysout.println(child);
|
|
sysout.println(child);
|
|
}
|
|
}
|
|
- return 0;
|
|
|
|
|
|
+ return 0;
|
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
syserr.println(analyzeException("ls", e, argsList));
|
|
syserr.println(analyzeException("ls", e, argsList));
|
|
}
|
|
}
|
|
- return -1;
|
|
|
|
- } catch (ParseException exp) {
|
|
|
|
- return usageError("Invalid syntax " + exp, LS_USAGE);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ return -1;
|
|
|
|
+ } catch (ParseException exp) {
|
|
|
|
+ return usageError("Invalid syntax " + exp, LS_USAGE);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
- public int resolve(String [] args) {
|
|
|
|
- Options resolveOption = new Options();
|
|
|
|
- CommandLineParser parser = new GnuParser();
|
|
|
|
- try {
|
|
|
|
- CommandLine line = parser.parse(resolveOption, args);
|
|
|
|
-
|
|
|
|
- List<String> argsList = line.getArgList();
|
|
|
|
- if (argsList.size() != 2) {
|
|
|
|
- return usageError("resolve requires exactly one path argument", RESOLVE_USAGE);
|
|
|
|
- }
|
|
|
|
- if (!validatePath(argsList.get(1)))
|
|
|
|
- return -1;
|
|
|
|
-
|
|
|
|
- try {
|
|
|
|
- ServiceRecord record = registry.resolve(argsList.get(1));
|
|
|
|
-
|
|
|
|
- for (Endpoint endpoint : record.external) {
|
|
|
|
- sysout.println(" Endpoint(ProtocolType="
|
|
|
|
- + endpoint.protocolType + ", Api="
|
|
|
|
- + endpoint.api + ");"
|
|
|
|
- + " Addresses(AddressType="
|
|
|
|
- + endpoint.addressType + ") are: ");
|
|
|
|
|
|
+ public int resolve(String[] args) {
|
|
|
|
+ Options resolveOption = new Options();
|
|
|
|
+ CommandLineParser parser = new GnuParser();
|
|
|
|
+ try {
|
|
|
|
+ CommandLine line = parser.parse(resolveOption, args);
|
|
|
|
+
|
|
|
|
+ List<String> argsList = line.getArgList();
|
|
|
|
+ if (argsList.size() != 2) {
|
|
|
|
+ return usageError("resolve requires exactly one path argument",
|
|
|
|
+ RESOLVE_USAGE);
|
|
|
|
+ }
|
|
|
|
+ if (!validatePath(argsList.get(1))) {
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ ServiceRecord record = registry.resolve(argsList.get(1));
|
|
|
|
+
|
|
|
|
+ for (Endpoint endpoint : record.external) {
|
|
|
|
+ sysout.println(" Endpoint(ProtocolType="
|
|
|
|
+ + endpoint.protocolType + ", Api="
|
|
|
|
+ + endpoint.api + ");"
|
|
|
|
+ + " Addresses(AddressType="
|
|
|
|
+ + endpoint.addressType + ") are: ");
|
|
|
|
|
|
for (Map<String, String> address : endpoint.addresses) {
|
|
for (Map<String, String> address : endpoint.addresses) {
|
|
- sysout.println(" [ ");
|
|
|
|
|
|
+ sysout.println("[ ");
|
|
for (Map.Entry<String, String> entry : address.entrySet()) {
|
|
for (Map.Entry<String, String> entry : address.entrySet()) {
|
|
- sysout.println(" " + entry.getKey()
|
|
|
|
- + ": \"" + entry.getValue() + "\"");
|
|
|
|
|
|
+ sysout.print("\t" + entry.getKey()
|
|
|
|
+ + ":" + entry.getValue());
|
|
}
|
|
}
|
|
- sysout.println(" ]");
|
|
|
|
|
|
+
|
|
|
|
+ sysout.println("\n]");
|
|
}
|
|
}
|
|
sysout.println();
|
|
sysout.println();
|
|
}
|
|
}
|
|
- return 0;
|
|
|
|
|
|
+ return 0;
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
syserr.println(analyzeException("resolve", e, argsList));
|
|
syserr.println(analyzeException("resolve", e, argsList));
|
|
}
|
|
}
|
|
- return -1;
|
|
|
|
- } catch (org.apache.commons.cli.ParseException exp) {
|
|
|
|
- return usageError("Invalid syntax " + exp, RESOLVE_USAGE);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public int bind(String [] args) {
|
|
|
|
- Option rest = OptionBuilder.withArgName("rest")
|
|
|
|
- .hasArg()
|
|
|
|
- .withDescription("rest Option")
|
|
|
|
- .create("rest");
|
|
|
|
- Option webui = OptionBuilder.withArgName("webui")
|
|
|
|
- .hasArg()
|
|
|
|
- .withDescription("webui Option")
|
|
|
|
- .create("webui");
|
|
|
|
- Option inet = OptionBuilder.withArgName("inet")
|
|
|
|
- .withDescription("inet Option")
|
|
|
|
- .create("inet");
|
|
|
|
- Option port = OptionBuilder.withArgName("port")
|
|
|
|
- .hasArg()
|
|
|
|
- .withDescription("port to listen on [9999]")
|
|
|
|
- .create("p");
|
|
|
|
- Option host = OptionBuilder.withArgName("host")
|
|
|
|
- .hasArg()
|
|
|
|
- .withDescription("host name")
|
|
|
|
- .create("h");
|
|
|
|
- Option apiOpt = OptionBuilder.withArgName("api")
|
|
|
|
- .hasArg()
|
|
|
|
- .withDescription("api")
|
|
|
|
- .create("api");
|
|
|
|
- Options inetOption = new Options();
|
|
|
|
- inetOption.addOption(inet);
|
|
|
|
- inetOption.addOption(port);
|
|
|
|
- inetOption.addOption(host);
|
|
|
|
- inetOption.addOption(apiOpt);
|
|
|
|
-
|
|
|
|
- Options webuiOpt = new Options();
|
|
|
|
- webuiOpt.addOption(webui);
|
|
|
|
- webuiOpt.addOption(apiOpt);
|
|
|
|
-
|
|
|
|
- Options restOpt = new Options();
|
|
|
|
- restOpt.addOption(rest);
|
|
|
|
- restOpt.addOption(apiOpt);
|
|
|
|
|
|
+ return -1;
|
|
|
|
+ } catch (ParseException exp) {
|
|
|
|
+ return usageError("Invalid syntax " + exp, RESOLVE_USAGE);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public int bind(String[] args) {
|
|
|
|
+ Option rest = OptionBuilder.withArgName("rest")
|
|
|
|
+ .hasArg()
|
|
|
|
+ .withDescription("rest Option")
|
|
|
|
+ .create("rest");
|
|
|
|
+ Option webui = OptionBuilder.withArgName("webui")
|
|
|
|
+ .hasArg()
|
|
|
|
+ .withDescription("webui Option")
|
|
|
|
+ .create("webui");
|
|
|
|
+ Option inet = OptionBuilder.withArgName("inet")
|
|
|
|
+ .withDescription("inet Option")
|
|
|
|
+ .create("inet");
|
|
|
|
+ Option port = OptionBuilder.withArgName("port")
|
|
|
|
+ .hasArg()
|
|
|
|
+ .withDescription("port to listen on [9999]")
|
|
|
|
+ .create("p");
|
|
|
|
+ Option host = OptionBuilder.withArgName("host")
|
|
|
|
+ .hasArg()
|
|
|
|
+ .withDescription("host name")
|
|
|
|
+ .create("h");
|
|
|
|
+ Option apiOpt = OptionBuilder.withArgName("api")
|
|
|
|
+ .hasArg()
|
|
|
|
+ .withDescription("api")
|
|
|
|
+ .create("api");
|
|
|
|
+ Options inetOption = new Options();
|
|
|
|
+ inetOption.addOption(inet);
|
|
|
|
+ inetOption.addOption(port);
|
|
|
|
+ inetOption.addOption(host);
|
|
|
|
+ inetOption.addOption(apiOpt);
|
|
|
|
+
|
|
|
|
+ Options webuiOpt = new Options();
|
|
|
|
+ webuiOpt.addOption(webui);
|
|
|
|
+ webuiOpt.addOption(apiOpt);
|
|
|
|
+
|
|
|
|
+ Options restOpt = new Options();
|
|
|
|
+ restOpt.addOption(rest);
|
|
|
|
+ restOpt.addOption(apiOpt);
|
|
|
|
|
|
|
|
|
|
CommandLineParser parser = new GnuParser();
|
|
CommandLineParser parser = new GnuParser();
|
|
ServiceRecord sr = new ServiceRecord();
|
|
ServiceRecord sr = new ServiceRecord();
|
|
- CommandLine line = null;
|
|
|
|
|
|
+ CommandLine line;
|
|
if (args.length <= 1) {
|
|
if (args.length <= 1) {
|
|
return usageError("Invalid syntax ", BIND_USAGE);
|
|
return usageError("Invalid syntax ", BIND_USAGE);
|
|
}
|
|
}
|
|
@@ -259,7 +302,12 @@ public class RegistryCli extends Configured implements Tool {
|
|
}
|
|
}
|
|
if (line.hasOption("inet") && line.hasOption("p") &&
|
|
if (line.hasOption("inet") && line.hasOption("p") &&
|
|
line.hasOption("h") && line.hasOption("api")) {
|
|
line.hasOption("h") && line.hasOption("api")) {
|
|
- portNum = Integer.parseInt(line.getOptionValue("p"));
|
|
|
|
|
|
+ try {
|
|
|
|
+ portNum = Integer.parseInt(line.getOptionValue("p"));
|
|
|
|
+ } catch (NumberFormatException exp) {
|
|
|
|
+ return usageError("Invalid Port - int required" + exp.getMessage(),
|
|
|
|
+ BIND_USAGE);
|
|
|
|
+ }
|
|
hostName = line.getOptionValue("h");
|
|
hostName = line.getOptionValue("h");
|
|
api = line.getOptionValue("api");
|
|
api = line.getOptionValue("api");
|
|
sr.addExternalEndpoint(
|
|
sr.addExternalEndpoint(
|
|
@@ -278,7 +326,7 @@ public class RegistryCli extends Configured implements Tool {
|
|
return usageError("Invalid syntax " + exp.getMessage(), BIND_USAGE);
|
|
return usageError("Invalid syntax " + exp.getMessage(), BIND_USAGE);
|
|
}
|
|
}
|
|
if (line.hasOption("webui") && line.hasOption("api")) {
|
|
if (line.hasOption("webui") && line.hasOption("api")) {
|
|
- URI theUri = null;
|
|
|
|
|
|
+ URI theUri;
|
|
try {
|
|
try {
|
|
theUri = new URI(line.getOptionValue("webui"));
|
|
theUri = new URI(line.getOptionValue("webui"));
|
|
} catch (URISyntaxException e) {
|
|
} catch (URISyntaxException e) {
|
|
@@ -315,86 +363,91 @@ public class RegistryCli extends Configured implements Tool {
|
|
return usageError("Invalid syntax", BIND_USAGE);
|
|
return usageError("Invalid syntax", BIND_USAGE);
|
|
}
|
|
}
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
- List<String> argsList = line.getArgList();
|
|
|
|
- if (argsList.size() != 2) {
|
|
|
|
- return usageError("bind requires exactly one path argument", BIND_USAGE);
|
|
|
|
- }
|
|
|
|
- if (!validatePath(argsList.get(1)))
|
|
|
|
- return -1;
|
|
|
|
-
|
|
|
|
- try {
|
|
|
|
- registry.bind(argsList.get(1), sr, BindFlags.OVERWRITE);
|
|
|
|
- return 0;
|
|
|
|
|
|
+ List<String> argsList = line.getArgList();
|
|
|
|
+ if (argsList.size() != 2) {
|
|
|
|
+ return usageError("bind requires exactly one path argument", BIND_USAGE);
|
|
|
|
+ }
|
|
|
|
+ if (!validatePath(argsList.get(1))) {
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ registry.bind(argsList.get(1), sr, BindFlags.OVERWRITE);
|
|
|
|
+ return 0;
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
syserr.println(analyzeException("bind", e, argsList));
|
|
syserr.println(analyzeException("bind", e, argsList));
|
|
}
|
|
}
|
|
|
|
|
|
return -1;
|
|
return -1;
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
- public int mknode(String [] args) {
|
|
|
|
- Options mknodeOption = new Options();
|
|
|
|
- CommandLineParser parser = new GnuParser();
|
|
|
|
- try {
|
|
|
|
- CommandLine line = parser.parse(mknodeOption, args);
|
|
|
|
-
|
|
|
|
- List<String> argsList = line.getArgList();
|
|
|
|
- if (argsList.size() != 2) {
|
|
|
|
- return usageError("mknode requires exactly one path argument", MKNODE_USAGE);
|
|
|
|
- }
|
|
|
|
- if (!validatePath(argsList.get(1)))
|
|
|
|
- return -1;
|
|
|
|
-
|
|
|
|
- try {
|
|
|
|
- registry.mknode(args[1], false);
|
|
|
|
- return 0;
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
|
+ public int mknode(String[] args) {
|
|
|
|
+ Options mknodeOption = new Options();
|
|
|
|
+ CommandLineParser parser = new GnuParser();
|
|
|
|
+ try {
|
|
|
|
+ CommandLine line = parser.parse(mknodeOption, args);
|
|
|
|
+
|
|
|
|
+ List<String> argsList = line.getArgList();
|
|
|
|
+ if (argsList.size() != 2) {
|
|
|
|
+ return usageError("mknode requires exactly one path argument",
|
|
|
|
+ MKNODE_USAGE);
|
|
|
|
+ }
|
|
|
|
+ if (!validatePath(argsList.get(1))) {
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ registry.mknode(args[1], false);
|
|
|
|
+ return 0;
|
|
|
|
+ } catch (Exception e) {
|
|
syserr.println(analyzeException("mknode", e, argsList));
|
|
syserr.println(analyzeException("mknode", e, argsList));
|
|
- }
|
|
|
|
- return -1;
|
|
|
|
- } catch (ParseException exp) {
|
|
|
|
- return usageError("Invalid syntax " + exp.toString(), MKNODE_USAGE);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ return -1;
|
|
|
|
+ } catch (ParseException exp) {
|
|
|
|
+ return usageError("Invalid syntax " + exp.toString(), MKNODE_USAGE);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
public int rm(String[] args) {
|
|
public int rm(String[] args) {
|
|
- Option recursive = OptionBuilder.withArgName("recursive")
|
|
|
|
- .withDescription("delete recursively").create("r");
|
|
|
|
|
|
+ Option recursive = OptionBuilder.withArgName("recursive")
|
|
|
|
+ .withDescription("delete recursively")
|
|
|
|
+ .create("r");
|
|
|
|
|
|
- Options rmOption = new Options();
|
|
|
|
- rmOption.addOption(recursive);
|
|
|
|
|
|
+ Options rmOption = new Options();
|
|
|
|
+ rmOption.addOption(recursive);
|
|
|
|
|
|
- boolean recursiveOpt = false;
|
|
|
|
|
|
+ boolean recursiveOpt = false;
|
|
|
|
|
|
- CommandLineParser parser = new GnuParser();
|
|
|
|
- try {
|
|
|
|
- CommandLine line = parser.parse(rmOption, args);
|
|
|
|
|
|
+ CommandLineParser parser = new GnuParser();
|
|
|
|
+ try {
|
|
|
|
+ CommandLine line = parser.parse(rmOption, args);
|
|
|
|
|
|
- List<String> argsList = line.getArgList();
|
|
|
|
- if (argsList.size() != 2) {
|
|
|
|
- return usageError("RM requires exactly one path argument", RM_USAGE);
|
|
|
|
- }
|
|
|
|
- if (!validatePath(argsList.get(1)))
|
|
|
|
- return -1;
|
|
|
|
|
|
+ List<String> argsList = line.getArgList();
|
|
|
|
+ if (argsList.size() != 2) {
|
|
|
|
+ return usageError("RM requires exactly one path argument", RM_USAGE);
|
|
|
|
+ }
|
|
|
|
+ if (!validatePath(argsList.get(1))) {
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
|
|
- try {
|
|
|
|
- if (line.hasOption("r")) {
|
|
|
|
- recursiveOpt = true;
|
|
|
|
- }
|
|
|
|
|
|
+ try {
|
|
|
|
+ if (line.hasOption("r")) {
|
|
|
|
+ recursiveOpt = true;
|
|
|
|
+ }
|
|
|
|
|
|
- registry.delete(argsList.get(1), recursiveOpt);
|
|
|
|
- return 0;
|
|
|
|
|
|
+ registry.delete(argsList.get(1), recursiveOpt);
|
|
|
|
+ return 0;
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
syserr.println(analyzeException("rm", e, argsList));
|
|
syserr.println(analyzeException("rm", e, argsList));
|
|
}
|
|
}
|
|
return -1;
|
|
return -1;
|
|
- } catch (ParseException exp) {
|
|
|
|
- return usageError("Invalid syntax " + exp.toString(), RM_USAGE);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ } catch (ParseException exp) {
|
|
|
|
+ return usageError("Invalid syntax " + exp.toString(), RM_USAGE);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* Given an exception and a possibly empty argument list, generate
|
|
* Given an exception and a possibly empty argument list, generate
|