Remove RpcServiceHandler 67/96167/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 13 May 2021 14:29:40 +0000 (16:29 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 13 May 2021 14:32:39 +0000 (16:32 +0200)
This is a useless indirection class, just remove it and deal with
DOMRpcService instead.

JIRA: NETCONF-773
Change-Id: I3808997bc1226d384d012a5153701cbd95fb6028
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/Rfc8040RestConfWiring.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/RpcServiceHandler.java [deleted file]
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfInvokeOperationsUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServicesWrapper.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImplTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfInvokeOperationsUtilTest.java

index cb329e384ca328d7c177867fc6e09cfbd1c579bc..4c05d56a5ffbdd37d79c91b4c691204db95402ee 100644 (file)
@@ -11,11 +11,11 @@ import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.apache.aries.blueprint.annotation.service.Reference;
 import org.opendaylight.mdsal.dom.api.DOMActionService;
+import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesNotifWrapper;
@@ -43,14 +43,14 @@ public class Rfc8040RestConfWiring {
     public Rfc8040RestConfWiring(final SchemaContextHandler schemaCtxHandler,
             final DOMMountPointServiceHandler domMountPointServiceHandler,
             final TransactionChainHandler transactionChainHandler,
-            final DOMDataBrokerHandler domDataBrokerHandler, final RpcServiceHandler rpcServiceHandler,
+            final DOMDataBrokerHandler domDataBrokerHandler, @Reference final DOMRpcService rpcService,
             @Reference final DOMActionService actionService,
             final NotificationServiceHandler notificationServiceHandler,
             final SSEInitializer sseInit,
             final Configuration configuration,
             @Reference final DOMSchemaService domSchemaService) {
         servicesWrapper = ServicesWrapper.newInstance(schemaCtxHandler, domMountPointServiceHandler,
-            transactionChainHandler, domDataBrokerHandler, rpcServiceHandler, actionService,
+            transactionChainHandler, domDataBrokerHandler, rpcService, actionService,
             notificationServiceHandler, domSchemaService, configuration);
         servicesNotifWrapper = ServicesNotifWrapper.newInstance(sseInit);
     }
diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/RpcServiceHandler.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/RpcServiceHandler.java
deleted file mode 100644 (file)
index d6e2d32..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, 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.restconf.nb.rfc8040.handlers;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import org.apache.aries.blueprint.annotation.service.Reference;
-import org.opendaylight.mdsal.dom.api.DOMRpcService;
-
-/**
- * Implementation of {@link RpcServiceHandler}.
- */
-// FIXME: remove this class
-@Singleton
-public class RpcServiceHandler {
-    private final DOMRpcService rpcService;
-
-    @Inject
-    public RpcServiceHandler(final @Reference DOMRpcService rpcService) {
-        this.rpcService = rpcService;
-    }
-
-    public DOMRpcService get() {
-        return this.rpcService;
-    }
-}
index 422aef06766cdcaa746e027f68f04f3e8eea3b64..aafb5e288132a05efddff68de284ec9f7e242f07 100644 (file)
@@ -17,13 +17,13 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
+import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
-import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfInvokeOperationsService;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfInvokeOperationsUtil;
@@ -40,12 +40,12 @@ import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
  */
 @Path("/")
 public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperationsService {
-    private final RpcServiceHandler rpcServiceHandler;
+    private final DOMRpcService rpcService;
     private final SchemaContextHandler schemaContextHandler;
 
-    public RestconfInvokeOperationsServiceImpl(final RpcServiceHandler rpcServiceHandler,
+    public RestconfInvokeOperationsServiceImpl(final DOMRpcService rpcService,
             final SchemaContextHandler schemaContextHandler) {
-        this.rpcServiceHandler = requireNonNull(rpcServiceHandler);
+        this.rpcService = requireNonNull(rpcService);
         this.schemaContextHandler = requireNonNull(schemaContextHandler);
     }
 
@@ -68,8 +68,7 @@ public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperat
                             ErrorTag.OPERATION_NOT_SUPPORTED);
                 }
             } else {
-                response = RestconfInvokeOperationsUtil.invokeRpc(payload.getData(), schemaPath,
-                        this.rpcServiceHandler);
+                response = RestconfInvokeOperationsUtil.invokeRpc(payload.getData(), schemaPath, this.rpcService);
             }
             schemaContextRef = this.schemaContextHandler.get();
         } else {
index c6c2d62b4f80bae1d8dd13eb33999b0d68b0f978..f4b9b2d20db11eb1c7b146bd6f5f0171908df725 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.restconf.nb.rfc8040.rests.utils;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Optional;
 import java.util.concurrent.CancellationException;
-import javax.ws.rs.core.Response.Status;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMActionResult;
@@ -22,7 +21,6 @@ import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
-import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.YangConstants;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -72,17 +70,12 @@ public final class RestconfInvokeOperationsUtil {
      *             input data
      * @param rpc
      *             RPC type
-     * @param rpcServiceHandler
-     *             rpc service handler to invoke rpc
+     * @param rpcService
+     *             rpc service to invoke rpc
      * @return {@link DOMRpcResult}
      */
     public static DOMRpcResult invokeRpc(final NormalizedNode<?, ?> data, final QName rpc,
-            final RpcServiceHandler rpcServiceHandler) {
-        final DOMRpcService rpcService = rpcServiceHandler.get();
-        if (rpcService == null) {
-            throw new RestconfDocumentedException(Status.SERVICE_UNAVAILABLE);
-        }
-
+            final DOMRpcService rpcService) {
         return prepareResult(rpcService.invokeRpc(rpc, nonnullInput(rpc, data)));
     }
 
index 1b3e05a2162d2ebacc473eec71057a647aaaa2e1..174297f41bec68056945f495afde5f6ca777ba4c 100644 (file)
@@ -11,6 +11,7 @@ import javax.ws.rs.Path;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 import org.opendaylight.mdsal.dom.api.DOMActionService;
+import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
@@ -20,7 +21,6 @@ import org.opendaylight.restconf.common.schema.SchemaExportContext;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfDataService;
@@ -72,7 +72,7 @@ public final class ServicesWrapper implements BaseServicesWrapper, TransactionSe
     public static ServicesWrapper newInstance(final SchemaContextHandler schemaCtxHandler,
             final DOMMountPointServiceHandler domMountPointServiceHandler,
             final TransactionChainHandler transactionChainHandler, final DOMDataBrokerHandler domDataBrokerHandler,
-            final RpcServiceHandler rpcServiceHandler, final DOMActionService actionService,
+            final DOMRpcService rpcService, final DOMActionService actionService,
             final NotificationServiceHandler notificationServiceHandler, final DOMSchemaService domSchemaService,
             final Configuration configuration) {
         RestconfOperationsService restconfOpsService = new RestconfOperationsServiceImpl(schemaCtxHandler,
@@ -86,8 +86,8 @@ public final class ServicesWrapper implements BaseServicesWrapper, TransactionSe
             configuration);
         RestconfDataService restconfDataService = new RestconfDataServiceImpl(schemaCtxHandler, transactionChainHandler,
             domMountPointServiceHandler, restconfSubscrService, actionService, configuration);
-        RestconfInvokeOperationsService restconfInvokeOpsService = new RestconfInvokeOperationsServiceImpl(
-            rpcServiceHandler, schemaCtxHandler);
+        RestconfInvokeOperationsService restconfInvokeOpsService = new RestconfInvokeOperationsServiceImpl(rpcService,
+            schemaCtxHandler);
         RestconfService restconfService = new RestconfImpl(schemaCtxHandler);
         return new ServicesWrapper(restconfDataService, restconfInvokeOpsService, restconfSubscrService,
             restconfOpsService, restconfSchemaService, restconfService);
index aaff6224427ce9d4b1bddb1a191d350f2a8fc5e5..1854e8634d4e4f5abca1647466d0abb91561d161 100644 (file)
@@ -32,7 +32,6 @@ import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
-import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -50,9 +49,6 @@ public class RestconfInvokeOperationsServiceImplTest {
 
     private RestconfInvokeOperationsServiceImpl invokeOperationsService;
 
-    @Mock
-    private RpcServiceHandler rpcServiceHandler;
-
     @Mock
     private DOMRpcService rpcService;
 
@@ -70,8 +66,7 @@ public class RestconfInvokeOperationsServiceImplTest {
             mock(DOMSchemaService.class));
         schemaContextHandler.onModelContextUpdated(contextRef);
         this.invokeOperationsService =
-                new RestconfInvokeOperationsServiceImpl(this.rpcServiceHandler, schemaContextHandler);
-        when(this.rpcServiceHandler.get()).thenReturn(this.rpcService);
+                new RestconfInvokeOperationsServiceImpl(this.rpcService, schemaContextHandler);
     }
 
     @Test
index b8f71da7eb01cbd0d4e4bbb3235b50ffeadd831e..5ef6ca27dc8fe1748656d87daf7a51e475a0500a 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.restconf.nb.rfc8040.rests.utils;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.doReturn;
 import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFailedFluentFuture;
 import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFluentFuture;
@@ -17,8 +18,6 @@ import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediate
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Optional;
-import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
@@ -30,7 +29,6 @@ import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
 import org.opendaylight.yangtools.yang.common.RpcError;
 
 @RunWith(MockitoJUnitRunner.StrictStubs.class)
@@ -38,23 +36,17 @@ public class RestconfInvokeOperationsUtilTest {
 
     private static final TestData DATA = new TestData();
 
-    private RpcServiceHandler serviceHandler;
     @Mock
     private DOMRpcService rpcService;
     @Mock
     private DOMMountPoint moutPoint;
 
-    @Before
-    public void setUp() {
-        serviceHandler = new RpcServiceHandler(rpcService);
-    }
-
     @Test
     public void invokeRpcTest() {
         final DOMRpcResult mockResult = new DefaultDOMRpcResult(DATA.output, Collections.emptyList());
         doReturn(immediateFluentFuture(mockResult)).when(rpcService).invokeRpc(DATA.rpc, DATA.input);
-        final DOMRpcResult rpcResult = RestconfInvokeOperationsUtil.invokeRpc(DATA.input, DATA.rpc, serviceHandler);
-        Assert.assertTrue(rpcResult.getErrors().isEmpty());
+        final DOMRpcResult rpcResult = RestconfInvokeOperationsUtil.invokeRpc(DATA.input, DATA.rpc, rpcService);
+        assertTrue(rpcResult.getErrors().isEmpty());
         assertEquals(DATA.output, rpcResult.getResult());
     }
 
@@ -64,7 +56,7 @@ public class RestconfInvokeOperationsUtilTest {
                 "No implementation of RPC " + DATA.errorRpc.toString() + " available.");
         doReturn(immediateFailedFluentFuture(exception)).when(rpcService).invokeRpc(DATA.errorRpc, DATA.input);
         final DOMRpcResult rpcResult =
-                RestconfInvokeOperationsUtil.invokeRpc(DATA.input, DATA.errorRpc, serviceHandler);
+                RestconfInvokeOperationsUtil.invokeRpc(DATA.input, DATA.errorRpc, rpcService);
         assertNull(rpcResult.getResult());
         final Collection<? extends RpcError> errorList = rpcResult.getErrors();
         assertEquals(1, errorList.size());
@@ -82,7 +74,7 @@ public class RestconfInvokeOperationsUtilTest {
         doReturn(immediateFluentFuture(mockResult)).when(rpcService).invokeRpc(DATA.rpc, DATA.input);
         final DOMRpcResult rpcResult =
                 RestconfInvokeOperationsUtil.invokeRpcViaMountPoint(moutPoint, DATA.input, DATA.rpc);
-        Assert.assertTrue(rpcResult.getErrors().isEmpty());
+        assertTrue(rpcResult.getErrors().isEmpty());
         assertEquals(DATA.output, rpcResult.getResult());
     }
 
@@ -98,8 +90,8 @@ public class RestconfInvokeOperationsUtilTest {
     public void checkResponseTest() {
         final DOMRpcResult mockResult = new DefaultDOMRpcResult(DATA.output, Collections.emptyList());
         doReturn(immediateFluentFuture(mockResult)).when(rpcService).invokeRpc(DATA.rpc, DATA.input);
-        final DOMRpcResult rpcResult = RestconfInvokeOperationsUtil.invokeRpc(DATA.input, DATA.rpc, serviceHandler);
-        Assert.assertTrue(rpcResult.getErrors().isEmpty());
+        final DOMRpcResult rpcResult = RestconfInvokeOperationsUtil.invokeRpc(DATA.input, DATA.rpc, rpcService);
+        assertTrue(rpcResult.getErrors().isEmpty());
         assertEquals(DATA.output, rpcResult.getResult());
         assertNotNull(RestconfInvokeOperationsUtil.checkResponse(rpcResult));
     }