@Override public TabularData getNodes() throws Exception { CompositeType nodeType = new CompositeType("Node", "Karaf Cellar cluster node", new String[]{ "id", "alias", "hostname", "port", "local" }, new String[]{ "ID of the node", "Alias of the node", "Hostname of the node", "Port number of the node", "Flag defining if the node is local" }, new OpenType[]{ SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.INTEGER, SimpleType.BOOLEAN }); TabularType tableType = new TabularType("Nodes", "Table of all Karaf Cellar nodes", nodeType, new String[]{ "id" }); TabularData table = new TabularDataSupport(tableType); Set<Node> nodes = clusterManager.listNodes(); for (Node node : nodes) { boolean local = (node.equals(clusterManager.getNode())); CompositeData data = new CompositeDataSupport(nodeType, new String[]{ "id", "alias", "hostname", "port", "local" }, new Object[]{ node.getId(), node.getAlias(), node.getHost(), node.getPort(), local }); table.put(data); } return table; }
@Override public TabularData getNodes() throws Exception { CompositeType nodeType = new CompositeType("Node", "Karaf Cellar cluster node", new String[]{ "id", "alias", "hostname", "port", "local" }, new String[]{ "ID of the node", "Alias of the node", "Hostname of the node", "Port number of the node", "Flag defining if the node is local" }, new OpenType[]{ SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.INTEGER, SimpleType.BOOLEAN }); TabularType tableType = new TabularType("Nodes", "Table of all Karaf Cellar nodes", nodeType, new String[]{ "id" }); TabularData table = new TabularDataSupport(tableType); Set<Node> nodes = clusterManager.listNodes(); for (Node node : nodes) { boolean local = (node.equals(clusterManager.getNode())); CompositeData data = new CompositeDataSupport(nodeType, new String[]{ "id", "alias", "hostname", "port", "local" }, new Object[]{ node.getId(), node.getAlias(), node.getHost(), node.getPort(), local }); table.put(data); } return table; }
@Override protected Object doExecute() throws Exception { Set<Node> nodes = clusterManager.listNodes(); if (nodes != null && !nodes.isEmpty()) { ShellTable table = new ShellTable(); table.column(" "); table.column("Id"); table.column("Alias"); table.column("Host Name"); table.column("Port"); for (Node node : nodes) { String local = ""; if (node.equals(clusterManager.getNode())) local = "x"; table.addRow().addContent(local, node.getId(), node.getAlias(), node.getHost(), node.getPort()); } table.print(System.out); } else { System.err.println("No node found in the cluster"); } return null; }