X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fstore%2Fimpl%2FSchemaAwareApplyOperation.java;h=909aaae1ca2483b365acef1f4072fbb41339a0c1;hp=2af522ea861791fcae324f2f5761b258d93b8845;hb=fd474e19dd339c1abb9ed528ff3fd052004d7fe2;hpb=8022ea0892ef0499580685b12bc130f29ae8bbbc diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaAwareApplyOperation.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaAwareApplyOperation.java index 2af522ea86..909aaae1ca 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaAwareApplyOperation.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaAwareApplyOperation.java @@ -15,10 +15,13 @@ import java.util.Map; 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; @@ -111,15 +114,17 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper 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); } @@ -135,11 +140,11 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper @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 current) throws DataPreconditionFailedException { @@ -166,7 +171,16 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper protected void checkMergeApplicable(final InstanceIdentifier path,final NodeModification modification, final Optional current) throws DataPreconditionFailedException { Optional 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()); + } } } @@ -224,8 +238,7 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper protected abstract StoreMetadataNode applySubtreeChange(NodeModification modification, StoreMetadataNode currentMeta, UnsignedLong subtreeVersion); - public static abstract class ValueNodeModificationStrategy extends - SchemaAwareApplyOperation { + public static abstract class ValueNodeModificationStrategy extends SchemaAwareApplyOperation { private final T schema; private final Class> nodeClass; @@ -237,8 +250,8 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper } @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 @@ -265,7 +278,7 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper final Optional currentMeta, final UnsignedLong subtreeVersion) { UnsignedLong nodeVersion = subtreeVersion; return StoreMetadataNode.builder().setNodeVersion(nodeVersion).setSubtreeVersion(subtreeVersion) - .setData(modification.getWritenValue()).build(); + .setData(modification.getWrittenValue()).build(); } @Override @@ -320,13 +333,20 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper @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. + */ } } @@ -334,7 +354,7 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper protected StoreMetadataNode applyWrite(final NodeModification modification, final Optional currentMeta, final UnsignedLong subtreeVersion) { - NormalizedNode newValue = modification.getWritenValue(); + NormalizedNode newValue = modification.getWrittenValue(); final UnsignedLong nodeVersion; if (currentMeta.isPresent()) { @@ -427,8 +447,7 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper protected abstract NormalizedNodeContainerBuilder createBuilder(NormalizedNode original); } - public static abstract class DataNodeContainerModificationStrategy extends - NormalizedNodeContainerModificationStrategy { + public static abstract class DataNodeContainerModificationStrategy extends NormalizedNodeContainerModificationStrategy { private final T schema; private final LoadingCache childCache = CacheBuilder.newBuilder() @@ -478,8 +497,7 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper } - public static class ContainerModificationStrategy extends - DataNodeContainerModificationStrategy { + public static class ContainerModificationStrategy extends DataNodeContainerModificationStrategy { public ContainerModificationStrategy(final ContainerSchemaNode schemaNode) { super(schemaNode, ContainerNode.class); @@ -493,8 +511,7 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper } } - public static class UnkeyedListItemModificationStrategy extends - DataNodeContainerModificationStrategy { + public static class UnkeyedListItemModificationStrategy extends DataNodeContainerModificationStrategy { public UnkeyedListItemModificationStrategy(final ListSchemaNode schemaNode) { super(schemaNode, UnkeyedListEntryNode.class); @@ -508,8 +525,7 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper } } - public static class AugmentationModificationStrategy extends - DataNodeContainerModificationStrategy { + public static class AugmentationModificationStrategy extends DataNodeContainerModificationStrategy { protected AugmentationModificationStrategy(final AugmentationSchema schema, final DataNodeContainer resolved) { super(createAugmentProxy(schema,resolved), AugmentationNode.class); @@ -525,12 +541,10 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper public static class ChoiceModificationStrategy extends NormalizedNodeContainerModificationStrategy { - private final ChoiceNode schema; private final Map childNodes; public ChoiceModificationStrategy(final ChoiceNode schemaNode) { super(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode.class); - this.schema = schemaNode; ImmutableMap.Builder child = ImmutableMap.builder(); for (ChoiceCaseNode caze : schemaNode.getCases()) { @@ -644,7 +658,7 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper @Override protected StoreMetadataNode applyWrite(final NodeModification modification, final Optional currentMeta, final UnsignedLong subtreeVersion) { - return StoreMetadataNode.createRecursively(modification.getWritenValue(), subtreeVersion); + return StoreMetadataNode.createRecursively(modification.getWrittenValue(), subtreeVersion); } @Override @@ -656,7 +670,7 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper } @Override - protected void verifyWritenStructure(final NormalizedNode writenValue) { + protected void verifyWrittenStructure(final NormalizedNode writtenValue) { } @@ -728,10 +742,6 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper } } - public void verifyIdentifier(final PathArgument identifier) { - - } - public static AugmentationSchema createAugmentProxy(final AugmentationSchema schema, final DataNodeContainer resolved) { Set realChildSchemas = new HashSet<>(); for(DataSchemaNode augChild : schema.getChildNodes()) {