Remove TransactionChainHandler 46/96846/6
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 8 Jul 2021 20:18:42 +0000 (22:18 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 9 Jul 2021 12:24:38 +0000 (14:24 +0200)
This class is pure overhead and serves no purpose. Remove it to
simplify lifecycle as well as improve latencies.

JIRA: NETCONF-773
Change-Id: I0506f17d05cec910057e40742adfbb04225f4211
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestconfApplication.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/TransactionChainHandler.java [deleted file]
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImpl.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/handlers/TransactionChainHandlerTest.java [deleted file]
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImplTest.java

index 028a8ba7b0299edac70d41b5abc100c07f764de9..1116992aa967ec34f0e6ca27c3f507bc73330184 100644 (file)
@@ -19,7 +19,6 @@ 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.nb.rfc8040.handlers.SchemaContextHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfDataServiceImpl;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfImpl;
@@ -33,8 +32,7 @@ import org.opendaylight.restconf.nb.rfc8040.streams.Configuration;
 public class RestconfApplication extends AbstractRestconfApplication {
     private RestconfApplication(final SchemaContextHandler schemaContextHandler,
             final DOMMountPointService mountPointService, final RestconfStreamsSubscriptionService streamSubscription,
-            final TransactionChainHandler transactionChainHandler, final DOMDataBroker dataBroker,
-            final DOMRpcService rpcService, final DOMActionService actionService,
+            final DOMDataBroker dataBroker, final DOMRpcService rpcService, final DOMActionService actionService,
             final DOMNotificationService notificationService, final DOMSchemaService domSchemaService,
             final Configuration configuration) {
         super(schemaContextHandler, mountPointService, List.of(
@@ -51,15 +49,13 @@ public class RestconfApplication extends AbstractRestconfApplication {
 
     @Inject
     public RestconfApplication(final SchemaContextHandler schemaContextHandler,
-            @Reference final DOMMountPointService mountPointService,
-            final TransactionChainHandler transactionChainHandler, @Reference final DOMDataBroker dataBroker,
+            @Reference final DOMMountPointService mountPointService, @Reference final DOMDataBroker dataBroker,
             @Reference final DOMRpcService rpcService, @Reference final DOMActionService actionService,
             @Reference final DOMNotificationService notificationService,
             @Reference final DOMSchemaService domSchemaService, final Configuration configuration) {
         this(schemaContextHandler, mountPointService,
             new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, schemaContextHandler,
-                transactionChainHandler, configuration),
-            transactionChainHandler, dataBroker, rpcService, actionService, notificationService, domSchemaService,
-            configuration);
+                configuration),
+            dataBroker, rpcService, actionService, notificationService, domSchemaService, configuration);
     }
 }
diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/TransactionChainHandler.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/TransactionChainHandler.java
deleted file mode 100644 (file)
index 6f6ba0f..0000000
+++ /dev/null
@@ -1,91 +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 static java.util.Objects.requireNonNull;
-
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import javax.annotation.PreDestroy;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import org.apache.aries.blueprint.annotation.service.Reference;
-import org.opendaylight.mdsal.dom.api.DOMDataBroker;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeTransaction;
-import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
-import org.opendaylight.mdsal.dom.api.DOMTransactionChainListener;
-import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Implementation of {@link TransactionChainHandler}.
- */
-// FIXME: untangle this class, what good is it, really?!
-@Singleton
-public class TransactionChainHandler implements AutoCloseable {
-    private static final Logger LOG = LoggerFactory.getLogger(TransactionChainHandler.class);
-
-    private final DOMTransactionChainListener transactionChainListener = new DOMTransactionChainListener() {
-        @Override
-        public void onTransactionChainFailed(final DOMTransactionChain chain, final DOMDataTreeTransaction transaction,
-                final Throwable cause) {
-            LOG.warn("TransactionChain({}) {} FAILED!", chain, transaction.getIdentifier(), cause);
-            transactionChainList.remove(chain);
-            throw new RestconfDocumentedException("TransactionChain(" + chain + ") not committed correctly", cause);
-        }
-
-        @Override
-        public void onTransactionChainSuccessful(final DOMTransactionChain chain) {
-            LOG.trace("TransactionChain({}) SUCCESSFUL", chain);
-            transactionChainList.remove(chain);
-        }
-    };
-
-    private final DOMDataBroker dataBroker;
-    private final Queue<DOMTransactionChain> transactionChainList;
-
-    /**
-     * Prepare transaction chain service for Restconf services.
-     */
-    @Inject
-    public TransactionChainHandler(@Reference final DOMDataBroker dataBroker) {
-        this.dataBroker = requireNonNull(dataBroker);
-        this.transactionChainList = new ConcurrentLinkedQueue<>();
-    }
-
-    /**
-     * Create and return new instance of object {@link DOMTransactionChain}.
-     * After use, is important to close transactionChain by method {@link DOMTransactionChain#close()}.
-     * @return new instance of object {@link DOMTransactionChain}
-     */
-    public DOMTransactionChain get() {
-        final DOMTransactionChain transactionChain = dataBroker.createTransactionChain(transactionChainListener);
-        this.transactionChainList.add(transactionChain);
-        LOG.trace("Started TransactionChain({})", transactionChain);
-        return transactionChain;
-    }
-
-    @Override
-    @PreDestroy
-    public synchronized void close() {
-        for (DOMTransactionChain transactionChain : this.transactionChainList) {
-            transactionChain.close();
-            LOG.trace("Closed TransactionChain({})", transactionChain);
-        }
-    }
-
-    /**
-     * Verify if {@link DOMTransactionChain} exist in {@link TransactionChainHandler} queue.
-     * @param transactionChain object to check.
-     * @return true if object still exist in {@link TransactionChainHandler}.
-     */
-    boolean verifyIfExistTransactionChain(final DOMTransactionChain transactionChain) {
-        return this.transactionChainList.contains(transactionChain);
-    }
-}
index a04f73995b5b629233522496db42934657895050..fe8fa79ee87a680f0dd8ced4a3ac7bfc4f52d632 100644 (file)
@@ -26,12 +26,10 @@ import javax.ws.rs.core.UriInfo;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
-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.common.errors.RestconfDocumentedException;
 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.RestconfStreamsSubscriptionService;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants;
 import org.opendaylight.restconf.nb.rfc8040.streams.Configuration;
@@ -71,16 +69,13 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
      * @param notificationService {@link DOMNotificationService}
      * @param schemaHandler
      *             handler of {@link SchemaContext}
-     * @param transactionChainHandler
-     *             handler of {@link DOMTransactionChain}
      * @param configuration
      *             configuration for restconf {@link Configuration}}
      */
     public RestconfStreamsSubscriptionServiceImpl(final DOMDataBroker dataBroker,
             final DOMNotificationService notificationService, final SchemaContextHandler schemaHandler,
-            final TransactionChainHandler transactionChainHandler, final Configuration configuration) {
-        this.handlersHolder = new HandlersHolder(dataBroker, notificationService,
-                transactionChainHandler, schemaHandler);
+            final Configuration configuration) {
+        this.handlersHolder = new HandlersHolder(dataBroker, notificationService, schemaHandler);
         streamUtils = configuration.isUseSSE() ? SubscribeToStreamUtil.serverSentEvents()
                 : SubscribeToStreamUtil.webSockets();
     }
@@ -136,14 +131,12 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
     public static final class HandlersHolder {
         private final DOMDataBroker dataBroker;
         private final DOMNotificationService notificationService;
-        private final TransactionChainHandler transactionChainHandler;
         private final SchemaContextHandler schemaHandler;
 
         private HandlersHolder(final DOMDataBroker dataBroker, final DOMNotificationService notificationService,
-                final TransactionChainHandler transactionChainHandler, final SchemaContextHandler schemaHandler) {
+                final SchemaContextHandler schemaHandler) {
             this.dataBroker = dataBroker;
             this.notificationService = notificationService;
-            this.transactionChainHandler = transactionChainHandler;
             this.schemaHandler = schemaHandler;
         }
 
@@ -165,15 +158,6 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
             return this.notificationService;
         }
 
-        /**
-         * Get {@link TransactionChainHandler}.
-         *
-         * @return the transactionChainHandler
-         */
-        public TransactionChainHandler getTransactionChainHandler() {
-            return this.transactionChainHandler;
-        }
-
         /**
          * Get {@link SchemaContextHandler}.
          *
diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/handlers/TransactionChainHandlerTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/handlers/TransactionChainHandlerTest.java
deleted file mode 100644 (file)
index 7c7d727..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright (c) 2019 PANTHEON.tech, s.r.o. 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 com.google.common.collect.ClassToInstanceMap;
-import org.eclipse.jdt.annotation.NonNull;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.opendaylight.mdsal.dom.api.DOMDataBroker;
-import org.opendaylight.mdsal.dom.api.DOMDataBrokerExtension;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeTransaction;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
-import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
-import org.opendaylight.mdsal.dom.api.DOMTransactionChainListener;
-import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-
-public class TransactionChainHandlerTest {
-
-    private TransactionChainHandler transactionChainHandler;
-    private static final String EXCEPTION_MESSAGE = "(TEST) Unsupported Method";
-
-    @After
-    public void shutdown() {
-        this.transactionChainHandler.close();
-    }
-
-    @Test
-    public void transactionChainTest() {
-        this.transactionChainHandler = new TransactionChainHandler(new DataBrokerLocal());
-        final DOMTransactionChain chain1 = this.transactionChainHandler.get();
-        final DOMTransactionChain chain2 = this.transactionChainHandler.get();
-        Assert.assertNotNull(chain1);
-        Assert.assertNotNull(chain2);
-        Assert.assertNotEquals(chain1, chain2);
-        chain1.close();
-        Assert.assertFalse(this.transactionChainHandler.verifyIfExistTransactionChain(chain1));
-
-        try {
-            chain2.newReadOnlyTransaction();
-        } catch (RestconfDocumentedException e) {
-            Assert.assertEquals(e.getCause().getLocalizedMessage(), EXCEPTION_MESSAGE);
-        }
-        Assert.assertFalse(this.transactionChainHandler.verifyIfExistTransactionChain(chain2));
-    }
-
-    private final class TxChainLocal implements DOMTransactionChain {
-        DOMTransactionChainListener listener;
-
-        TxChainLocal(DOMTransactionChainListener listener) {
-            this.listener = listener;
-        }
-
-        @Override
-        public DOMDataTreeReadTransaction newReadOnlyTransaction() {
-            final DOMDataTreeTransaction domDataTreeTransaction = Mockito.mock(DOMDataTreeTransaction.class);
-            listener.onTransactionChainFailed(this,
-                    domDataTreeTransaction, new Throwable(EXCEPTION_MESSAGE));
-            return null;
-        }
-
-        @Override
-        public DOMDataTreeWriteTransaction newWriteOnlyTransaction() {
-            return null;
-        }
-
-        @Override
-        public DOMDataTreeReadWriteTransaction newReadWriteTransaction() {
-            return null;
-        }
-
-        @Override
-        public void close() {
-            listener.onTransactionChainSuccessful(this);
-        }
-    }
-
-    private final class DataBrokerLocal implements DOMDataBroker {
-
-        @Override
-        public @NonNull DOMTransactionChain createTransactionChain(DOMTransactionChainListener listener) {
-            return new TxChainLocal(listener);
-        }
-
-        @Override
-        public @NonNull DOMTransactionChain createMergingTransactionChain(DOMTransactionChainListener listener) {
-            return null;
-        }
-
-        @Override
-        public @NonNull ClassToInstanceMap<DOMDataBrokerExtension> getExtensions() {
-            return null;
-        }
-
-        @Override
-        public DOMDataTreeReadTransaction newReadOnlyTransaction() {
-            return null;
-        }
-
-        @Override
-        public DOMDataTreeWriteTransaction newWriteOnlyTransaction() {
-            return null;
-        }
-
-        @Override
-        public DOMDataTreeReadWriteTransaction newReadWriteTransaction() {
-            return null;
-        }
-    }
-}
index 561900b741ddb5bf2e771bdabf31f31fa4649d36..5f0fd4d6627ecbd777f276554f5d8fa9ae3c8110 100644 (file)
@@ -40,7 +40,6 @@ import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.util.SimpleUriInfo;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.restconf.nb.rfc8040.streams.Configuration;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenerAdapter;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenersBroker;
@@ -67,7 +66,6 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     private Configuration configurationWs;
     private Configuration configurationSse;
 
-    private TransactionChainHandler transactionHandler;
     private SchemaContextHandler schemaHandler;
 
     @Before
@@ -131,7 +129,7 @@ public class RestconfStreamsSubscriptionServiceImplTest {
                 NotificationOutputType.XML);
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
                 new RestconfStreamsSubscriptionServiceImpl(this.dataBroker, this.notificationService,
-                        this.schemaHandler, this.transactionHandler, configurationSse);
+                        this.schemaHandler, this.configurationSse);
         final NormalizedNodeContext response = streamsSubscriptionService
                 .subscribeToStream(
                         "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
@@ -150,7 +148,7 @@ public class RestconfStreamsSubscriptionServiceImplTest {
                 NotificationOutputType.XML);
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
                 new RestconfStreamsSubscriptionServiceImpl(this.dataBroker, this.notificationService,
-                        this.schemaHandler, this.transactionHandler, configurationWs);
+                        this.schemaHandler, this.configurationWs);
         final NormalizedNodeContext response = streamsSubscriptionService
                 .subscribeToStream(
                         "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
@@ -164,7 +162,7 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     public void testSubscribeToStreamMissingDatastoreInPath() {
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
                 new RestconfStreamsSubscriptionServiceImpl(this.dataBroker, this.notificationService,
-                        this.schemaHandler, this.transactionHandler, configurationWs);
+                        this.schemaHandler, this.configurationWs);
         streamsSubscriptionService.subscribeToStream("toaster:toaster/toasterStatus/scope=ONE", this.uriInfo);
     }
 
@@ -172,7 +170,7 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     public void testSubscribeToStreamMissingScopeInPath() {
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
                 new RestconfStreamsSubscriptionServiceImpl(this.dataBroker, this.notificationService,
-                        this.schemaHandler, this.transactionHandler, configurationWs);
+                        this.schemaHandler, this.configurationWs);
         streamsSubscriptionService.subscribeToStream("toaster:toaster/toasterStatus/datastore=OPERATIONAL",
                 this.uriInfo);
     }