package org.opendaylight.restconf.nb.rfc8040;
import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSet.Builder;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
-import java.util.Set;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
private static final Logger LOG = LoggerFactory.getLogger(RestConnectorProvider.class);
- public static final TransactionChainListener TRANSACTION_CHAIN_LISTENER = new TransactionChainListener() {
- @Override
- public void onTransactionChainFailed(final TransactionChain<?, ?> chain,
- final AsyncTransaction<?, ?> transaction, final Throwable cause) {
- LOG.warn("TransactionChain({}) {} FAILED!", chain, transaction.getIdentifier(), cause);
- resetTransactionChainForAdapaters(chain);
- throw new RestconfDocumentedException("TransactionChain(" + chain + ") not committed correctly", cause);
- }
-
- @Override
- public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
- LOG.trace("TransactionChain({}) {} SUCCESSFUL", chain);
- }
- };
-
- @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
- private static volatile TransactionChainHandler transactionChainHandler;
- @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
- private static volatile DOMDataBroker dataBroker;
@SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
private static volatile DOMMountPointServiceHandler mountPointServiceHandler;
private final DOMNotificationService notificationService;
private final DOMMountPointService mountPointService;
private final DOMSchemaService domSchemaService;
- private final Builder<Object> servicesProperties;
+ private final TransactionChainHandler transactionChainHandler;
+ private final DOMDataBroker dataBroker;
private ListenerRegistration<SchemaContextListener> listenerRegistration;
private SchemaContextHandler schemaCtxHandler;
- private T wrapperServices;
-
- // FIXME: refactor this class and its users to interact via builder pattern, where individual
- // services are injected and then the provider is created
- public RestConnectorProvider(final DOMDataBroker domDataBroker,
- final DOMSchemaService domSchemaService, final DOMRpcService rpcService,
- final DOMNotificationService notificationService, final DOMMountPointService mountPointService) {
- this(domDataBroker, domSchemaService, rpcService, notificationService, mountPointService, null);
- }
+ private final T wrapperServices;
public RestConnectorProvider(final DOMDataBroker domDataBroker, final DOMSchemaService domSchemaService,
final DOMRpcService rpcService, final DOMNotificationService notificationService,
- final DOMMountPointService mountPointService, final T wrapperServices) {
- this.servicesProperties = ImmutableSet.<Object>builder();
+ final DOMMountPointService mountPointService, final TransactionChainHandler transactionChainHandler,
+ final T wrapperServices) {
this.wrapperServices = wrapperServices;
this.domSchemaService = Preconditions.checkNotNull(domSchemaService);
this.rpcService = Preconditions.checkNotNull(rpcService);
this.notificationService = Preconditions.checkNotNull(notificationService);
this.mountPointService = Preconditions.checkNotNull(mountPointService);
-
- RestConnectorProvider.dataBroker = Preconditions.checkNotNull(domDataBroker);
+ this.transactionChainHandler = Preconditions.checkNotNull(transactionChainHandler);
+ this.dataBroker = Preconditions.checkNotNull(domDataBroker);
}
public synchronized void start() {
mountPointServiceHandler = new DOMMountPointServiceHandler(mountPointService);
- servicesProperties.add(mountPointServiceHandler);
final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(dataBroker);
- servicesProperties.add(brokerHandler);
-
- RestConnectorProvider.transactionChainHandler = new TransactionChainHandler(dataBroker
- .createTransactionChain(RestConnectorProvider.TRANSACTION_CHAIN_LISTENER));
- servicesProperties.add(transactionChainHandler);
this.schemaCtxHandler = new SchemaContextHandler(transactionChainHandler);
- servicesProperties.add(schemaCtxHandler);
this.listenerRegistration = domSchemaService.registerSchemaContextListener(this.schemaCtxHandler);
final RpcServiceHandler rpcServiceHandler = new RpcServiceHandler(rpcService);
- servicesProperties.add(rpcServiceHandler);
final NotificationServiceHandler notificationServiceHandler =
new NotificationServiceHandler(notificationService);
- servicesProperties.add(notificationServiceHandler);
if (wrapperServices != null) {
wrapperServices.setHandlers(this.schemaCtxHandler, RestConnectorProvider.mountPointServiceHandler,
- RestConnectorProvider.transactionChainHandler, brokerHandler, rpcServiceHandler,
+ transactionChainHandler, brokerHandler, rpcServiceHandler,
notificationServiceHandler, domSchemaService);
}
}
return mountPointServiceHandler;
}
- /**
- * After {@link TransactionChain} failed, this updates {@link TransactionChainHandler} with new transaction chain.
- *
- * @param chain
- * old {@link TransactionChain}
- */
- public static void resetTransactionChainForAdapaters(final TransactionChain<?, ?> chain) {
- LOG.trace("Resetting TransactionChain({})", chain);
- chain.close();
- RestConnectorProvider.transactionChainHandler.update(
- Preconditions.checkNotNull(dataBroker).createTransactionChain(
- RestConnectorProvider.TRANSACTION_CHAIN_LISTENER)
- );
- }
-
/**
* Get current {@link DOMMountPointService} from {@link DOMMountPointServiceHandler}.
* @return {@link DOMMountPointService}
this.listenerRegistration.close();
}
- // close transaction chain
- if (transactionChainHandler != null && transactionChainHandler.get() != null) {
- transactionChainHandler.get().close();
- }
-
- transactionChainHandler = null;
mountPointServiceHandler = null;
- dataBroker = null;
- }
-
- public final synchronized Set<Object> getServicesProperties() {
- return servicesProperties.build();
}
}
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
import org.opendaylight.restconf.nb.rfc8040.Rfc8040.IetfYangLibrary;
import org.opendaylight.restconf.nb.rfc8040.Rfc8040.MonitoringModule;
import org.opendaylight.restconf.nb.rfc8040.utils.mapping.RestconfMappingNodeUtil;
https://bugs.opendaylight.org/show_bug.cgi?id=7728
*/
LOG.warn("Ignoring that another cluster node is already putting the same data to DS.", e);
- RestConnectorProvider.resetTransactionChainForAdapaters(this.transactionChainHandler.get());
+ this.transactionChainHandler.reset();
}
}
}
package org.opendaylight.restconf.nb.rfc8040.handlers;
-import com.google.common.base.Preconditions;
+import java.util.Objects;
+import javax.annotation.Nullable;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Implementation of {@link TransactionChainHandler}.
*
*/
-public class TransactionChainHandler implements Handler<DOMTransactionChain> {
+public class TransactionChainHandler implements Handler<DOMTransactionChain>, AutoCloseable {
+ private static final Logger LOG = LoggerFactory.getLogger(TransactionChainHandler.class);
- private DOMTransactionChain transactionChain;
+ private final TransactionChainListener transactionChainListener = new TransactionChainListener() {
+ @Override
+ public void onTransactionChainFailed(final TransactionChain<?, ?> chain,
+ final AsyncTransaction<?, ?> transaction, final Throwable cause) {
+ LOG.warn("TransactionChain({}) {} FAILED!", chain, transaction.getIdentifier(), cause);
+ reset();
+ throw new RestconfDocumentedException("TransactionChain(" + chain + ") not committed correctly", cause);
+ }
+
+ @Override
+ public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
+ LOG.trace("TransactionChain({}) {} SUCCESSFUL", chain);
+ }
+ };
+
+ @Nullable
+ private final DOMDataBroker dataBroker;
+ private volatile DOMTransactionChain transactionChain;
/**
* Prepare transaction chain service for Restconf services.
- *
- * @param transactionChain Transaction chain
*/
- public TransactionChainHandler(final DOMTransactionChain transactionChain) {
- Preconditions.checkNotNull(transactionChain);
- this.transactionChain = transactionChain;
+ public TransactionChainHandler(final DOMDataBroker dataBroker) {
+ this.dataBroker = Objects.requireNonNull(dataBroker);
+ transactionChain = Objects.requireNonNull(dataBroker.createTransactionChain(transactionChainListener));
}
@Override
- @SuppressWarnings("checkstyle:hiddenField")
- public void update(final DOMTransactionChain transactionChain) {
- Preconditions.checkNotNull(transactionChain);
- this.transactionChain = transactionChain;
+ public DOMTransactionChain get() {
+ return this.transactionChain;
+ }
+
+ public synchronized void reset() {
+ LOG.trace("Resetting TransactionChain({})", transactionChain);
+ transactionChain.close();
+ transactionChain = dataBroker.createTransactionChain(transactionChainListener);
}
@Override
- public DOMTransactionChain get() {
- return this.transactionChain;
+ public synchronized void close() {
+ transactionChain.close();
}
}
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map.Entry;
+import java.util.Objects;
import javax.annotation.Nonnull;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
import org.opendaylight.restconf.common.context.WriterParameters;
import org.opendaylight.restconf.common.errors.RestconfError;
import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.restconf.common.patch.PatchStatusContext;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
final TransactionChainHandler transactionChainHandler,
final DOMMountPointServiceHandler mountPointServiceHandler,
final RestconfStreamsSubscriptionService delegRestconfSubscrService) {
- this.schemaContextHandler = schemaContextHandler;
- this.transactionChainHandler = transactionChainHandler;
- this.mountPointServiceHandler = mountPointServiceHandler;
- this.delegRestconfSubscrService = delegRestconfSubscrService;
+ this.schemaContextHandler = Objects.requireNonNull(schemaContextHandler);
+ this.transactionChainHandler = Objects.requireNonNull(transactionChainHandler);
+ this.mountPointServiceHandler = Objects.requireNonNull(mountPointServiceHandler);
+ this.delegRestconfSubscrService = Objects.requireNonNull(delegRestconfSubscrService);
}
@Override
instanceIdentifier, uriInfo, tagged);
final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint();
- final DOMTransactionChain transactionChain;
+ final TransactionChainHandler localTransactionChainHandler;
if (mountPoint == null) {
- transactionChain = this.transactionChainHandler.get();
+ localTransactionChainHandler = this.transactionChainHandler;
} else {
- transactionChain = transactionChainOfMountPoint(mountPoint);
+ localTransactionChainHandler = transactionChainOfMountPoint(mountPoint);
}
final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(
- instanceIdentifier, mountPoint, transactionChain);
+ instanceIdentifier, mountPoint, localTransactionChainHandler);
final NormalizedNode<?, ?> node =
ReadDataTransactionUtil.readData(identifier, parameters.getContent(), transactionNode, withDefa,
schemaContextRef, uriInfo);
PutDataTransactionUtil.validateListKeysEqualityInPayloadAndUri(payload);
final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
- final DOMTransactionChain transactionChain;
+ final TransactionChainHandler localTransactionChainHandler;
final SchemaContextRef ref;
if (mountPoint == null) {
- transactionChain = this.transactionChainHandler.get();
+ localTransactionChainHandler = this.transactionChainHandler;
ref = new SchemaContextRef(this.schemaContextHandler.get());
} else {
- transactionChain = transactionChainOfMountPoint(mountPoint);
+ localTransactionChainHandler = transactionChainOfMountPoint(mountPoint);
ref = new SchemaContextRef(mountPoint.getSchemaContext());
}
final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(
- payload.getInstanceIdentifierContext(), mountPoint, transactionChain);
+ payload.getInstanceIdentifierContext(), mountPoint, localTransactionChainHandler);
return PutDataTransactionUtil.putData(payload, ref, transactionNode, insert, point);
}
checkQueryParams(insertUsed, pointUsed, insert);
final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
- final DOMTransactionChain transactionChain;
+ final TransactionChainHandler localTransactionChainHandler;
final SchemaContextRef ref;
if (mountPoint == null) {
- transactionChain = this.transactionChainHandler.get();
+ localTransactionChainHandler = this.transactionChainHandler;
ref = new SchemaContextRef(this.schemaContextHandler.get());
} else {
- transactionChain = transactionChainOfMountPoint(mountPoint);
+ localTransactionChainHandler = transactionChainOfMountPoint(mountPoint);
ref = new SchemaContextRef(mountPoint.getSchemaContext());
}
final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(
- payload.getInstanceIdentifierContext(), mountPoint, transactionChain);
+ payload.getInstanceIdentifierContext(), mountPoint, localTransactionChainHandler);
return PostDataTransactionUtil.postData(uriInfo, payload, transactionNode, ref, insert, point);
}
identifier, schemaContextRef.get(), Optional.of(this.mountPointServiceHandler.get()));
final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint();
- final DOMTransactionChain transactionChain;
+ final TransactionChainHandler localTransactionChainHandler;
if (mountPoint == null) {
- transactionChain = this.transactionChainHandler.get();
+ localTransactionChainHandler = this.transactionChainHandler;
} else {
- transactionChain = transactionChainOfMountPoint(mountPoint);
+ localTransactionChainHandler = transactionChainOfMountPoint(mountPoint);
}
final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(instanceIdentifier, mountPoint,
- transactionChain);
+ localTransactionChainHandler);
return DeleteDataTransactionUtil.deleteData(transactionNode);
}
Preconditions.checkNotNull(context);
final DOMMountPoint mountPoint = context.getInstanceIdentifierContext().getMountPoint();
- final DOMTransactionChain transactionChain;
+ final TransactionChainHandler localTransactionChainHandler;
final SchemaContextRef ref;
if (mountPoint == null) {
- transactionChain = this.transactionChainHandler.get();
+ localTransactionChainHandler = this.transactionChainHandler;
ref = new SchemaContextRef(this.schemaContextHandler.get());
} else {
- transactionChain = transactionChainOfMountPoint(mountPoint);
+ localTransactionChainHandler = transactionChainOfMountPoint(mountPoint);
ref = new SchemaContextRef(mountPoint.getSchemaContext());
}
final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(
- context.getInstanceIdentifierContext(), mountPoint, transactionChain);
+ context.getInstanceIdentifierContext(), mountPoint, localTransactionChainHandler);
return PatchDataTransactionUtil.patchData(context, transactionNode, ref);
}
* Prepare transaction chain to access data of mount point.
* @param mountPoint
* mount point reference
- * @return {@link DOMTransactionChain}
+ * @return {@link TransactionChainHandler}
*/
- private static DOMTransactionChain transactionChainOfMountPoint(@Nonnull final DOMMountPoint mountPoint) {
+ private static TransactionChainHandler transactionChainOfMountPoint(@Nonnull final DOMMountPoint mountPoint) {
final Optional<DOMDataBroker> domDataBrokerService = mountPoint.getService(DOMDataBroker.class);
if (domDataBrokerService.isPresent()) {
- return domDataBrokerService.get().createTransactionChain(RestConnectorProvider.TRANSACTION_CHAIN_LISTENER);
+ return new TransactionChainHandler(domDataBrokerService.get());
}
final String errMsg = "DOM data broker service isn't available for mount point " + mountPoint.getIdentifier();
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
/**
* This class represent delegation wrapper for transaction variables.
private final DOMMountPoint mountPoint;
private LogicalDatastoreType configuration = null;
private final DOMTransactionChain transactionChain;
+ private final TransactionChainHandler transactionChainHandler;
/**
* Set base type of variables, which ones we need for transaction.
* {@link InstanceIdentifierContext} of data for transaction
* @param mountPoint
* mount point if is present
- * @param transactionChain
- * transaction chain for creating specific type of transaction
- * in specific operation
+ * @param transactionChainHandler
+ * used to obtain the transaction chain for creating specific type of transaction
+ * in specific operation
*/
public TransactionVarsWrapper(final InstanceIdentifierContext<?> instanceIdentifier, final DOMMountPoint mountPoint,
- final DOMTransactionChain transactionChain) {
+ final TransactionChainHandler transactionChainHandler) {
this.instanceIdentifier = instanceIdentifier;
this.mountPoint = mountPoint;
- this.transactionChain = transactionChain;
+ this.transactionChainHandler = transactionChainHandler;
+ transactionChain = transactionChainHandler.get();
}
/**
public DOMTransactionChain getTransactionChain() {
return this.transactionChain;
}
+
+ public TransactionChainHandler getTransactionChainHandler() {
+ return transactionChainHandler;
+ }
}
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
*/
public static Response deleteData(final TransactionVarsWrapper transactionNode) {
final CheckedFuture<Void, TransactionCommitFailedException> future = submitData(
- transactionNode.getTransactionChain(), transactionNode.getTransactionChain().newReadWriteTransaction(),
+ transactionNode.getTransactionChainHandler(),
transactionNode.getInstanceIdentifier().getInstanceIdentifier());
final ResponseFactory response = new ResponseFactory(Status.NO_CONTENT);
FutureCallbackTx.addCallback(future, RestconfDataServiceConstant.DeleteData.DELETE_TX_TYPE, response);
/**
* Delete data via transaction. Return error if data to delete does not exist.
*
- * @param transactionChain
- * transaction chain
+ * @param transactionChainHandler
+ * transaction chain handler
* @param readWriteTx
* read and write transaction
* @param path
* @return {@link CheckedFuture}
*/
private static CheckedFuture<Void, TransactionCommitFailedException> submitData(
- final DOMTransactionChain transactionChain, final DOMDataReadWriteTransaction readWriteTx,
- final YangInstanceIdentifier path) {
- TransactionUtil.checkItemExists(transactionChain, readWriteTx, LogicalDatastoreType.CONFIGURATION, path,
+ final TransactionChainHandler transactionChainHandler, final YangInstanceIdentifier path) {
+ final DOMDataReadWriteTransaction readWriteTx = transactionChainHandler.get().newReadWriteTransaction();
+ TransactionUtil.checkItemExists(transactionChainHandler, readWriteTx, LogicalDatastoreType.CONFIGURATION, path,
RestconfDataServiceConstant.DeleteData.DELETE_TX_TYPE);
readWriteTx.delete(LogicalDatastoreType.CONFIGURATION, path);
return readWriteTx.submit();
import org.opendaylight.restconf.common.patch.PatchEntity;
import org.opendaylight.restconf.common.patch.PatchStatusContext;
import org.opendaylight.restconf.common.patch.PatchStatusEntity;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfDataServiceConstant.PatchData;
return new PatchStatusContext(context.getPatchId(), ImmutableList.copyOf(editCollection), true, null);
} else {
tx.cancel();
- RestConnectorProvider.resetTransactionChainForAdapaters(transactionNode.getTransactionChain());
+ transactionNode.getTransactionChainHandler().reset();
return new PatchStatusContext(context.getPatchId(), ImmutableList.copyOf(editCollection),
false, null);
}
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.TransactionChainHandler;
import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
final DOMTransactionChain domTransactionChain = transactionNode.getTransactionChain();
final DOMDataReadWriteTransaction newReadWriteTransaction = domTransactionChain.newReadWriteTransaction();
if (insert == null) {
- makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(), newReadWriteTransaction);
return newReadWriteTransaction.submit();
} else {
final DataSchemaNode schemaNode = PutDataTransactionUtil.checkListAndOrderedType(schemaContext, path);
switch (insert) {
case "first":
if (schemaNode instanceof ListSchemaNode) {
- final NormalizedNode<?, ?> readData =
- PutDataTransactionUtil.readList(path.getParent(), schemaContext, domTransactionChain,
- schemaNode);
+ final NormalizedNode<?, ?> readData = PutDataTransactionUtil.readList(path.getParent(),
+ schemaContext, transactionNode.getTransactionChainHandler(), schemaNode);
final OrderedMapNode readList = (OrderedMapNode) readData;
if (readList == null || readList.getValue().isEmpty()) {
- makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(),
+ newReadWriteTransaction);
return newReadWriteTransaction.submit();
} else {
newReadWriteTransaction.delete(LogicalDatastoreType.CONFIGURATION,
path.getParent().getParent());
simplePost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION, path, data,
- schemaContext, domTransactionChain);
- makePost(path, readData, schemaContext, domTransactionChain,
+ schemaContext, transactionNode.getTransactionChainHandler());
+ makePost(path, readData, schemaContext, transactionNode.getTransactionChainHandler(),
newReadWriteTransaction);
return newReadWriteTransaction.submit();
}
} else {
- final NormalizedNode<?, ?> readData = PutDataTransactionUtil
- .readList(path.getParent(), schemaContext, domTransactionChain, schemaNode);
+ final NormalizedNode<?, ?> readData = PutDataTransactionUtil.readList(path.getParent(),
+ schemaContext, transactionNode.getTransactionChainHandler(), schemaNode);
final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
if (readLeafList == null || readLeafList.getValue().isEmpty()) {
- makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(),
+ newReadWriteTransaction);
return newReadWriteTransaction.submit();
} else {
newReadWriteTransaction.delete(LogicalDatastoreType.CONFIGURATION,
path.getParent().getParent());
simplePost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION, path, data,
- schemaContext, domTransactionChain);
- makePost(path, readData, schemaContext, domTransactionChain, newReadWriteTransaction);
+ schemaContext, transactionNode.getTransactionChainHandler());
+ makePost(path, readData, schemaContext, transactionNode.getTransactionChainHandler(),
+ newReadWriteTransaction);
return newReadWriteTransaction.submit();
}
}
case "last":
- makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(),
+ newReadWriteTransaction);
return newReadWriteTransaction.submit();
case "before":
if (schemaNode instanceof ListSchemaNode) {
- final NormalizedNode<?, ?> readData =
- PutDataTransactionUtil.readList(path.getParent(), schemaContext, domTransactionChain,
- schemaNode);
+ final NormalizedNode<?, ?> readData = PutDataTransactionUtil.readList(path.getParent(),
+ schemaContext, transactionNode.getTransactionChainHandler(), schemaNode);
final OrderedMapNode readList = (OrderedMapNode) readData;
if (readList == null || readList.getValue().isEmpty()) {
- makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(),
+ newReadWriteTransaction);
return newReadWriteTransaction.submit();
} else {
insertWithPointListPost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION, path,
- data, schemaContext, point, readList, true, domTransactionChain);
+ data, schemaContext, point, readList, true,
+ transactionNode.getTransactionChainHandler());
return newReadWriteTransaction.submit();
}
} else {
- final NormalizedNode<?, ?> readData =
- PutDataTransactionUtil.readList(path.getParent(), schemaContext, domTransactionChain,
- schemaNode);
+ final NormalizedNode<?, ?> readData = PutDataTransactionUtil.readList(path.getParent(),
+ schemaContext, transactionNode.getTransactionChainHandler(), schemaNode);
final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
if (readLeafList == null || readLeafList.getValue().isEmpty()) {
- makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(),
+ newReadWriteTransaction);
return newReadWriteTransaction.submit();
} else {
insertWithPointLeafListPost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION,
- path, data, schemaContext, point, readLeafList, true, domTransactionChain);
+ path, data, schemaContext, point, readLeafList, true,
+ transactionNode.getTransactionChainHandler());
return newReadWriteTransaction.submit();
}
}
case "after":
if (schemaNode instanceof ListSchemaNode) {
- final NormalizedNode<?, ?> readData =
- PutDataTransactionUtil.readList(path.getParent(), schemaContext, domTransactionChain,
- schemaNode);
+ final NormalizedNode<?, ?> readData = PutDataTransactionUtil.readList(path.getParent(),
+ schemaContext, transactionNode.getTransactionChainHandler(), schemaNode);
final OrderedMapNode readList = (OrderedMapNode) readData;
if (readList == null || readList.getValue().isEmpty()) {
- makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(),
+ newReadWriteTransaction);
return newReadWriteTransaction.submit();
} else {
insertWithPointListPost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION, path,
- data, schemaContext, point, readList, false, domTransactionChain);
+ data, schemaContext, point, readList, false,
+ transactionNode.getTransactionChainHandler());
return newReadWriteTransaction.submit();
}
} else {
- final NormalizedNode<?, ?> readData =
- PutDataTransactionUtil.readList(path.getParent(), schemaContext, domTransactionChain,
- schemaNode);
+ final NormalizedNode<?, ?> readData = PutDataTransactionUtil.readList(path.getParent(),
+ schemaContext, transactionNode.getTransactionChainHandler(), schemaNode);
final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
if (readLeafList == null || readLeafList.getValue().isEmpty()) {
- makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(),
+ newReadWriteTransaction);
return newReadWriteTransaction.submit();
} else {
insertWithPointLeafListPost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION,
- path, data, schemaContext, point, readLeafList, true, domTransactionChain);
+ path, data, schemaContext, point, readLeafList, true,
+ transactionNode.getTransactionChainHandler());
return newReadWriteTransaction.submit();
}
}
private static void insertWithPointLeafListPost(final DOMDataReadWriteTransaction rwTransaction,
final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
final SchemaContext schemaContext, final String point, final OrderedLeafSetNode<?> readLeafList,
- final boolean before, final DOMTransactionChain domTransactionChain) {
+ final boolean before, final TransactionChainHandler transactionChainHandler) {
rwTransaction.delete(datastore, path.getParent().getParent());
final InstanceIdentifierContext<?> instanceIdentifier =
ParserIdentifier.toInstanceIdentifier(point, schemaContext, Optional.absent());
rwTransaction.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
for (final LeafSetEntryNode<?> nodeChild : readLeafList.getValue()) {
if (lastInsertedPosition == lastItemPosition) {
- TransactionUtil.checkItemDoesNotExists(domTransactionChain, rwTransaction, datastore, path,
+ TransactionUtil.checkItemDoesNotExists(transactionChainHandler, rwTransaction, datastore, path,
RestconfDataServiceConstant.PostData.POST_TX_TYPE);
rwTransaction.put(datastore, path, payload);
}
final YangInstanceIdentifier childPath = path.getParent().getParent().node(nodeChild.getIdentifier());
- TransactionUtil.checkItemDoesNotExists(domTransactionChain, rwTransaction, datastore, childPath,
+ TransactionUtil.checkItemDoesNotExists(transactionChainHandler, rwTransaction, datastore, childPath,
RestconfDataServiceConstant.PostData.POST_TX_TYPE);
rwTransaction.put(datastore, childPath, nodeChild);
lastInsertedPosition++;
private static void insertWithPointListPost(final DOMDataReadWriteTransaction rwTransaction,
final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
final SchemaContext schemaContext, final String point, final MapNode readList, final boolean before,
- final DOMTransactionChain domTransactionChain) {
+ final TransactionChainHandler transactionChainHandler) {
rwTransaction.delete(datastore, path.getParent().getParent());
final InstanceIdentifierContext<?> instanceIdentifier =
ParserIdentifier.toInstanceIdentifier(point, schemaContext, Optional.absent());
rwTransaction.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
for (final MapEntryNode mapEntryNode : readList.getValue()) {
if (lastInsertedPosition == lastItemPosition) {
- TransactionUtil.checkItemDoesNotExists(domTransactionChain, rwTransaction, datastore, path,
+ TransactionUtil.checkItemDoesNotExists(transactionChainHandler, rwTransaction, datastore, path,
RestconfDataServiceConstant.PostData.POST_TX_TYPE);
rwTransaction.put(datastore, path, payload);
}
final YangInstanceIdentifier childPath = path.getParent().getParent().node(mapEntryNode.getIdentifier());
- TransactionUtil.checkItemDoesNotExists(domTransactionChain, rwTransaction, datastore, childPath,
+ TransactionUtil.checkItemDoesNotExists(transactionChainHandler, rwTransaction, datastore, childPath,
RestconfDataServiceConstant.PostData.POST_TX_TYPE);
rwTransaction.put(datastore, childPath, mapEntryNode);
lastInsertedPosition++;
}
private static void makePost(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data,
- final SchemaContext schemaContext, final DOMTransactionChain transactionChain,
+ final SchemaContext schemaContext, final TransactionChainHandler transactionChainHandler,
final DOMDataReadWriteTransaction transaction) {
if (data instanceof MapNode) {
boolean merge = false;
for (final MapEntryNode child : ((MapNode) data).getValue()) {
final YangInstanceIdentifier childPath = path.node(child.getIdentifier());
TransactionUtil.checkItemDoesNotExists(
- transactionChain, transaction, LogicalDatastoreType.CONFIGURATION, childPath,
+ transactionChainHandler, transaction, LogicalDatastoreType.CONFIGURATION, childPath,
RestconfDataServiceConstant.PostData.POST_TX_TYPE);
if (!merge) {
merge = true;
}
} else {
TransactionUtil.checkItemDoesNotExists(
- transactionChain, transaction, LogicalDatastoreType.CONFIGURATION, path,
+ transactionChainHandler, transaction, LogicalDatastoreType.CONFIGURATION, path,
RestconfDataServiceConstant.PostData.POST_TX_TYPE);
TransactionUtil.ensureParentsByMerge(path, schemaContext, transaction);
private static void simplePost(final DOMDataReadWriteTransaction rwTransaction,
final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
- final SchemaContext schemaContext, final DOMTransactionChain transactionChain) {
- TransactionUtil.checkItemDoesNotExists(transactionChain, rwTransaction, datastore, path,
+ final SchemaContext schemaContext, final TransactionChainHandler transactionChainHandler) {
+ TransactionUtil.checkItemDoesNotExists(transactionChainHandler, rwTransaction, datastore, path,
RestconfDataServiceConstant.PostData.POST_TX_TYPE);
TransactionUtil.ensureParentsByMerge(path, schemaContext, rwTransaction);
rwTransaction.put(datastore, path, payload);
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
-import org.opendaylight.controller.md.sal.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.common.errors.RestconfError.ErrorTag;
import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
import org.opendaylight.restconf.common.validation.RestconfValidationUtils;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
final ResponseFactory responseFactory =
new ResponseFactory(existsResponse.result ? Status.NO_CONTENT : Status.CREATED);
final CheckedFuture<Void, TransactionCommitFailedException> submitData = submitData(path, schemaContext,
- transactionNode.getTransactionChain(), readWriteTransaction, payload.getData(), insert, point);
+ transactionNode.getTransactionChainHandler(), readWriteTransaction, payload.getData(), insert, point);
FutureCallbackTx.addCallback(submitData, RestconfDataServiceConstant.PutData.PUT_TX_TYPE, responseFactory);
return responseFactory.build();
}
* path of data
* @param schemaContext
* {@link SchemaContext}
- * @param domTransactionChain
+ * @param transactionChainHandler
* write transaction
* @param data
* data
* @return {@link CheckedFuture}
*/
private static CheckedFuture<Void, TransactionCommitFailedException> submitData(final YangInstanceIdentifier path,
- final SchemaContext schemaContext, final DOMTransactionChain domTransactionChain,
+ final SchemaContext schemaContext, final TransactionChainHandler transactionChainHandler,
final DOMDataReadWriteTransaction readWriteTransaction,
final NormalizedNode<?, ?> data, final String insert, final String point) {
if (insert == null) {
case "first":
if (schemaNode instanceof ListSchemaNode) {
final NormalizedNode<?, ?> readData =
- readList(path, schemaContext, domTransactionChain, schemaNode);
+ readList(path, schemaContext, transactionChainHandler, schemaNode);
final OrderedMapNode readList = (OrderedMapNode) readData;
if (readList == null || readList.getValue().isEmpty()) {
return makePut(path, schemaContext, readWriteTransaction, data);
}
} else {
final NormalizedNode<?, ?> readData =
- readList(path, schemaContext, domTransactionChain, schemaNode);
+ readList(path, schemaContext, transactionChainHandler, schemaNode);
final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
if (readLeafList == null || readLeafList.getValue().isEmpty()) {
case "before":
if (schemaNode instanceof ListSchemaNode) {
final NormalizedNode<?, ?> readData =
- readList(path, schemaContext, domTransactionChain, schemaNode);
+ readList(path, schemaContext, transactionChainHandler, schemaNode);
final OrderedMapNode readList = (OrderedMapNode) readData;
if (readList == null || readList.getValue().isEmpty()) {
return makePut(path, schemaContext, readWriteTransaction, data);
}
} else {
final NormalizedNode<?, ?> readData =
- readList(path, schemaContext, domTransactionChain, schemaNode);
+ readList(path, schemaContext, transactionChainHandler, schemaNode);
final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
if (readLeafList == null || readLeafList.getValue().isEmpty()) {
case "after":
if (schemaNode instanceof ListSchemaNode) {
final NormalizedNode<?, ?> readData =
- readList(path, schemaContext, domTransactionChain, schemaNode);
+ readList(path, schemaContext, transactionChainHandler, schemaNode);
final OrderedMapNode readList = (OrderedMapNode) readData;
if (readList == null || readList.getValue().isEmpty()) {
return makePut(path, schemaContext, readWriteTransaction, data);
}
} else {
final NormalizedNode<?, ?> readData =
- readList(path, schemaContext, domTransactionChain, schemaNode);
+ readList(path, schemaContext, transactionChainHandler, schemaNode);
final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
if (readLeafList == null || readLeafList.getValue().isEmpty()) {
}
public static NormalizedNode<?, ?> readList(final YangInstanceIdentifier path, final SchemaContext schemaContext,
- final DOMTransactionChain domTransactionChain, final DataSchemaNode schemaNode) {
+ final TransactionChainHandler transactionChainHandler, final DataSchemaNode schemaNode) {
final InstanceIdentifierContext<?> iid = new InstanceIdentifierContext<SchemaNode>(
path.getParent(), schemaNode, null, schemaContext);
- final TransactionVarsWrapper transactionNode =
- new TransactionVarsWrapper(iid, null, domTransactionChain);
+ final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(iid, null, transactionChainHandler);
final NormalizedNode<?, ?> readData = ReadDataTransactionUtil
.readData(RestconfDataServiceConstant.ReadData.CONFIG, transactionNode, schemaContext);
return readData;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
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.RestConnectorProvider;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
/**
* Check if items already exists at specified {@code path}. Throws {@link RestconfDocumentedException} if
* data does NOT already exists.
- * @param transactionChain Transaction chain
+ * @param transactionChainHandler Transaction chain handler
* @param rwTransaction Transaction
* @param store Datastore
* @param path Path to be checked
* @param operationType Type of operation (READ, POST, PUT, DELETE...)
*/
- public static void checkItemExists(final DOMTransactionChain transactionChain,
+ public static void checkItemExists(final TransactionChainHandler transactionChainHandler,
final DOMDataReadWriteTransaction rwTransaction,
final LogicalDatastoreType store, final YangInstanceIdentifier path,
final String operationType) {
if (!response.result) {
// close transaction and reset transaction chain
rwTransaction.cancel();
- RestConnectorProvider.resetTransactionChainForAdapaters(transactionChain);
+ transactionChainHandler.reset();
// throw error
final String errMsg = "Operation via Restconf was not executed because data does not exist";
/**
* Check if items do NOT already exists at specified {@code path}. Throws {@link RestconfDocumentedException} if
* data already exists.
- * @param transactionChain Transaction chain
+ * @param transactionChainHandler Transaction chain handler
* @param rwTransaction Transaction
* @param store Datastore
* @param path Path to be checked
* @param operationType Type of operation (READ, POST, PUT, DELETE...)
*/
- public static void checkItemDoesNotExists(final DOMTransactionChain transactionChain,
+ public static void checkItemDoesNotExists(final TransactionChainHandler transactionChainHandler,
final DOMDataReadWriteTransaction rwTransaction,
final LogicalDatastoreType store, final YangInstanceIdentifier path,
final String operationType) {
if (response.result) {
// close transaction and reset transaction chain
rwTransaction.cancel();
- RestConnectorProvider.resetTransactionChainForAdapaters(transactionChain);
+ transactionChainHandler.reset();
// throw error
final String errMsg = "Operation via Restconf was not executed because data already exists";
<bean id="wrapper" class="org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl"
factory-method="getInstance" />
+ <bean id="transactionChainHandler" class="org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler"
+ destroy-method="close">
+ <argument ref="domDataBroker"/>
+ </bean>
+
<bean id="restconfProvider" class="org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider"
init-method="start" destroy-method="close">
<argument ref="domDataBroker"/>
<argument ref="domRpcService"/>
<argument ref="domNotificationService"/>
<argument ref="domMountPointService"/>
+ <argument ref="transactionChainHandler"/>
<argument ref="wrapper"/>
</bean>
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
*/
public class RestConnectorProviderTest {
// service under test
- private RestConnectorProvider connectorProvider;
+ private RestConnectorProvider<?> connectorProvider;
@Mock private DOMMountPointService mockMountPointService;
@Mock private DOMDataBroker mockDataBroker;
doReturn(mockRegistration).when(domSchemaService).registerSchemaContextListener(
Mockito.any(SchemaContextHandler.class));
- this.connectorProvider = new RestConnectorProvider(mockDataBroker, domSchemaService, mockRpcService,
- mockNotificationService, mockMountPointService, ServicesWrapperImpl.getInstance());
+ this.connectorProvider = new RestConnectorProvider<>(mockDataBroker, domSchemaService, mockRpcService,
+ mockNotificationService, mockMountPointService,
+ new TransactionChainHandler(mockDataBroker), ServicesWrapperImpl.getInstance());
}
/**
// verify interaction
verify(this.mockRegistration).close();
- verify(mockTransactionChain).close();
}
}
doReturn(schemaContext).when(mockSchemaContextHandler).get();
- final TransactionChainHandler txChainHandler = new TransactionChainHandler(mockTxChain);
+ final TransactionChainHandler txChainHandler = new TransactionChainHandler(mockDOMDataBroker);
final DOMMountPointServiceHandler mountPointServiceHandler =
new DOMMountPointServiceHandler(mockMountPointService);
service = new JSONRestconfServiceRfc8040Impl(ServicesWrapperImpl.getInstance(), mountPointServiceHandler);
new RestConnectorProvider<>(mockDOMDataBroker, domSchemaService, mockRpcService, mockNotificationService,
- mockMountPointService).start();
+ mockMountPointService, txChainHandler, null).start();
SchemaContextHandler.setSchemaContext(schemaContext);
}
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
import static org.opendaylight.restconf.common.patch.PatchEditOperation.CREATE;
import static org.opendaylight.restconf.common.patch.PatchEditOperation.DELETE;
import static org.opendaylight.restconf.common.patch.PatchEditOperation.REMOVE;
import static org.opendaylight.restconf.common.patch.PatchEditOperation.REPLACE;
import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
-import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import org.mockito.MockitoAnnotations;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.restconf.common.patch.PatchEntity;
import org.opendaylight.restconf.common.patch.PatchStatusContext;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
private ContainerNode buildPlayerCont;
private ContainerNode buildLibraryCont;
private MapNode buildPlaylistList;
-
- @Mock
private TransactionChainHandler transactionChainHandler;
+
@Mock
private DOMTransactionChain domTransactionChain;
@Mock
@Mock
private DOMDataBroker mountDataBroker;
@Mock
- private DOMTransactionChain transactionChain;
+ private DOMTransactionChain mountTransactionChain;
@Mock
private RestconfStreamsSubscriptionService delegRestconfSubscrService;
YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT)));
this.schemaNode = DataSchemaContextTree.from(this.contextRef.get()).getChild(this.iidBase).getDataSchemaNode();
- final TransactionChainHandler txHandler = Mockito.mock(TransactionChainHandler.class);
- final DOMTransactionChain domTx = Mockito.mock(DOMTransactionChain.class);
- Mockito.when(txHandler.get()).thenReturn(domTx);
- final DOMDataWriteTransaction wTx = Mockito.mock(DOMDataWriteTransaction.class);
- Mockito.when(domTx.newWriteOnlyTransaction()).thenReturn(wTx);
- final CheckedFuture<Void, TransactionCommitFailedException> checked = Mockito.mock(CheckedFuture.class);
- Mockito.when(wTx.submit()).thenReturn(checked);
- Mockito.when(checked.checkedGet()).thenReturn(null);
- final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(txHandler);
+ doReturn(Futures.immediateCheckedFuture(null)).when(this.write).submit();
+ doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
+
+ doReturn(this.read).when(domTransactionChain).newReadOnlyTransaction();
+ doReturn(this.readWrite).when(domTransactionChain).newReadWriteTransaction();
+ doReturn(this.write).when(domTransactionChain).newWriteOnlyTransaction();
+
+ DOMDataBroker mockDataBroker = Mockito.mock(DOMDataBroker.class);
+ Mockito.doReturn(domTransactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
+
+ transactionChainHandler = new TransactionChainHandler(mockDataBroker);
+
+ final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(transactionChainHandler);
schemaContextHandler.onGlobalContextUpdated(this.contextRef.get());
this.dataService = new RestconfDataServiceImpl(schemaContextHandler, this.transactionChainHandler,
this.mountPointServiceHandler, this.delegRestconfSubscrService);
- doReturn(this.domTransactionChain).when(this.transactionChainHandler).get();
- doReturn(this.read).when(this.domTransactionChain).newReadOnlyTransaction();
- doReturn(this.readWrite).when(this.domTransactionChain).newReadWriteTransaction();
- doReturn(this.write).when(this.domTransactionChain).newWriteOnlyTransaction();
doReturn(this.mountPointService).when(this.mountPointServiceHandler).get();
doReturn(Optional.of(this.mountPoint)).when(this.mountPointService)
.getMountPoint(any(YangInstanceIdentifier.class));
doReturn(this.contextRef.get()).when(this.mountPoint).getSchemaContext();
doReturn(Optional.of(this.mountDataBroker)).when(this.mountPoint).getService(DOMDataBroker.class);
- doReturn(this.transactionChain).when(this.mountDataBroker)
+ doReturn(this.mountTransactionChain).when(this.mountDataBroker)
.createTransactionChain(any(TransactionChainListener.class));
- doReturn(this.read).when(this.transactionChain).newReadOnlyTransaction();
- doReturn(this.readWrite).when(this.transactionChain).newReadWriteTransaction();
+ doReturn(this.read).when(this.mountTransactionChain).newReadOnlyTransaction();
+ doReturn(this.readWrite).when(this.mountTransactionChain).newReadWriteTransaction();
}
@Test
doReturn(Futures.immediateCheckedFuture(Boolean.TRUE)).when(this.readWrite)
.exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, payload.getData());
- doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
final Response response = this.dataService.putData(null, payload, this.uriInfo);
assertNotNull(response);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
@Test
public void testPutDataWithMountPoint() {
- final DOMDataBroker dataBroker = Mockito.mock(DOMDataBroker.class);
- doReturn(Optional.of(dataBroker)).when(mountPoint).getService(DOMDataBroker.class);
- doReturn(this.transactionChainHandler.get()).when(dataBroker)
- .createTransactionChain(RestConnectorProvider.TRANSACTION_CHAIN_LISTENER);
+// final DOMDataBroker dataBroker = Mockito.mock(DOMDataBroker.class);
+// doReturn(Optional.of(dataBroker)).when(mountPoint).getService(DOMDataBroker.class);
+// doReturn(this.transactionChainHandler.get()).when(dataBroker)
+// .createTransactionChain(RestConnectorProvider.TRANSACTION_CHAIN_LISTENER);
final InstanceIdentifierContext<DataSchemaNode> iidContext =
new InstanceIdentifierContext<>(this.iidBase, this.schemaNode, mountPoint, this.contextRef.get());
final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, this.buildBaseCont);
doReturn(Futures.immediateCheckedFuture(Boolean.TRUE)).when(this.readWrite)
.exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, payload.getData());
- doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
final Response response = this.dataService.putData(null, payload, this.uriInfo);
assertNotNull(response);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
doReturn(Futures.immediateCheckedFuture(false))
.when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, node);
doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, node, payload.getData());
- doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
doReturn(UriBuilder.fromUri("http://localhost:8181/restconf/15/")).when(this.uriInfo).getBaseUriBuilder();
final Response response = this.dataService.postData(null, payload, this.uriInfo);
@Test
public void testDeleteData() {
doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, this.iidBase);
- doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
doReturn(Futures.immediateCheckedFuture(true))
.when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
final Response response = this.dataService.deleteData("example-jukebox:jukebox");
@Test
public void testDeleteDataMountPoint() {
doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, this.iidBase);
- doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
doReturn(Futures.immediateCheckedFuture(true))
.when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
final Response response =
doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseCont))).when(this.read)
.read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, this.buildBaseCont);
- doReturn(Futures.immediateCheckedFuture(null)).when(this.write).submit();
doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidleaf);
- doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
doReturn(Futures.immediateCheckedFuture(false))
.when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
doReturn(Futures.immediateCheckedFuture(true))
doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseCont))).when(this.read)
.read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, this.buildBaseCont);
- doReturn(Futures.immediateCheckedFuture(null)).when(this.write).submit();
doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidleaf);
- doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
doReturn(Futures.immediateCheckedFuture(false))
.when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
doReturn(Futures.immediateCheckedFuture(true))
@Test
public void testPatchDataDeleteNotExist() throws Exception {
- final Field handler = RestConnectorProvider.class.getDeclaredField("transactionChainHandler");
- final Field broker = RestConnectorProvider.class.getDeclaredField("dataBroker");
-
- handler.setAccessible(true);
- handler.set(RestConnectorProvider.class, mock(TransactionChainHandler.class));
-
- broker.setAccessible(true);
- broker.set(RestConnectorProvider.class, mock(DOMDataBroker.class));
final InstanceIdentifierContext<? extends SchemaNode> iidContext =
new InstanceIdentifierContext<>(this.iidBase, this.schemaNode, null, this.contextRef.get());
final List<PatchEntity> entity = new ArrayList<>();
doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseCont))).when(this.read)
.read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, this.buildBaseCont);
- doReturn(Futures.immediateCheckedFuture(null)).when(this.write).submit();
doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidleaf);
- doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
doReturn(Futures.immediateCheckedFuture(false))
.when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
doReturn(Futures.immediateCheckedFuture(false))
doReturn(true).when(this.readWrite).cancel();
final PatchStatusContext status = this.dataService.patchData(patch, this.uriInfo);
- handler.set(RestConnectorProvider.class, null);
- handler.setAccessible(false);
-
- broker.set(RestConnectorProvider.class, null);
- broker.setAccessible(false);
-
assertFalse(status.isOk());
assertEquals(3, status.getEditCollection().size());
assertTrue(status.getEditCollection().get(0).isOk());
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
import com.google.common.util.concurrent.Futures;
-import java.lang.reflect.Field;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
-import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
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.RestConnectorProvider;
import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
private InstanceIdentifierContext<?> context;
@Mock
private DOMDataReadWriteTransaction readWrite;
+ @Mock
+ private DOMDataBroker mockDataBroker;
- // Fields used when delete operation fails to reset transaction chain
- private static Field handler;
- private static Field broker;
-
- @BeforeClass
- public static void setup() throws Exception {
- DeleteDataTransactionUtilTest.handler = RestConnectorProvider.class.getDeclaredField("transactionChainHandler");
- DeleteDataTransactionUtilTest.broker = RestConnectorProvider.class.getDeclaredField("dataBroker");
-
- DeleteDataTransactionUtilTest.handler.setAccessible(true);
- DeleteDataTransactionUtilTest.handler.set(RestConnectorProvider.class, mock(TransactionChainHandler.class));
-
- DeleteDataTransactionUtilTest.broker.setAccessible(true);
- DeleteDataTransactionUtilTest.broker.set(RestConnectorProvider.class, mock(DOMDataBroker.class));
- }
-
- @AfterClass
- public static void clean() throws Exception {
- DeleteDataTransactionUtilTest.handler.set(RestConnectorProvider.class, null);
- DeleteDataTransactionUtilTest.handler.setAccessible(false);
-
- DeleteDataTransactionUtilTest.broker.set(RestConnectorProvider.class, null);
- DeleteDataTransactionUtilTest.broker.setAccessible(false);
- }
+ private TransactionChainHandler transactionChainHandler;
@Before
public void init() throws Exception {
Mockito.when(this.transactionChain.newReadWriteTransaction()).thenReturn(this.readWrite);
Mockito.when(this.readWrite.submit()).thenReturn(Futures.immediateCheckedFuture(null));
Mockito.when(this.context.getInstanceIdentifier()).thenReturn(YangInstanceIdentifier.EMPTY);
+
+ Mockito.doReturn(transactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
+ transactionChainHandler = new TransactionChainHandler(mockDataBroker);
}
/**
// test
final Response response = DeleteDataTransactionUtil.deleteData(
- new TransactionVarsWrapper(this.context, null, this.transactionChain));
+ new TransactionVarsWrapper(this.context, null, transactionChainHandler));
// assert success
assertEquals("Not expected response received", Status.NO_CONTENT.getStatusCode(), response.getStatus());
// test and assert error
try {
- DeleteDataTransactionUtil.deleteData(new TransactionVarsWrapper(this.context, null, this.transactionChain));
+ DeleteDataTransactionUtil.deleteData(new TransactionVarsWrapper(this.context, null,
+ transactionChainHandler));
fail("Delete operation should fail due to missing data");
} catch (final RestconfDocumentedException e) {
assertEquals(ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.opendaylight.restconf.common.patch.PatchEditOperation.CREATE;
import static org.opendaylight.restconf.common.patch.PatchEditOperation.DELETE;
import static org.opendaylight.restconf.common.patch.PatchEditOperation.REPLACE;
import com.google.common.util.concurrent.Futures;
-import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
import org.opendaylight.restconf.common.patch.PatchEntity;
import org.opendaylight.restconf.common.patch.PatchStatusContext;
import org.opendaylight.restconf.common.patch.PatchStatusEntity;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef;
@Mock
private DOMDataReadWriteTransaction rwTransaction;
+ @Mock
+ private DOMDataBroker mockDataBroker;
+
+ private TransactionChainHandler transactionChainHandler;
private SchemaContextRef refSchemaCtx;
private YangInstanceIdentifier instanceIdContainer;
private YangInstanceIdentifier instanceIdCreateAndDelete;
private YangInstanceIdentifier targetNodeMerge;
private MapNode buildArtistList;
- // Fields used when delete operation fails to reset transaction chain
- private static Field handler;
- private static Field broker;
-
@Before
public void setUp() throws Exception {
initMocks(this);
- PatchDataTransactionUtilTest.handler = RestConnectorProvider.class.getDeclaredField("transactionChainHandler");
- PatchDataTransactionUtilTest.broker = RestConnectorProvider.class.getDeclaredField("dataBroker");
-
- PatchDataTransactionUtilTest.handler.setAccessible(true);
- PatchDataTransactionUtilTest.handler.set(RestConnectorProvider.class, mock(TransactionChainHandler.class));
-
- PatchDataTransactionUtilTest.broker.setAccessible(true);
- PatchDataTransactionUtilTest.broker.set(RestConnectorProvider.class, mock(DOMDataBroker.class));
+ Mockito.doReturn(transactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
+ transactionChainHandler = new TransactionChainHandler(mockDataBroker);
this.refSchemaCtx = new SchemaContextRef(
YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT)));
final InstanceIdentifierContext<? extends SchemaNode> iidContext =
new InstanceIdentifierContext<>(this.instanceIdMerge, null, null, this.refSchemaCtx.get());
final PatchContext patchContext = new PatchContext(iidContext, entities, "patchRMRm");
- final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, this.transactionChain);
+ final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, transactionChainHandler);
final PatchStatusContext patchStatusContext =
PatchDataTransactionUtil.patchData(patchContext, wrapper, this.refSchemaCtx);
final InstanceIdentifierContext<? extends SchemaNode> iidContext =
new InstanceIdentifierContext<>(this.instanceIdCreateAndDelete, null, null, this.refSchemaCtx.get());
final PatchContext patchContext = new PatchContext(iidContext, entities, "patchCD");
- final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, this.transactionChain);
+ final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, transactionChainHandler);
final PatchStatusContext patchStatusContext =
PatchDataTransactionUtil.patchData(patchContext, wrapper, this.refSchemaCtx);
final InstanceIdentifierContext<? extends SchemaNode> iidContext =
new InstanceIdentifierContext<>(this.instanceIdCreateAndDelete, null, null, this.refSchemaCtx.get());
final PatchContext patchContext = new PatchContext(iidContext, entities, "patchD");
- final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, this.transactionChain);
+ final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, transactionChainHandler);
final PatchStatusContext patchStatusContext =
PatchDataTransactionUtil.patchData(patchContext, wrapper, this.refSchemaCtx);
final InstanceIdentifierContext<? extends SchemaNode> iidContext =
new InstanceIdentifierContext<>(this.instanceIdCreateAndDelete, null, null, this.refSchemaCtx.get());
final PatchContext patchContext = new PatchContext(iidContext, entities, "patchM");
- final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, this.transactionChain);
+ final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, transactionChainHandler);
final PatchStatusContext patchStatusContext =
PatchDataTransactionUtil.patchData(patchContext, wrapper, this.refSchemaCtx);
}
assertTrue(patchStatusContext.isOk());
}
-}
\ No newline at end of file
+}
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
import org.opendaylight.yangtools.util.SingletonSet;
private UriInfo uriInfo;
@Mock
private UriBuilder uriBuilder;
+ @Mock
+ private DOMDataBroker mockDataBroker;
+ private TransactionChainHandler transactionChainHandler;
private SchemaContextRef refSchemaCtx;
private ContainerNode buildBaseCont;
private SchemaContext schema;
doReturn(UriBuilder.fromUri("http://localhost:8181/restconf/16/")).when(this.uriInfo).getBaseUriBuilder();
doReturn(this.readWrite).when(this.transactionChain).newReadWriteTransaction();
doReturn(this.read).when(this.transactionChain).newReadOnlyTransaction();
+
+ Mockito.doReturn(transactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
+ transactionChainHandler = new TransactionChainHandler(mockDataBroker);
}
@Test
doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, node, payload.getData());
doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
final TransactionVarsWrapper wrapper =
- new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain);
+ new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChainHandler);
final Response response =
PostDataTransactionUtil.postData(this.uriInfo, payload, wrapper, this.refSchemaCtx, null, null);
assertEquals(201, response.getStatus());
doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, node, payload.getData());
doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
final TransactionVarsWrapper wrapper =
- new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain);
+ new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChainHandler);
final Response response =
PostDataTransactionUtil.postData(this.uriInfo, payload, wrapper, this.refSchemaCtx, null, null);
assertEquals(201, response.getStatus());
final DOMException domException = new DOMException((short) 414, "Post request failed");
doReturn(Futures.immediateFailedCheckedFuture(domException)).when(this.readWrite).submit();
final TransactionVarsWrapper wrapper =
- new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain);
+ new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChainHandler);
try {
PostDataTransactionUtil.postData(this.uriInfo, payload, wrapper, this.refSchemaCtx, null, null);
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
import org.opendaylight.yangtools.yang.common.QName;
private DOMDataReadOnlyTransaction read;
@Mock
private DOMDataWriteTransaction write;
+ @Mock
+ private DOMDataBroker mockDataBroker;
-
+ private TransactionChainHandler transactionChainHandler;
private SchemaContextRef refSchemaCtx;
private LeafNode buildLeaf;
private ContainerNode buildBaseCont;
.withChild(buildList)
.build();
+ Mockito.doReturn(transactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
+ transactionChainHandler = new TransactionChainHandler(mockDataBroker);
}
@Test
doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
PutDataTransactionUtil.putData(payload, this.refSchemaCtx,
- new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain), null,
+ new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChainHandler), null,
null);
verify(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION,
payload.getInstanceIdentifierContext().getInstanceIdentifier());
doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
PutDataTransactionUtil.putData(payload, this.refSchemaCtx,
- new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain), null,
+ new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChainHandler), null,
null);
verify(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION,
payload.getInstanceIdentifierContext().getInstanceIdentifier());
payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData());
doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
PutDataTransactionUtil.putData(payload, this.refSchemaCtx,
- new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain), null,
+ new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChainHandler), null,
null);
verify(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iid2);
verify(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, this.iid2, payload.getData());
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
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.TransactionChainHandler;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
when(containerChildNode.getQName()).thenReturn(containerChildQName);
when(containerSchemaNode.getDataChildByName(containerChildQName)).thenReturn(containerChildNode);
- wrapper = new TransactionVarsWrapper(this.context, null, this.transactionChain);
+ DOMDataBroker mockDataBroker = Mockito.mock(DOMDataBroker.class);
+ Mockito.doReturn(transactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
+ wrapper = new TransactionVarsWrapper(this.context, null, new TransactionChainHandler(mockDataBroker));
}
@Test
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.Mockito;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
SchemaContext sc = YangParserTestUtils.parseYangResource(
"/instanceidentifier/yang/instance-identifier-patch-module.yang");
- transactionChainHandler = new TransactionChainHandler(domDataBroker.createTransactionChain(
- Mockito.mock(TransactionChainListener.class)));
+ transactionChainHandler = new TransactionChainHandler(domDataBroker);
schemaContextHandler = new SchemaContextHandler(transactionChainHandler);
SchemaContextHandler.setSchemaContext(sc);
}