From: Robert Varga Date: Fri, 9 Jul 2021 15:53:48 +0000 (+0200) Subject: RestconfTransaction always operates on a single datastore X-Git-Tag: v2.0.1~14 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=420eacdfeb8c643e79bf17c2b70da3fd644eb93e;p=netconf.git RestconfTransaction always operates on a single datastore Previous refactors in this area have suffered from lack of actual clarity. All legitimate users of RestconfTransaction operate on CONFIGURATION, hence use that without allowing a possiblity to mix&match datastore access. Change-Id: Ief9ff8d51e12c3cd3e04e55f9cd04b2b42f81068 Signed-off-by: Robert Varga --- diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java index 3d71a525a0..e4085e18c3 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java @@ -38,6 +38,8 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.mdsal.dom.api.DOMActionResult; import org.opendaylight.mdsal.dom.api.DOMActionService; import org.opendaylight.mdsal.dom.api.DOMDataBroker; +import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteOperations; +import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction; import org.opendaylight.mdsal.dom.api.DOMMountPoint; import org.opendaylight.mdsal.dom.api.DOMMountPointService; import org.opendaylight.mdsal.dom.api.DOMSchemaService; @@ -56,7 +58,6 @@ import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfDataServi import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService; import org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy; import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy; -import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfTransaction; import org.opendaylight.restconf.nb.rfc8040.rests.utils.DeleteDataTransactionUtil; import org.opendaylight.restconf.nb.rfc8040.rests.utils.PatchDataTransactionUtil; import org.opendaylight.restconf.nb.rfc8040.rests.utils.PlainPatchDataTransactionUtil; @@ -114,12 +115,14 @@ public class RestconfDataServiceImpl implements RestconfDataService { private final DOMMountPointService mountPointService; private final SubscribeToStreamUtil streamUtils; private final DOMActionService actionService; + private final DOMDataBroker dataBroker; public RestconfDataServiceImpl(final SchemaContextHandler schemaContextHandler, final DOMDataBroker dataBroker, final DOMMountPointService mountPointService, final RestconfStreamsSubscriptionService delegRestconfSubscrService, final DOMActionService actionService, final Configuration configuration) { this.schemaContextHandler = requireNonNull(schemaContextHandler); + this.dataBroker = requireNonNull(dataBroker); this.restconfStrategy = new MdsalRestconfStrategy(dataBroker); this.mountPointService = requireNonNull(mountPointService); this.delegRestconfSubscrService = requireNonNull(delegRestconfSubscrService); @@ -141,15 +144,23 @@ public class RestconfDataServiceImpl implements RestconfDataService { final WriterParameters parameters = ReadDataTransactionUtil.parseUriParameters(instanceIdentifier, uriInfo); final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint(); + + // FIXME: this looks quite crazy, why do we even have it? + if (mountPoint == null && identifier != null && identifier.contains(STREAMS_PATH) + && !identifier.contains(STREAM_PATH_PART)) { + createAllYangNotificationStreams(schemaContextRef, uriInfo); + } + final RestconfStrategy strategy = getRestconfStrategy(mountPoint); final NormalizedNode node; if (parameters.getFieldPaths() != null && !parameters.getFieldPaths().isEmpty()) { node = ReadDataTransactionUtil.readData(parameters.getContent(), instanceIdentifier.getInstanceIdentifier(), strategy, parameters.getWithDefault(), schemaContextRef, parameters.getFieldPaths()); } else { - node = readData(identifier, parameters.getContent(), instanceIdentifier.getInstanceIdentifier(), strategy, - parameters.getWithDefault(), schemaContextRef, uriInfo); + node = ReadDataTransactionUtil.readData(parameters.getContent(), instanceIdentifier.getInstanceIdentifier(), + strategy, parameters.getWithDefault(), schemaContextRef); } + // FIXME: this is utter craziness, refactor it properly! if (identifier != null && identifier.contains(STREAM_PATH) && identifier.contains(STREAM_ACCESS_PATH_PART) && identifier.contains(STREAM_LOCATION_PATH_PART)) { @@ -178,40 +189,15 @@ public class RestconfDataServiceImpl implements RestconfDataService { return Response.status(200).entity(new NormalizedNodeContext(instanceIdentifier, node, parameters)).build(); } - /** - * Read specific type of data from data store via transaction and if identifier read data from - * streams then put streams from actual schema context to datastore. - * - * @param identifier identifier of data to read - * @param content type of data to read (config, state, all) - * @param strategy {@link RestconfStrategy} - object that perform the actual DS operations - * @param withDefa value of with-defaults parameter - * @param schemaContext schema context - * @param uriInfo uri info - * @return {@link NormalizedNode} - */ - private NormalizedNode readData(final String identifier, final String content, - final YangInstanceIdentifier path, final RestconfStrategy strategy, final String withDefa, - final EffectiveModelContext schemaContext, final UriInfo uriInfo) { - if (identifier != null && identifier.contains(STREAMS_PATH) && !identifier.contains(STREAM_PATH_PART)) { - createAllYangNotificationStreams(strategy, schemaContext, uriInfo); - } - return ReadDataTransactionUtil.readData(content, path, strategy, withDefa, schemaContext); - } - - private void createAllYangNotificationStreams(final RestconfStrategy strategy, - final EffectiveModelContext schemaContext, final UriInfo uriInfo) { - final RestconfTransaction transaction = strategy.prepareWriteExecution(); - + private void createAllYangNotificationStreams(final EffectiveModelContext schemaContext, final UriInfo uriInfo) { + final DOMDataTreeWriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); for (final NotificationDefinition notificationDefinition : schemaContext.getNotifications()) { - final NotificationListenerAdapter notifiStreamXML = + writeNotificationStreamToDatastore(schemaContext, uriInfo, transaction, CreateStreamUtil.createYangNotifiStream(notificationDefinition, schemaContext, - NotificationOutputType.XML); - final NotificationListenerAdapter notifiStreamJSON = + NotificationOutputType.XML)); + writeNotificationStreamToDatastore(schemaContext, uriInfo, transaction, CreateStreamUtil.createYangNotifiStream(notificationDefinition, schemaContext, - NotificationOutputType.JSON); - writeNotificationStreamToDatastore(schemaContext, uriInfo, transaction, notifiStreamXML); - writeNotificationStreamToDatastore(schemaContext, uriInfo, transaction, notifiStreamJSON); + NotificationOutputType.JSON)); } try { transaction.commit().get(); @@ -221,13 +207,13 @@ public class RestconfDataServiceImpl implements RestconfDataService { } private void writeNotificationStreamToDatastore(final EffectiveModelContext schemaContext, - final UriInfo uriInfo, final RestconfTransaction transaction, final NotificationListenerAdapter listener) { + final UriInfo uriInfo, final DOMDataTreeWriteOperations tx, final NotificationListenerAdapter listener) { final URI uri = streamUtils.prepareUriByStreamName(uriInfo, listener.getStreamName()); final MapEntryNode mapToStreams = RestconfMappingNodeUtil.mapYangNotificationStreamByIetfRestconfMonitoring( listener.getSchemaPath().lastNodeIdentifier(), schemaContext.getNotifications(), null, listener.getOutputType(), uri); - transaction.merge(LogicalDatastoreType.OPERATIONAL, + tx.merge(LogicalDatastoreType.OPERATIONAL, Rfc8040.restconfStateStreamPath(mapToStreams.getIdentifier()), mapToStreams); } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/MdsalRestconfTransaction.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/MdsalRestconfTransaction.java index e6b93d2bb5..0e7b2461f5 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/MdsalRestconfTransaction.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/MdsalRestconfTransaction.java @@ -8,6 +8,7 @@ package org.opendaylight.restconf.nb.rfc8040.rests.transactions; import static com.google.common.base.Verify.verifyNotNull; +import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION; import static org.opendaylight.restconf.nb.rfc8040.rests.utils.DeleteDataTransactionUtil.DELETE_TX_TYPE; import static org.opendaylight.restconf.nb.rfc8040.rests.utils.PostDataTransactionUtil.checkItemDoesNotExists; @@ -16,7 +17,6 @@ import java.util.Collection; import java.util.Map; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.mdsal.common.api.CommitInfo; -import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.mdsal.common.api.ReadFailedException; import org.opendaylight.mdsal.dom.api.DOMDataBroker; import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction; @@ -48,65 +48,63 @@ final class MdsalRestconfTransaction extends RestconfTransaction { } @Override - public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) { - final FluentFuture isExists = verifyNotNull(rwTx).exists(store, path); + public void delete(final YangInstanceIdentifier path) { + final FluentFuture isExists = verifyNotNull(rwTx).exists(CONFIGURATION, path); DeleteDataTransactionUtil.checkItemExists(isExists, path, DELETE_TX_TYPE); - rwTx.delete(store, path); + rwTx.delete(CONFIGURATION, path); } @Override - public void remove(final LogicalDatastoreType store, final YangInstanceIdentifier path) { - verifyNotNull(rwTx).delete(store, path); + public void remove(final YangInstanceIdentifier path) { + verifyNotNull(rwTx).delete(CONFIGURATION, path); } @Override - public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode data) { - verifyNotNull(rwTx).merge(store, path, data); + public void merge(final YangInstanceIdentifier path, final NormalizedNode data) { + verifyNotNull(rwTx).merge(CONFIGURATION, path, data); } @Override - public void create(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode data, + public void create(final YangInstanceIdentifier path, final NormalizedNode data, final SchemaContext schemaContext) { if (data instanceof MapNode || data instanceof LeafSetNode) { final NormalizedNode emptySubTree = ImmutableNodes.fromInstanceId(schemaContext, path); - merge(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.create(emptySubTree.getIdentifier()), - emptySubTree); + merge(YangInstanceIdentifier.create(emptySubTree.getIdentifier()), emptySubTree); TransactionUtil.ensureParentsByMerge(path, schemaContext, this); final Collection children = ((NormalizedNodeContainer) data).body(); final BatchedExistenceCheck check = - BatchedExistenceCheck.start(verifyNotNull(rwTx), LogicalDatastoreType.CONFIGURATION, path, children); + BatchedExistenceCheck.start(verifyNotNull(rwTx), CONFIGURATION, path, children); for (final NormalizedNode child : children) { final YangInstanceIdentifier childPath = path.node(child.getIdentifier()); - verifyNotNull(rwTx).put(store, childPath, child); + verifyNotNull(rwTx).put(CONFIGURATION, childPath, child); } // ... finally collect existence checks and abort the transaction if any of them failed. checkExistence(path, check); } else { - final FluentFuture isExists = verifyNotNull(rwTx).exists(store, path); + final FluentFuture isExists = verifyNotNull(rwTx).exists(CONFIGURATION, path); checkItemDoesNotExists(isExists, path); TransactionUtil.ensureParentsByMerge(path, schemaContext, this); - verifyNotNull(rwTx).put(store, path, data); + verifyNotNull(rwTx).put(CONFIGURATION, path, data); } } @Override - public void replace(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode data, + public void replace(final YangInstanceIdentifier path, final NormalizedNode data, final SchemaContext schemaContext) { if (data instanceof MapNode || data instanceof LeafSetNode) { final NormalizedNode emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path); - merge(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), - emptySubtree); + merge(YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree); TransactionUtil.ensureParentsByMerge(path, schemaContext, this); for (final NormalizedNode child : ((NormalizedNodeContainer) data).body()) { final YangInstanceIdentifier childPath = path.node(child.getIdentifier()); - verifyNotNull(rwTx).put(store, childPath, child); + verifyNotNull(rwTx).put(CONFIGURATION, childPath, child); } } else { TransactionUtil.ensureParentsByMerge(path, schemaContext, this); - verifyNotNull(rwTx).put(store, path, data); + verifyNotNull(rwTx).put(CONFIGURATION, path, data); } } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/NetconfRestconfTransaction.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/NetconfRestconfTransaction.java index f28f406199..f5c48882d7 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/NetconfRestconfTransaction.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/NetconfRestconfTransaction.java @@ -8,6 +8,7 @@ package org.opendaylight.restconf.nb.rfc8040.rests.transactions; import static java.util.Objects.requireNonNull; +import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION; import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.FluentFuture; @@ -27,7 +28,6 @@ import java.util.function.Supplier; import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.mdsal.common.api.CommitInfo; -import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.mdsal.common.api.TransactionCommitFailedException; import org.opendaylight.mdsal.dom.api.DOMRpcResult; import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult; @@ -69,51 +69,49 @@ final class NetconfRestconfTransaction extends RestconfTransaction { } @Override - public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) { - enqueueOperation(() -> netconfService.delete(store, path)); + public void delete(final YangInstanceIdentifier path) { + enqueueOperation(() -> netconfService.delete(CONFIGURATION, path)); } @Override - public void remove(final LogicalDatastoreType store, final YangInstanceIdentifier path) { - enqueueOperation(() -> netconfService.remove(store, path)); + public void remove(final YangInstanceIdentifier path) { + enqueueOperation(() -> netconfService.remove(CONFIGURATION, path)); } @Override - public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode data) { - enqueueOperation(() -> netconfService.merge(store, path, data, Optional.empty())); + public void merge(final YangInstanceIdentifier path, final NormalizedNode data) { + enqueueOperation(() -> netconfService.merge(CONFIGURATION, path, data, Optional.empty())); } @Override - public void create(final LogicalDatastoreType store, final YangInstanceIdentifier path, - final NormalizedNode data, final SchemaContext schemaContext) { + public void create(final YangInstanceIdentifier path, final NormalizedNode data, + final SchemaContext schemaContext) { if (data instanceof MapNode || data instanceof LeafSetNode) { final NormalizedNode emptySubTree = ImmutableNodes.fromInstanceId(schemaContext, path); - merge(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.create(emptySubTree.getIdentifier()), - emptySubTree); + merge(YangInstanceIdentifier.create(emptySubTree.getIdentifier()), emptySubTree); for (final NormalizedNode child : ((NormalizedNodeContainer) data).body()) { final YangInstanceIdentifier childPath = path.node(child.getIdentifier()); - enqueueOperation(() -> netconfService.create(store, childPath, child, Optional.empty())); + enqueueOperation(() -> netconfService.create(CONFIGURATION, childPath, child, Optional.empty())); } } else { - enqueueOperation(() -> netconfService.create(store, path, data, Optional.empty())); + enqueueOperation(() -> netconfService.create(CONFIGURATION, path, data, Optional.empty())); } } @Override - public void replace(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode data, + public void replace(final YangInstanceIdentifier path, final NormalizedNode data, final SchemaContext schemaContext) { if (data instanceof MapNode || data instanceof LeafSetNode) { final NormalizedNode emptySubTree = ImmutableNodes.fromInstanceId(schemaContext, path); - merge(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.create(emptySubTree.getIdentifier()), - emptySubTree); + merge(YangInstanceIdentifier.create(emptySubTree.getIdentifier()), emptySubTree); for (final NormalizedNode child : ((NormalizedNodeContainer) data).body()) { final YangInstanceIdentifier childPath = path.node(child.getIdentifier()); - enqueueOperation(() -> netconfService.replace(store, childPath, child, Optional.empty())); + enqueueOperation(() -> netconfService.replace(CONFIGURATION, childPath, child, Optional.empty())); } } else { - enqueueOperation(() -> netconfService.replace(store, path, data, Optional.empty())); + enqueueOperation(() -> netconfService.replace(CONFIGURATION, path, data, Optional.empty())); } } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/RestconfTransaction.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/RestconfTransaction.java index 162e8be046..ef87b33e3c 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/RestconfTransaction.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/RestconfTransaction.java @@ -11,7 +11,6 @@ import com.google.common.annotations.Beta; import com.google.common.util.concurrent.FluentFuture; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.mdsal.common.api.CommitInfo; -import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; @@ -43,47 +42,40 @@ public abstract class RestconfTransaction { /** * Delete data from the datastore. * - * @param store the logical data store which should be modified * @param path the data object path */ - public abstract void delete(LogicalDatastoreType store, YangInstanceIdentifier path); + public abstract void delete(YangInstanceIdentifier path); /** * Remove data from the datastore. * - * @param store the logical data store which should be modified * @param path the data object path */ - public abstract void remove(LogicalDatastoreType store, YangInstanceIdentifier path); + public abstract void remove(YangInstanceIdentifier path); /** * Merges a piece of data with the existing data at a specified path. * - * @param store the logical data store which should be modified * @param path the data object path * @param data the data object to be merged to the specified path */ - public abstract void merge(LogicalDatastoreType store, YangInstanceIdentifier path, NormalizedNode data); + public abstract void merge(YangInstanceIdentifier path, NormalizedNode data); /** * Stores a piece of data at the specified path. * - * @param store the logical data store which should be modified * @param path the data object path * @param data the data object to be merged to the specified path * @param schemaContext static view of compiled yang files */ - public abstract void create(LogicalDatastoreType store, YangInstanceIdentifier path, NormalizedNode data, - SchemaContext schemaContext); + public abstract void create(YangInstanceIdentifier path, NormalizedNode data, SchemaContext schemaContext); /** * Replace a piece of data at the specified path. * - * @param store the logical data store which should be modified * @param path the data object path * @param data the data object to be merged to the specified path * @param schemaContext static view of compiled yang files */ - public abstract void replace(LogicalDatastoreType store, YangInstanceIdentifier path, NormalizedNode data, - SchemaContext schemaContext); + public abstract void replace(YangInstanceIdentifier path, NormalizedNode data, SchemaContext schemaContext); } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtil.java index 9552679356..e26cba1f11 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtil.java @@ -11,7 +11,6 @@ import com.google.common.util.concurrent.FluentFuture; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import org.opendaylight.mdsal.common.api.CommitInfo; -import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag; import org.opendaylight.restconf.common.errors.RestconfError.ErrorType; @@ -41,7 +40,7 @@ public final class DeleteDataTransactionUtil { public static Response deleteData(final RestconfStrategy strategy, final YangInstanceIdentifier path) { final RestconfTransaction transaction = strategy.prepareWriteExecution(); try { - transaction.delete(LogicalDatastoreType.CONFIGURATION, path); + transaction.delete(path); } catch (RestconfDocumentedException e) { // close transaction if any and pass exception further transaction.cancel(); diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PatchDataTransactionUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PatchDataTransactionUtil.java index b9ca979824..620b100778 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PatchDataTransactionUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PatchDataTransactionUtil.java @@ -157,7 +157,7 @@ public final class PatchDataTransactionUtil { final RestconfTransaction transaction) { LOG.trace("POST {} within Restconf Patch: {} with payload {}", LogicalDatastoreType.CONFIGURATION.name(), path, payload); - transaction.create(LogicalDatastoreType.CONFIGURATION, path, payload, schemaContext); + transaction.create(path, payload, schemaContext); } /** @@ -169,7 +169,7 @@ public final class PatchDataTransactionUtil { private static void deleteDataWithinTransaction(final YangInstanceIdentifier path, final RestconfTransaction transaction) { LOG.trace("Delete {} within Restconf Patch: {}", LogicalDatastoreType.CONFIGURATION.name(), path); - transaction.delete(LogicalDatastoreType.CONFIGURATION, path); + transaction.delete(path); } /** @@ -185,7 +185,7 @@ public final class PatchDataTransactionUtil { LOG.trace("Merge {} within Restconf Patch: {} with payload {}", LogicalDatastoreType.CONFIGURATION.name(), path, payload); TransactionUtil.ensureParentsByMerge(path, schemaContext, transaction); - transaction.merge(LogicalDatastoreType.CONFIGURATION, path, payload); + transaction.merge(path, payload); } /** @@ -197,7 +197,7 @@ public final class PatchDataTransactionUtil { private static void removeDataWithinTransaction(final YangInstanceIdentifier path, final RestconfTransaction transaction) { LOG.trace("Remove {} within Restconf Patch: {}", LogicalDatastoreType.CONFIGURATION.name(), path); - transaction.remove(LogicalDatastoreType.CONFIGURATION, path); + transaction.remove(path); } /** @@ -212,6 +212,6 @@ public final class PatchDataTransactionUtil { final RestconfTransaction transaction) { LOG.trace("PUT {} within Restconf Patch: {} with payload {}", LogicalDatastoreType.CONFIGURATION.name(), path, payload); - transaction.replace(LogicalDatastoreType.CONFIGURATION, path, payload, schemaContext); + transaction.replace(path, payload, schemaContext); } } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PlainPatchDataTransactionUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PlainPatchDataTransactionUtil.java index 5fcbe665b3..473ba0e353 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PlainPatchDataTransactionUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PlainPatchDataTransactionUtil.java @@ -12,7 +12,6 @@ import com.google.common.util.concurrent.FluentFuture; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import org.opendaylight.mdsal.common.api.CommitInfo; -import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.mdsal.dom.api.DOMTransactionChain; import org.opendaylight.restconf.common.context.NormalizedNodeContext; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; @@ -54,7 +53,7 @@ public final class PlainPatchDataTransactionUtil { try { LOG.trace("Merge CONFIGURATION within Restconf Patch: {} with payload {}", path, data); TransactionUtil.ensureParentsByMerge(path, schemaContext, transaction); - transaction.merge(LogicalDatastoreType.CONFIGURATION, path, data); + transaction.merge(path, data); } catch (final RestconfDocumentedException e) { transaction.cancel(); throw new IllegalArgumentException(e); diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PostDataTransactionUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PostDataTransactionUtil.java index 32edd65421..70008b7e13 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PostDataTransactionUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PostDataTransactionUtil.java @@ -105,14 +105,13 @@ public final class PostDataTransactionUtil { case FIRST: readData = PutDataTransactionUtil.readList(strategy, path.getParent().getParent()); if (readData == null || ((NormalizedNodeContainer) readData).isEmpty()) { - transaction.replace(LogicalDatastoreType.CONFIGURATION, path, data, schemaContext); + transaction.replace(path, data, schemaContext); return transaction.commit(); } checkItemDoesNotExists(strategy.exists(LogicalDatastoreType.CONFIGURATION, path), path); - transaction.remove(LogicalDatastoreType.CONFIGURATION, path.getParent().getParent()); - transaction.replace(LogicalDatastoreType.CONFIGURATION, path, data, schemaContext); - transaction.replace(LogicalDatastoreType.CONFIGURATION, path.getParent().getParent(), readData, - schemaContext); + transaction.remove(path.getParent().getParent()); + transaction.replace(path, data, schemaContext); + transaction.replace(path.getParent().getParent(), readData, schemaContext); return transaction.commit(); case LAST: makePost(path, data, schemaContext, transaction); @@ -120,7 +119,7 @@ public final class PostDataTransactionUtil { case BEFORE: readData = PutDataTransactionUtil.readList(strategy, path.getParent().getParent()); if (readData == null || ((NormalizedNodeContainer) readData).isEmpty()) { - transaction.replace(LogicalDatastoreType.CONFIGURATION, path, data, schemaContext); + transaction.replace(path, data, schemaContext); return transaction.commit(); } checkItemDoesNotExists(strategy.exists(LogicalDatastoreType.CONFIGURATION, path), path); @@ -130,7 +129,7 @@ public final class PostDataTransactionUtil { case AFTER: readData = PutDataTransactionUtil.readList(strategy, path.getParent().getParent()); if (readData == null || ((NormalizedNodeContainer) readData).isEmpty()) { - transaction.replace(LogicalDatastoreType.CONFIGURATION, path, data, schemaContext); + transaction.replace(path, data, schemaContext); return transaction.commit(); } checkItemDoesNotExists(strategy.exists(LogicalDatastoreType.CONFIGURATION, path), path); @@ -149,7 +148,7 @@ public final class PostDataTransactionUtil { final NormalizedNodeContainer readList, final boolean before, final RestconfTransaction transaction) { final YangInstanceIdentifier parent = path.getParent().getParent(); - transaction.remove(LogicalDatastoreType.CONFIGURATION, parent); + transaction.remove(parent); final InstanceIdentifierContext instanceIdentifier = ParserIdentifier.toInstanceIdentifier(point, schemaContext, Optional.empty()); int lastItemPosition = 0; @@ -164,14 +163,13 @@ public final class PostDataTransactionUtil { } int lastInsertedPosition = 0; final NormalizedNode emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, parent); - transaction.merge(LogicalDatastoreType.CONFIGURATION, - YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree); + transaction.merge(YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree); for (final NormalizedNode nodeChild : readList.body()) { if (lastInsertedPosition == lastItemPosition) { - transaction.replace(LogicalDatastoreType.CONFIGURATION, path, data, schemaContext); + transaction.replace(path, data, schemaContext); } final YangInstanceIdentifier childPath = parent.node(nodeChild.getIdentifier()); - transaction.replace(LogicalDatastoreType.CONFIGURATION, childPath, nodeChild, schemaContext); + transaction.replace(childPath, nodeChild, schemaContext); lastInsertedPosition++; } } @@ -179,7 +177,7 @@ public final class PostDataTransactionUtil { private static void makePost(final YangInstanceIdentifier path, final NormalizedNode data, final SchemaContext schemaContext, final RestconfTransaction transaction) { try { - transaction.create(LogicalDatastoreType.CONFIGURATION, path, data, schemaContext); + transaction.create(path, data, schemaContext); } catch (RestconfDocumentedException e) { // close transaction if any and pass exception further transaction.cancel(); diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PutDataTransactionUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PutDataTransactionUtil.java index 3c31d3e26a..c9ca113e8c 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PutDataTransactionUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PutDataTransactionUtil.java @@ -102,9 +102,9 @@ public final class PutDataTransactionUtil { if (readData == null || ((NormalizedNodeContainer) readData).isEmpty()) { return makePut(path, schemaContext, transaction, data); } - transaction.remove(LogicalDatastoreType.CONFIGURATION, path.getParent()); - transaction.replace(LogicalDatastoreType.CONFIGURATION, path, data, schemaContext); - transaction.replace(LogicalDatastoreType.CONFIGURATION, path.getParent(), readData, schemaContext); + transaction.remove(path.getParent()); + transaction.replace(path, data, schemaContext); + transaction.replace(path.getParent(), readData, schemaContext); return transaction.commit(); case LAST: return makePut(path, schemaContext, transaction, data); @@ -143,7 +143,7 @@ public final class PutDataTransactionUtil { final NormalizedNode data, final EffectiveModelContext schemaContext, final String point, final NormalizedNodeContainer readList, final boolean before) { - transaction.remove(LogicalDatastoreType.CONFIGURATION, path.getParent()); + transaction.remove(path.getParent()); final InstanceIdentifierContext instanceIdentifier = ParserIdentifier.toInstanceIdentifier(point, schemaContext, Optional.empty()); int lastItemPosition = 0; @@ -158,15 +158,13 @@ public final class PutDataTransactionUtil { } int lastInsertedPosition = 0; final NormalizedNode emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path.getParent()); - transaction.merge(LogicalDatastoreType.CONFIGURATION, - YangInstanceIdentifier.create(emptySubtree.getIdentifier()), - emptySubtree); + transaction.merge(YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree); for (final NormalizedNode nodeChild : readList.body()) { if (lastInsertedPosition == lastItemPosition) { - transaction.replace(LogicalDatastoreType.CONFIGURATION, path, data, schemaContext); + transaction.replace(path, data, schemaContext); } final YangInstanceIdentifier childPath = path.getParent().node(nodeChild.getIdentifier()); - transaction.replace(LogicalDatastoreType.CONFIGURATION, childPath, nodeChild, schemaContext); + transaction.replace(childPath, nodeChild, schemaContext); lastInsertedPosition++; } } @@ -175,7 +173,7 @@ public final class PutDataTransactionUtil { final SchemaContext schemaContext, final RestconfTransaction transaction, final NormalizedNode data) { - transaction.replace(LogicalDatastoreType.CONFIGURATION, path, data, schemaContext); + transaction.replace(path, data, schemaContext); return transaction.commit(); } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/TransactionUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/TransactionUtil.java index 93b3a94158..490af7165b 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/TransactionUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/TransactionUtil.java @@ -10,7 +10,6 @@ package org.opendaylight.restconf.nb.rfc8040.rests.utils; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfTransaction; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; @@ -59,6 +58,6 @@ public final class TransactionUtil { final NormalizedNode parentStructure = ImmutableNodes.fromInstanceId(schemaContext, YangInstanceIdentifier.create(normalizedPathWithoutChildArgs)); - transaction.merge(LogicalDatastoreType.CONFIGURATION, rootNormalizedPath, parentStructure); + transaction.merge(rootNormalizedPath, parentStructure); } }