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 static org.opendaylight.openflowplugin.applications.southboundcli.util.ShellUtil.LINE_SEPARATOR;
12 import java.util.Formatter;
13 import org.apache.karaf.shell.api.action.Action;
14 import org.apache.karaf.shell.api.action.Command;
15 import org.apache.karaf.shell.api.action.lifecycle.Reference;
16 import org.apache.karaf.shell.api.action.lifecycle.Service;
17 import org.apache.karaf.shell.api.console.Session;
18 import org.opendaylight.openflowplugin.applications.southboundcli.DpnTracker;
19 import org.opendaylight.openflowplugin.applications.southboundcli.util.OFNode;
22 @Command(scope = "openflow", name = "getallnodes", description = "Print all nodes from the operational datastore")
23 public final class GetAllNodesCommand implements Action {
27 DpnTracker dpnTracker;
30 public Object execute() throws Exception {
31 if (dpnTracker == null) {
36 final var ofNodeList = dpnTracker.currentNodes();
37 if (ofNodeList.isEmpty()) {
38 session.getConsole().println("No node is connected yet");
42 final var stringBuilder = new StringBuilder();
43 try (var formatter = new Formatter(stringBuilder)) {
44 session.getConsole().println("Number of nodes: " + ofNodeList.size());
45 session.getConsole().println(getAllLocalNodesHeaderOutput());
46 session.getConsole().println(LINE_SEPARATOR);
47 for (OFNode ofNode : ofNodeList) {
48 session.getConsole().println(formatter.format("%-15s %3s %-15s %n",
49 ofNode.getNodeId(), "", ofNode.getNodeName()).toString());
50 stringBuilder.setLength(0);
56 private static String getAllLocalNodesHeaderOutput() {
57 try (var formatter = new Formatter()) {
58 return formatter.format("%-15s %3s %-15s", "NodeId", "", "NodeName").toString();