X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=servicehandler%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fservicehandler%2Flisteners%2FNetworkModelListenerImpl.java;h=1aace331bbcf72b5b91f72ef417560fe39ab9eb5;hb=f327d205217ec8eefa4326881f8d06f1378db37a;hp=b1a162a3bf2abc6f5bfbb764bb65fdaaeaf2b824;hpb=5e3f7dd89cb088ef4957f5559a82b8c6436afa17;p=transportpce.git diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/NetworkModelListenerImpl.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/NetworkModelListenerImpl.java index b1a162a3b..1aace331b 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/NetworkModelListenerImpl.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/NetworkModelListenerImpl.java @@ -18,53 +18,59 @@ import org.opendaylight.mdsal.binding.api.NotificationPublishService; import org.opendaylight.transportpce.common.OperationResult; import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations; 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.TransportpceNetworkmodelListener; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkmodel.rev201116.topology.update.result.TopologyChanges; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkmodel.rev201116.topology.update.result.TopologyChangesKey; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State; -import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.list.Services; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.AToZDirection; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.AToZDirectionBuilder; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ZToADirection; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ZToADirectionBuilder; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZ; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZBuilder; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZKey; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ztoa.direction.ZToA; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ztoa.direction.ZToABuilder; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ztoa.direction.ZToAKey; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.Resource; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.ResourceBuilder; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.resource.TerminationPoint; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.list.Services; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.AToZDirection; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.AToZDirectionBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.ZToADirection; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.ZToADirectionBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.atoz.direction.AToZ; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.atoz.direction.AToZBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.atoz.direction.AToZKey; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.ztoa.direction.ZToA; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.ztoa.direction.ZToABuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.ztoa.direction.ZToAKey; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.Resource; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.ResourceBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.resource.resource.Link; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.resource.resource.TerminationPoint; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.service.path.PathDescription; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.service.path.PathDescriptionBuilder; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.ServicePathList; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class NetworkModelListenerImpl implements TransportpceNetworkmodelListener { +@Component +public class NetworkModelListenerImpl implements TransportpceNetworkmodelListener, NetworkListener { private static final Logger LOG = LoggerFactory.getLogger(NetworkModelListenerImpl.class); - private final NotificationPublishService notificationPublishService; // to be used for T-API notification private ServiceDataStoreOperations serviceDataStoreOperations; private TopologyUpdateResult topologyUpdateResult; - public NetworkModelListenerImpl(NotificationPublishService notificationPublishService, - ServiceDataStoreOperations serviceDataStoreOperations) { - this.notificationPublishService = notificationPublishService; + @Activate + public NetworkModelListenerImpl(@Reference NotificationPublishService notificationPublishService, + @Reference ServiceDataStoreOperations serviceDataStoreOperations) { this.serviceDataStoreOperations = serviceDataStoreOperations; } @Override public void onTopologyUpdateResult(TopologyUpdateResult notification) { - LOG.debug("Topology update notification: {}", notification.toString()); + LOG.debug("Topology update notification: {}", notification); if (compareTopologyUpdateResult(notification)) { LOG.warn("TopologyUpdateResult already wired !"); return; } - topologyUpdateResult = notification; + topologyUpdateResult = new TopologyUpdateResultBuilder() + .setTopologyChanges(new HashMap<>(notification.getTopologyChanges())) + .build(); // Update service datastore and service path description updateServicePaths(notification); } @@ -73,16 +79,15 @@ public class NetworkModelListenerImpl implements TransportpceNetworkmodelListene * Process topology update result. * @param notification the result notification. */ - private void updateServicePaths(TopologyUpdateResult notification) { + protected void updateServicePaths(TopologyUpdateResult notification) { @Nullable Map topologyChanges = notification.getTopologyChanges(); Optional servicePathListOptional = this.serviceDataStoreOperations.getServicePaths(); - ServicePathList servicePathList = null; - if (!servicePathListOptional.isPresent()) { + if (servicePathListOptional.isEmpty()) { LOG.warn("Enable to retrieve service path list"); return; } - servicePathList = servicePathListOptional.get(); + ServicePathList servicePathList = servicePathListOptional.orElseThrow(); for (ServicePaths servicePaths : servicePathList.getServicePaths().values()) { String serviceName = servicePaths.getServicePathName(); PathDescription pathDescription = servicePaths.getPathDescription(); @@ -98,60 +103,55 @@ public class NetworkModelListenerImpl implements TransportpceNetworkmodelListene // update service in the datastore. Only path description with all elements in service can have a service // in service. Therefore we check if all the states of the path description resources are inService Optional serviceOptional = this.serviceDataStoreOperations.getService(serviceName); - Services services = null; - if (!serviceOptional.isPresent()) { + if (serviceOptional.isEmpty()) { LOG.error("Couldn't retrieve service"); continue; } - services = serviceOptional.get(); - OperationResult operationResult1 = null; + Services services = serviceOptional.orElseThrow(); + State newState; switch (services.getOperationalState()) { case InService: - if (!allElementsinPathinService(updatedAtoZ, updatedZtoA)) { - LOG.debug("Service={} needs to be updated to outOfService", serviceName); - //if (operationResult1 != null && operationResult1.isSuccess()) { - //null check probably no more needed - if (this.serviceDataStoreOperations - .modifyService(serviceName, State.OutOfService, AdminStates.OutOfService) - .isSuccess()) { - LOG.info("Service state of {} correctly updated to outOfService in datastore", serviceName); - continue; - } else { - LOG.error("Service state of {} cannot be updated to outOfService in datastore", - serviceName); - } + if (allElementsinPathinService(updatedAtoZ, updatedZtoA)) { + LOG.debug("Service {} state does not need to be modified", serviceName); + continue; } + newState = State.OutOfService; break; case OutOfService: - if (allElementsinPathinService(updatedAtoZ, updatedZtoA)) { - LOG.debug("Service={} needs to be updated to inService", serviceName); - //if (operationResult1 != null && operationResult1.isSuccess()) { - //null check probably no more needed - if (this.serviceDataStoreOperations - .modifyService(serviceName, State.InService, AdminStates.InService) - .isSuccess()) { - LOG.info("Service state of {} correctly updated to inService in datastore", serviceName); - continue; - } else { - LOG.error("Service state of {} cannot be updated to inService in datastore", serviceName); - } + if (!allElementsinPathinService(updatedAtoZ, updatedZtoA)) { + LOG.debug("Service {} state does not need to be modified", serviceName); + continue; } + newState = State.InService; break; default: LOG.warn("Service {} state not managed", serviceName); continue; } - LOG.debug("Service {} state does not need to be modified", serviceName); + + + LOG.debug("Service={} needs to be updated to {}", serviceName, newState); + //if (operationResult1 != null && operationResult1.isSuccess()) { + //null check probably no more needed + if (this.serviceDataStoreOperations + .modifyService(serviceName, newState, services.getAdministrativeState()) + .isSuccess()) { + LOG.info("Service state of {} correctly updated to {} in datastore", serviceName, newState); + continue; + } + LOG.error("Service state of {} cannot be updated to {} in datastore", serviceName, newState); + } } - private Map changePathElementStateZA(Map topologyChanges, + protected Map changePathElementStateZA(Map topologyChanges, PathDescription pathDescription) { - Map newztoaMap = new HashMap<>(pathDescription.getZToADirection().getZToA()); List tpResources = pathDescription.getZToADirection().getZToA().values().stream() - .filter(ele -> ele.getResource().getResource().implementedInterface().getSimpleName() - .equals("TerminationPoint")) + .filter(ele -> ele.getResource().getResource() instanceof TerminationPoint) + .collect(Collectors.toList()); + List linkResources = pathDescription.getZToADirection().getZToA().values().stream() + .filter(ele -> ele.getResource().getResource() instanceof Link) .collect(Collectors.toList()); for (ZToA ztoA : tpResources) { String ztoAid = ztoA.getId(); @@ -172,18 +172,35 @@ public class NetworkModelListenerImpl implements TransportpceNetworkmodelListene .setResource(updatedResource) .build(); newztoaMap.put(updatedZToA.key(), updatedZToA); + for (ZToA ztoALink : linkResources) { + Link link = (Link)ztoALink.getResource().getResource(); + if (link.getLinkId().contains(tp.getTpNodeId()) + && link.getLinkId().contains(tp.getTpId()) + && ztoALink.getResource().getState() != updatedState) { + ZToA updatedZToAlink = new ZToABuilder(ztoALink) + .setId(ztoAid) + .setResource(new ResourceBuilder() + .setResource(link) + .setState(updatedState) + .build()) + .build(); + newztoaMap.put(updatedZToAlink.key(), updatedZToAlink); + } + } } } return newztoaMap; } - private Map changePathElementStateAZ(Map changePathElementStateAZ(Map topologyChanges, PathDescription pathDescription) { Map newatozMap = new HashMap<>(pathDescription.getAToZDirection().getAToZ()); List tpResources = pathDescription.getAToZDirection().getAToZ().values().stream() - .filter(ele -> ele.getResource().getResource().implementedInterface().getSimpleName() - .equals("TerminationPoint")) + .filter(ele -> ele.getResource().getResource() instanceof TerminationPoint) + .collect(Collectors.toList()); + List linkResources = pathDescription.getAToZDirection().getAToZ().values().stream() + .filter(ele -> ele.getResource().getResource() instanceof Link) .collect(Collectors.toList()); for (AToZ atoZ : tpResources) { String atoZid = atoZ.getId(); @@ -204,6 +221,21 @@ public class NetworkModelListenerImpl implements TransportpceNetworkmodelListene .setResource(updatedResource) .build(); newatozMap.put(updatedAToZ.key(), updatedAToZ); + for (AToZ atozLink : linkResources) { + Link link = (Link)atozLink.getResource().getResource(); + if (link.getLinkId().contains(tp.getTpNodeId()) + && link.getLinkId().contains(tp.getTpId()) + && atozLink.getResource().getState() != updatedState) { + AToZ updatedAToZlink = new AToZBuilder(atozLink) + .setId(atoZid) + .setResource(new ResourceBuilder() + .setResource(link) + .setState(updatedState) + .build()) + .build(); + newatozMap.put(updatedAToZlink.key(), updatedAToZlink); + } + } } } return newatozMap; @@ -223,7 +255,7 @@ public class NetworkModelListenerImpl implements TransportpceNetworkmodelListene .build(); } - private boolean allElementsinPathinService(Map updatedAtoZ, Map updatedZtoA) { + protected boolean allElementsinPathinService(Map updatedAtoZ, Map updatedZtoA) { boolean allEleminService = true; Iterator i1 = updatedAtoZ.values().iterator(); Iterator i2 = updatedZtoA.values().iterator(); @@ -240,16 +272,11 @@ public class NetworkModelListenerImpl implements TransportpceNetworkmodelListene } private boolean compareTopologyUpdateResult(TopologyUpdateResult notification) { - if (topologyUpdateResult == null) { - return false; - } - if (topologyUpdateResult.getTopologyChanges().values() - .equals(notification.getTopologyChanges().values())) { - return false; - } - return true; + return topologyUpdateResult != null + && topologyUpdateResult.getTopologyChanges().equals(notification.getTopologyChanges()); } + @Override public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) { this.serviceDataStoreOperations = serviceData; }