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=f380c273732c5fb174c51a07cc2f554b21f394c0;hp=8dc65e2ced109f6052879d4e842049ae45af7fa2;hb=2c146f582dee58e36dc22505b4c6bedb4641342f;hpb=2db9424fea93b515367614389b82665dc0987c4b 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 8dc65e2ced..f380c27373 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 @@ -1,17 +1,26 @@ +/* + * Copyright (c) 2014 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.controller.sal.dom.broker.impl; -import java.awt.PageAttributes.OriginType; +import static com.google.common.base.Preconditions.checkState; + +import java.io.Console; import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; -import java.util.HashSet; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.Future; -import java.util.concurrent.atomic.AtomicLong; + +import javax.activation.UnsupportedDataTypeException; import org.opendaylight.controller.md.sal.common.api.TransactionStatus; import org.opendaylight.controller.md.sal.common.api.data.DataModification; @@ -19,40 +28,40 @@ import org.opendaylight.controller.md.sal.common.api.data.DataReader; import org.opendaylight.controller.md.sal.common.impl.AbstractDataModification; import org.opendaylight.controller.md.sal.common.impl.util.AbstractLockableDelegator; import org.opendaylight.controller.sal.core.api.data.DataStore; -import org.opendaylight.controller.sal.core.api.model.SchemaServiceListener; +import org.opendaylight.controller.sal.dom.broker.util.YangDataOperations; +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.InstanceIdentifier.PathArgument; +import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.InstanceIdentifierBuilder; import org.opendaylight.yangtools.yang.data.api.Node; +import org.opendaylight.yangtools.yang.data.api.SimpleNode; import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl; -import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; +import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition; +import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.SchemaNode; -import org.opendaylight.yangtools.yang.util.YangDataOperations; -import org.opendaylight.yangtools.yang.util.YangSchemaUtils; +import org.opendaylight.yangtools.yang.model.api.SchemaContextListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.collect.FluentIterable; - -import static com.google.common.base.Preconditions.*; -import org.opendaylight.yangtools.yang.util.YangDataOperations; +import com.google.common.collect.ImmutableSet; public class SchemaAwareDataStoreAdapter extends AbstractLockableDelegator implements // DataStore, // - SchemaServiceListener, // + SchemaContextListener, // AutoCloseable { private final static Logger LOG = LoggerFactory.getLogger(SchemaAwareDataStoreAdapter.class); private SchemaContext schema = null; private boolean validationEnabled = false; - private DataReader reader = new MergeFirstLevelReader(); + private final DataReader reader = new MergeFirstLevelReader(); @Override public boolean containsConfigurationPath(InstanceIdentifier path) { @@ -153,7 +162,7 @@ public class SchemaAwareDataStoreAdapter extends AbstractLockableDelegator original) { - // NOOP for now NormalizedDataModification normalized = new NormalizedDataModification(original); for (Entry entry : original.getUpdatedConfigurationData().entrySet()) { - normalized.putConfigurationData(entry.getKey(), entry.getValue()); + normalized.putDeepConfigurationData(entry.getKey(), entry.getValue()); } for (Entry entry : original.getUpdatedOperationalData().entrySet()) { - normalized.putOperationalData(entry.getKey(), entry.getValue()); + normalized.putDeepOperationalData(entry.getKey(), entry.getValue()); } for (InstanceIdentifier entry : original.getRemovedConfigurationData()) { - normalized.removeConfigurationData(entry); + normalized.deepRemoveConfigurationData(entry); } for (InstanceIdentifier entry : original.getRemovedOperationalData()) { - normalized.removeOperationalData(entry); + normalized.deepRemoveOperationalData(entry); } return normalized; } + private Iterable getConfigurationSubpaths(InstanceIdentifier entry) { + // FIXME: This should be replaced by index + Iterable paths = getStoredConfigurationPaths(); + + return getChildrenPaths(entry, paths); + + } + + public Iterable getOperationalSubpaths(InstanceIdentifier entry) { + // FIXME: This should be indexed + 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) { + if (entry.contains(potential)) { + children.add(entry); + } + } + return children.build(); + } + private final Comparator> preparationComparator = new Comparator>() { @Override public int compare(Entry o1, Entry o2) { @@ -288,7 +322,9 @@ public class SchemaAwareDataStoreAdapter extends AbstractLockableDelegator { - private Object identifier; + 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) { @@ -297,6 +333,37 @@ public class SchemaAwareDataStoreAdapter extends AbstractLockableDelegator paths = getOperationalSubpaths(entry); + removeOperationalData(entry); + for (InstanceIdentifier potential : paths) { + removeOperationalData(potential); + } + } + + public void deepRemoveConfigurationData(InstanceIdentifier entry) { + Iterable paths = getConfigurationSubpaths(entry); + removeConfigurationData(entry); + for (InstanceIdentifier potential : paths) { + removeConfigurationData(potential); + } + } + + public void putDeepConfigurationData(InstanceIdentifier entryKey, CompositeNode entryData) { + this.putCompositeNodeData(entryKey, entryData, CONFIGURATIONAL_DATA_STORE_MARKER); + } + + public void putDeepOperationalData(InstanceIdentifier entryKey, CompositeNode entryData) { + this.putCompositeNodeData(entryKey, entryData, OPERATIONAL_DATA_STORE_MARKER); + } + @Override public Object getIdentifier() { return this.identifier; @@ -321,9 +388,71 @@ public class SchemaAwareDataStoreAdapter extends AbstractLockableDelegator child : entryData.getChildren()) { + InstanceIdentifier subEntryId = InstanceIdentifier.builder(entryKey).node(child.getNodeType()).toInstance(); + if (child instanceof CompositeNode) { + DataSchemaNode subSchema = schemaNodeFor(subEntryId); + CompositeNode compNode = (CompositeNode) child; + InstanceIdentifier instanceId = null; + + if (subSchema instanceof ListSchemaNode) { + ListSchemaNode listSubSchema = (ListSchemaNode) subSchema; + Map mapOfSubValues = this.getValuesFromListSchema(listSubSchema, (CompositeNode) child); + if (mapOfSubValues != null) { + instanceId = InstanceIdentifier.builder(entryKey).nodeWithKey(listSubSchema.getQName(), mapOfSubValues).toInstance(); + } + } + else if (subSchema instanceof ContainerSchemaNode) { + ContainerSchemaNode containerSchema = (ContainerSchemaNode) subSchema; + instanceId = InstanceIdentifier.builder(entryKey).node(subSchema.getQName()).toInstance(); + } + if (instanceId != null) { + this.putCompositeNodeData(instanceId, compNode, dataStoreIdentifier); + } + } + } + } + + private Map getValuesFromListSchema (ListSchemaNode listSchema, 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; + } + } }