X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fdom%2Fbroker%2Fimpl%2FSchemaAwareDataStoreAdapter.java;h=b32d906d1e70cc8dc5997fea3c57c3379943b6b5;hb=88f10eb38c632b3ef5c75375532763b9ceb8addf;hp=1f908140b0ba60ca286095e4c693804609ec3472;hpb=8ed4cbed171ee99f57e49823e971b52202637c4c;p=controller.git 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 1f908140b0..b32d906d1e 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,34 +1,42 @@ +/* + * 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.util.ArrayList; -import java.util.Collections; import java.util.Comparator; -import java.util.HashSet; -import java.util.List; -import java.util.Map; import java.util.Map.Entry; -import java.util.Set; -import java.util.concurrent.atomic.AtomicLong; +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; +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.Node; import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl; +import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.base.Predicate; import com.google.common.collect.FluentIterable; - -import static com.google.common.base.Preconditions.*; +import com.google.common.collect.ImmutableSet; public class SchemaAwareDataStoreAdapter extends AbstractLockableDelegator implements // DataStore, // @@ -39,8 +47,7 @@ public class SchemaAwareDataStoreAdapter extends AbstractLockableDelegator reader = new MergeFirstLevelReader(); + private final DataReader reader = new MergeFirstLevelReader(); @Override public boolean containsConfigurationPath(InstanceIdentifier path) { @@ -100,7 +107,8 @@ public class SchemaAwareDataStoreAdapter extends AbstractLockableDelegator requestCommit( DataModification modification) { validateAgainstSchema(modification); - DataModification cleanedUp = prepareMergedTransaction(modification); + NormalizedDataModification cleanedUp = prepareMergedTransaction(modification); + cleanedUp.status = TransactionStatus.SUBMITED; return retrieveDelegate().requestCommit(cleanedUp); } @@ -118,7 +126,7 @@ public class SchemaAwareDataStoreAdapter extends AbstractLockableDelegator prepareMergedTransaction( + protected CompositeNode mergeData(InstanceIdentifier path, CompositeNode stored, CompositeNode modified, + boolean config) { + long startTime = System.nanoTime(); + try { + DataSchemaNode node = schemaNodeFor(path); + return YangDataOperations.merge(node, stored, modified, config); + } finally { + // System.out.println("Merge time: " + ((System.nanoTime() - + // startTime) / 1000.0d)); + } + } + + private DataSchemaNode schemaNodeFor(InstanceIdentifier path) { + checkState(schema != null, "YANG Schema is not available"); + return YangSchemaUtils.getSchemaNode(schema, path); + } + + private NormalizedDataModification prepareMergedTransaction( DataModification original) { - // NOOP for now - return 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()) { + normalized.deepRemoveConfigurationData(entry); + } + for (InstanceIdentifier entry : original.getRemovedOperationalData()) { + 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>() { @@ -242,4 +305,67 @@ public class SchemaAwareDataStoreAdapter extends AbstractLockableDelegator { + + private final Object identifier; + private TransactionStatus status; + + public NormalizedDataModification(DataModification original) { + super(getDelegate()); + identifier = original; + status = TransactionStatus.NEW; + } + + /** + * + * Ensures all subpaths are removed - this currently does slow lookup in + * all keys. + * + * @param entry + */ + public void deepRemoveOperationalData(InstanceIdentifier entry) { + Iterable 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); + } + } + + @Override + public Object getIdentifier() { + return this.identifier; + } + + @Override + public TransactionStatus getStatus() { + return status; + } + + @Override + public Future> commit() { + throw new UnsupportedOperationException("Commit should not be invoked on this"); + } + + @Override + protected CompositeNode mergeConfigurationData(InstanceIdentifier path, CompositeNode stored, + CompositeNode modified) { + return mergeData(path, stored, modified, true); + } + + @Override + protected CompositeNode mergeOperationalData(InstanceIdentifier path, CompositeNode stored, + CompositeNode modified) { + return mergeData(path, stored, modified, false); + } + } + }