X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=inventory%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Finventory%2Flistener%2FDeviceListener.java;h=dac8cd441212e8efad96d10d631542ff6dd731d0;hb=b1b3bafd549bb501937cea5c976d5344608b6ed3;hp=d5ba4047ee45547f7c3765c57152ca9d0d1635b5;hpb=f5a8fe61d265bce36b2fca393d82685a22ac326a;p=transportpce.git diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/DeviceListener.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/DeviceListener.java index d5ba4047e..dac8cd441 100644 --- a/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/DeviceListener.java +++ b/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/DeviceListener.java @@ -5,7 +5,6 @@ * 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.transportpce.inventory.listener; import java.util.Collection; @@ -17,9 +16,8 @@ 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.rev240120.ConnectionOper.ConnectionStatus; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev231121.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; @@ -43,34 +41,29 @@ public class DeviceListener implements DataTreeChangeListener { } @Override - public void onDataTreeChanged(Collection> changes) { - //LOG.debug("testing np1:"+changes.toString()); + public void onDataTreeChanged(List> changes) { + //LOG.debug("testing np1: {}", changes.toString()); String openROADMversion = ""; List> changesWithoutDefaultNetconfNode = getRealDevicesOnly(changes); for (DataTreeModification device : changesWithoutDefaultNetconfNode) { - String nodeId = device.getRootNode().getDataAfter().key().getNodeId().getValue(); - NetconfNode netconfNode = device.getRootNode().getDataAfter().augmentation(NetconfNode.class); - NetconfNodeConnectionStatus.ConnectionStatus connectionStatus = - netconfNode.getConnectionStatus(); + String nodeId = device.getRootNode().dataAfter().key().getNodeId().getValue(); + NetconfNode netconfNode = device.getRootNode().dataAfter().augmentation(NetconfNode.class); + 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().modificationType().toString()); + LOG.debug("DL Capability Count {}", count); + LOG.debug("DL Connection Status {}", connectionStatus); + LOG.debug("DL device.getRootNode().getDataBefore() {}", device.getRootNode().dataBefore()); + LOG.debug("DL device.getRootNode().getDataAfter() {}", device.getRootNode().dataAfter()); 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); @@ -90,7 +83,7 @@ public class DeviceListener implements DataTreeChangeListener { */ 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)) @@ -118,14 +111,14 @@ public class DeviceListener implements DataTreeChangeListener { */ private static List> getRealDevicesOnly(Collection> changes) { return changes.stream() - .filter(change -> (change.getRootNode().getDataAfter() != null + .filter(change -> (change.getRootNode().dataAfter() != null && !StringConstants.DEFAULT_NETCONF_NODEID - .equalsIgnoreCase(change.getRootNode().getDataAfter().key().getNodeId().getValue()) - && change.getRootNode().getDataAfter().augmentation(NetconfNode.class) != null) - || (change.getRootNode().getDataBefore() != null + .equalsIgnoreCase(change.getRootNode().dataAfter().key().getNodeId().getValue()) + && change.getRootNode().dataAfter().augmentation(NetconfNode.class) != null) + || (change.getRootNode().dataBefore() != null && !StringConstants.DEFAULT_NETCONF_NODEID.equalsIgnoreCase( - change.getRootNode().getDataBefore().key().getNodeId().getValue()) - && change.getRootNode().getDataBefore().augmentation(NetconfNode.class) != null + change.getRootNode().dataBefore().key().getNodeId().getValue()) + && change.getRootNode().dataBefore().augmentation(NetconfNode.class) != null )).collect(Collectors.toList()); } @@ -135,15 +128,7 @@ public class DeviceListener implements DataTreeChangeListener { * */ private static boolean isCreate(DataTreeModification change) { - return change.getRootNode().getModificationType().toString().equalsIgnoreCase("WRITE"); - } - - /** - * In the filtered collection checks if the modification is update. - * - */ - private static boolean isUpdate(DataTreeModification change) { - return ModificationType.SUBTREE_MODIFIED.equals(change.getRootNode().getModificationType()); + return change.getRootNode().modificationType().toString().equalsIgnoreCase("WRITE"); } /** @@ -151,7 +136,7 @@ public class DeviceListener implements DataTreeChangeListener { * */ private static boolean isDelete(DataTreeModification change) { - return change.getRootNode().getDataBefore() != null && change.getRootNode().getDataAfter() == null - && ModificationType.DELETE.equals(change.getRootNode().getModificationType()); + return change.getRootNode().dataBefore() != null && change.getRootNode().dataAfter() == null + && ModificationType.DELETE.equals(change.getRootNode().modificationType()); } -} +} \ No newline at end of file