X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=networkmodel%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fnetworkmodel%2Fservice%2FNetworkModelServiceImpl.java;h=a184642af42a6ff702b3c961764ca24dd4539147;hb=c2f1377c6fb6f0307d5b5956acdcd56581d9d834;hp=42665ef5fbea328ba316d89db38c6cb5ee21a2ee;hpb=cb8ebd04e8e896faf9f2157ca182939191dd7ea2;p=transportpce.git diff --git a/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/service/NetworkModelServiceImpl.java b/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/service/NetworkModelServiceImpl.java index 42665ef5f..a184642af 100644 --- a/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/service/NetworkModelServiceImpl.java +++ b/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/service/NetworkModelServiceImpl.java @@ -8,6 +8,7 @@ package org.opendaylight.transportpce.networkmodel.service; import com.google.common.util.concurrent.ListenableFuture; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -19,6 +20,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; import org.eclipse.jdt.annotation.Nullable; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.transportpce.common.NetworkUtils; import org.opendaylight.transportpce.common.mapping.PortMapping; @@ -30,6 +32,11 @@ import org.opendaylight.transportpce.networkmodel.util.LinkIdUtil; import org.opendaylight.transportpce.networkmodel.util.OpenRoadmNetwork; import org.opendaylight.transportpce.networkmodel.util.OpenRoadmOtnTopology; import org.opendaylight.transportpce.networkmodel.util.OpenRoadmTopology; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkmodel.rev201116.TopologyUpdateResult; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkmodel.rev201116.TopologyUpdateResultBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkmodel.rev201116.topology.update.result.OrdTopologyChanges; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkmodel.rev201116.topology.update.result.OrdTopologyChangesBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkmodel.rev201116.topology.update.result.OrdTopologyChangesKey; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.network.nodes.NodeInfo; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.network.nodes.NodeInfo.OpenroadmVersion; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1Builder; @@ -41,6 +48,7 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.No import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates; import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529.Link1; import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529.TerminationPoint1; +import org.opendaylight.yang.gen.v1.http.org.transportpce.d._interface.ord.topology.types.rev201116.TopologyNotificationTypes; import org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.OtnLinkType; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks; @@ -80,9 +88,14 @@ public class NetworkModelServiceImpl implements NetworkModelService { // Maps that include topology component changed with its new operational state private Map linksChanged; private Map terminationPointsChanged; + // Variables for creating and sending topology update notification + private final NotificationPublishService notificationPublishService; + private Map topologyChanges; + private TopologyUpdateResult notification = null; public NetworkModelServiceImpl(final NetworkTransactionService networkTransactionService, - final R2RLinkDiscovery linkDiscovery, PortMapping portMapping) { + final R2RLinkDiscovery linkDiscovery, PortMapping portMapping, + final NotificationPublishService notificationPublishService) { this.networkTransactionService = networkTransactionService; this.linkDiscovery = linkDiscovery; @@ -91,6 +104,8 @@ public class NetworkModelServiceImpl implements NetworkModelService { this.otnTopologyShardMountedDevice = new HashMap(); this.linksChanged = new HashMap(); this.terminationPointsChanged = new HashMap(); + this.notificationPublishService = notificationPublishService; + this.topologyChanges = new HashMap(); } public void init() { @@ -268,6 +283,7 @@ public class NetworkModelServiceImpl implements NetworkModelService { // Clear maps for each NETCONF notification received this.linksChanged.clear(); this.terminationPointsChanged.clear(); + this.topologyChanges.clear(); // 1. Get the list links and nodes of the current openroadm network topology List linkList = null; List nodesList = null; @@ -314,7 +330,8 @@ public class NetworkModelServiceImpl implements NetworkModelService { updateOpenRoadmNetworkTopologyTPs(nodesList, nodeId); // 4. Update the links of the topology affected by the changes on TPs (if any) updateOpenRoadmNetworkTopologyLinks(linkList, nodesList); - // TODO: send notification to service handler + // Send notification to service handler + sendNotification(TopologyNotificationTypes.OpenroadmTopologyUpdate, this.topologyChanges); break; case "port": LOG.info("port circuit pack modified"); @@ -764,14 +781,26 @@ public class NetworkModelServiceImpl implements NetworkModelService { newTpOperationalState = State.InService; // Add TP and state inService to the links Map this.linksChanged.put(tpId, State.InService); - // TODO: update change list for service handler notification + // Update topology change list for service handler notification + this.topologyChanges.put( + new OrdTopologyChangesKey(node.getNodeId().getValue() + "-" + tpId), + new OrdTopologyChangesBuilder() + .setId(node.getNodeId().getValue() + "-" + tpId) + .setState(newTpOperationalState) + .build()); break; case OutOfService: newTpAdminState = AdminStates.OutOfService; newTpOperationalState = State.OutOfService; // Add TP and state outOfService to the links Map this.linksChanged.put(tpId, State.OutOfService); - // TODO: update change list for service handler notification + // Update topology change list for service handler notification + this.topologyChanges.put( + new OrdTopologyChangesKey(node.getNodeId().getValue() + "-" + tpId), + new OrdTopologyChangesBuilder() + .setId(node.getNodeId().getValue() + "-" + tpId) + .setState(newTpOperationalState) + .build()); break; case Degraded: LOG.warn("Operational state Degraded not handled"); @@ -905,6 +934,9 @@ public class NetworkModelServiceImpl implements NetworkModelService { private void updateLinkStates(Link link, State state, AdminStates adminStates) { // TODO: add change to list of changes + // Update topology change list + this.topologyChanges.put(new OrdTopologyChangesKey(link.getLinkId().getValue()), + new OrdTopologyChangesBuilder().setId(link.getLinkId().getValue()).setState(state).build()); org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1 link1 = new Link1Builder() .setOperationalState(state).setAdministrativeState(adminStates).build(); Link updLink = new LinkBuilder().withKey(link.key()).addAugmentation(link1).build(); @@ -921,4 +953,23 @@ public class NetworkModelServiceImpl implements NetworkModelService { LOG.error("Couldnt commit changed to openroadm topology. Error={}", e.getMessage()); } } + + @SuppressFBWarnings( + value = "UPM_UNCALLED_PRIVATE_METHOD", + justification = "false positive, this method is used by public updateOpenRoadmNetworkTopology") + private void sendNotification(TopologyNotificationTypes notificationType, + Map topologyChangesMap) { + if (topologyChangesMap.isEmpty()) { + LOG.warn("Empty Topology Change map. No updates in topology"); + return; + } + TopologyUpdateResultBuilder topologyUpdateResultBuilder = new TopologyUpdateResultBuilder() + .setNotificationType(notificationType).setOrdTopologyChanges(topologyChangesMap); + this.notification = topologyUpdateResultBuilder.build(); + try { + notificationPublishService.putNotification(this.notification); + } catch (InterruptedException e) { + LOG.error("Notification offer rejected. Error={}", e.getMessage()); + } + } }