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.Option;
16 import org.apache.karaf.shell.api.action.lifecycle.Reference;
17 import org.apache.karaf.shell.api.action.lifecycle.Service;
18 import org.apache.karaf.shell.api.console.Session;
19 import org.opendaylight.mdsal.binding.api.DataBroker;
20 import org.opendaylight.openflowplugin.applications.southboundcli.util.OFNode;
21 import org.opendaylight.openflowplugin.applications.southboundcli.util.ShellUtil;
24 @Command(scope = "openflow", name = "shownode", description = "shownode -d <NodeID>")
26 public class ShowNodeCommand implements Action {
27 public static final String OUTPUT_FORMAT = "%-24s %-20s %-15s";
28 public static final String NEW_LINE = "%-24s %-20s %-15s %n";
30 @Option(name = "-d", description = "Node Id", required = true)
35 DataBroker dataBroker;
38 public Object execute() {
40 session.getConsole().println("NodeID not specified");
43 OFNode node = ShellUtil.getNode(Long.parseLong(nodeId), dataBroker);
45 printNodeHeaderOutput();
46 session.getConsole().println(LINE_SEPARATOR);
47 printNodeOutput(node);
49 session.getConsole().println("No node available for this NodeID");
54 private void printNodeHeaderOutput() {
55 Formatter formatter = new Formatter();
56 String header = formatter.format(OUTPUT_FORMAT, "NodeId", "Name", "Ports").toString();
58 session.getConsole().println(header);
61 private void printNodeOutput(final OFNode ofNode) {
62 String ofNodeId = ofNode.getNodeId().toString();
63 String ofNodeName = ofNode.getNodeName();
64 session.getConsole().print(new Formatter().format(NEW_LINE, ofNodeId, ofNodeName, ofNode.getPorts()));