*/
package org.opendaylight.openflowplugin.applications.southboundcli.cli;
+import static org.opendaylight.openflowplugin.applications.southboundcli.util.ShellUtil.LINE_SEPARATOR;
+
import java.util.Formatter;
-import org.apache.karaf.shell.commands.Command;
-import org.apache.karaf.shell.commands.Option;
-import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.apache.karaf.shell.api.action.Action;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Option;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.console.Session;
import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.openflowplugin.applications.southboundcli.util.OFNode;
import org.opendaylight.openflowplugin.applications.southboundcli.util.ShellUtil;
+@Service
@Command(scope = "openflow", name = "shownode", description = "shownode -d <NodeID>")
-public class ShowNodeCommandProvider extends OsgiCommandSupport {
+@Deprecated
+public class ShowNodeCommand implements Action {
public static final String OUTPUT_FORMAT = "%-24s %-20s %-15s";
public static final String NEW_LINE = "%-24s %-20s %-15s %n";
- public static final String HEADER_SEPARATOR = "---------------------------------------------"
- + "---------------------------------------";
- @Option(name = "-d", description = "Node Id", required = true, multiValued = false)
+ @Option(name = "-d", description = "Node Id", required = true)
String nodeId;
+ @Reference
+ Session session;
+ @Reference
+ DataBroker dataBroker;
- private DataBroker dataBroker;
-
- public void setDataBroker(final DataBroker dataBroker) {
- this.dataBroker = dataBroker;
- }
-
- @SuppressWarnings("checkstyle:RegexpSinglelineJava")
- @Deprecated
@Override
- protected Object doExecute() {
+ public Object execute() {
if (nodeId == null) {
- System.out.println("NodeID not specified");
+ session.getConsole().println("NodeID not specified");
return null;
}
OFNode node = ShellUtil.getNode(Long.parseLong(nodeId), dataBroker);
if (node != null) {
printNodeHeaderOutput();
- printHeaderSeparator();
+ session.getConsole().println(LINE_SEPARATOR);
printNodeOutput(node);
} else {
- System.out.println("No node available for this NodeID");
+ session.getConsole().println("No node available for this NodeID");
}
return null;
}
- @SuppressWarnings("checkstyle:RegexpSinglelineJava")
- private static void printNodeHeaderOutput() {
+ private void printNodeHeaderOutput() {
Formatter formatter = new Formatter();
String header = formatter.format(OUTPUT_FORMAT, "NodeId", "Name", "Ports").toString();
formatter.close();
- System.out.println(header);
- }
-
- @SuppressWarnings("checkstyle:RegexpSinglelineJava")
- private static void printHeaderSeparator() {
- System.out.println(HEADER_SEPARATOR);
+ session.getConsole().println(header);
}
- @SuppressWarnings("checkstyle:RegexpSinglelineJava")
- private static void printNodeOutput(final OFNode ofNode) {
+ private void printNodeOutput(final OFNode ofNode) {
String ofNodeId = ofNode.getNodeId().toString();
String ofNodeName = ofNode.getNodeName();
- System.out.print(new Formatter().format(NEW_LINE, ofNodeId, ofNodeName, ofNode.getPorts()).toString());
+ session.getConsole().print(new Formatter().format(NEW_LINE, ofNodeId, ofNodeName, ofNode.getPorts()));
}
}
\ No newline at end of file