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%2Fsal%2Fdom%2Fbroker%2Fimpl%2FSchemaAwareDataStoreAdapter.java;h=6a456ba0e8d2af5393cd09d3186d3dfbd4fb14d3;hp=b32d906d1e70cc8dc5997fea3c57c3379943b6b5;hb=ed6019236d78a69577888f60064c3714eaa80f6a;hpb=db0081760bd611555397fe110da793dcdc7c98e9 diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/SchemaAwareDataStoreAdapter.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/SchemaAwareDataStoreAdapter.java index b32d906d1e..6a456ba0e8 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/SchemaAwareDataStoreAdapter.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/SchemaAwareDataStoreAdapter.java @@ -8,12 +8,17 @@ package org.opendaylight.controller.sal.dom.broker.impl; import static com.google.common.base.Preconditions.checkState; - +import com.google.common.base.Predicate; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; import java.util.ArrayList; import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.Future; - import org.opendaylight.controller.md.sal.common.api.TransactionStatus; import org.opendaylight.controller.md.sal.common.api.data.DataModification; import org.opendaylight.controller.md.sal.common.api.data.DataReader; @@ -25,32 +30,29 @@ import org.opendaylight.controller.sal.dom.broker.util.YangSchemaUtils; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.Node; +import org.opendaylight.yangtools.yang.data.api.SimpleNode; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl; +import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; +import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener; +import org.opendaylight.yangtools.yang.model.api.SchemaContextListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Predicate; -import com.google.common.collect.FluentIterable; -import com.google.common.collect.ImmutableSet; - -public class SchemaAwareDataStoreAdapter extends AbstractLockableDelegator implements // - DataStore, // - SchemaServiceListener, // - AutoCloseable { +@Deprecated +public class SchemaAwareDataStoreAdapter extends AbstractLockableDelegator implements DataStore, SchemaContextListener, AutoCloseable { private final static Logger LOG = LoggerFactory.getLogger(SchemaAwareDataStoreAdapter.class); private SchemaContext schema = null; private boolean validationEnabled = false; - private final DataReader reader = new MergeFirstLevelReader(); + private final DataReader reader = new MergeFirstLevelReader(); @Override - public boolean containsConfigurationPath(InstanceIdentifier path) { + public boolean containsConfigurationPath(final YangInstanceIdentifier path) { try { getDelegateReadLock().lock(); return getDelegate().containsConfigurationPath(path); @@ -61,7 +63,7 @@ public class SchemaAwareDataStoreAdapter extends AbstractLockableDelegator getStoredConfigurationPaths() { + public Iterable getStoredConfigurationPaths() { try { getDelegateReadLock().lock(); return getDelegate().getStoredConfigurationPaths(); @@ -83,7 +85,7 @@ public class SchemaAwareDataStoreAdapter extends AbstractLockableDelegator getStoredOperationalPaths() { + public Iterable getStoredOperationalPaths() { try { getDelegateReadLock().lock(); return getDelegate().getStoredOperationalPaths(); @@ -94,18 +96,18 @@ public class SchemaAwareDataStoreAdapter extends AbstractLockableDelegator requestCommit( - DataModification modification) { + public org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler.DataCommitTransaction requestCommit( + final DataModification modification) { validateAgainstSchema(modification); NormalizedDataModification cleanedUp = prepareMergedTransaction(modification); cleanedUp.status = TransactionStatus.SUBMITED; @@ -116,11 +118,11 @@ public class SchemaAwareDataStoreAdapter extends AbstractLockableDelegator modification) { + private void validateAgainstSchema(final DataModification modification) { if (!validationEnabled) { return; } @@ -132,12 +134,12 @@ public class SchemaAwareDataStoreAdapter extends AbstractLockableDelegator original) { + final DataModification original) { NormalizedDataModification normalized = new NormalizedDataModification(original); - for (Entry entry : original.getUpdatedConfigurationData().entrySet()) { - normalized.putConfigurationData(entry.getKey(), entry.getValue()); - } - for (Entry entry : original.getUpdatedOperationalData().entrySet()) { - normalized.putOperationalData(entry.getKey(), entry.getValue()); - } - for (InstanceIdentifier entry : original.getRemovedConfigurationData()) { + LOG.trace("Transaction: {} Removed Configuration {}, Removed Operational {}", original.getIdentifier(), + original.getRemovedConfigurationData(), original.getRemovedConfigurationData()); + LOG.trace("Transaction: {} Created Configuration {}, Created Operational {}", original.getIdentifier(), + original.getCreatedConfigurationData().entrySet(), original.getCreatedOperationalData().entrySet()); + LOG.trace("Transaction: {} Updated Configuration {}, Updated Operational {}", original.getIdentifier(), + original.getUpdatedConfigurationData().entrySet(), original.getUpdatedOperationalData().entrySet()); + + for (YangInstanceIdentifier entry : original.getRemovedConfigurationData()) { normalized.deepRemoveConfigurationData(entry); } - for (InstanceIdentifier entry : original.getRemovedOperationalData()) { + for (YangInstanceIdentifier entry : original.getRemovedOperationalData()) { normalized.deepRemoveOperationalData(entry); } + for (Entry entry : original.getUpdatedConfigurationData().entrySet()) { + normalized.putDeepConfigurationData(entry.getKey(), entry.getValue()); + } + for (Entry entry : original.getUpdatedOperationalData().entrySet()) { + normalized.putDeepOperationalData(entry.getKey(), entry.getValue()); + } return normalized; } - private Iterable getConfigurationSubpaths(InstanceIdentifier entry) { + private Iterable getConfigurationSubpaths(final YangInstanceIdentifier entry) { // FIXME: This should be replaced by index - Iterable paths = getStoredConfigurationPaths(); + Iterable paths = getStoredConfigurationPaths(); return getChildrenPaths(entry, paths); } - public Iterable getOperationalSubpaths(InstanceIdentifier entry) { + public Iterable getOperationalSubpaths(final YangInstanceIdentifier entry) { // FIXME: This should be indexed - Iterable paths = getStoredOperationalPaths(); + Iterable paths = getStoredOperationalPaths(); return getChildrenPaths(entry, paths); } - private static final Iterable getChildrenPaths(InstanceIdentifier entry, - Iterable paths) { - ImmutableSet.Builder children = ImmutableSet.builder(); - for (InstanceIdentifier potential : paths) { + private static final Iterable getChildrenPaths(final YangInstanceIdentifier entry, + final Iterable paths) { + ImmutableSet.Builder children = ImmutableSet.builder(); + for (YangInstanceIdentifier potential : paths) { if (entry.contains(potential)) { children.add(entry); } @@ -207,40 +216,40 @@ public class SchemaAwareDataStoreAdapter extends AbstractLockableDelegator> preparationComparator = new Comparator>() { + private final Comparator> preparationComparator = new Comparator>() { @Override - public int compare(Entry o1, Entry o2) { - InstanceIdentifier o1Key = o1.getKey(); - InstanceIdentifier o2Key = o2.getKey(); - return Integer.compare(o1Key.getPath().size(), o2Key.getPath().size()); + public int compare(final Entry o1, final Entry o2) { + YangInstanceIdentifier o1Key = o1.getKey(); + YangInstanceIdentifier o2Key = o2.getKey(); + return Integer.compare(Iterables.size(o1Key.getPathArguments()), Iterables.size(o2Key.getPathArguments())); } }; - private class MergeFirstLevelReader implements DataReader { + private class MergeFirstLevelReader implements DataReader { @Override - public CompositeNode readConfigurationData(final InstanceIdentifier path) { + public CompositeNode readConfigurationData(final YangInstanceIdentifier path) { getDelegateReadLock().lock(); try { - if (path.getPath().isEmpty()) { + if (Iterables.isEmpty(path.getPathArguments())) { return null; } QName qname = null; CompositeNode original = getDelegate().readConfigurationData(path); ArrayList> childNodes = new ArrayList>(); if (original != null) { - childNodes.addAll(original.getChildren()); + childNodes.addAll(original.getValue()); qname = original.getNodeType(); } else { - qname = path.getPath().get(path.getPath().size() - 1).getNodeType(); + qname = path.getLastPathArgument().getNodeType(); } - FluentIterable directChildren = FluentIterable.from(getStoredConfigurationPaths()) - .filter(new Predicate() { + FluentIterable directChildren = FluentIterable.from(getStoredConfigurationPaths()) + .filter(new Predicate() { @Override - public boolean apply(InstanceIdentifier input) { + public boolean apply(final YangInstanceIdentifier input) { if (path.contains(input)) { - int nesting = input.getPath().size() - path.getPath().size(); + int nesting = Iterables.size(input.getPathArguments()) - Iterables.size(path.getPathArguments()); if (nesting == 1) { return true; } @@ -248,7 +257,7 @@ public class SchemaAwareDataStoreAdapter extends AbstractLockableDelegator> childNodes = new ArrayList>(); if (original != null) { - childNodes.addAll(original.getChildren()); + childNodes.addAll(original.getValue()); qname = original.getNodeType(); } else { - qname = path.getPath().get(path.getPath().size() - 1).getNodeType(); + qname = path.getLastPathArgument().getNodeType(); } - FluentIterable directChildren = FluentIterable.from(getStoredOperationalPaths()) - .filter(new Predicate() { + FluentIterable directChildren = FluentIterable.from(getStoredOperationalPaths()) + .filter(new Predicate() { @Override - public boolean apply(InstanceIdentifier input) { + public boolean apply(final YangInstanceIdentifier input) { if (path.contains(input)) { - int nesting = input.getPath().size() - path.getPath().size(); + int nesting = Iterables.size(input.getPathArguments()) - Iterables.size(path.getPathArguments()); if (nesting == 1) { return true; } @@ -292,7 +301,7 @@ public class SchemaAwareDataStoreAdapter extends AbstractLockableDelegator { + private class NormalizedDataModification extends AbstractDataModification { + private final String CONFIGURATIONAL_DATA_STORE_MARKER = "configurational"; + private final String OPERATIONAL_DATA_STORE_MARKER = "operational"; private final Object identifier; private TransactionStatus status; - public NormalizedDataModification(DataModification original) { + public NormalizedDataModification(final DataModification original) { super(getDelegate()); identifier = original; status = TransactionStatus.NEW; @@ -324,22 +335,30 @@ public class SchemaAwareDataStoreAdapter extends AbstractLockableDelegator paths = getOperationalSubpaths(entry); + public void deepRemoveOperationalData(final YangInstanceIdentifier entry) { + Iterable paths = getOperationalSubpaths(entry); removeOperationalData(entry); - for (InstanceIdentifier potential : paths) { + for (YangInstanceIdentifier potential : paths) { removeOperationalData(potential); } } - public void deepRemoveConfigurationData(InstanceIdentifier entry) { - Iterable paths = getConfigurationSubpaths(entry); + public void deepRemoveConfigurationData(final YangInstanceIdentifier entry) { + Iterable paths = getConfigurationSubpaths(entry); removeConfigurationData(entry); - for (InstanceIdentifier potential : paths) { + for (YangInstanceIdentifier potential : paths) { removeConfigurationData(potential); } } + public void putDeepConfigurationData(final YangInstanceIdentifier entryKey, final CompositeNode entryData) { + this.putCompositeNodeData(entryKey, entryData, CONFIGURATIONAL_DATA_STORE_MARKER); + } + + public void putDeepOperationalData(final YangInstanceIdentifier entryKey, final CompositeNode entryData) { + this.putCompositeNodeData(entryKey, entryData, OPERATIONAL_DATA_STORE_MARKER); + } + @Override public Object getIdentifier() { return this.identifier; @@ -356,16 +375,82 @@ public class SchemaAwareDataStoreAdapter extends AbstractLockableDelegator child : entryData.getValue()) { + YangInstanceIdentifier subEntryId = YangInstanceIdentifier.builder(entryKey).node(child.getNodeType()) + .toInstance(); + if (child instanceof CompositeNode) { + DataSchemaNode subSchema = schemaNodeFor(subEntryId); + CompositeNode compNode = (CompositeNode) child; + YangInstanceIdentifier instanceId = null; + + if (subSchema instanceof ListSchemaNode) { + ListSchemaNode listSubSchema = (ListSchemaNode) subSchema; + Map mapOfSubValues = this.getValuesFromListSchema(listSubSchema, + (CompositeNode) child); + if (mapOfSubValues != null) { + instanceId = YangInstanceIdentifier.builder(entryKey) + .nodeWithKey(listSubSchema.getQName(), mapOfSubValues).toInstance(); + } + } else if (subSchema instanceof ContainerSchemaNode) { + ContainerSchemaNode containerSchema = (ContainerSchemaNode) subSchema; + instanceId = YangInstanceIdentifier.builder(entryKey).node(subSchema.getQName()).toInstance(); + } + if (instanceId != null) { + this.putCompositeNodeData(instanceId, compNode, dataStoreIdentifier); + } + } + } + } + + private Map getValuesFromListSchema(final ListSchemaNode listSchema, final CompositeNode entryData) { + List keyDef = listSchema.getKeyDefinition(); + if (keyDef != null && !keyDef.isEmpty()) { + Map map = new HashMap(); + for (QName key : keyDef) { + List> data = entryData.get(key); + if (data != null && !data.isEmpty()) { + for (Node nodeData : data) { + if (nodeData instanceof SimpleNode) { + map.put(key, data.get(0).getValue()); + } + } + } + } + return map; + } + return null; + } + } }