2 * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowplugin.applications.southboundcli.cli;
10 import java.util.Formatter;
11 import java.util.List;
12 import org.apache.felix.gogo.commands.Command;
13 import org.apache.karaf.shell.console.OsgiCommandSupport;
14 import org.opendaylight.openflowplugin.applications.southboundcli.NodeListener;
15 import org.opendaylight.openflowplugin.applications.southboundcli.util.OFNode;
16 import org.opendaylight.openflowplugin.applications.southboundcli.util.ShellUtil;
18 @Command(scope = "openflow", name = "getallnodes", description = "Print all nodes from the operational datastore")
19 public class GetAllNodesCommandProvider extends OsgiCommandSupport {
20 private NodeListener nodeListener;
22 public void setNodeListener(final NodeListener nodeListener) {
23 this.nodeListener = nodeListener;
26 @SuppressWarnings("checkstyle:RegexpSinglelineJava")
28 protected Object doExecute() throws Exception {
29 List<OFNode> ofNodeList = ShellUtil.getAllNodes(nodeListener);
30 if (ofNodeList.isEmpty()) {
31 System.out.println("No node is connected yet");
33 StringBuilder stringBuilder = new StringBuilder();
34 Formatter formatter = new Formatter(stringBuilder);
35 System.out.println("Number of nodes: " + ofNodeList.size());
36 System.out.println(getAllLocalNodesHeaderOutput());
37 System.out.println("--------------------------------------------------------------------------");
38 for (OFNode ofNode : ofNodeList) {
39 System.out.println(formatter.format("%-15s %3s %-15s %n",
40 ofNode.getNodeId(), "", ofNode.getNodeName()).toString());
41 stringBuilder.setLength(0);
48 private static String getAllLocalNodesHeaderOutput() {
49 Formatter formatter = new Formatter();
50 String header = formatter.format("%-15s %3s %-15s", "NodeId", "", "NodeName").toString();