From 5e89fe2242ea395f6aee61b1f060c7b6183aeb27 Mon Sep 17 00:00:00 2001 From: Gilles Thouenon Date: Thu, 16 Mar 2023 13:37:32 +0100 Subject: [PATCH] Remove tapi-blueprint.xml file - Convert TapiProvider to OSGI DS. - Adapt TapiProviderTest accordingly. JIRA: TRNSPRTPCE-736 Signed-off-by: Gilles Thouenon Change-Id: I1e4ece95c9604d56d8eb00300866d1d5f5359fbe (cherry picked from commit 40f7b65724bf8057eb16cd544b5135c9fdb36606) --- .../tpce/module/TransportPCEImpl.java | 47 +++------- .../transportpce/tapi/impl/TapiProvider.java | 90 +++++++++--------- .../OSGI-INF/blueprint/tapi-blueprint.xml | 93 ------------------- .../tapi/provider/TapiProviderTest.java | 42 +++------ 4 files changed, 70 insertions(+), 202 deletions(-) delete mode 100644 tapi/src/main/resources/OSGI-INF/blueprint/tapi-blueprint.xml diff --git a/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java b/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java index f88c16ad1..19b5523a5 100644 --- a/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java +++ b/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java @@ -9,9 +9,10 @@ package io.lighty.controllers.tpce.module; import io.lighty.core.controller.api.AbstractLightyModule; import io.lighty.core.controller.api.LightyServices; + import java.util.Arrays; import java.util.List; -import org.opendaylight.mdsal.binding.api.NotificationService; + import org.opendaylight.transportpce.common.crossconnect.CrossConnect; import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl; import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl121; @@ -73,18 +74,11 @@ import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOper import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl; import org.opendaylight.transportpce.tapi.impl.TapiProvider; import org.opendaylight.transportpce.tapi.listeners.TapiNetworkModelListenerImpl; -import org.opendaylight.transportpce.tapi.listeners.TapiPceListenerImpl; -import org.opendaylight.transportpce.tapi.listeners.TapiRendererListenerImpl; -import org.opendaylight.transportpce.tapi.listeners.TapiServiceHandlerListenerImpl; -import org.opendaylight.transportpce.tapi.topology.TapiNetconfTopologyListener; import org.opendaylight.transportpce.tapi.topology.TapiNetworkModelService; import org.opendaylight.transportpce.tapi.topology.TapiNetworkModelServiceImpl; import org.opendaylight.transportpce.tapi.topology.TapiNetworkUtilsImpl; -import org.opendaylight.transportpce.tapi.topology.TapiOrLinkListener; -import org.opendaylight.transportpce.tapi.topology.TapiPortMappingListener; import org.opendaylight.transportpce.tapi.utils.TapiLink; import org.opendaylight.transportpce.tapi.utils.TapiLinkImpl; -import org.opendaylight.transportpce.tapi.utils.TapiListener; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.TransportpceOlmService; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.tapinetworkutils.rev210408.TransportpceTapinetworkutilsService; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.OrgOpenroadmServiceService; @@ -199,28 +193,16 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP if (activateTapi) { LOG.info("Creating tapi beans ..."); TapiLink tapiLink = new TapiLinkImpl(networkTransaction); - TapiRendererListenerImpl tapiRendererListenerImpl = new TapiRendererListenerImpl(lightyServices - .getBindingDataBroker(), lightyServices.getBindingNotificationPublishService()); - TapiPceListenerImpl tapiPceListenerImpl = new TapiPceListenerImpl(lightyServices.getBindingDataBroker()); - TapiServiceHandlerListenerImpl tapiServiceHandlerListener = new TapiServiceHandlerListenerImpl( - lightyServices.getBindingDataBroker()); - TransportpceTapinetworkutilsService tapiNetworkutilsServiceImpl = new TapiNetworkUtilsImpl( - networkTransaction, tapiLink); + new TapiNetworkUtilsImpl(networkTransaction, tapiLink); TapiNetworkModelService tapiNetworkModelService = new TapiNetworkModelServiceImpl(networkTransaction, deviceTransactionManager, tapiLink, lightyServices.getBindingNotificationPublishService()); - TapiNetconfTopologyListener tapiNetConfTopologyListener = - new TapiNetconfTopologyListener(tapiNetworkModelService); - TapiOrLinkListener orLinkListener = new TapiOrLinkListener(tapiLink, networkTransaction); - TapiPortMappingListener tapiPortMappingListener = - new TapiPortMappingListener(tapiNetworkModelService); TapiNetworkModelListenerImpl tapiNetworkModelListenerImpl = new TapiNetworkModelListenerImpl(networkTransaction, lightyServices.getBindingNotificationPublishService()); tapiProvider = initTapi(lightyServices, servicehandler, networkTransaction, serviceDataStoreOperations, - tapiNetConfTopologyListener, tapiPortMappingListener, tapiNetworkutilsServiceImpl, - tapiPceListenerImpl, tapiRendererListenerImpl, tapiServiceHandlerListener, - lightyServices.getNotificationService(), orLinkListener, tapiNetworkModelListenerImpl); + tapiNetworkModelListenerImpl, tapiLink, tapiNetworkModelService); + } if (activateNbiNotification) { LOG.info("Creating nbi-notifications beans ..."); @@ -235,7 +217,6 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP protected boolean initProcedure() { if (tapiProvider != null) { LOG.info("Initializing tapi provider ..."); - tapiProvider.init(); } if (nbiNotificationsProvider != null) { LOG.info("Initializing nbi-notifications provider ..."); @@ -273,18 +254,14 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP private TapiProvider initTapi(LightyServices lightyServices, OrgOpenroadmServiceService servicehandler, NetworkTransactionService networkTransactionService, ServiceDataStoreOperations serviceDataStoreOperations, - TapiNetconfTopologyListener tapiNetConfTopologyListener, - TapiPortMappingListener tapiPortMappingListener, - TransportpceTapinetworkutilsService tapiNetworkutilsServiceImpl, - TapiPceListenerImpl pceListenerImpl, TapiRendererListenerImpl rendererListenerImpl, - TapiServiceHandlerListenerImpl serviceHandlerListenerImpl, - NotificationService notificationService, TapiOrLinkListener orLinkListener, - TapiNetworkModelListenerImpl tapiNetworkModelListenerImpl) { + TapiNetworkModelListenerImpl tapiNetworkModelListenerImpl, + TapiLink tapiLink, TapiNetworkModelService tapiNetworkModelService) { + TransportpceTapinetworkutilsService tapiNetworkUtils = new TapiNetworkUtilsImpl(networkTransactionService, + tapiLink); return new TapiProvider(lightyServices.getBindingDataBroker(), lightyServices.getRpcProviderService(), - servicehandler, serviceDataStoreOperations, new TapiListener(), networkTransactionService, - tapiNetConfTopologyListener, tapiPortMappingListener, tapiNetworkutilsServiceImpl, pceListenerImpl, - rendererListenerImpl, serviceHandlerListenerImpl, notificationService, orLinkListener, - tapiNetworkModelListenerImpl); + lightyServices.getNotificationService(), lightyServices.getBindingNotificationPublishService(), + networkTransactionService, servicehandler, serviceDataStoreOperations, tapiNetworkUtils, + tapiNetworkModelListenerImpl, tapiNetworkModelService); } private RendererProvider initRenderer(LightyServices lightyServices, TransportpceOlmService olmPowerServiceRpc, diff --git a/tapi/src/main/java/org/opendaylight/transportpce/tapi/impl/TapiProvider.java b/tapi/src/main/java/org/opendaylight/transportpce/tapi/impl/TapiProvider.java index 426544c25..8ce95c339 100644 --- a/tapi/src/main/java/org/opendaylight/transportpce/tapi/impl/TapiProvider.java +++ b/tapi/src/main/java/org/opendaylight/transportpce/tapi/impl/TapiProvider.java @@ -8,9 +8,9 @@ package org.opendaylight.transportpce.tapi.impl; import java.util.HashMap; -import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.mdsal.binding.api.DataBroker; import org.opendaylight.mdsal.binding.api.DataTreeIdentifier; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; import org.opendaylight.mdsal.binding.api.NotificationService; import org.opendaylight.mdsal.binding.api.RpcProviderService; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; @@ -24,6 +24,7 @@ import org.opendaylight.transportpce.tapi.listeners.TapiPceListenerImpl; import org.opendaylight.transportpce.tapi.listeners.TapiRendererListenerImpl; import org.opendaylight.transportpce.tapi.listeners.TapiServiceHandlerListenerImpl; import org.opendaylight.transportpce.tapi.topology.TapiNetconfTopologyListener; +import org.opendaylight.transportpce.tapi.topology.TapiNetworkModelService; import org.opendaylight.transportpce.tapi.topology.TapiOrLinkListener; import org.opendaylight.transportpce.tapi.topology.TapiPortMappingListener; import org.opendaylight.transportpce.tapi.topology.TapiTopologyImpl; @@ -54,6 +55,10 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology. import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.concepts.ObjectRegistration; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,6 +68,7 @@ import org.slf4j.LoggerFactory; * @author Gilles Thouenon (gilles.thouenon@orange.com) on behalf of Orange * */ +@Component public class TapiProvider { private static final Logger LOG = LoggerFactory.getLogger(TapiProvider.class); @@ -76,6 +82,12 @@ public class TapiProvider { .child(Link.class); private final DataBroker dataBroker; private final RpcProviderService rpcProviderService; + private final NotificationService notificationService; + private final NetworkTransactionService networkTransactionService; + private final OrgOpenroadmServiceService serviceHandler; + private final ServiceDataStoreOperations serviceDataStoreOperations; + private final TransportpceTapinetworkutilsService tapiNetworkUtils; + private TapiNotificationListener tapiNetworkModelListenerImpl; private ObjectRegistration rpcRegistration; private ObjectRegistration tapiNetworkutilsServiceRpcRegistration; private ListenerRegistration dataTreeChangeListenerRegistration; @@ -85,50 +97,27 @@ public class TapiProvider { private ListenerRegistration rendererlistenerRegistration; private ListenerRegistration servicehandlerlistenerRegistration; private ListenerRegistration tapinetworkmodellistenerRegistration; - private final OrgOpenroadmServiceService serviceHandler; - private final ServiceDataStoreOperations serviceDataStoreOperations; - private final TapiListener tapiListener; - private final TapiNetconfTopologyListener topologyListener; - private final TapiOrLinkListener orLinkListener; - private TapiPortMappingListener tapiPortMappingListener; - private final NetworkTransactionService networkTransactionService; - private final TransportpceTapinetworkutilsService tapiNetworkUtils; - private TapiPceListenerImpl pceListenerImpl; - private TapiRendererListenerImpl rendererListenerImpl; - private TapiServiceHandlerListenerImpl serviceHandlerListenerImpl; - private final NotificationService notificationService; - private TapiNotificationListener tapiNetworkModelListenerImpl; - public TapiProvider(DataBroker dataBroker, RpcProviderService rpcProviderService, - OrgOpenroadmServiceService serviceHandler,ServiceDataStoreOperations serviceDataStoreOperations, - TapiListener tapiListener, NetworkTransactionService networkTransactionService, - TapiNetconfTopologyListener topologyListener, TapiPortMappingListener tapiPortMappingListener, - TransportpceTapinetworkutilsService tapiNetworkUtils, TapiPceListenerImpl pceListenerImpl, - TapiRendererListenerImpl rendererListenerImpl, TapiServiceHandlerListenerImpl serviceHandlerListenerImpl, - NotificationService notificationService, TapiOrLinkListener orLinkListener, - TapiNotificationListener tapiNetworkModelListenerImpl) { + @Activate + public TapiProvider(@Reference DataBroker dataBroker, + @Reference RpcProviderService rpcProviderService, + @Reference NotificationService notificationService, + @Reference NotificationPublishService notificationPublishService, + @Reference NetworkTransactionService networkTransactionService, + @Reference OrgOpenroadmServiceService serviceHandler, + @Reference ServiceDataStoreOperations serviceDataStoreOperations, + @Reference TransportpceTapinetworkutilsService tapiNetworkUtils, + @Reference TapiNotificationListener tapiNetworkModelListenerImpl, + @Reference TapiNetworkModelService tapiNetworkModelServiceImpl) { this.dataBroker = dataBroker; this.rpcProviderService = rpcProviderService; + this.notificationService = notificationService; + this.networkTransactionService = networkTransactionService; this.serviceHandler = serviceHandler; this.serviceDataStoreOperations = serviceDataStoreOperations; - this.tapiListener = tapiListener; - this.networkTransactionService = networkTransactionService; - this.topologyListener = topologyListener; - this.tapiPortMappingListener = tapiPortMappingListener; this.tapiNetworkUtils = tapiNetworkUtils; - this.pceListenerImpl = pceListenerImpl; - this.rendererListenerImpl = rendererListenerImpl; - this.serviceHandlerListenerImpl = serviceHandlerListenerImpl; - this.notificationService = notificationService; - this.orLinkListener = orLinkListener; this.tapiNetworkModelListenerImpl = tapiNetworkModelListenerImpl; - //this.notificationPublishService = notificationPublishService; - } - /** - * Method called when the blueprint container is created. - */ - public void init() { LOG.info("TapiProvider Session Initiated"); TapiContext tapiContext = new TapiContext(this.networkTransactionService); LOG.info("Empty TAPI context created: {}", tapiContext.getTapiContext()); @@ -140,6 +129,9 @@ public class TapiProvider { tapiContext, this.serviceDataStoreOperations); tapiInitialORMapping.performTopoInitialMapping(); tapiInitialORMapping.performServInitialMapping(); + TapiPceListenerImpl pceListenerImpl = new TapiPceListenerImpl(dataBroker); + TapiRendererListenerImpl rendererListenerImpl = new TapiRendererListenerImpl(dataBroker, + notificationPublishService); TapiConnectivityImpl tapi = new TapiConnectivityImpl(this.serviceHandler, tapiContext, connectivityUtils, pceListenerImpl, rendererListenerImpl); @@ -148,6 +140,10 @@ public class TapiProvider { rpcRegistration = rpcProviderService.registerRpcImplementation(TapiConnectivityService.class, tapi); rpcProviderService.registerRpcImplementation(TapiTopologyService.class, topo); rpcProviderService.registerRpcImplementation(TapiCommonService.class, topo); + + TapiNetconfTopologyListener topologyListener = new TapiNetconfTopologyListener(tapiNetworkModelServiceImpl); + TapiOrLinkListener orLinkListener = new TapiOrLinkListener(tapiLink, networkTransactionService); + TapiPortMappingListener tapiPortMappingListener = new TapiPortMappingListener(tapiNetworkModelServiceImpl); dataTreeChangeListenerRegistration1 = dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, LINK_II), orLinkListener); @@ -160,22 +156,26 @@ public class TapiProvider { tapiNetworkutilsServiceRpcRegistration = rpcProviderService.registerRpcImplementation(TransportpceTapinetworkutilsService.class, this.tapiNetworkUtils); - @NonNull - InstanceIdentifier sipIID = InstanceIdentifier.create(ServiceInterfacePoints.class); - dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create( - LogicalDatastoreType.CONFIGURATION, sipIID), tapiListener); + TapiListener tapiListener = new TapiListener(); + dataBroker.registerDataTreeChangeListener( + DataTreeIdentifier.create( + LogicalDatastoreType.CONFIGURATION, + InstanceIdentifier.create(ServiceInterfacePoints.class)), + tapiListener); // Notification Listener pcelistenerRegistration = notificationService.registerNotificationListener(pceListenerImpl); rendererlistenerRegistration = notificationService.registerNotificationListener(rendererListenerImpl); - servicehandlerlistenerRegistration = - notificationService.registerNotificationListener(serviceHandlerListenerImpl); - tapinetworkmodellistenerRegistration = - notificationService.registerNotificationListener(tapiNetworkModelListenerImpl); + TapiServiceHandlerListenerImpl serviceHandlerListenerImpl = new TapiServiceHandlerListenerImpl(dataBroker); + servicehandlerlistenerRegistration = notificationService + .registerNotificationListener(serviceHandlerListenerImpl); + tapinetworkmodellistenerRegistration = notificationService + .registerNotificationListener(tapiNetworkModelListenerImpl); } /** * Method called when the blueprint container is destroyed. */ + @Deactivate public void close() { LOG.info("TapiProvider Session Closed"); if (dataTreeChangeListenerRegistration != null) { diff --git a/tapi/src/main/resources/OSGI-INF/blueprint/tapi-blueprint.xml b/tapi/src/main/resources/OSGI-INF/blueprint/tapi-blueprint.xml deleted file mode 100644 index 8c9a568fd..000000000 --- a/tapi/src/main/resources/OSGI-INF/blueprint/tapi-blueprint.xml +++ /dev/null @@ -1,93 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tapi/src/test/java/org/opendaylight/transportpce/tapi/provider/TapiProviderTest.java b/tapi/src/test/java/org/opendaylight/transportpce/tapi/provider/TapiProviderTest.java index 76077e6fb..9427914c4 100644 --- a/tapi/src/test/java/org/opendaylight/transportpce/tapi/provider/TapiProviderTest.java +++ b/tapi/src/test/java/org/opendaylight/transportpce/tapi/provider/TapiProviderTest.java @@ -16,24 +16,20 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.mdsal.binding.api.NotificationService; import org.opendaylight.mdsal.binding.api.RpcProviderService; import org.opendaylight.transportpce.common.network.NetworkTransactionImpl; import org.opendaylight.transportpce.common.network.NetworkTransactionService; import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations; import org.opendaylight.transportpce.tapi.impl.TapiProvider; -import org.opendaylight.transportpce.tapi.listeners.TapiNetworkModelListenerImpl; -import org.opendaylight.transportpce.tapi.listeners.TapiPceListenerImpl; -import org.opendaylight.transportpce.tapi.listeners.TapiRendererListenerImpl; -import org.opendaylight.transportpce.tapi.listeners.TapiServiceHandlerListenerImpl; -import org.opendaylight.transportpce.tapi.topology.TapiNetconfTopologyListener; -import org.opendaylight.transportpce.tapi.topology.TapiOrLinkListener; -import org.opendaylight.transportpce.tapi.topology.TapiPortMappingListener; -import org.opendaylight.transportpce.tapi.utils.TapiListener; +import org.opendaylight.transportpce.tapi.topology.TapiNetworkModelService; import org.opendaylight.transportpce.test.AbstractTest; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.tapinetworkutils.rev210408.TransportpceTapinetworkutilsService; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.OrgOpenroadmServiceService; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.TapiCommonService; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.TapiConnectivityService; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.TapiNotificationListener; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.TapiTopologyService; @ExtendWith(MockitoExtension.class) @@ -43,28 +39,19 @@ public class TapiProviderTest extends AbstractTest { @Mock private RpcProviderService rpcProviderRegistry; @Mock + private NotificationService notificationService; + @Mock + private NotificationPublishService notificationPublishService; + @Mock private OrgOpenroadmServiceService serviceHandler; @Mock private ServiceDataStoreOperations serviceDataStoreOperations; @Mock - private TapiListener tapiListener; - @Mock private TransportpceTapinetworkutilsService tapiNetworkUtils; @Mock - private TapiPortMappingListener tapiPortMappingListener; - @Mock - private TapiNetconfTopologyListener topologyListener; - @Mock - private TapiOrLinkListener orLinkListener; + private TapiNotificationListener tapiNetworkModelListenerImpl; @Mock - private TapiPceListenerImpl pceListenerImpl; - @Mock - private TapiRendererListenerImpl rendererListenerImpl; - @Mock - private TapiServiceHandlerListenerImpl serviceHandlerListenerImpl; - @Mock - private TapiNetworkModelListenerImpl networkModelListener; - + private TapiNetworkModelService tapiNetworkModelServiceImpl; @BeforeAll static void setUp() { @@ -73,12 +60,9 @@ public class TapiProviderTest extends AbstractTest { @Test void testInitRegisterTapiToRpcRegistry() { - TapiProvider provider = new TapiProvider(getDataBroker(), rpcProviderRegistry, serviceHandler, - serviceDataStoreOperations, tapiListener, networkTransactionService, topologyListener, - tapiPortMappingListener, tapiNetworkUtils, pceListenerImpl, rendererListenerImpl, - serviceHandlerListenerImpl, getNotificationService(), orLinkListener, networkModelListener); - - provider.init(); + TapiProvider provider = new TapiProvider(getDataBroker(), rpcProviderRegistry, notificationService, + notificationPublishService, networkTransactionService, serviceHandler, serviceDataStoreOperations, + tapiNetworkUtils, tapiNetworkModelListenerImpl, tapiNetworkModelServiceImpl); verify(rpcProviderRegistry, times(1)).registerRpcImplementation(any(), any(TapiConnectivityService.class)); verify(rpcProviderRegistry, times(2)).registerRpcImplementation(any(), any(TapiTopologyService.class)); -- 2.36.6