in shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupSupport.java [48:123]
protected Object doExecute(ManageGroupAction action, String group, Group source, Collection<String> nodeIdsOrAliases, Boolean suppressOutput) throws Exception {
ManageGroupCommand command = new ManageGroupCommand(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 {
recipientList.add(clusterManager.getNode());
}
if (recipientList.size() < 1) {
return null;
}
command.setDestination(recipientList);
command.setAction(action);
if (group != null) {
command.setGroupName(group);
}
if (source != null) {
command.setSourceGroup(source);
}
Map<Node, ManageGroupResult> results = executionContext.execute(command);
if (!suppressOutput) {
if (results == null || results.isEmpty()) {
System.out.println("No result received within given timeout");
} else {
ShellTable table = new ShellTable();
table.column(" ");
table.column("Group");
table.column("Members");
for (Node node : results.keySet()) {
ManageGroupResult result = results.get(node);
if (result != null && result.getGroups() != null) {
for (Group g : result.getGroups()) {
StringBuffer buffer = new StringBuffer();
if (g.getNodes() != null && !g.getNodes().isEmpty()) {
String local = "";
for (Node member : g.getNodes()) {
// display only up and running nodes in the cluster
if (clusterManager.findNodeById(member.getId()) != null) {
if (member.getAlias() != null) {
buffer.append(member.getAlias());
} else {
buffer.append(member.getId());
}
if (member.equals(clusterManager.getNode())) {
local = "x";
buffer.append("(x)");
}
buffer.append(" ");
}
}
table.addRow().addContent(local, g.getName(), buffer.toString());
} else table.addRow().addContent("", g.getName(), "");
}
}
}
table.print(System.out);
}
}
return null;
}