Do not use RpcService in TPCE pce module 82/108082/4
authorGilles Thouenon <gilles.thouenon@orange.com>
Sun, 1 Oct 2023 08:23:23 +0000 (10:23 +0200)
committerguillaume.lambert <guillaume.lambert@orange.com>
Wed, 11 Oct 2023 11:40:57 +0000 (13:40 +0200)
- Migrate usage of RpcService to the new style yang.binding.Rpc-based
implementation for pce module
- Remove PceProvider class which no longer serves any purpose
- Adapt lighty implementation

JIRA: TRNSPRTPCE-752
Signed-off-by: Gilles Thouenon <gilles.thouenon@orange.com>
Change-Id: Ibb9f98aa7df493f7da76d8f210c90381e816b5db

lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java
pce/src/main/java/org/opendaylight/transportpce/pce/impl/PceProvider.java [deleted file]
pce/src/main/java/org/opendaylight/transportpce/pce/impl/PceServiceRPCImpl.java
pce/src/main/java/org/opendaylight/transportpce/pce/service/PathComputationServiceImpl.java
pce/src/test/java/org/opendaylight/transportpce/pce/impl/PceProviderTest.java [deleted file]
pce/src/test/java/org/opendaylight/transportpce/pce/impl/PceServiceRPCImplTest.java

index 739c34014afcbbdb98b52417e2902b8f6a1057b6..ff08a080deb8d236a9426adab31f1db447bb116e 100644 (file)
@@ -43,7 +43,6 @@ import org.opendaylight.transportpce.olm.OlmPowerServiceRpcImpl;
 import org.opendaylight.transportpce.olm.power.PowerMgmtImpl;
 import org.opendaylight.transportpce.olm.service.OlmPowerServiceImpl;
 import org.opendaylight.transportpce.pce.gnpy.consumer.GnpyConsumerImpl;
-import org.opendaylight.transportpce.pce.impl.PceProvider;
 import org.opendaylight.transportpce.pce.impl.PceServiceRPCImpl;
 import org.opendaylight.transportpce.pce.service.PathComputationService;
 import org.opendaylight.transportpce.pce.service.PathComputationServiceImpl;
@@ -89,8 +88,6 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
     // because implementation has additional public methods ...
     private final DeviceTransactionManagerImpl deviceTransactionManager;
     private final NetworkTransactionService networkTransaction;
-    // pce beans
-    private final PceProvider pceProvider;
     // network model beans
     private final NetworkModelProvider networkModelProvider;
     // service-handler beans
@@ -138,8 +135,9 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
                 new GnpyConsumerImpl(
                     "http://127.0.0.1:8008", "gnpy", "gnpy", lightyServices.getAdapterContext().currentSerializer()),
                 portMapping);
-        pceProvider = new PceProvider(lgServRPS, pathComputationService, new PceServiceRPCImpl(pathComputationService));
-
+        rpcRegistrations.add(
+            new PceServiceRPCImpl(lgServRPS, pathComputationService)
+                .getRegisteredRpc());
         LOG.info("Creating OLM beans ...");
         MappingUtils mappingUtils = new MappingUtilsImpl(lgServBDB);
         CrossConnect crossConnect = initCrossConnect(mappingUtils);
@@ -237,8 +235,6 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
         servicehandlerProvider.close();
         LOG.info("Shutting down network-model provider ...");
         networkModelProvider.close();
-        LOG.info("Shutting down PCE provider ...");
-        pceProvider.close();
         LOG.info("Shutting down transaction providers ...");
         deviceTransactionManager.preDestroy();
         LOG.info("Closing registered RPCs...");
diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/impl/PceProvider.java b/pce/src/main/java/org/opendaylight/transportpce/pce/impl/PceProvider.java
deleted file mode 100644 (file)
index 273c681..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright © 2017 AT&T, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.transportpce.pce.impl;
-
-import org.opendaylight.mdsal.binding.api.RpcProviderService;
-import org.opendaylight.transportpce.pce.service.PathComputationService;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.TransportpcePceService;
-import org.opendaylight.yangtools.concepts.ObjectRegistration;
-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;
-
-/*
- * Class to register
- * Pce Service & Notification.
- */
-@Component
-public class PceProvider {
-
-    private static final Logger LOG = LoggerFactory.getLogger(PceProvider.class);
-
-    private final RpcProviderService rpcService;
-    private ObjectRegistration<TransportpcePceService> rpcRegistration;
-
-    @Activate
-    public PceProvider(@Reference RpcProviderService rpcProviderService,
-            @Reference PathComputationService pathComputationService,
-            @Reference TransportpcePceService pceServiceRPCImpl) {
-        this.rpcService = rpcProviderService;
-        rpcRegistration = rpcService.registerRpcImplementation(TransportpcePceService.class, pceServiceRPCImpl);
-        LOG.info("PceProvider Session Initiated");
-    }
-
-    /*
-     * Method called when the blueprint container is destroyed.
-     */
-    @Deactivate
-    public void close() {
-        LOG.info("PceProvider Closed");
-        rpcRegistration.close();
-    }
-}
index b108b169a0be6f76c2b6e53eba075842c202bcc8..f742c2d70b34cfbb72b1158c64a304de427a15c4 100644 (file)
@@ -7,20 +7,28 @@
  */
 package org.opendaylight.transportpce.pce.impl;
 
+import com.google.common.collect.ImmutableClassToInstanceMap;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.concurrent.ExecutionException;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.transportpce.pce.service.PathComputationService;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.CancelResourceReserve;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.CancelResourceReserveInput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.CancelResourceReserveOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequest;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestInput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRerouteRequest;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRerouteRequestInput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRerouteRequestOutput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.TransportpcePceService;
+import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.binding.Rpc;
 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.Deactivate;
 import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -28,21 +36,35 @@ import org.slf4j.LoggerFactory;
 /**
  * PceService implementation.
  */
-@Component
+@Component(immediate = true)
 public class PceServiceRPCImpl implements TransportpcePceService {
 
     private static final Logger LOG = LoggerFactory.getLogger(PceServiceRPCImpl.class);
 
     private final PathComputationService pathComputationService;
+    private Registration reg;
 
     @Activate
-    public PceServiceRPCImpl(@Reference PathComputationService pathComputationService) {
+    public PceServiceRPCImpl(@Reference RpcProviderService rpcProviderService,
+            @Reference PathComputationService pathComputationService) {
         this.pathComputationService = pathComputationService;
+        this.reg = rpcProviderService.registerRpcImplementations(ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
+            .put(CancelResourceReserve.class, this::cancelResourceReserve)
+            .put(PathComputationRequest.class, this::pathComputationRequest)
+            .put(PathComputationRerouteRequest.class, this::pathComputationRerouteRequest)
+            .build());
+
         LOG.info("PceServiceRPCImpl instantiated");
     }
 
+    @Deactivate
+    public void close() {
+        this.reg.close();
+        LOG.info("PceServiceRPCImpl Closed");
+    }
+
     @Override
-    public ListenableFuture<RpcResult<CancelResourceReserveOutput>>
+    public final ListenableFuture<RpcResult<CancelResourceReserveOutput>>
             cancelResourceReserve(CancelResourceReserveInput input) {
         LOG.info("RPC cancelResourceReserve request received");
         try {
@@ -57,7 +79,7 @@ public class PceServiceRPCImpl implements TransportpcePceService {
     }
 
     @Override
-    public ListenableFuture<RpcResult<PathComputationRequestOutput>>
+    public final ListenableFuture<RpcResult<PathComputationRequestOutput>>
             pathComputationRequest(PathComputationRequestInput input) {
         LOG.info("RPC path computation request received");
         LOG.debug("input parameters are : input = {}", input);
@@ -73,7 +95,7 @@ public class PceServiceRPCImpl implements TransportpcePceService {
     }
 
     @Override
-    public ListenableFuture<RpcResult<PathComputationRerouteRequestOutput>> pathComputationRerouteRequest(
+    public final ListenableFuture<RpcResult<PathComputationRerouteRequestOutput>> pathComputationRerouteRequest(
             PathComputationRerouteRequestInput input) {
         LOG.info("RPC path computation reroute request received");
         LOG.debug("input parameters are : input = {}", input);
@@ -87,4 +109,8 @@ public class PceServiceRPCImpl implements TransportpcePceService {
             return RpcResultBuilder.success((PathComputationRerouteRequestOutput) null).buildFuture();
         }
     }
+
+    public Registration getRegisteredRpc() {
+        return reg;
+    }
 }
index 2b056f4fa777f6d7bc8e947976a7ea8a0a4c1628..3d34aa1d2d9bd5dabd6af21df692a334b605a19f 100644 (file)
@@ -82,7 +82,7 @@ public class PathComputationServiceImpl implements PathComputationService {
         this.executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(5));
         this.gnpyConsumer = gnpyConsumer;
         this.portMapping = portMapping;
-        LOG.debug("PathComputationServiceImpl instantiated");
+        LOG.info("PathComputationServiceImpl instantiated");
     }
 
     @SuppressFBWarnings(
diff --git a/pce/src/test/java/org/opendaylight/transportpce/pce/impl/PceProviderTest.java b/pce/src/test/java/org/opendaylight/transportpce/pce/impl/PceProviderTest.java
deleted file mode 100644 (file)
index 7d393b3..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright © 2020 Orange Labs, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.transportpce.pce.impl;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
-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.RpcProviderService;
-import org.opendaylight.transportpce.pce.service.PathComputationService;
-import org.opendaylight.transportpce.test.AbstractTest;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.TransportpcePceService;
-
-@ExtendWith(MockitoExtension.class)
-public class PceProviderTest extends AbstractTest {
-
-    @Mock
-    private RpcProviderService rpcService;
-    @Mock
-    private PathComputationService pathComputationService;
-    @Mock
-    private TransportpcePceService pceServiceRPCImpl;
-
-    @Test
-    void testInit() {
-        new PceProvider(rpcService, pathComputationService, pceServiceRPCImpl);
-        verify(rpcService, times(1)).registerRpcImplementation(any(), any(TransportpcePceService.class));
-    }
-}
index 6ebb56e10f5bcac1b0edb01daa70fbc328ecd8f3..36afe64203ccead2f1b350f89e2fea1409914cd9 100644 (file)
@@ -10,12 +10,18 @@ package org.opendaylight.transportpce.pce.impl;
 
 
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
 
 import java.util.concurrent.ExecutionException;
 import org.junit.jupiter.api.BeforeEach;
 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.RpcProviderService;
 import org.opendaylight.transportpce.common.mapping.PortMapping;
 import org.opendaylight.transportpce.common.network.NetworkTransactionImpl;
 import org.opendaylight.transportpce.pce.service.PathComputationService;
@@ -27,7 +33,7 @@ import org.opendaylight.transportpce.pce.utils.TransactionUtils;
 import org.opendaylight.transportpce.test.AbstractTest;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.CancelResourceReserveInputBuilder;
 
-
+@ExtendWith(MockitoExtension.class)
 public class PceServiceRPCImplTest extends AbstractTest {
 
     private PathComputationService pathComputationService;
@@ -36,6 +42,9 @@ public class PceServiceRPCImplTest extends AbstractTest {
     private PceServiceRPCImpl pceServiceRPC;
     @Mock
     private PortMapping portMapping;
+    @Mock
+    private RpcProviderService rpcProviderService;
+
 
     @BeforeEach
     void setUp() throws ExecutionException, InterruptedException {
@@ -45,7 +54,12 @@ public class PceServiceRPCImplTest extends AbstractTest {
         networkTransaction =  new NetworkTransactionImpl(getDataBroker());
         pathComputationService = new PathComputationServiceImpl(networkTransaction, notificationPublishService,
                 null, portMapping);
-        pceServiceRPC = new PceServiceRPCImpl(pathComputationService);
+        pceServiceRPC = new PceServiceRPCImpl(rpcProviderService, pathComputationService);
+    }
+
+    @Test
+    void testRpcRegistration() {
+        verify(rpcProviderService, times(1)).registerRpcImplementations(any());
     }
 
     @Test