in shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java [33:93]
protected Object doExecute(List<String> nodeIdsOrAliases, SwitchStatus status) throws Exception {
ConsumerSwitchCommand command = new ConsumerSwitchCommand(clusterManager.generateId());
command.setTimeout(timeout * 1000);
// looking for nodes and check if exist
Set<Node> recipientList = new HashSet<Node>();
if (nodeIdsOrAliases != null && !nodeIdsOrAliases.isEmpty()) {
for (String nodeIdOrAlias : nodeIdsOrAliases) {
Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias);
if (node == null) {
System.err.println("Cluster node " + nodeIdOrAlias + " doesn't exist");
} else {
recipientList.add(node);
}
}
} else {
if (status == null) {
// in case of status display, select all nodes
recipientList = clusterManager.listNodes();
} else {
// in case of status change, select only the local node
recipientList.add(clusterManager.getNode());
}
}
if (recipientList.size() < 1) {
return null;
}
command.setDestination(recipientList);
command.setStatus(status);
Map<Node, ConsumerSwitchResult> results = executionContext.execute(command);
if (results == null || results.isEmpty()) {
System.out.println("No result received within given timeout");
} else {
ShellTable table = new ShellTable();
table.column(" ");
table.column("Node");
table.column("Status");
for (Node node : results.keySet()) {
String local = "";
if (node.equals(clusterManager.getNode())) {
local = "x";
}
ConsumerSwitchResult result = results.get(node);
String statusString = "OFF";
if (result.getStatus()) {
statusString = "ON";
}
String nodeName = node.getAlias();
if (nodeName == null) {
nodeName = node.getId();
}
table.addRow().addContent(local, nodeName, statusString);
}
table.print(System.out);
}
return null;
}