// no arguments to read, just call getNodes
List resNodes = client.getNodes();
if (resNodes != null && resNodes.size() > 0) {
for (Iterator i = resNodes.iterator(); i.hasNext();) {
ResourceNode node = (ResourceNode) i.next();
System.out.println("node: [id=" + node.getNodeId()
+ ",capacity=" + node.getCapacity() + ",url="
+ node.getIpAddr() + "]");
}
}
}else if (operation.equals("--getQueues")) {
List<String> queueNames = client.getQueues();
System.out.println("Queues:");
for (String queueName : queueNames)
System.out.println(" - " + queueName);
System.out.println();
}else if (operation.equals("--addNode")) {
String nodeId = null;
String nodeUrl = null;
String capacity = null;
for (int i = 4; i < args.length; i++) {
if (args[i].equals("--nodeId")) {
nodeId = args[++i];
}else if (args[i].equals("--ipAddr")) {
nodeUrl = args[++i];
}else if (args[i].equals("--capacity")) {
capacity = args[++i];
}
}
if (nodeId == null || nodeUrl == null || capacity == null) {
System.err.println(addNodeOperation);
System.exit(1);
}
client.addNode(new ResourceNode(nodeId, new URL(nodeUrl), Integer.parseInt(capacity)));
System.out.println("Successfully added node!");
}else if (operation.equals("--removeNode")) {
String nodeId = null;
for (int i = 4; i < args.length; i++) {
if (args[i].equals("--nodeId")) {
nodeId = args[++i];
}
}
if (nodeId == null) {
System.err.println(removeNodeOperation);
System.exit(1);
}
client.removeNode(nodeId);
System.out.println("Successfully removed node!");
}else if (operation.equals("--setNodeCapacity")){
String nodeId = null;
String capacity = null;
for (int i = 4; i < args.length; i++) {
if (args[i].equals("--nodeId")) {
nodeId = args[++i];
}else if (args[i].equals("--capacity")) {
capacity = args[++i];
}
}
if (nodeId == null || capacity == null) {
System.err.println(setNodeCapacityOperation);
System.exit(1);
}
client.setNodeCapacity(nodeId, Integer.parseInt(capacity));
System.out.println("Successfully set node capacity!");
}else if (operation.equals("--addQueue")) {
String queueName = null;
for (int i = 4; i < args.length; i++) {
if (args[i].equals("--queueName")) {
queueName = args[++i];
}
}
if (queueName == null) {
System.err.println(addQueueOperation);
System.exit(1);
}
client.addQueue(queueName);
System.out.println("Successfully added queue!");
}else if (operation.equals("--removeQueue")) {
String queueName = null;
for (int i = 4; i < args.length; i++) {
if (args[i].equals("--queueName")) {
queueName = args[++i];
}
}
if (queueName == null) {
System.err.println(removeQueueOperation);
System.exit(1);
}
client.removeQueue(queueName);
System.out.println("Successfully removed queue!");
}else if (operation.equals("--addNodeToQueue")) {
String nodeId = null;
String queueName = null;
for (int i = 4; i < args.length; i++) {
if (args[i].equals("--nodeId")) {
nodeId = args[++i];
}else if (args[i].equals("--queueName")) {
queueName = args[++i];
}
}
if (nodeId == null || queueName == null) {
System.err.println(addNodeToQueueOperation);
System.exit(1);
}
client.addNodeToQueue(nodeId, queueName);
System.out.println("Successfully added node to queue!");
}else if (operation.equals("--removeNodeFromQueue")) {
String nodeId = null;
String queueName = null;
for (int i = 4; i < args.length; i++) {
if (args[i].equals("--nodeId")) {
nodeId = args[++i];
}else if (args[i].equals("--queueName")) {
queueName = args[++i];
}
}
if (nodeId == null || queueName == null) {
System.err.println(removeNodeFromQueueOperation);
System.exit(1);
}
client.removeNodeFromQueue(nodeId, queueName);
System.out.println("Successfully removed node from queue!");
}else if (operation.equals("--getNodeLoad")){
String nodeId = null;
for (int i = 4; i < args.length; i++) {
if (args[i].equals("--nodeId")) {
nodeId = args[++i];
}
}
if(nodeId == null){
System.err.println(getNodeLoadOperation);
System.exit(1);
}
String result = client.getNodeLoad(nodeId);
System.out.println("Load for " + nodeId + ": " + result);
}else if (operation.equals("--getNodesInQueue")) {
String queueName = null;
for (int i = 4; i < args.length; i++) {
if (args[i].equals("--queueName")) {
queueName = args[++i];
}
}
if (queueName == null) {
System.err.println(getNodesInQueueOperation);
System.exit(1);
}
List<String> nodeIds = client.getNodesInQueue(queueName);
System.out.println("Nodes in Queue '" + queueName + "':");
for (String nodeId : nodeIds)
System.out.println(" - " + nodeId);
System.out.println();
}else if (operation.equals("--getQueuesWithNode")) {
String nodeId = null;
for (int i = 4; i < args.length; i++) {
if (args[i].equals("--nodeId")) {
nodeId = args[++i];
}
}
if (nodeId == null) {
System.err.println(getQueuesWithNodeOperation);
System.exit(1);
}
List<String> queueNames = client.getQueuesWithNode(nodeId);
System.out.println("Queues with node '" + nodeId + "':");
for (String queueName : queueNames)
System.out.println(" - " + queueName);
System.out.println();
} else if (operation.equals("--getExecNode")) {
String jobId = null;
for (int i = 4; i < args.length; i++) {
if (args[i].equals("--id")) {
jobId = args[++i];
}
}
if (jobId == null) {
System.err.println(getExecutionNodeOperation);
System.exit(1);
}
String execNode = client.getExecutionNode(jobId);
if (execNode == null || (execNode != null && execNode.equals(""))) {
System.out.println("Job: [" + jobId
+ "] not executing on any known node!");
} else {
System.out.println(execNode);
}
} else if (operation.equals("--kill")) {
String jobId = null;
for (int i = 4; i < args.length; i++) {
if (args[i].equals("--id")) {
jobId = args[++i];
}
}
if (jobId == null) {
System.err.println(killOperation);
System.exit(1);
}
if (client.killJob(jobId)) {
System.out.println("Job: [" + jobId + "] successfully killed.");
} else {
System.out.println("Unable to kill job: [" + jobId + "]");
}
} else if (operation.equals("--getNodeById")) {
String nodeId = null;
for (int i = 4; i < args.length; i++) {
if (args[i].equals("--nodeId")) {
nodeId = args[++i];
}
}
if (nodeId == null) {
System.err.println(getNodeByIdOperation);
System.exit(1);
}
ResourceNode node = client.getNodeById(nodeId);
if (node != null) {
System.out.println("node: [id=" + node.getNodeId()
+ ",capacity=" + node.getCapacity() + ",url="
+ node.getIpAddr() + "]");
}
} else if (operation.equals("--getJobInfo")) {
String jobId = null;
for (int i = 4; i < args.length; i++) {