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;
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(
@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);
}
}
+++ /dev/null
-/*
- * 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);
- }
-}
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;
* @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();
}
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;
}
return this.notificationService;
}
- /**
- * Get {@link TransactionChainHandler}.
- *
- * @return the transactionChainHandler
- */
- public TransactionChainHandler getTransactionChainHandler() {
- return this.transactionChainHandler;
- }
-
/**
* Get {@link SchemaContextHandler}.
*
+++ /dev/null
-/*
- * 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;
- }
- }
-}
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;
private Configuration configurationWs;
private Configuration configurationSse;
- private TransactionChainHandler transactionHandler;
private SchemaContextHandler schemaHandler;
@Before
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",
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",
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);
}
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);
}