try {
List<String> args = new ArrayList<String>();
if (cmd.getArgs().size() > 1) {
args = cmd.getArgs().subList(1, cmd.getArgs().size());
}
long cmdid = client.submit(new Command(cmd.getArgs().get(0),
(String[]) args.toArray(new String[args.size()])));
lastCmdId = cmdid;
// Do not change this, other programs will likely depend on this.
System.out.println("[id: " + cmdid + "] Submitted command : "
+ cmd.getArgs().get(0));
return cmdid;
} catch (IOException e) {
disconnect();
LOG.debug("config failed due to transport error", e);
return -1;
}
}
/*
* Wait waits for the specified cmdid to be done (success or error), for a
* specified amount of time. If no cmdid is specified, it is assumed to be
* the last command issued by the shell, or the last command in the master's
* command queue.
*
* 0 wait time means forever.
*/
if (cmd.getCommand().equals("wait")) {
long millis = CMD_WAIT_TIME_MS;
long cmdid = lastCmdId;
// args are time, and then cmdid.
List<String> args = cmd.getArgs();
if (args.size() >= 1) {
long ms = Long.parseLong(args.get(0));
if (ms < 0) {
System.out.println("Wait time <0 is illegal");
return -1;
}
// if 0, effectively wait forever.
millis = (ms == 0) ? Long.MAX_VALUE : ms;
}
if (args.size() >= 2) {
cmdid = Long.parseLong(args.get(1));
}
try {
return pollWait(cmdid, millis);
} catch (IOException e) {
disconnect();
LOG.debug("config failed due to transport error", e);
return -1;
} catch (InterruptedException e) {
System.out.println("Interrupted during command processing");
LOG.debug("Interrupted!", e);
return -1;
}
}
/*
* Exec sends a command to the master and polls for a response. These are
* the commands which cause the master to do some processing. We wait
* synchronously for success or failure.
*
* There is no schema checking for these commands - so it is possible to
* send ill-formed commands and receive a failure notification with no idea
* of what went wrong.
*/
if (cmd.getCommand().equals("exec")) {
try {
List<String> args = new ArrayList<String>();
if (cmd.getArgs().size() > 1) {
args = cmd.getArgs().subList(1, cmd.getArgs().size());
}
long cmdid = client.submit(new Command(cmd.getArgs().get(0),
(String[]) args.toArray(new String[args.size()])));
System.out.println("[id: " + cmdid + "] Execing command : "
+ cmd.getArgs().get(0));
lastCmdId = cmdid;