Migrate Optional.get() callers
[transportpce.git] / inventory / src / main / java / org / opendaylight / transportpce / inventory / listener / DeviceListener.java
index 70f5822225316a8a260b49456182839085e755af..3ba26dfe48a82ecec611a87df8749a37241967d8 100644 (file)
@@ -12,15 +12,13 @@ import java.util.Collection;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 import java.util.stream.Collectors;
-
 import org.opendaylight.mdsal.binding.api.DataObjectModification.ModificationType;
 import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
 import org.opendaylight.mdsal.binding.api.DataTreeModification;
 import org.opendaylight.transportpce.common.StringConstants;
 import org.opendaylight.transportpce.inventory.DeviceInventory;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev221225.ConnectionOper.ConnectionStatus;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.NetconfNode;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -45,33 +43,28 @@ public class DeviceListener implements DataTreeChangeListener<Node> {
 
     @Override
     public void onDataTreeChanged(Collection<DataTreeModification<Node>> changes) {
-        //LOG.debug("testing np1:"+changes.toString());
+        //LOG.debug("testing np1: {}", changes.toString());
         String openROADMversion = "";
         List<DataTreeModification<Node>> changesWithoutDefaultNetconfNode = getRealDevicesOnly(changes);
         for (DataTreeModification<Node> device : changesWithoutDefaultNetconfNode) {
             String nodeId = device.getRootNode().getDataAfter().key().getNodeId().getValue();
             NetconfNode netconfNode = device.getRootNode().getDataAfter().augmentation(NetconfNode.class);
-            NetconfNodeConnectionStatus.ConnectionStatus connectionStatus =
-                    netconfNode.getConnectionStatus();
+            ConnectionStatus connectionStatus = netconfNode.getConnectionStatus();
             long count = netconfNode.getAvailableCapabilities().getAvailableCapability().stream()
                     .filter(cp -> cp.getCapability().contains(StringConstants.OPENROADM_DEVICE_MODEL_NAME))
                     .count();
-            LOG.info("DL ################## Modification Type {}",
-                device.getRootNode().getModificationType().toString());
-            LOG.info("DL ################## Capability Count {}", count);
-            LOG.info("DL ################## Connection Status {}", connectionStatus);
-            LOG.info("DL ################## device.getRootNode().getDataBefore() {}",
-                device.getRootNode().getDataBefore());
-            LOG.info("DL ################## device.getRootNode().getDataAfter() {}",
-                device.getRootNode().getDataAfter());
-
+            LOG.debug("DL Modification Type {}", device.getRootNode().getModificationType().toString());
+            LOG.debug("DL Capability Count {}", count);
+            LOG.debug("DL Connection Status {}", connectionStatus);
+            LOG.debug("DL device.getRootNode().getDataBefore() {}", device.getRootNode().getDataBefore());
+            LOG.debug("DL device.getRootNode().getDataAfter() {}", device.getRootNode().getDataAfter());
 
             if (isCreate(device)) {
                 LOG.info("Node {} was created", nodeId);
                 try {
                     processModifiedSubtree(nodeId, netconfNode, openROADMversion);
                 } catch (InterruptedException | ExecutionException e) {
-                    LOG.error(e.getMessage(), e);
+                    LOG.error("something wrong when creating node {}", nodeId, e);
                 }
             } else if (isDelete(device)) {
                 LOG.info("Node {} was deleted", nodeId);
@@ -91,7 +84,7 @@ public class DeviceListener implements DataTreeChangeListener<Node> {
      */
     private void processModifiedSubtree(String nodeId, NetconfNode netconfNode, String openROADMversion)
             throws InterruptedException, ExecutionException {
-        NetconfNodeConnectionStatus.ConnectionStatus connectionStatus = netconfNode.getConnectionStatus();
+        ConnectionStatus connectionStatus = netconfNode.getConnectionStatus();
 
         long count = netconfNode.getAvailableCapabilities().getAvailableCapability().stream()
                 .filter(cp -> cp.getCapability().contains(StringConstants.OPENROADM_DEVICE_MODEL_NAME))
@@ -139,14 +132,6 @@ public class DeviceListener implements DataTreeChangeListener<Node> {
         return change.getRootNode().getModificationType().toString().equalsIgnoreCase("WRITE");
     }
 
-    /**
-     * In the filtered collection checks if the modification is update.
-     *
-     */
-    private static boolean isUpdate(DataTreeModification<Node> change) {
-        return ModificationType.SUBTREE_MODIFIED.equals(change.getRootNode().getModificationType());
-    }
-
     /**
      * In the filtered collection checks if the node was deleted.
      *
@@ -155,4 +140,4 @@ public class DeviceListener implements DataTreeChangeListener<Node> {
         return change.getRootNode().getDataBefore() != null && change.getRootNode().getDataAfter() == null
                 && ModificationType.DELETE.equals(change.getRootNode().getModificationType());
     }
-}
+}
\ No newline at end of file