import java.util.Set;
import java.util.concurrent.ExecutionException;
-import org.opendaylight.controller.md.sal.dom.store.impl.tree.ModificationType;
-import org.opendaylight.controller.md.sal.dom.store.impl.tree.NodeModification;
-import org.opendaylight.controller.md.sal.dom.store.impl.tree.StoreMetadataNode;
-import org.opendaylight.controller.md.sal.dom.store.impl.tree.StoreNodeCompositeBuilder;
+import org.opendaylight.controller.md.sal.dom.store.impl.tree.DataPreconditionFailedException;
+import org.opendaylight.controller.md.sal.dom.store.impl.tree.ModificationApplyOperation;
+import org.opendaylight.controller.md.sal.dom.store.impl.tree.StoreUtils;
+import org.opendaylight.controller.md.sal.dom.store.impl.tree.data.ModificationType;
+import org.opendaylight.controller.md.sal.dom.store.impl.tree.data.NodeModification;
+import org.opendaylight.controller.md.sal.dom.store.impl.tree.data.StoreMetadataNode;
+import org.opendaylight.controller.md.sal.dom.store.impl.tree.data.StoreNodeCompositeBuilder;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.AugmentationIdentifier;
public static SchemaAwareApplyOperation from(final DataNodeContainer resolvedTree,
final AugmentationTarget augSchemas, final AugmentationIdentifier identifier) {
AugmentationSchema augSchema = null;
- allAugments: for (AugmentationSchema potential : augSchemas.getAvailableAugmentations()) {
- boolean containsAll = true;
- for (DataSchemaNode child : potential.getChildNodes()) {
- if (identifier.getPossibleChildNames().contains(child.getQName())) {
- augSchema = potential;
- break allAugments;
+
+ allAugments:
+ for (AugmentationSchema potential : augSchemas.getAvailableAugmentations()) {
+ for (DataSchemaNode child : potential.getChildNodes()) {
+ if (identifier.getPossibleChildNames().contains(child.getQName())) {
+ augSchema = potential;
+ break allAugments;
+ }
}
}
- }
+
if (augSchema != null) {
return new AugmentationModificationStrategy(augSchema, resolvedTree);
}
@Override
public void verifyStructure(final NodeModification modification) throws IllegalArgumentException {
if (modification.getModificationType() == ModificationType.WRITE) {
- verifyWritenStructure(modification.getWritenValue());
+ verifyWrittenStructure(modification.getWrittenValue());
}
}
- protected abstract void verifyWritenStructure(NormalizedNode<?, ?> writenValue);
+ protected abstract void verifyWrittenStructure(NormalizedNode<?, ?> writtenValue);
@Override
public void checkApplicable(final InstanceIdentifier path,final NodeModification modification, final Optional<StoreMetadataNode> current) throws DataPreconditionFailedException {
protected void checkMergeApplicable(final InstanceIdentifier path,final NodeModification modification, final Optional<StoreMetadataNode> current) throws DataPreconditionFailedException {
Optional<StoreMetadataNode> original = modification.getOriginal();
if (original.isPresent() && current.isPresent()) {
- checkNotConflicting(path,original.get(), current.get());
+ /*
+ * We need to do conflict detection only and only if the value of leaf changed
+ * before two transactions. If value of leaf is unchanged between two transactions
+ * it should not cause transaction to fail, since result of this merge
+ * leads to same data.
+ */
+ if(!original.get().getData().equals(current.get().getData())) {
+
+ checkNotConflicting(path,original.get(), current.get());
+ }
}
}
protected abstract StoreMetadataNode applySubtreeChange(NodeModification modification,
StoreMetadataNode currentMeta, UnsignedLong subtreeVersion);
- public static abstract class ValueNodeModificationStrategy<T extends DataSchemaNode> extends
- SchemaAwareApplyOperation {
+ public static abstract class ValueNodeModificationStrategy<T extends DataSchemaNode> extends SchemaAwareApplyOperation {
private final T schema;
private final Class<? extends NormalizedNode<?, ?>> nodeClass;
}
@Override
- protected void verifyWritenStructure(final NormalizedNode<?, ?> writenValue) {
- checkArgument(nodeClass.isInstance(writenValue), "Node should must be of type %s", nodeClass);
+ protected void verifyWrittenStructure(final NormalizedNode<?, ?> writtenValue) {
+ checkArgument(nodeClass.isInstance(writtenValue), "Node should must be of type %s", nodeClass);
}
@Override
final Optional<StoreMetadataNode> currentMeta, final UnsignedLong subtreeVersion) {
UnsignedLong nodeVersion = subtreeVersion;
return StoreMetadataNode.builder().setNodeVersion(nodeVersion).setSubtreeVersion(subtreeVersion)
- .setData(modification.getWritenValue()).build();
+ .setData(modification.getWrittenValue()).build();
}
@Override
@SuppressWarnings("rawtypes")
@Override
- protected void verifyWritenStructure(final NormalizedNode<?, ?> writenValue) {
- checkArgument(nodeClass.isInstance(writenValue), "Node should must be of type %s", nodeClass);
- checkArgument(writenValue instanceof NormalizedNodeContainer);
- NormalizedNodeContainer writenCont = (NormalizedNodeContainer) writenValue;
- for (Object child : writenCont.getValue()) {
+ protected void verifyWrittenStructure(final NormalizedNode<?, ?> writtenValue) {
+ checkArgument(nodeClass.isInstance(writtenValue), "Node should must be of type %s", nodeClass);
+ checkArgument(writtenValue instanceof NormalizedNodeContainer);
+
+ NormalizedNodeContainer container = (NormalizedNodeContainer) writtenValue;
+ for (Object child : container.getValue()) {
checkArgument(child instanceof NormalizedNode);
- NormalizedNode childNode = (NormalizedNode) child;
+
+ /*
+ * FIXME: fail-fast semantics:
+ *
+ * We can validate the data structure here, aborting the commit
+ * before it ever progresses to being committed.
+ */
}
}
protected StoreMetadataNode applyWrite(final NodeModification modification,
final Optional<StoreMetadataNode> currentMeta, final UnsignedLong subtreeVersion) {
- NormalizedNode<?, ?> newValue = modification.getWritenValue();
+ NormalizedNode<?, ?> newValue = modification.getWrittenValue();
final UnsignedLong nodeVersion;
if (currentMeta.isPresent()) {
protected abstract NormalizedNodeContainerBuilder createBuilder(NormalizedNode<?, ?> original);
}
- public static abstract class DataNodeContainerModificationStrategy<T extends DataNodeContainer> extends
- NormalizedNodeContainerModificationStrategy {
+ public static abstract class DataNodeContainerModificationStrategy<T extends DataNodeContainer> extends NormalizedNodeContainerModificationStrategy {
private final T schema;
private final LoadingCache<PathArgument, ModificationApplyOperation> childCache = CacheBuilder.newBuilder()
}
- public static class ContainerModificationStrategy extends
- DataNodeContainerModificationStrategy<ContainerSchemaNode> {
+ public static class ContainerModificationStrategy extends DataNodeContainerModificationStrategy<ContainerSchemaNode> {
public ContainerModificationStrategy(final ContainerSchemaNode schemaNode) {
super(schemaNode, ContainerNode.class);
}
}
- public static class UnkeyedListItemModificationStrategy extends
- DataNodeContainerModificationStrategy<ListSchemaNode> {
+ public static class UnkeyedListItemModificationStrategy extends DataNodeContainerModificationStrategy<ListSchemaNode> {
public UnkeyedListItemModificationStrategy(final ListSchemaNode schemaNode) {
super(schemaNode, UnkeyedListEntryNode.class);
}
}
- public static class AugmentationModificationStrategy extends
- DataNodeContainerModificationStrategy<AugmentationSchema> {
+ public static class AugmentationModificationStrategy extends DataNodeContainerModificationStrategy<AugmentationSchema> {
protected AugmentationModificationStrategy(final AugmentationSchema schema, final DataNodeContainer resolved) {
super(createAugmentProxy(schema,resolved), AugmentationNode.class);
public static class ChoiceModificationStrategy extends NormalizedNodeContainerModificationStrategy {
- private final ChoiceNode schema;
private final Map<PathArgument, ModificationApplyOperation> childNodes;
public ChoiceModificationStrategy(final ChoiceNode schemaNode) {
super(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode.class);
- this.schema = schemaNode;
ImmutableMap.Builder<PathArgument, ModificationApplyOperation> child = ImmutableMap.builder();
for (ChoiceCaseNode caze : schemaNode.getCases()) {
@Override
protected StoreMetadataNode applyWrite(final NodeModification modification,
final Optional<StoreMetadataNode> currentMeta, final UnsignedLong subtreeVersion) {
- return StoreMetadataNode.createRecursively(modification.getWritenValue(), subtreeVersion);
+ return StoreMetadataNode.createRecursively(modification.getWrittenValue(), subtreeVersion);
}
@Override
}
@Override
- protected void verifyWritenStructure(final NormalizedNode<?, ?> writenValue) {
+ protected void verifyWrittenStructure(final NormalizedNode<?, ?> writtenValue) {
}
}
}
- public void verifyIdentifier(final PathArgument identifier) {
-
- }
-
public static AugmentationSchema createAugmentProxy(final AugmentationSchema schema, final DataNodeContainer resolved) {
Set<DataSchemaNode> realChildSchemas = new HashSet<>();
for(DataSchemaNode augChild : schema.getChildNodes()) {