Refactoring of Tapi Step2
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / topology / TapiPortMappingListener.java
index 71011434dd597832f1524390635699f825051344..309643c20ad122f082bd3914231892ecc3b05bf8 100644 (file)
@@ -12,9 +12,9 @@ import java.util.Map;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
 import org.opendaylight.mdsal.binding.api.DataTreeModification;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210425.mapping.Mapping;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210425.mapping.MappingKey;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210425.network.Nodes;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.mapping.Mapping;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.mapping.MappingKey;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.network.Nodes;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -43,15 +43,29 @@ public class TapiPortMappingListener implements DataTreeChangeListener<Nodes> {
                 Map<MappingKey, Mapping> mappingBef = nodesBef.getMapping();
                 LOG.info("Change in node {} with OR version = {}", nodeId,
                     nodesAft.getNodeInfo().getOpenroadmVersion().getName());
-                if (mappingAft != null && mappingBef == null) {
+                if (mappingAft == null) {
+                    LOG.warn("Mapping already existed in the datastore, which means that node {} already existed "
+                        + "in TAPI topology. The action to take will be different", nodeId);
+                    continue;
+                }
+                if (mappingBef == null) {
                     LOG.info("New mapping for node {} = {}", nodeId, mappingAft);
                     LOG.info("As the mapping is now created for the first time, "
                         + "we can proceed with the creation of the node {} in the TAPI topology", nodeId);
                     this.tapiNetworkModelService.createTapiNode(nodeId,
                         nodesAft.getNodeInfo().getOpenroadmVersion().getIntValue(), nodesAft);
                 } else {
-                    LOG.warn("Mapping already existed in the datastore, which means that node {} already existed "
-                        + "in TAPI topology. The action to take will be different", nodeId);
+                    for (Map.Entry<MappingKey, Mapping> entry : mappingAft.entrySet()) {
+                        Mapping oldMapping = mappingBef.get(entry.getKey());
+                        Mapping newMapping = mappingAft.get(entry.getKey());
+                        if (oldMapping == null || newMapping == null) {
+                            continue;
+                        }
+                        if (!oldMapping.getPortAdminState().equals(newMapping.getPortAdminState())
+                                || !oldMapping.getPortOperState().equals(newMapping.getPortOperState())) {
+                            this.tapiNetworkModelService.updateTapiTopology(nodeId, entry.getValue());
+                        }
+                    }
                 }
             }
         }