Do not use RpcService in TPCE olm module 40/108040/3
authorGilles Thouenon <gilles.thouenon@orange.com>
Fri, 29 Sep 2023 11:56:34 +0000 (13:56 +0200)
committerGilles Thouenon <gilles.thouenon@orange.com>
Sat, 30 Sep 2023 09:39:03 +0000 (11:39 +0200)
- Migrate usage of RpcService to the new style yang.binding.Rpc-based
implementation for olm module
- Remove olm provider which no longer serves any purpose
- Adapt lighty implementation

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

lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java
olm/src/main/java/org/opendaylight/transportpce/olm/OlmPowerServiceRpcImpl.java
olm/src/main/java/org/opendaylight/transportpce/olm/OlmProvider.java [deleted file]
olm/src/test/java/org/opendaylight/transportpce/olm/OlmPowerServiceRpcImplTest.java

index f0f17c0a74011d303db83b4eda3499da448d547c..8a3db47e36062f2e32904733874cf1bd86ef720e 100644 (file)
@@ -9,6 +9,8 @@ package io.lighty.controllers.tpce.module;
 
 import io.lighty.core.controller.api.AbstractLightyModule;
 import io.lighty.core.controller.api.LightyServices;
+import java.util.ArrayList;
+import java.util.List;
 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl121;
@@ -38,7 +40,6 @@ import org.opendaylight.transportpce.networkmodel.service.FrequenciesServiceImpl
 import org.opendaylight.transportpce.networkmodel.service.NetworkModelService;
 import org.opendaylight.transportpce.networkmodel.service.NetworkModelServiceImpl;
 import org.opendaylight.transportpce.olm.OlmPowerServiceRpcImpl;
-import org.opendaylight.transportpce.olm.OlmProvider;
 import org.opendaylight.transportpce.olm.power.PowerMgmtImpl;
 import org.opendaylight.transportpce.olm.service.OlmPowerServiceImpl;
 import org.opendaylight.transportpce.pce.gnpy.consumer.GnpyConsumerImpl;
@@ -75,6 +76,7 @@ import org.opendaylight.transportpce.tapi.utils.TapiLink;
 import org.opendaylight.transportpce.tapi.utils.TapiLinkImpl;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.TransportpceOlmService;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.OrgOpenroadmServiceService;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -91,8 +93,6 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
     private final PceProvider pceProvider;
     // network model beans
     private final NetworkModelProvider networkModelProvider;
-    // OLM beans
-    private final OlmProvider olmProvider;
     // renderer beans
     private final RendererProvider rendererProvider;
     // service-handler beans
@@ -101,6 +101,7 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
     private TapiProvider tapiProvider;
     // nbi-notifications beans
     private NbiNotificationsProvider nbiNotificationsProvider;
+    private List<Registration> rpcRegistrations = new ArrayList<>();
 
     public TransportPCEImpl(
             LightyServices lightyServices, boolean activateNbiNotification, boolean activateTapi,
@@ -145,14 +146,15 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
         MappingUtils mappingUtils = new MappingUtilsImpl(lgServBDB);
         CrossConnect crossConnect = initCrossConnect(mappingUtils);
         OpenRoadmInterfaces openRoadmInterfaces = initOpenRoadmInterfaces(mappingUtils, portMapping);
-        TransportpceOlmService olmPowerServiceRpc = new OlmPowerServiceRpcImpl(
+        OlmPowerServiceRpcImpl olmPowerServiceRpc = new OlmPowerServiceRpcImpl(
             new OlmPowerServiceImpl(
                 lgServBDB,
                 new PowerMgmtImpl(
                     openRoadmInterfaces, crossConnect, deviceTransactionManager,
                     portMapping, Long.valueOf(olmtimer1).longValue(), Long.valueOf(olmtimer2).longValue()),
-                deviceTransactionManager, portMapping, mappingUtils, openRoadmInterfaces));
-        olmProvider = new OlmProvider(lgServRPS, olmPowerServiceRpc);
+                deviceTransactionManager, portMapping, mappingUtils, openRoadmInterfaces),
+            lgServRPS);
+        rpcRegistrations.add(olmPowerServiceRpc.getRegisteredRpc());
         LOG.info("Creating renderer beans ...");
         initOpenRoadmFactory(mappingUtils, openRoadmInterfaces, portMapping);
         DeviceRendererService deviceRendererService = new DeviceRendererServiceImpl(
@@ -238,14 +240,16 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
         servicehandlerProvider.close();
         LOG.info("Shutting down renderer provider ...");
         rendererProvider.close();
-        LOG.info("Shutting down OLM provider ...");
-        olmProvider.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...");
+        for (Registration reg : rpcRegistrations) {
+            reg.close();
+        }
         LOG.info("Shutdown done.");
         return true;
     }
index 09e82845f436c2495cbdb76571b55ffd58d0fd4f..5f01d43b3219cf6040933dec97b203349b9ab6ab 100644 (file)
@@ -8,26 +8,37 @@
 
 package org.opendaylight.transportpce.olm;
 
+import com.google.common.collect.ImmutableClassToInstanceMap;
 import com.google.common.util.concurrent.ListenableFuture;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.transportpce.olm.service.OlmPowerService;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBase;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBaseInput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBaseOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrent;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentInput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPm;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmInput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerReset;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerResetInput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerResetOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetup;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndown;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownInput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.TransportpceOlmService;
+import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.binding.Rpc;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 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;
@@ -39,10 +50,27 @@ import org.slf4j.LoggerFactory;
 public class OlmPowerServiceRpcImpl implements TransportpceOlmService {
     private static final Logger LOG = LoggerFactory.getLogger(OlmPowerServiceRpcImpl.class);
     private final OlmPowerService olmPowerService;
+    private Registration reg;
 
     @Activate
-    public OlmPowerServiceRpcImpl(@Reference OlmPowerService olmPowerService) {
+    public OlmPowerServiceRpcImpl(@Reference OlmPowerService olmPowerService,
+            @Reference RpcProviderService rpcProviderService) {
         this.olmPowerService = olmPowerService;
+        this.reg = rpcProviderService.registerRpcImplementations(ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
+            .put(GetPm.class, this::getPm)
+            .put(ServicePowerSetup.class, this::servicePowerSetup)
+            .put(ServicePowerTurndown.class, this::servicePowerTurndown)
+            .put(CalculateSpanlossBase.class, this::calculateSpanlossBase)
+            .put(CalculateSpanlossCurrent.class, this::calculateSpanlossCurrent)
+            .put(ServicePowerReset.class, this::servicePowerReset)
+            .build());
+        LOG.info("OlmPowerServiceRpcImpl instantiated");
+    }
+
+    @Deactivate
+    public void close() {
+        this.reg.close();
+        LOG.info("OlmPowerServiceRpcImpl Closed");
     }
 
     /**
@@ -63,7 +91,7 @@ public class OlmPowerServiceRpcImpl implements TransportpceOlmService {
      * @return Result of the request
      */
     @Override
-    public ListenableFuture<RpcResult<GetPmOutput>> getPm(GetPmInput input) {
+    public final ListenableFuture<RpcResult<GetPmOutput>> getPm(GetPmInput input) {
         if (input.getNodeId() == null) {
             LOG.error("getPm: NodeId can not be null");
             return RpcResultBuilder.<GetPmOutput>failed()
@@ -94,7 +122,7 @@ public class OlmPowerServiceRpcImpl implements TransportpceOlmService {
      * @return Result of the request
      */
     @Override
-    public ListenableFuture<RpcResult<ServicePowerSetupOutput>> servicePowerSetup(
+    public final ListenableFuture<RpcResult<ServicePowerSetupOutput>> servicePowerSetup(
             ServicePowerSetupInput input) {
         return RpcResultBuilder.success(this.olmPowerService.servicePowerSetup(input)).buildFuture();
     }
@@ -120,7 +148,7 @@ public class OlmPowerServiceRpcImpl implements TransportpceOlmService {
      * @return Result of the request
      */
     @Override
-    public ListenableFuture<RpcResult<ServicePowerTurndownOutput>>
+    public final ListenableFuture<RpcResult<ServicePowerTurndownOutput>>
         servicePowerTurndown(ServicePowerTurndownInput input) {
         return RpcResultBuilder.success(this.olmPowerService.servicePowerTurndown(input)).buildFuture();
     }
@@ -148,19 +176,24 @@ public class OlmPowerServiceRpcImpl implements TransportpceOlmService {
      * @return Result of the request
      */
     @Override
-    public ListenableFuture<RpcResult<CalculateSpanlossBaseOutput>>
+    public final ListenableFuture<RpcResult<CalculateSpanlossBaseOutput>>
         calculateSpanlossBase(CalculateSpanlossBaseInput input) {
         return RpcResultBuilder.success(this.olmPowerService.calculateSpanlossBase(input)).buildFuture();
     }
 
     @Override
-    public ListenableFuture<RpcResult<CalculateSpanlossCurrentOutput>> calculateSpanlossCurrent(
+    public final ListenableFuture<RpcResult<CalculateSpanlossCurrentOutput>> calculateSpanlossCurrent(
             CalculateSpanlossCurrentInput input) {
         return RpcResultBuilder.success(this.olmPowerService.calculateSpanlossCurrent(input)).buildFuture();
     }
 
     @Override
-    public ListenableFuture<RpcResult<ServicePowerResetOutput>> servicePowerReset(ServicePowerResetInput input) {
+    public final ListenableFuture<RpcResult<ServicePowerResetOutput>> servicePowerReset(ServicePowerResetInput input) {
         return RpcResultBuilder.success(this.olmPowerService.servicePowerReset(input)).buildFuture();
     }
+
+    public Registration getRegisteredRpc() {
+        return reg;
+    }
+
 }
diff --git a/olm/src/main/java/org/opendaylight/transportpce/olm/OlmProvider.java b/olm/src/main/java/org/opendaylight/transportpce/olm/OlmProvider.java
deleted file mode 100644 (file)
index 3a33a43..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright © 2017 AT&T 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.olm;
-
-import org.opendaylight.mdsal.binding.api.RpcProviderService;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.TransportpceOlmService;
-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;
-
-/**
- * The Class OlmProvider.
- */
-@Component
-public class OlmProvider {
-    private static final Logger LOG = LoggerFactory.getLogger(OlmProvider.class);
-    private ObjectRegistration<TransportpceOlmService> olmRPCRegistration;
-
-    /**
-     * Instantiates a new olm provider.
-     * @param olmPowerServiceRpc
-     *            implementation of TransportpceOlmService
-     * @param rpcProviderService
-     *            the rpc provider service
-     */
-    @Activate
-    public OlmProvider(@Reference final RpcProviderService rpcProviderService,
-            @Reference final TransportpceOlmService olmPowerServiceRpc) {
-        olmRPCRegistration = rpcProviderService.registerRpcImplementation(TransportpceOlmService.class,
-                olmPowerServiceRpc);
-        LOG.info("OlmProvider Session Initiated");
-    }
-
-    /**
-     * Method called when the blueprint container is destroyed.
-     */
-    @Deactivate
-    public void close() {
-        LOG.info("OlmProvider Closed");
-        // Clean up the RPC service registration
-        if (olmRPCRegistration != null) {
-            olmRPCRegistration.close();
-        }
-    }
-}
index 6248ecb6d0cc227161caab925bb161e4c622a136..acaf517acc2311ab6470b07cb82b0898ecfd3d5e 100644 (file)
@@ -23,6 +23,7 @@ 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.olm.service.OlmPowerService;
 import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil;
 import org.opendaylight.transportpce.test.AbstractTest;
@@ -42,6 +43,7 @@ import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev21
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutputBuilder;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownInput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.TransportpceOlmService;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev161014.ResourceTypeEnum;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.PmGranularity;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.olm.get.pm.input.ResourceIdentifierBuilder;
@@ -55,11 +57,13 @@ class OlmPowerServiceRpcImplTest extends AbstractTest {
 
     @Mock
     private OlmPowerService olmPowerService;
-    private OlmPowerServiceRpcImpl olmPowerServiceRpc;
+    @Mock
+    private RpcProviderService rpcProviderService;
+    private TransportpceOlmService olmPowerServiceRpc;
 
     @BeforeEach
     public void setUp() {
-        this.olmPowerServiceRpc = new OlmPowerServiceRpcImpl(this.olmPowerService);
+        this.olmPowerServiceRpc = new OlmPowerServiceRpcImpl(this.olmPowerService, rpcProviderService);
     }
 
     @Test