Do not return null for registered RPCs 57/108157/4
authorGilles Thouenon <gilles.thouenon@orange.com>
Mon, 2 Oct 2023 13:17:02 +0000 (15:17 +0200)
committerguillaume.lambert <guillaume.lambert@orange.com>
Wed, 11 Oct 2023 12:11:34 +0000 (14:11 +0200)
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 <gilles.thouenon@orange.com>
Change-Id: I4fb891e2d784a40350709f98471b990403472b3e

nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsImpl.java
servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java
servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImplTest.java
tapi/src/main/java/org/opendaylight/transportpce/tapi/connectivity/TapiConnectivityImpl.java
tapi/src/main/java/org/opendaylight/transportpce/tapi/topology/TapiTopologyImpl.java

index 8ee9e7b5864ec23c66f483ccc4d68a38c280403c..824ea89a64175f22bebf9f1b99ae4fbe61aba4bb 100644 (file)
@@ -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<RpcResult<UpdateNotificationSubscriptionServiceOutput>>
             updateNotificationSubscriptionService(UpdateNotificationSubscriptionServiceInput input) {
         // TODO --> Not yet implemented
-        return null;
+        return RpcResultBuilder.<UpdateNotificationSubscriptionServiceOutput>failed()
+            .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
+            .buildFuture();
     }
 
     @Override
index a5674cde5a8e549dbb97e590199789de9dd656ed..555910d30b7aa9b04796dfe0674ac247b9c43e45 100644 (file)
@@ -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<RpcResult<EquipmentNotificationOutput>>
             equipmentNotification(EquipmentNotificationInput input) {
         // TODO Auto-generated method stub
-        return null;
+        return RpcResultBuilder.<EquipmentNotificationOutput>failed()
+            .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
+            .buildFuture();
     }
 
     @Override
     public final ListenableFuture<RpcResult<ServiceRerouteConfirmOutput>>
             serviceRerouteConfirm(ServiceRerouteConfirmInput input) {
         // TODO Auto-generated method stub
-        return null;
+        return RpcResultBuilder.<ServiceRerouteConfirmOutput>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<RpcResult<ServiceReversionOutput>> serviceReversion(ServiceReversionInput input) {
         // TODO Auto-generated method stub
-        return null;
+        return RpcResultBuilder.<ServiceReversionOutput>failed()
+            .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
+            .buildFuture();
     }
 
     @Override
     public final ListenableFuture<RpcResult<ServiceRollOutput>> serviceRoll(ServiceRollInput input) {
         // TODO Auto-generated method stub
-        return null;
+        return RpcResultBuilder.<ServiceRollOutput>failed()
+            .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
+            .buildFuture();
     }
 
     @Override
     public final ListenableFuture<RpcResult<NetworkReOptimizationOutput>>
             networkReOptimization(NetworkReOptimizationInput input) {
         // TODO Auto-generated method stub
-        return null;
+        return RpcResultBuilder.<NetworkReOptimizationOutput>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.<ServiceDeleteComplexResultNotificationRequestOutput>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.<ServiceCreateResultNotificationRequestOutput>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.<ServiceDeleteResultNotificationRequestOutput>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.<ServiceCreateComplexResultNotificationRequestOutput>failed()
+            .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
+            .buildFuture();
     }
 
     @Override
     public final ListenableFuture<RpcResult<ServiceFeasibilityCheckBulkOutput>> serviceFeasibilityCheckBulk(
         ServiceFeasibilityCheckBulkInput input) {
         // TODO Auto-generated method stub
-        return null;
+        return RpcResultBuilder.<ServiceFeasibilityCheckBulkOutput>failed()
+            .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
+            .buildFuture();
     }
 
     @Override
     public final ListenableFuture<RpcResult<ServiceCreateBulkOutput>> serviceCreateBulk(ServiceCreateBulkInput input) {
         // TODO Auto-generated method stub
-        return null;
+        return RpcResultBuilder.<ServiceCreateBulkOutput>failed()
+            .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
+            .buildFuture();
     }
 
     @Override
     public final ListenableFuture<RpcResult<TempServiceCreateBulkOutput>> tempServiceCreateBulk(
         TempServiceCreateBulkInput input) {
         // TODO Auto-generated method stub
-        return null;
+        return RpcResultBuilder.<TempServiceCreateBulkOutput>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.<ServiceRollResultNotificationRequestOutput>failed()
+            .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
+            .buildFuture();
     }
 
     @Override
     public final ListenableFuture<RpcResult<ServiceReconfigureBulkOutput>> serviceReconfigureBulk(
         ServiceReconfigureBulkInput input) {
         // TODO Auto-generated method stub
-        return null;
+        return RpcResultBuilder.<ServiceReconfigureBulkOutput>failed()
+            .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
+            .buildFuture();
     }
 
     @Override
     public final ListenableFuture<RpcResult<ServiceReconfigureResultNotificationRequestOutput>>
             serviceReconfigureResultNotificationRequest(ServiceReconfigureResultNotificationRequestInput input) {
         // TODO Auto-generated method stub
-        return null;
+        return RpcResultBuilder.<ServiceReconfigureResultNotificationRequestOutput>failed()
+            .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
+            .buildFuture();
     }
 
     @Override
     public final ListenableFuture<RpcResult<ServiceRestorationResultNotificationRequestOutput>>
             serviceRestorationResultNotificationRequest(ServiceRestorationResultNotificationRequestInput input) {
         // TODO Auto-generated method stub
-        return null;
+        return RpcResultBuilder.<ServiceRestorationResultNotificationRequestOutput>failed()
+            .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
+            .buildFuture();
     }
 
     @Override
     public final ListenableFuture<RpcResult<ServiceReversionResultNotificationRequestOutput>>
             serviceReversionResultNotificationRequest(ServiceReversionResultNotificationRequestInput input) {
         // TODO Auto-generated method stub
-        return null;
+        return RpcResultBuilder.<ServiceReversionResultNotificationRequestOutput>failed()
+            .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
+            .buildFuture();
     }
 
     @Override
     public final ListenableFuture<RpcResult<ServiceRerouteConfirmResultNotificationRequestOutput>>
             serviceRerouteConfirmResultNotificationRequest(ServiceRerouteConfirmResultNotificationRequestInput input) {
         // TODO Auto-generated method stub
-        return null;
+        return RpcResultBuilder.<ServiceRerouteConfirmResultNotificationRequestOutput>failed()
+            .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
+            .buildFuture();
     }
 
     @Override
     public final ListenableFuture<RpcResult<
             OpticalTunnelCreateOutput>> opticalTunnelCreate(OpticalTunnelCreateInput input) {
         // TODO Auto-generated method stub
-        return null;
+        return RpcResultBuilder.<OpticalTunnelCreateOutput>failed()
+            .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
+            .buildFuture();
     }
 
     @Override
     public final ListenableFuture<RpcResult<OpticalTunnelRequestCancelOutput>> opticalTunnelRequestCancel(
             OpticalTunnelRequestCancelInput input) {
         // TODO Auto-generated method stub
-        return null;
+        return RpcResultBuilder.<OpticalTunnelRequestCancelOutput>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<RpcResult<ServiceSrlgGetOutput>> serviceSrlgGet(ServiceSrlgGetInput input) {
         // TODO Auto-generated method stub
-        return null;
+        return RpcResultBuilder.<ServiceSrlgGetOutput>failed()
+            .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
+            .buildFuture();
     }
 
     @Override
     public final ListenableFuture<RpcResult<EndTerminalPerformanceInfoRequestOutput>> endTerminalPerformanceInfoRequest(
         EndTerminalPerformanceInfoRequestInput input) {
         // TODO Auto-generated method stub
-        return null;
+        return RpcResultBuilder.<EndTerminalPerformanceInfoRequestOutput>failed()
+            .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
+            .buildFuture();
     }
 
     @Override
     public final ListenableFuture<RpcResult<EndTerminalActivationRequestOutput>> endTerminalActivationRequest(
             EndTerminalActivationRequestInput input) {
         // TODO Auto-generated method stub
-        return null;
+        return RpcResultBuilder.<EndTerminalActivationRequestOutput>failed()
+            .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
+            .buildFuture();
     }
 
     @Override
     public final ListenableFuture<RpcResult<EndTerminalDeactivationRequestOutput>> endTerminalDeactivationRequest(
             EndTerminalDeactivationRequestInput input) {
         // TODO Auto-generated method stub
-        return null;
+        return RpcResultBuilder.<EndTerminalDeactivationRequestOutput>failed()
+            .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
+            .buildFuture();
     }
 
     @Override
     public final ListenableFuture<RpcResult<EndTerminalPowerControlOutput>> endTerminalPowerControl(
             EndTerminalPowerControlInput input) {
         // TODO Auto-generated method stub
-        return null;
+        return RpcResultBuilder.<EndTerminalPowerControlOutput>failed()
+            .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
+            .buildFuture();
     }
 
     public Registration getRegisteredRpc() {
index be7eb840fd5df1787586695456433a7cd0dea54b..4c2507c04e49cfd92c95c746b0fbdc59bddd184b 100644 (file)
@@ -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<RpcResult<ServiceSrlgGetOutput>> 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<RpcResult<ServiceCreateOutput>> result =
index 449b212e991121b93b5de5b3138de4eb61c09e62..6b750a188a27935fbabda9bb3192cb954a338f0e 100644 (file)
@@ -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<RpcResult<UpdateConnectivityServiceOutput>> 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.<UpdateConnectivityServiceOutput>failed()
+            .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
+            .buildFuture();
     }
 
     @Override
index d895858d4de6d628b9b3cfe1726a7473a933e093..087d5f404ebe47bbbb3c60550a9a2b6077aee78e 100644 (file)
@@ -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<RpcResult<UpdateServiceInterfacePointOutput>>
             updateServiceInterfacePoint(UpdateServiceInterfacePointInput input) {
-        // TODO --> not yet implemented
-        return null;
+        return RpcResultBuilder.<UpdateServiceInterfacePointOutput>failed()
+            .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
+            .buildFuture();
     }
 
     private Topology createAbstracted100GTpdrTopology(Topology topology) {