From: Gilles Thouenon Date: Mon, 2 Oct 2023 13:17:02 +0000 (+0200) Subject: Do not return null for registered RPCs X-Git-Tag: 9.0.0~92 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=transportpce.git;a=commitdiff_plain;h=9f17579836675a4a48db481176726bb050ec8ca1 Do not return null for registered RPCs Some unimplemented RPCs return null and raise a NPE on javax.servlet. Return a RpcResult with error instead. TRNSPRTPCE-763 Signed-off-by: Gilles Thouenon Change-Id: I4fb891e2d784a40350709f98471b990403472b3e --- diff --git a/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsImpl.java b/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsImpl.java index 8ee9e7b58..824ea89a6 100644 --- a/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsImpl.java +++ b/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsImpl.java @@ -89,6 +89,7 @@ import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev18121 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.notification.subscription.service.SubscriptionFilterBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.Rpc; +import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; @@ -243,7 +244,9 @@ public class NbiNotificationsImpl implements NbiNotificationsService, TapiNotifi public ListenableFuture> updateNotificationSubscriptionService(UpdateNotificationSubscriptionServiceInput input) { // TODO --> Not yet implemented - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java index a5674cde5..555910d30 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java @@ -169,7 +169,10 @@ import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.notification.pro import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; import org.opendaylight.yangtools.concepts.Registration; import org.opendaylight.yangtools.yang.binding.Rpc; +import org.opendaylight.yangtools.yang.common.ErrorTag; +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; @@ -292,7 +295,7 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { input, ResponseCodes.FINAL_ACK_YES, validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED); } - //Check any presence of services with the same name + //Check any presence of services with the same nameequipmentNotification String serviceName = input.getServiceName(); if (this.serviceDataStoreOperations.getService(serviceName).isPresent()) { LOG.warn(SERVICE_CREATE_MSG, LogMessages.serviceInDS(serviceName)); @@ -569,14 +572,18 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { public final ListenableFuture> equipmentNotification(EquipmentNotificationInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override public final ListenableFuture> serviceRerouteConfirm(ServiceRerouteConfirmInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override @@ -643,20 +650,26 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { @Override public final ListenableFuture> serviceReversion(ServiceReversionInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override public final ListenableFuture> serviceRoll(ServiceRollInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override public final ListenableFuture> networkReOptimization(NetworkReOptimizationInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override @@ -767,7 +780,9 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { ServiceDeleteComplexResultNotificationRequestOutput>> serviceDeleteComplexResultNotificationRequest( ServiceDeleteComplexResultNotificationRequestInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override @@ -775,7 +790,9 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { ServiceCreateResultNotificationRequestOutput>> serviceCreateResultNotificationRequest( ServiceCreateResultNotificationRequestInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override @@ -783,7 +800,9 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { ServiceDeleteResultNotificationRequestOutput>> serviceDeleteResultNotificationRequest( ServiceDeleteResultNotificationRequestInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override @@ -791,27 +810,35 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { ServiceCreateComplexResultNotificationRequestOutput>> serviceCreateComplexResultNotificationRequest( ServiceCreateComplexResultNotificationRequestInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override public final ListenableFuture> serviceFeasibilityCheckBulk( ServiceFeasibilityCheckBulkInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override public final ListenableFuture> serviceCreateBulk(ServiceCreateBulkInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override public final ListenableFuture> tempServiceCreateBulk( TempServiceCreateBulkInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override @@ -819,56 +846,72 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { ServiceRollResultNotificationRequestOutput>> serviceRollResultNotificationRequest( ServiceRollResultNotificationRequestInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override public final ListenableFuture> serviceReconfigureBulk( ServiceReconfigureBulkInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override public final ListenableFuture> serviceReconfigureResultNotificationRequest(ServiceReconfigureResultNotificationRequestInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override public final ListenableFuture> serviceRestorationResultNotificationRequest(ServiceRestorationResultNotificationRequestInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override public final ListenableFuture> serviceReversionResultNotificationRequest(ServiceReversionResultNotificationRequestInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override public final ListenableFuture> serviceRerouteConfirmResultNotificationRequest(ServiceRerouteConfirmResultNotificationRequestInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override public final ListenableFuture> opticalTunnelCreate(OpticalTunnelCreateInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override public final ListenableFuture> opticalTunnelRequestCancel( OpticalTunnelRequestCancelInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override @@ -942,35 +985,45 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { @Override public final ListenableFuture> serviceSrlgGet(ServiceSrlgGetInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override public final ListenableFuture> endTerminalPerformanceInfoRequest( EndTerminalPerformanceInfoRequestInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override public final ListenableFuture> endTerminalActivationRequest( EndTerminalActivationRequestInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override public final ListenableFuture> endTerminalDeactivationRequest( EndTerminalDeactivationRequestInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override public final ListenableFuture> endTerminalPowerControl( EndTerminalPowerControlInput input) { // TODO Auto-generated method stub - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } public Registration getRegisteredRpc() { diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImplTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImplTest.java index be7eb840f..4c2507c04 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImplTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImplTest.java @@ -7,7 +7,10 @@ */ package org.opendaylight.transportpce.servicehandler.impl; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -73,6 +76,8 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.Service import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRestorationInput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRestorationInputBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRestorationOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceSrlgGetInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceSrlgGetOutput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceCreateInput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceCreateInputBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceCreateOutput; @@ -89,12 +94,14 @@ import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdes import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.resource.resource.TerminationPointBuilder; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.ResponseParametersBuilder; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.response.parameters.PathDescriptionBuilder; +import org.opendaylight.yangtools.yang.common.ErrorSeverity; +import org.opendaylight.yangtools.yang.common.ErrorTag; +import org.opendaylight.yangtools.yang.common.ErrorType; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.Uint32; @ExtendWith(MockitoExtension.class) public class ServicehandlerImplTest extends AbstractTest { - @Mock private RpcProviderService rpcProviderService; @Mock @@ -147,6 +154,24 @@ public class ServicehandlerImplTest extends AbstractTest { verify(rpcProviderService, times(1)).registerRpcImplementations(any()); } + @Test + void testNotImplementedRpc() throws InterruptedException, ExecutionException { + ListenableFuture> result = new ServicehandlerImpl(rpcProviderService, + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .serviceSrlgGet(new ServiceSrlgGetInputBuilder().build()); + result.addListener(() -> endSignal.countDown(), executorService); + endSignal.await(); + assertNotNull(result.get()); + assertFalse(result.get().isSuccessful()); + assertNull(result.get().getResult()); + assertEquals(ErrorType.RPC, result.get().getErrors().get(0).getErrorType()); + assertEquals(ErrorSeverity.ERROR, result.get().getErrors().get(0).getSeverity()); + assertEquals(ErrorTag.OPERATION_NOT_SUPPORTED, result.get().getErrors().get(0).getTag()); + assertEquals("RPC not implemented yet", result.get().getErrors().get(0).getMessage()); + } + @Test void createServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ListenableFuture> result = diff --git a/tapi/src/main/java/org/opendaylight/transportpce/tapi/connectivity/TapiConnectivityImpl.java b/tapi/src/main/java/org/opendaylight/transportpce/tapi/connectivity/TapiConnectivityImpl.java index 449b212e9..6b750a188 100644 --- a/tapi/src/main/java/org/opendaylight/transportpce/tapi/connectivity/TapiConnectivityImpl.java +++ b/tapi/src/main/java/org/opendaylight/transportpce/tapi/connectivity/TapiConnectivityImpl.java @@ -85,6 +85,7 @@ import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev18121 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.get.connectivity.service.list.output.Service; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.get.connectivity.service.list.output.ServiceKey; import org.opendaylight.yangtools.yang.binding.Rpc; +import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; @@ -230,7 +231,9 @@ public class TapiConnectivityImpl implements TapiConnectivityService { public ListenableFuture> updateConnectivityService( UpdateConnectivityServiceInput input) { // TODO Auto-generated method stub. More complicated as it depends on what needs to be updated... left aside - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } @Override diff --git a/tapi/src/main/java/org/opendaylight/transportpce/tapi/topology/TapiTopologyImpl.java b/tapi/src/main/java/org/opendaylight/transportpce/tapi/topology/TapiTopologyImpl.java index d895858d4..087d5f404 100644 --- a/tapi/src/main/java/org/opendaylight/transportpce/tapi/topology/TapiTopologyImpl.java +++ b/tapi/src/main/java/org/opendaylight/transportpce/tapi/topology/TapiTopologyImpl.java @@ -118,6 +118,7 @@ import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.to import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; import org.opendaylight.yangtools.yang.binding.Rpc; +import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; @@ -343,8 +344,9 @@ public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService @Override public ListenableFuture> updateServiceInterfacePoint(UpdateServiceInterfacePointInput input) { - // TODO --> not yet implemented - return null; + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet") + .buildFuture(); } private Topology createAbstracted100GTpdrTopology(Topology topology) {