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.utils.PatchDataTransactionUtil;
import org.opendaylight.restconf.nb.rfc8040.rests.utils.ReadDataTransactionUtil;
import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants;
import org.opendaylight.restconf.nb.rfc8040.streams.StreamsConfiguration;
@VisibleForTesting
PatchStatusContext yangPatchData(final InstanceIdentifierContext targetResource, final PatchContext context) {
- return PatchDataTransactionUtil.patchData(context, getRestconfStrategy(targetResource.getMountPoint()),
+ return getRestconfStrategy(targetResource.getMountPoint()).patchData(context,
targetResource.getSchemaContext());
}
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
+import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
import org.opendaylight.restconf.api.query.PointParam;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.restconf.common.errors.RestconfError;
import org.opendaylight.restconf.common.errors.RestconfFuture;
import org.opendaylight.restconf.common.errors.SettableRestconfFuture;
+import org.opendaylight.restconf.common.patch.PatchContext;
+import org.opendaylight.restconf.common.patch.PatchStatusContext;
+import org.opendaylight.restconf.common.patch.PatchStatusEntity;
import org.opendaylight.restconf.nb.rfc8040.Insert;
import org.opendaylight.restconf.nb.rfc8040.rests.utils.TransactionUtil;
import org.opendaylight.restconf.nb.rfc8040.utils.parser.YangInstanceIdentifierDeserializer;
};
}
+ /**
+ * Process edit operations of one {@link PatchContext}.
+ *
+ * @param patch Patch context to be processed
+ * @param context Global schema context
+ * @return {@link PatchStatusContext}
+ */
+ public final @NonNull PatchStatusContext patchData(final PatchContext patch, final EffectiveModelContext context) {
+ final var editCollection = new ArrayList<PatchStatusEntity>();
+ final var tx = prepareWriteExecution();
+
+ boolean noError = true;
+ for (var patchEntity : patch.getData()) {
+ if (noError) {
+ final var targetNode = patchEntity.getTargetNode();
+ final var editId = patchEntity.getEditId();
+
+ switch (patchEntity.getOperation()) {
+ case Create:
+ try {
+ tx.create(targetNode, patchEntity.getNode(), context);
+ editCollection.add(new PatchStatusEntity(editId, true, null));
+ } catch (RestconfDocumentedException e) {
+ editCollection.add(new PatchStatusEntity(editId, false, e.getErrors()));
+ noError = false;
+ }
+ break;
+ case Delete:
+ try {
+ tx.delete(targetNode);
+ editCollection.add(new PatchStatusEntity(editId, true, null));
+ } catch (RestconfDocumentedException e) {
+ editCollection.add(new PatchStatusEntity(editId, false, e.getErrors()));
+ noError = false;
+ }
+ break;
+ case Merge:
+ try {
+ TransactionUtil.ensureParentsByMerge(targetNode, context, tx);
+ tx.merge(targetNode, patchEntity.getNode());
+ editCollection.add(new PatchStatusEntity(editId, true, null));
+ } catch (RestconfDocumentedException e) {
+ editCollection.add(new PatchStatusEntity(editId, false, e.getErrors()));
+ noError = false;
+ }
+ break;
+ case Replace:
+ try {
+ tx.replace(targetNode, patchEntity.getNode(), context);
+ editCollection.add(new PatchStatusEntity(editId, true, null));
+ } catch (RestconfDocumentedException e) {
+ editCollection.add(new PatchStatusEntity(editId, false, e.getErrors()));
+ noError = false;
+ }
+ break;
+ case Remove:
+ try {
+ tx.remove(targetNode);
+ editCollection.add(new PatchStatusEntity(editId, true, null));
+ } catch (RestconfDocumentedException e) {
+ editCollection.add(new PatchStatusEntity(editId, false, e.getErrors()));
+ noError = false;
+ }
+ break;
+ default:
+ editCollection.add(new PatchStatusEntity(editId, false, List.of(
+ new RestconfError(ErrorType.PROTOCOL, ErrorTag.OPERATION_NOT_SUPPORTED,
+ "Not supported Yang Patch operation"))));
+ noError = false;
+ break;
+ }
+ } else {
+ break;
+ }
+ }
+
+ // if no errors then submit transaction, otherwise cancel
+ if (noError) {
+ try {
+ TransactionUtil.syncCommit(tx.commit(), "PATCH", null);
+ } catch (RestconfDocumentedException e) {
+ // if errors occurred during transaction commit then patch failed and global errors are reported
+ return new PatchStatusContext(patch.getPatchId(), List.copyOf(editCollection), false, e.getErrors());
+ }
+
+ return new PatchStatusContext(patch.getPatchId(), List.copyOf(editCollection), true, null);
+ } else {
+ tx.cancel();
+ return new PatchStatusContext(patch.getPatchId(), List.copyOf(editCollection), false, null);
+ }
+ }
+
private static void insertWithPointPost(final RestconfTransaction tx, final YangInstanceIdentifier path,
final NormalizedNode data, final PointParam point, final NormalizedNodeContainer<?> readList,
final YangInstanceIdentifier grandParentPath, final boolean before, final EffectiveModelContext context) {
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.restconf.nb.rfc8040.rests.utils;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-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.common.patch.PatchStatusEntity;
-import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
-import org.opendaylight.yangtools.yang.common.ErrorTag;
-import org.opendaylight.yangtools.yang.common.ErrorType;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-
-public final class PatchDataTransactionUtil {
- private PatchDataTransactionUtil() {
- // Hidden on purpose
- }
-
- /**
- * Process edit operations of one {@link PatchContext}.
- *
- * @param patch Patch context to be processed
- * @param strategy object that perform the actual DS operations
- * @param context Global schema context
- * @return {@link PatchStatusContext}
- */
- public static PatchStatusContext patchData(final PatchContext patch, final RestconfStrategy strategy,
- final EffectiveModelContext context) {
- final var editCollection = new ArrayList<PatchStatusEntity>();
- final var tx = strategy.prepareWriteExecution();
-
- boolean noError = true;
- for (var patchEntity : patch.getData()) {
- if (noError) {
- final var targetNode = patchEntity.getTargetNode();
- final var editId = patchEntity.getEditId();
-
- switch (patchEntity.getOperation()) {
- case Create:
- try {
- tx.create(targetNode, patchEntity.getNode(), context);
- editCollection.add(new PatchStatusEntity(editId, true, null));
- } catch (RestconfDocumentedException e) {
- editCollection.add(new PatchStatusEntity(editId, false, e.getErrors()));
- noError = false;
- }
- break;
- case Delete:
- try {
- tx.delete(targetNode);
- editCollection.add(new PatchStatusEntity(editId, true, null));
- } catch (RestconfDocumentedException e) {
- editCollection.add(new PatchStatusEntity(editId, false, e.getErrors()));
- noError = false;
- }
- break;
- case Merge:
- try {
- TransactionUtil.ensureParentsByMerge(targetNode, context, tx);
- tx.merge(targetNode, patchEntity.getNode());
- editCollection.add(new PatchStatusEntity(editId, true, null));
- } catch (RestconfDocumentedException e) {
- editCollection.add(new PatchStatusEntity(editId, false, e.getErrors()));
- noError = false;
- }
- break;
- case Replace:
- try {
- tx.replace(targetNode, patchEntity.getNode(), context);
- editCollection.add(new PatchStatusEntity(editId, true, null));
- } catch (RestconfDocumentedException e) {
- editCollection.add(new PatchStatusEntity(editId, false, e.getErrors()));
- noError = false;
- }
- break;
- case Remove:
- try {
- tx.remove(targetNode);
- editCollection.add(new PatchStatusEntity(editId, true, null));
- } catch (RestconfDocumentedException e) {
- editCollection.add(new PatchStatusEntity(editId, false, e.getErrors()));
- noError = false;
- }
- break;
- default:
- editCollection.add(new PatchStatusEntity(editId, false, List.of(
- new RestconfError(ErrorType.PROTOCOL, ErrorTag.OPERATION_NOT_SUPPORTED,
- "Not supported Yang Patch operation"))));
- noError = false;
- break;
- }
- } else {
- break;
- }
- }
-
- // if no errors then submit transaction, otherwise cancel
- if (noError) {
- try {
- TransactionUtil.syncCommit(tx.commit(), "PATCH", null);
- } catch (RestconfDocumentedException e) {
- // if errors occurred during transaction commit then patch failed and global errors are reported
- return new PatchStatusContext(patch.getPatchId(), List.copyOf(editCollection), false, e.getErrors());
- }
-
- return new PatchStatusContext(patch.getPatchId(), List.copyOf(editCollection), true, null);
- } else {
- tx.cancel();
- return new PatchStatusContext(patch.getPatchId(), List.copyOf(editCollection), false, null);
- }
- }
-}
import org.opendaylight.restconf.common.patch.PatchEntity;
import org.opendaylight.restconf.common.patch.PatchStatusContext;
import org.opendaylight.restconf.nb.rfc8040.AbstractJukeboxTest;
-import org.opendaylight.restconf.nb.rfc8040.rests.utils.PatchDataTransactionUtil;
import org.opendaylight.restconf.nb.rfc8040.rests.utils.ReadDataTransactionUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.patch.rev170222.yang.patch.yang.patch.Edit.Operation;
import org.opendaylight.yangtools.yang.common.ErrorTag;
@Test
public final void testDeleteNonexistentData() {
- final var patchStatusContext = PatchDataTransactionUtil.patchData(new PatchContext(
+ final var patchStatusContext = deleteNonexistentDataTestStrategy().patchData(new PatchContext(
InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, GAP_IID),
- List.of(new PatchEntity("edit", Operation.Delete, CREATE_AND_DELETE_TARGET)), "patchD"),
- deleteNonexistentDataTestStrategy(), JUKEBOX_SCHEMA);
+ List.of(new PatchEntity("edit", Operation.Delete, CREATE_AND_DELETE_TARGET)), "patchD"), JUKEBOX_SCHEMA);
assertFalse(patchStatusContext.ok());
}
}
private static void patch(final PatchContext patchContext, final RestconfStrategy strategy, final boolean failed) {
- final var patchStatusContext = PatchDataTransactionUtil.patchData(patchContext, strategy, JUKEBOX_SCHEMA);
+ final var patchStatusContext = strategy.patchData(patchContext, JUKEBOX_SCHEMA);
for (var entity : patchStatusContext.editCollection()) {
if (failed) {
assertTrue("Edit " + entity.getEditId() + " failed", entity.isOk());