Turn NetworkUtilsImpl into a Component 89/108389/2
authorGilles Thouenon <gilles.thouenon@orange.com>
Wed, 27 Sep 2023 15:34:37 +0000 (17:34 +0200)
committerGilles Thouenon <gilles.thouenon@orange.com>
Fri, 13 Oct 2023 09:32:29 +0000 (09:32 +0000)
Instead of instanciating this implementation from NetworkModelProvider,
convert it into a simple component.

Signed-off-by: Gilles Thouenon <gilles.thouenon@orange.com>
Change-Id: Ie051ab82455d5d17864bfde5049f6f2b5c6f8e5a

lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/NetworkModelProvider.java
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/NetworkUtilsImpl.java
networkmodel/src/test/java/org/opendaylight/transportpce/networkmodel/NetworkModelProviderTest.java

index db80fd3c0286b2465a4548af672ec9adbfc7b496..93308a42b0e784b3b35e6037bedf205f4ca41a2c 100644 (file)
@@ -32,6 +32,7 @@ import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfa
 import org.opendaylight.transportpce.nbinotifications.impl.NbiNotificationsProvider;
 import org.opendaylight.transportpce.networkmodel.NetConfTopologyListener;
 import org.opendaylight.transportpce.networkmodel.NetworkModelProvider;
+import org.opendaylight.transportpce.networkmodel.NetworkUtilsImpl;
 import org.opendaylight.transportpce.networkmodel.listeners.PortMappingListener;
 import org.opendaylight.transportpce.networkmodel.service.FrequenciesServiceImpl;
 import org.opendaylight.transportpce.networkmodel.service.NetworkModelService;
@@ -128,7 +129,8 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
                 lgServRPS,
                 networkModelService, deviceTransactionManager, portMapping,
                 lgServNS,
-                new FrequenciesServiceImpl(lgServBDB));
+                new FrequenciesServiceImpl(lgServBDB),
+                new NetworkUtilsImpl(lgServBDB));
 
         LOG.info("Creating PCE beans ...");
         // TODO: pass those parameters through command line
index a1c359452bed1a0c0172a55a1ba5dd54a0e0e94b..0eafd00f110bdccfff67998b72a647e4278a1ac1 100644 (file)
@@ -69,13 +69,14 @@ public class NetworkModelProvider {
             @Reference DeviceTransactionManager deviceTransactionManager,
             @Reference PortMapping portMapping,
             @Reference NotificationService notificationService,
-            @Reference FrequenciesService frequenciesService) {
+            @Reference FrequenciesService frequenciesService,
+            @Reference TransportpceNetworkutilsService networkUtils) {
         this.dataBroker = dataBroker;
         this.rpcProviderService = rpcProviderService;
         this.notificationService = notificationService;
         this.frequenciesService = frequenciesService;
         this.listeners = new ArrayList<>();
-        this.networkutilsService = new NetworkUtilsImpl(dataBroker);
+        this.networkutilsService = networkUtils;
         this.topologyListener = new NetConfTopologyListener(networkModelService, dataBroker, deviceTransactionManager,
             portMapping);
         this.tpceNetwork = new TpceNetwork(networkTransactionService);
index b954aa37e3162d7b661a8d098016b8a626e5ea4c..c75b62d22ba83ca79d2dabb282d597292d6421c2 100644 (file)
@@ -39,16 +39,22 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.top
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+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;
 
+@Component
 public class NetworkUtilsImpl implements TransportpceNetworkutilsService {
 
     private static final Logger LOG = LoggerFactory.getLogger(NetworkUtilsImpl.class);
     private final DataBroker dataBroker;
 
-    public NetworkUtilsImpl(DataBroker dataBroker) {
+    @Activate
+    public NetworkUtilsImpl(@Reference DataBroker dataBroker) {
         this.dataBroker = dataBroker;
+        LOG.info("NetworkUtilsImpl instanciated");
     }
 
     @Override
index 8d5ba9f8c6867aed38f1111c9152721c31728d77..c0ff6eccac8859694be50cfa848b1ee6d886b684 100644 (file)
@@ -50,7 +50,8 @@ public class NetworkModelProviderTest {
     NotificationService notificationService;
     @Mock
     FrequenciesService frequenciesService;
-
+    @Mock
+    TransportpceNetworkutilsService networkUtils;
 
     @Test
     void networkmodelProviderInitTest() {
@@ -65,7 +66,7 @@ public class NetworkModelProviderTest {
         when(networkTransactionService.commit()).then(answer);
 
         new NetworkModelProvider(networkTransactionService, dataBroker, rpcProviderService, networkModelService,
-                deviceTransactionManager, portMapping, notificationService, frequenciesService);
+                deviceTransactionManager, portMapping, notificationService, frequenciesService, networkUtils);
 
         verify(rpcProviderService, times(1))
             .registerRpcImplementation(any(), any(TransportpceNetworkutilsService.class));