Integrate CLI on a proper management interface 81/94581/1
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 9 Jan 2021 21:56:17 +0000 (22:56 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 10 Jan 2021 08:53:06 +0000 (09:53 +0100)
We are currently wiring these through blueprint, which allows class
injection -- but this needs to be a proper interface.

Change-Id: I704f329bc6c8b75f01f5d7cd29471648c028f922
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundProvider.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundProviderInfo.java [new file with mode: 0644]
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/TransactionHistoryCmd.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/cli/HwvtepCacheDisplayCmd.java

index e664a46f0063ccbf6b5e18ae179711464da12622..10412e837aeae07241a27c338fc0629d8e8c4735 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.ovsdb.hwvtepsouthbound;
 import static java.util.Objects.requireNonNull;
 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
 
+import com.google.common.collect.Maps;
 import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.MoreExecutors;
@@ -672,14 +673,6 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo
         return entityConnectionMap.get(entity);
     }
 
-    public Map<InstanceIdentifier<Node>, TransactionHistory> getControllerTxHistory() {
-        return controllerTxHistory;
-    }
-
-    public Map<InstanceIdentifier<Node>, TransactionHistory> getDeviceUpdateHistory() {
-        return deviceUpdateHistory;
-    }
-
     private static class HwvtepDeviceEntityOwnershipListener implements EntityOwnershipListener {
         private final HwvtepConnectionManager hcm;
         private final EntityOwnershipListenerRegistration listenerRegistration;
@@ -700,6 +693,23 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo
         }
     }
 
+    final Map<InstanceIdentifier<Node>, HwvtepDeviceInfo> allConnectedInstances() {
+        return Maps.transformValues(Collections.unmodifiableMap(nodeIidVsConnectionInstance),
+            HwvtepConnectionInstance::getDeviceInfo);
+    }
+
+    final Map<InstanceIdentifier<Node>, TransactionHistory> controllerTxHistory() {
+        return Collections.unmodifiableMap(controllerTxHistory);
+    }
+
+    final Map<InstanceIdentifier<Node>, TransactionHistory> deviceUpdateHistory() {
+        return Collections.unmodifiableMap(deviceUpdateHistory);
+    }
+
+    public void cleanupOperationalNode(final InstanceIdentifier<Node> nodeIid) {
+        txInvoker.invoke(new HwvtepGlobalRemoveCommand(nodeIid));
+    }
+
     private enum ConnectionReconciliationTriggers {
         /*
         Reconciliation trigger for scenario where controller's attempt
@@ -713,12 +723,4 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo
         */
         ON_DISCONNECT
     }
-
-    public Map<InstanceIdentifier<Node>, HwvtepConnectionInstance> getAllConnectedInstances() {
-        return Collections.unmodifiableMap(nodeIidVsConnectionInstance);
-    }
-
-    public void cleanupOperationalNode(final InstanceIdentifier<Node> nodeIid) {
-        txInvoker.invoke(new HwvtepGlobalRemoveCommand(nodeIid));
-    }
 }
index cf1f37711c879e106bf55a24e47ca1c7d11dfa3b..71fcb7a5614dffcc42101459b85017cb342a51e7 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.ovsdb.hwvtepsouthbound;
 
 import com.google.common.util.concurrent.FluentFuture;
 import java.util.Collection;
+import java.util.Map;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -38,19 +39,22 @@ import org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md.TransactionInvoke
 import org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md.TransactionInvokerImpl;
 import org.opendaylight.ovsdb.lib.OvsdbConnection;
 import org.opendaylight.ovsdb.utils.mdsal.utils.Scheduler;
+import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionHistory;
 import org.opendaylight.serviceutils.upgrade.UpgradeState;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @Singleton
-@Service(classes = HwvtepSouthboundProvider.class) // only because HwvtepCacheDisplayCmd needs a @Reference to this
-public class HwvtepSouthboundProvider implements ClusteredDataTreeChangeListener<Topology>, AutoCloseable {
+@Service(classes = HwvtepSouthboundProviderInfo.class)
+public class HwvtepSouthboundProvider
+        implements HwvtepSouthboundProviderInfo, ClusteredDataTreeChangeListener<Topology>, AutoCloseable {
 
     private static final Logger LOG = LoggerFactory.getLogger(HwvtepSouthboundProvider.class);
     private static final String ENTITY_TYPE = "ovsdb-hwvtepsouthbound-provider";
@@ -245,4 +249,19 @@ public class HwvtepSouthboundProvider implements ClusteredDataTreeChangeListener
     public HwvtepConnectionManager getHwvtepConnectionManager() {
         return cm;
     }
+
+    @Override
+    public Map<InstanceIdentifier<Node>, HwvtepDeviceInfo> getAllConnectedInstances() {
+        return cm.allConnectedInstances();
+    }
+
+    @Override
+    public Map<InstanceIdentifier<Node>, TransactionHistory> getControllerTxHistory() {
+        return cm.controllerTxHistory();
+    }
+
+    @Override
+    public Map<InstanceIdentifier<Node>, TransactionHistory> getDeviceUpdateHistory() {
+        return cm.deviceUpdateHistory();
+    }
 }
diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundProviderInfo.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundProviderInfo.java
new file mode 100644 (file)
index 0000000..2d1d6f8
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.ovsdb.hwvtepsouthbound;
+
+import com.google.common.annotations.Beta;
+import java.util.Map;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionHistory;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+@Beta
+public interface HwvtepSouthboundProviderInfo {
+
+    @NonNull Map<InstanceIdentifier<Node>, HwvtepDeviceInfo> getAllConnectedInstances();
+
+    @NonNull Map<InstanceIdentifier<Node>, TransactionHistory> getControllerTxHistory();
+
+    @NonNull Map<InstanceIdentifier<Node>, TransactionHistory> getDeviceUpdateHistory();
+}
index f9e8017d35c9e188c30ee5ed0867a2cbaa657d4f..f02f17a35ed6fc7fe81f03a81a0d3ac46fc8c534 100644 (file)
@@ -30,7 +30,7 @@ public class TransactionHistoryCmd extends OsgiCommandSupport {
     String nodeid;
     private static final String SEPERATOR = "#######################################################";
 
-    private final HwvtepSouthboundProvider hwvtepProvider;
+    private final HwvtepSouthboundProviderInfo hwvtepProvider;
 
     public TransactionHistoryCmd(HwvtepSouthboundProvider hwvtepProvider) {
         this.hwvtepProvider = hwvtepProvider;
@@ -38,20 +38,18 @@ public class TransactionHistoryCmd extends OsgiCommandSupport {
 
     @Override
     protected Object doExecute() throws Exception {
-        Map<InstanceIdentifier<Node>, TransactionHistory> controllerTxLogs
-                = hwvtepProvider.getHwvtepConnectionManager().getControllerTxHistory();
-        Map<InstanceIdentifier<Node>, TransactionHistory> deviceUpdateLogs
-                = hwvtepProvider.getHwvtepConnectionManager().getDeviceUpdateHistory();
+        Map<InstanceIdentifier<Node>, TransactionHistory> controllerTxLogs = hwvtepProvider.getControllerTxHistory();
+        Map<InstanceIdentifier<Node>, TransactionHistory> deviceUpdateLogs = hwvtepProvider.getDeviceUpdateHistory();
         if (nodeid != null) {
-            InstanceIdentifier<Node> iid = HwvtepSouthboundMapper.createInstanceIdentifier(new NodeId(nodeid));
-            printLogs(controllerTxLogs, deviceUpdateLogs, iid);
+            printLogs(controllerTxLogs, deviceUpdateLogs,
+                HwvtepSouthboundMapper.createInstanceIdentifier(new NodeId(nodeid)));
         } else {
             Map<InstanceIdentifier<Node>, TransactionHistory> txlogs
                     = controllerTxLogs.isEmpty() ? deviceUpdateLogs : controllerTxLogs;
             txlogs.keySet().forEach(iid -> {
                 printLogs(controllerTxLogs, deviceUpdateLogs, iid);
             });
-            session.getConsole().println("Device tx logs size " + deviceUpdateLogs.keySet().size());
+            session.getConsole().println("Device tx logs size " + deviceUpdateLogs.size());
         }
         return null;
     }
@@ -73,7 +71,7 @@ public class TransactionHistoryCmd extends OsgiCommandSupport {
     }
 
     private void printLogs(List<Pair<HwvtepTransactionLogElement, Boolean>> logs) {
-        logs.forEach((pair) -> {
+        logs.forEach(pair -> {
             HwvtepTransactionLogElement log = pair.getLeft();
             session.getConsole().print(new Date(log.getDate()));
             session.getConsole().print(" ");
index be3d5fe0aa8ff22cc2f263ee38aaebbfa02749b8..132c09e4dbe35902cc9daa421c8328aa27871622 100644 (file)
@@ -14,9 +14,8 @@ import org.apache.karaf.shell.api.action.Argument;
 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.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepDeviceInfo;
-import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundProvider;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundProviderInfo;
 import org.opendaylight.ovsdb.lib.notation.UUID;
 import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalPort;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
@@ -43,7 +42,7 @@ public class HwvtepCacheDisplayCmd implements Action {
     private String nodeid;
 
     @Reference
-    private HwvtepSouthboundProvider hwvtepSouthboundProvider;
+    private HwvtepSouthboundProviderInfo hwvtepSouthboundProvider;
 
     private static final TopologyId HWVTEP_TOPOLOGY_ID = new TopologyId(new Uri("hwvtep:1"));
     private static final String SEPERATOR = "#######################################################";
@@ -54,10 +53,10 @@ public class HwvtepCacheDisplayCmd implements Action {
     @Override
     @SuppressWarnings("checkstyle:RegexpSinglelineJava")
     public Object execute() throws Exception {
-        Map<InstanceIdentifier<Node>, HwvtepConnectionInstance> allConnectedInstances =
-                hwvtepSouthboundProvider.getHwvtepConnectionManager().getAllConnectedInstances();
+        Map<InstanceIdentifier<Node>, HwvtepDeviceInfo> allConnectedInstances =
+                hwvtepSouthboundProvider.getAllConnectedInstances();
         if (nodeid == null) {
-            allConnectedInstances.entrySet().forEach((entry) -> {
+            allConnectedInstances.entrySet().forEach(entry -> {
                 System.out.println(SEPERATOR + " START " + SEPERATOR);
                 print(entry.getKey(), entry.getValue());
                 System.out.println(SEPERATOR + " END " + SEPERATOR);
@@ -83,7 +82,7 @@ public class HwvtepCacheDisplayCmd implements Action {
     }
 
     @SuppressWarnings("checkstyle:RegexpSinglelineJava")
-    private static void print(InstanceIdentifier<Node> iid, HwvtepConnectionInstance connectionInstance) {
+    private static void print(InstanceIdentifier<Node> iid, HwvtepDeviceInfo deviceInfo) {
         PrintStream printStream = System.out;
         printStream.print("Printing for Node :  ");
         printStream.println(iid.firstKeyOf(Node.class).getNodeId().getValue());
@@ -91,23 +90,21 @@ public class HwvtepCacheDisplayCmd implements Action {
         printStream.println(SECTION_SEPERATOR);
         printStream.println("Config data");
         printStream.println(SECTION_SEPERATOR);
-        HwvtepDeviceInfo deviceInfo = connectionInstance.getDeviceInfo();
-        deviceInfo.getConfigData().entrySet().forEach((entry) -> {
+        deviceInfo.getConfigData().entrySet().forEach(entry -> {
             printEntry(printStream, entry);
         });
 
-
         printStream.println(SECTION_SEPERATOR);
         printStream.println("Oper data");
         printStream.println(SECTION_SEPERATOR);
-        deviceInfo.getOperData().entrySet().forEach((entry) -> {
+        deviceInfo.getOperData().entrySet().forEach(entry -> {
             printEntry(printStream, entry);
         });
 
         printStream.println(SECTION_SEPERATOR);
         printStream.println("Uuid data");
         printStream.println(SECTION_SEPERATOR);
-        deviceInfo.getUuidData().entrySet().forEach((entry) -> {
+        deviceInfo.getUuidData().entrySet().forEach(entry -> {
             printEntryUUID(printStream, entry);
         });
         printStream.println(SECTION_SEPERATOR);
@@ -121,7 +118,7 @@ public class HwvtepCacheDisplayCmd implements Action {
         Map<InstanceIdentifier, HwvtepDeviceInfo.DeviceData> map = entry.getValue();
         String clsName = cls.getSimpleName();
         console.println(clsName + " - ");
-        map.values().forEach((deviceData) -> {
+        map.values().forEach(deviceData -> {
             printTable(console, clsName, deviceData);
         });
     }
@@ -209,7 +206,7 @@ public class HwvtepCacheDisplayCmd implements Action {
         Map<UUID, HwvtepDeviceInfo.DeviceData> map = entry.getValue();
         String clsName = cls.getSimpleName();
         console.println(clsName + " - ");
-        map.values().forEach((deviceData) -> {
+        map.values().forEach(deviceData -> {
             printTable(console, clsName, deviceData);
         });
     }