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 org.apache.karaf.shell.commands.Command;
12 import org.apache.karaf.shell.commands.Option;
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;
18 @Command(scope = "openflow", name = "shownode", description = "shownode -d <NodeID>")
19 public class ShowNodeCommandProvider extends OsgiCommandSupport {
20 public static final String OUTPUT_FORMAT = "%-24s %-20s %-15s";
21 public static final String NEW_LINE = "%-24s %-20s %-15s %n";
22 public static final String HEADER_SEPARATOR = "---------------------------------------------"
23 + "---------------------------------------";
25 @Option(name = "-d", description = "Node Id", required = true, multiValued = false)
28 private DataBroker dataBroker;
30 public void setDataBroker(final DataBroker dataBroker) {
31 this.dataBroker = dataBroker;
34 @SuppressWarnings("checkstyle:RegexpSinglelineJava")
37 protected Object doExecute() {
39 System.out.println("NodeID not specified");
42 OFNode node = ShellUtil.getNode(Long.parseLong(nodeId), dataBroker);
44 printNodeHeaderOutput();
45 printHeaderSeparator();
46 printNodeOutput(node);
48 System.out.println("No node available for this NodeID");
53 @SuppressWarnings("checkstyle:RegexpSinglelineJava")
54 private static void printNodeHeaderOutput() {
55 Formatter formatter = new Formatter();
56 String header = formatter.format(OUTPUT_FORMAT, "NodeId", "Name", "Ports").toString();
58 System.out.println(header);
61 @SuppressWarnings("checkstyle:RegexpSinglelineJava")
62 private static void printHeaderSeparator() {
63 System.out.println(HEADER_SEPARATOR);
66 @SuppressWarnings("checkstyle:RegexpSinglelineJava")
67 private static void printNodeOutput(final OFNode ofNode) {
68 String ofNodeId = ofNode.getNodeId().toString();
69 String ofNodeName = ofNode.getNodeName();
70 System.out.print(new Formatter().format(NEW_LINE, ofNodeId, ofNodeName, ofNode.getPorts()).toString());