From: Ruslan Kashapov Date: Fri, 12 Apr 2024 08:51:28 +0000 (+0300) Subject: Eliminate blueprint for southbound-cli commands X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=openflowplugin.git;a=commitdiff_plain;h=HEAD Eliminate blueprint for southbound-cli commands Command implementations updated to recent karaf api. Command artifacts renamed for consistency. JIRA: OPNFLWPLUG-1113 Signed-off-by: Ruslan Kashapov Change-Id: I741542d706975e27b3850238367fc74ccbd0dfba --- diff --git a/applications/southbound-cli/pom.xml b/applications/southbound-cli/pom.xml index e3a5e59d1e..88f48eaa7a 100644 --- a/applications/southbound-cli/pom.xml +++ b/applications/southbound-cli/pom.xml @@ -25,7 +25,7 @@ org.apache.karaf.shell - org.apache.karaf.shell.console + org.apache.karaf.shell.core provided @@ -63,4 +63,13 @@ + + + + org.apache.karaf.tooling + karaf-services-maven-plugin + + + + diff --git a/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/DefaultDpnTracker.java b/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/DefaultDpnTracker.java index f0a37a076a..d126a6803e 100644 --- a/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/DefaultDpnTracker.java +++ b/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/DefaultDpnTracker.java @@ -33,7 +33,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Singleton -@Component(service = DpnTracker.class) +@Component(service = DpnTracker.class, immediate = true) public final class DefaultDpnTracker implements DpnTracker, DataTreeChangeListener, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(DefaultDpnTracker.class); public static final String DEFAULT_DPN_NAME = "UNKNOWN"; diff --git a/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/GetAllNodesCommandProvider.java b/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/GetAllNodesCommand.java similarity index 57% rename from applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/GetAllNodesCommandProvider.java rename to applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/GetAllNodesCommand.java index 65c643a220..e2015dfced 100644 --- a/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/GetAllNodesCommandProvider.java +++ b/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/GetAllNodesCommand.java @@ -7,38 +7,45 @@ */ package org.opendaylight.openflowplugin.applications.southboundcli.cli; -import static java.util.Objects.requireNonNull; +import static org.opendaylight.openflowplugin.applications.southboundcli.util.ShellUtil.LINE_SEPARATOR; import java.util.Formatter; -import org.apache.felix.gogo.commands.Command; -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.lifecycle.Reference; +import org.apache.karaf.shell.api.action.lifecycle.Service; +import org.apache.karaf.shell.api.console.Session; import org.opendaylight.openflowplugin.applications.southboundcli.DpnTracker; import org.opendaylight.openflowplugin.applications.southboundcli.util.OFNode; +@Service @Command(scope = "openflow", name = "getallnodes", description = "Print all nodes from the operational datastore") -public class GetAllNodesCommandProvider extends OsgiCommandSupport { - private final DpnTracker dpnTracker; +public final class GetAllNodesCommand implements Action { + @Reference + Session session; + @Reference + DpnTracker dpnTracker; - public GetAllNodesCommandProvider(final DpnTracker dpnTracker) { - this.dpnTracker = requireNonNull(dpnTracker); - } - - @SuppressWarnings("checkstyle:RegexpSinglelineJava") @Override - protected Object doExecute() throws Exception { + public Object execute() throws Exception { + if (dpnTracker == null) { + // not initialized + return null; + } + final var ofNodeList = dpnTracker.currentNodes(); if (ofNodeList.isEmpty()) { - System.out.println("No node is connected yet"); + session.getConsole().println("No node is connected yet"); return null; } final var stringBuilder = new StringBuilder(); try (var formatter = new Formatter(stringBuilder)) { - System.out.println("Number of nodes: " + ofNodeList.size()); - System.out.println(getAllLocalNodesHeaderOutput()); - System.out.println("--------------------------------------------------------------------------"); + session.getConsole().println("Number of nodes: " + ofNodeList.size()); + session.getConsole().println(getAllLocalNodesHeaderOutput()); + session.getConsole().println(LINE_SEPARATOR); for (OFNode ofNode : ofNodeList) { - System.out.println(formatter.format("%-15s %3s %-15s %n", + session.getConsole().println(formatter.format("%-15s %3s %-15s %n", ofNode.getNodeId(), "", ofNode.getNodeName()).toString()); stringBuilder.setLength(0); } diff --git a/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/GetFlowGroupCacheProvider.java b/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/GetFlowGroupCacheCommand.java similarity index 74% rename from applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/GetFlowGroupCacheProvider.java rename to applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/GetFlowGroupCacheCommand.java index 6f443ef14a..a36077b94f 100644 --- a/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/GetFlowGroupCacheProvider.java +++ b/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/GetFlowGroupCacheCommand.java @@ -8,6 +8,7 @@ package org.opendaylight.openflowplugin.applications.southboundcli.cli; import static org.opendaylight.openflowplugin.applications.frm.util.FrmUtil.OPENFLOW_PREFIX; +import static org.opendaylight.openflowplugin.applications.southboundcli.util.ShellUtil.LINE_SEPARATOR; import java.time.LocalDateTime; import java.time.ZoneOffset; @@ -15,33 +16,34 @@ import java.util.Collection; import java.util.Formatter; import java.util.Map; import java.util.Map.Entry; -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.openflowplugin.api.openflow.FlowGroupInfo; import org.opendaylight.openflowplugin.api.openflow.FlowGroupInfoHistories; import org.opendaylight.openflowplugin.api.openflow.FlowGroupInfoHistory; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; +@Service @Command(scope = "openflow", name = "getflownodecache", description = "Print all flow/group cache") -public class GetFlowGroupCacheProvider extends OsgiCommandSupport { - // FIXME: use String.repeat(), this does look arbitrary - private static final String LINE_SEPARATOR = - "--------------------------------------------------------------------------------------------------------------" - + "------------------------------"; - +public final class GetFlowGroupCacheCommand implements Action { @Option(name = "-d", description = "Node Id") String dpnId; - private final FlowGroupInfoHistories histories; - - public GetFlowGroupCacheProvider(final FlowGroupInfoHistories histories) { - this.histories = histories; - } + @Reference + Session session; + @Reference + FlowGroupInfoHistories histories; @Override - @SuppressWarnings("checkstyle:RegexpSinglelineJava") - protected Object doExecute() { + public Object execute() { + if (histories == null) { + // not initialized + return null; + } if (dpnId == null) { printAllNodes(); return null; @@ -61,14 +63,14 @@ public class GetFlowGroupCacheProvider extends OsgiCommandSupport { StringBuilder sb = new StringBuilder(); Formatter fmt = new Formatter(sb); - System.out.println(String.format("Number of flows and groups in cache for node %s : %d", nodeId, + session.getConsole().println(String.format("Number of flows and groups in cache for node %s : %d", nodeId, entries.size())); - System.out.println(getLocalNodeHeaderOutput()); - System.out.println(LINE_SEPARATOR); + session.getConsole().println(getLocalNodeHeaderOutput()); + session.getConsole().println(LINE_SEPARATOR); for (FlowGroupInfo entry : entries) { - System.out.println(fmt.format("%-10s %1s %-8s %1s %-23s %1s %-60s", entry.getDescription(), "", - entry.getStatus(), "", getTime(entry), "", entry.getId()).toString()); + session.getConsole().println(fmt.format("%-10s %1s %-8s %1s %-23s %1s %-60s", entry.getDescription(), "", + entry.getStatus(), "", getTime(entry), "", entry.getId())); sb.setLength(0); } fmt.close(); @@ -89,14 +91,14 @@ public class GetFlowGroupCacheProvider extends OsgiCommandSupport { StringBuilder sb = new StringBuilder(); Formatter fmt = new Formatter(sb); - System.out.println(getAllLocalNodesHeaderOutput()); - System.out.println(LINE_SEPARATOR); + session.getConsole().println(getAllLocalNodesHeaderOutput()); + session.getConsole().println(LINE_SEPARATOR); for (Entry entry : allHistories.entrySet()) { // FIXME: just seek/substring String[] temp = entry.getKey().getValue().split(":"); String node = temp[1]; for (FlowGroupInfo info : entry.getValue().readEntries()) { - System.out.println(fmt.format("%-15s %1s %-10s %1s %-8s %1s %-21s %1s %-60s", node, "", + session.getConsole().println(fmt.format("%-15s %1s %-10s %1s %-8s %1s %-21s %1s %-60s", node, "", info.getDescription(), "", info.getStatus(), "", getTime(info), "", info.getId()).toString()); sb.setLength(0); } diff --git a/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/GetReconciliationStateProvider.java b/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/GetReconciliationStateCommand.java similarity index 66% rename from applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/GetReconciliationStateProvider.java rename to applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/GetReconciliationStateCommand.java index 6edce23129..c140a502df 100644 --- a/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/GetReconciliationStateProvider.java +++ b/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/GetReconciliationStateCommand.java @@ -7,22 +7,32 @@ */ package org.opendaylight.openflowplugin.applications.southboundcli.cli; +import static org.opendaylight.openflowplugin.applications.southboundcli.util.ShellUtil.LINE_SEPARATOR; + import java.util.ArrayList; -import org.apache.karaf.shell.commands.Command; -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.lifecycle.Reference; +import org.apache.karaf.shell.api.action.lifecycle.Service; +import org.apache.karaf.shell.api.console.Session; import org.opendaylight.openflowplugin.applications.frm.ReconciliationJMXServiceMBean; +@Service @Command(scope = "openflow", name = "getreconciliationstate", description = "Print reconciliation state for all devices") -public class GetReconciliationStateProvider extends OsgiCommandSupport { - private final ReconciliationJMXServiceMBean reconciliationJMXServiceMBean; - - public GetReconciliationStateProvider(final ReconciliationJMXServiceMBean reconciliationJMXServiceMBean) { - this.reconciliationJMXServiceMBean = reconciliationJMXServiceMBean; - } +public final class GetReconciliationStateCommand implements Action { + @Reference + Session session; + @Reference + ReconciliationJMXServiceMBean reconciliationJMXServiceMBean; @Override - protected Object doExecute() { + public Object execute() { + if (reconciliationJMXServiceMBean == null) { + // not initialized + return null; + } + final var reconciliationStates = reconciliationJMXServiceMBean.acquireReconciliationStates(); if (!reconciliationStates.isEmpty()) { final var result = new ArrayList(); @@ -31,7 +41,7 @@ public class GetReconciliationStateProvider extends OsgiCommandSupport { result.add(status); }); session.getConsole().println(getHeaderOutput()); - session.getConsole().println(getLineSeparator()); + session.getConsole().println(LINE_SEPARATOR); result.stream().forEach(p -> session.getConsole().println(p)); } else { session.getConsole().println("Reconciliation data not available"); @@ -42,8 +52,4 @@ public class GetReconciliationStateProvider extends OsgiCommandSupport { private static String getHeaderOutput() { return String.format("%-17s %-25s %-25s", "DatapathId", "Reconciliation Status", "Reconciliation Time"); } - - private static String getLineSeparator() { - return "-------------------------------------------------------------------"; - } } \ No newline at end of file diff --git a/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/Reconciliation.java b/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/ReconcileCommand.java similarity index 66% rename from applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/Reconciliation.java rename to applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/ReconcileCommand.java index 7d4adbeae1..cf4a9f77f5 100644 --- a/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/Reconciliation.java +++ b/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/ReconcileCommand.java @@ -7,30 +7,34 @@ */ package org.opendaylight.openflowplugin.applications.southboundcli.cli; +import static org.opendaylight.openflowplugin.applications.southboundcli.util.ShellUtil.LINE_SEPARATOR; + import java.util.Formatter; import java.util.List; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; -import org.apache.karaf.shell.commands.Argument; -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.Argument; +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.openflowplugin.applications.southboundcli.ReconcileService; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.reconciliation.service.rev180227.ReconcileOutput; import org.opendaylight.yangtools.yang.common.Uint64; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Service @Command(scope = "openflow", name = "reconcile", description = "Launch reconciliation for openflow nodes") -public class Reconciliation extends OsgiCommandSupport { - private static final Logger LOG = LoggerFactory.getLogger(Reconciliation.class); - - private ReconcileService reconciliationService = null; - - public void setReconciliationService(final ReconcileService reconciliationService) { - this.reconciliationService = reconciliationService; - } +public final class ReconcileCommand implements Action { + private static final Logger LOG = LoggerFactory.getLogger(ReconcileCommand.class); + @Reference + Session session; + @Reference + ReconcileService reconciliationService = null; @Argument(name = "nodeId", description = "The NODE Id", multiValued = true) List nodeIds; @@ -38,9 +42,13 @@ public class Reconciliation extends OsgiCommandSupport { @Option(name = "-all", description = "Reconcile all operative NODEs") boolean reconcileAllNodes; - @SuppressWarnings("checkstyle:RegexpSinglelineJava") @Override - protected Object doExecute() throws Exception { + public Object execute() throws Exception { + if (reconciliationService == null) { + // not initialized + return null; + } + final var nodes = nodeIds == null ? Set.of() : nodeIds.stream().map(Uint64::valueOf).collect(Collectors.toSet()); final var rpcOutput = reconcileAllNodes ? reconciliationService.reconcileAll() @@ -49,10 +57,10 @@ public class Reconciliation extends OsgiCommandSupport { try { final var rpcResult = rpcOutput.get(); if (rpcResult.isSuccessful()) { - System.out.println("Reconciliation triggered for the node(s)"); + session.getConsole().println("Reconciliation triggered for the node(s)"); printInProgressNodes(rpcResult.getResult()); } else { - System.out.println(rpcResult.getErrors().stream().findFirst().orElseThrow().getMessage()); + session.getConsole().println(rpcResult.getErrors().stream().findFirst().orElseThrow().getMessage()); } } catch (ExecutionException e) { LOG.error("Error occurred while invoking reconcile RPC for node {}", nodes, e); @@ -60,16 +68,15 @@ public class Reconciliation extends OsgiCommandSupport { return null; } - @SuppressWarnings("checkstyle:RegexpSinglelineJava") - private static void printInProgressNodes(final ReconcileOutput reconcileOutput) { + private void printInProgressNodes(final ReconcileOutput reconcileOutput) { final var inprogressNodes = reconcileOutput.getInprogressNodes(); if (inprogressNodes.size() > 0) { final var stringBuilder = new StringBuilder(); try (var formatter = new Formatter(stringBuilder)) { - System.out.println(getReconcileHeaderOutput()); - System.out.println("----------------------------------------------------"); + session.getConsole().println(getReconcileHeaderOutput()); + session.getConsole().println(LINE_SEPARATOR); for (Uint64 node : inprogressNodes) { - System.out.println(formatter.format("%-15s %n",node).toString()); + session.getConsole().println(formatter.format("%-15s %n",node)); stringBuilder.setLength(0); } } diff --git a/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/ReconciliationCount.java b/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/ReconciliationCountCommand.java similarity index 65% rename from applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/ReconciliationCount.java rename to applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/ReconciliationCountCommand.java index 16c9b95329..cc7c14d3b0 100644 --- a/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/ReconciliationCount.java +++ b/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/ReconciliationCountCommand.java @@ -8,40 +8,43 @@ package org.opendaylight.openflowplugin.applications.southboundcli.cli; -import java.util.Collection; import java.util.Formatter; -import org.apache.karaf.shell.commands.Command; -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.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.ShellUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.reconciliation.service.rev180227.reconciliation.counter.ReconcileCounter; +@Service @Command(scope = "openflow", name = "getReconciliationCount", description = "Displays the number of reconciliation triggered for openflow nodes") -public class ReconciliationCount extends OsgiCommandSupport { +public final class ReconciliationCountCommand implements Action { + @Reference + Session session; + @Reference + DataBroker dataBroker; - private DataBroker dataBroker; - - public void setDataBroker(final DataBroker dataBroker) { - this.dataBroker = dataBroker; - } - - @SuppressWarnings("checkstyle:RegexpSinglelineJava") @Override - protected Object doExecute() { - Collection result = ShellUtil.getReconcileCount(dataBroker); + public Object execute() { + if (dataBroker == null) { + // not initialized + return null; + } + final var result = ShellUtil.getReconcileCount(dataBroker); if (result.isEmpty()) { - System.out.println("Reconciliation count not yet available for openflow nodes."); + session.getConsole().println("Reconciliation count not yet available for openflow nodes."); } else { StringBuilder stringBuilder = new StringBuilder(); final Formatter formatter = new Formatter(stringBuilder); - System.out.println(getReconcileCountHeaderOutput()); - System.out.println("--------------------------------------------------------------------------" - + "---------------------------"); + session.getConsole().println(getReconcileCountHeaderOutput()); + session.getConsole().println("-".repeat(100)); for (ReconcileCounter reconcile : result) { - System.out.println(formatter.format("%-15s %3s %-15s %9s %-20s %4s %-20s %n", + session.getConsole().println(formatter.format("%-15s %3s %-15s %9s %-20s %4s %-20s %n", reconcile.getNodeId(), "", reconcile.getSuccessCount(), "", reconcile.getFailureCount(), "", - reconcile.getLastRequestTime().getValue()).toString()); + reconcile.getLastRequestTime().getValue())); stringBuilder.setLength(0); } formatter.close(); diff --git a/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/ShowNodeCommandProvider.java b/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/ShowNodeCommand.java similarity index 53% rename from applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/ShowNodeCommandProvider.java rename to applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/ShowNodeCommand.java index d75ced1e69..4f4a41a22b 100644 --- a/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/ShowNodeCommandProvider.java +++ b/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/ShowNodeCommand.java @@ -7,66 +7,60 @@ */ 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 ") -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 diff --git a/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/util/ShellUtil.java b/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/util/ShellUtil.java index 9a91a4fe6b..d0be9bc924 100644 --- a/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/util/ShellUtil.java +++ b/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/util/ShellUtil.java @@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory; public final class ShellUtil { private static final Logger LOG = LoggerFactory.getLogger(ShellUtil.class); + public static final String LINE_SEPARATOR = "-".repeat(100); public static final String NODE_PREFIX = "openflow:"; private ShellUtil() { diff --git a/applications/southbound-cli/src/main/resources/OSGI-INF/blueprint/commands.xml b/applications/southbound-cli/src/main/resources/OSGI-INF/blueprint/commands.xml deleted file mode 100644 index 6c68e0924a..0000000000 --- a/applications/southbound-cli/src/main/resources/OSGI-INF/blueprint/commands.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -