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
9 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.mdsal.binding.api.DataBroker;
15 import org.opendaylight.openflowplugin.applications.southboundcli.util.OFNode;
16 import org.opendaylight.openflowplugin.applications.southboundcli.util.ShellUtil;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 @Command(scope = "openflow", name = "getallnodes", description = "Print all nodes from the operational datastore")
21 public class GetAllNodesCommandProvider extends OsgiCommandSupport {
22 private static final Logger LOG = LoggerFactory.getLogger(GetAllNodesCommandProvider.class);
24 private DataBroker dataBroker;
26 public void setDataBroker(final DataBroker dataBroker) {
27 this.dataBroker = dataBroker;
31 protected Object doExecute() {
32 List<OFNode> ofNodeList = ShellUtil.getAllNodes(dataBroker);
33 if (ofNodeList.isEmpty()) {
34 session.getConsole().println("No node is connected yet");
36 StringBuilder stringBuilder = new StringBuilder();
37 Formatter formatter = new Formatter(stringBuilder);
38 session.getConsole().println("Number of nodes: " + ofNodeList.size());
39 session.getConsole().println(getAllLocalNodesHeaderOutput());
40 session.getConsole().println("--------------------------------------------------------------------------");
41 for (OFNode ofNode : ofNodeList) {
42 session.getConsole().println(formatter.format("%-15s %3s %-15s %n",
43 ofNode.getNodeId(), "", ofNode.getNodeName()).toString());
44 stringBuilder.setLength(0);
51 private String getAllLocalNodesHeaderOutput() {
52 Formatter formatter = new Formatter();
53 String header = formatter.format("%-15s %3s %-15s %n", "NodeId", "", "NodeName").toString();