From: Gilles Thouenon Date: Fri, 29 Sep 2023 11:56:34 +0000 (+0200) Subject: Do not use RpcService in TPCE olm module X-Git-Tag: 9.0.0~103^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=transportpce.git;a=commitdiff_plain;h=cb41f80cf1b6e12834b91ad1a651061f13a0d9a8 Do not use RpcService in TPCE olm module - 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 Change-Id: I13a455c52ade0b7d36253fb7baa6995db0862870 --- 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 f0f17c0a7..8a3db47e3 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,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 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; } diff --git a/olm/src/main/java/org/opendaylight/transportpce/olm/OlmPowerServiceRpcImpl.java b/olm/src/main/java/org/opendaylight/transportpce/olm/OlmPowerServiceRpcImpl.java index 09e82845f..5f01d43b3 100644 --- a/olm/src/main/java/org/opendaylight/transportpce/olm/OlmPowerServiceRpcImpl.java +++ b/olm/src/main/java/org/opendaylight/transportpce/olm/OlmPowerServiceRpcImpl.java @@ -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.>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> getPm(GetPmInput input) { + public final ListenableFuture> getPm(GetPmInput input) { if (input.getNodeId() == null) { LOG.error("getPm: NodeId can not be null"); return RpcResultBuilder.failed() @@ -94,7 +122,7 @@ public class OlmPowerServiceRpcImpl implements TransportpceOlmService { * @return Result of the request */ @Override - public ListenableFuture> servicePowerSetup( + public final ListenableFuture> 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> + public final ListenableFuture> 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> + public final ListenableFuture> calculateSpanlossBase(CalculateSpanlossBaseInput input) { return RpcResultBuilder.success(this.olmPowerService.calculateSpanlossBase(input)).buildFuture(); } @Override - public ListenableFuture> calculateSpanlossCurrent( + public final ListenableFuture> calculateSpanlossCurrent( CalculateSpanlossCurrentInput input) { return RpcResultBuilder.success(this.olmPowerService.calculateSpanlossCurrent(input)).buildFuture(); } @Override - public ListenableFuture> servicePowerReset(ServicePowerResetInput input) { + public final ListenableFuture> 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 index 3a33a43a3..000000000 --- a/olm/src/main/java/org/opendaylight/transportpce/olm/OlmProvider.java +++ /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 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(); - } - } -} diff --git a/olm/src/test/java/org/opendaylight/transportpce/olm/OlmPowerServiceRpcImplTest.java b/olm/src/test/java/org/opendaylight/transportpce/olm/OlmPowerServiceRpcImplTest.java index 6248ecb6d..acaf517ac 100644 --- a/olm/src/test/java/org/opendaylight/transportpce/olm/OlmPowerServiceRpcImplTest.java +++ b/olm/src/test/java/org/opendaylight/transportpce/olm/OlmPowerServiceRpcImplTest.java @@ -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