Merge "NPE in RaftActor#onGetOnDemandRaftStats"
authorTom Pantelis <tpanteli@brocade.com>
Fri, 24 Apr 2015 16:12:30 +0000 (16:12 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 24 Apr 2015 16:12:30 +0000 (16:12 +0000)
15 files changed:
features/mdsal/src/main/resources/features.xml
opendaylight/adsal/topologymanager/implementation/src/test/java/org/opendaylight/controller/topologymanager/internal/TopologyManagerImplTest.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ConcurrentDOMDataBroker.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ConcurrentDOMDataBrokerTest.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/util/InstanceIdToNodes.java [deleted file]
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/util/NetconfBaseOps.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/util/NetconfMessageTransformUtil.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/util/NodeContainerProxy.java
opendaylight/md-sal/sal-netconf-connector/src/test/java/org/opendaylight/controller/sal/connect/netconf/util/InstanceIdToNodesTest.java [deleted file]
opendaylight/md-sal/sal-netconf-connector/src/test/resources/schemas/filter-test.yang [deleted file]
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/YangStoreService.java
opendaylight/netconf/mdsal-netconf-connector/pom.xml
opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/ops/get/AbstractGet.java
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/xml/XmlElement.java

index f8bbfec..a992d2f 100644 (file)
     <feature name='odl-netconf-mdsal' version='${project.version}' description="OpenDaylight :: Netconf :: Mdsal">
         <feature version='${config.version}'>odl-config-all</feature>
         <feature version='${netconf.version}'>odl-netconf-all</feature>
-        <!-- TODO remove dependency on sal netconf connector (odl-yangtools-models, sal-netconf-connector, model-inventory-->
-        <feature version='${yangtools.version}'>odl-yangtools-models</feature>
-        <bundle>mvn:org.opendaylight.controller/sal-netconf-connector/${project.version}</bundle>
-        <bundle>mvn:org.opendaylight.controller.model/model-inventory/${project.version}</bundle>
         <bundle>mvn:org.opendaylight.controller/netconf-ssh/${netconf.version}</bundle>
         <feature version='${mdsal.version}'>odl-mdsal-broker</feature>
         <bundle>mvn:org.opendaylight.controller/mdsal-netconf-connector/${netconf.version}</bundle>
index a361285..2c57270 100644 (file)
@@ -8,8 +8,18 @@
 
 package org.opendaylight.controller.topologymanager.internal;
 
-import org.junit.Assert;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
 import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.controller.sal.core.Bandwidth;
@@ -40,17 +50,6 @@ import org.opendaylight.controller.switchmanager.Switch;
 import org.opendaylight.controller.switchmanager.SwitchConfig;
 import org.opendaylight.controller.topologymanager.TopologyUserLinkConfig;
 
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
-
 public class TopologyManagerImplTest {
     private TopologyManagerImpl topoManagerImpl;
 
@@ -783,15 +782,26 @@ public class TopologyManagerImplTest {
         }
 
         Assert.assertTrue(topoManagerImpl.flushUpdateQueue(5000));
-        // Give TopologyManger time to update its edges DB.
-        Thread.sleep(1000);
-        Assert.assertEquals(1, topoManagerImpl.getEdges().size());
+        verifyEdgesSize(1);
         Assert.assertNotNull(topoManagerImpl.getEdges().get(edge));
     }
 
+    private void verifyEdgesSize(int expSize) throws InterruptedException {
+        int timeout = 5000;
+        for(int i = 0; i < timeout / 50; i++) {
+            if(topoManagerImpl.getEdges().size() == expSize) {
+                return;
+            }
+
+            Thread.sleep(50);
+        }
+
+        Assert.fail(String.format("Expected edges size %d. Actual was %d",
+                topoManagerImpl.getEdges().size(), expSize));
+    }
+
     @Test
-    public void testNotifyNodeConnector() throws ConstructionException,
-           InterruptedException {
+    public void testNotifyNodeConnector() throws Exception {
         TestSwitchManager swMgr = new TestSwitchManager();
         topoManagerImpl.setSwitchManager(swMgr);
         topoManagerImpl.nonClusterObjectCreate();
@@ -803,14 +813,14 @@ public class TopologyManagerImplTest {
         Map<String, Property> propMap = new HashMap<>();
         swMgr.addNodeConnectors(nc1);
         topoManagerImpl.notifyNodeConnector(nc1, UpdateType.ADDED, propMap);
-        Assert.assertEquals(0, topoManagerImpl.getEdges().size());
+        verifyEdgesSize(0);
 
         topoManagerImpl.notifyNodeConnector(nc1, UpdateType.CHANGED, propMap);
-        Assert.assertEquals(0, topoManagerImpl.getEdges().size());
+        verifyEdgesSize(0);
 
         swMgr.clear();
         topoManagerImpl.notifyNodeConnector(nc1, UpdateType.REMOVED, propMap);
-        Assert.assertEquals(0, topoManagerImpl.getEdges().size());
+        verifyEdgesSize(0);
 
         // Test NodeConnector notification in the case that there is a related
         // edge update just before the notification.
@@ -830,9 +840,7 @@ public class TopologyManagerImplTest {
         swMgr.addNodeConnectors(nc2);
         topoManagerImpl.notifyNodeConnector(nc2, UpdateType.CHANGED, propMap);
         Assert.assertTrue(topoManagerImpl.flushUpdateQueue(5000));
-        // Give TopologyManger time to update its edges DB.
-        Thread.sleep(1000);
-        Assert.assertEquals(2, topoManagerImpl.getEdges().size());
+        verifyEdgesSize(2);
 
         teu1 = new TopoEdgeUpdate(edge1, props, UpdateType.REMOVED);
         teu2 = new TopoEdgeUpdate(edge2, props, UpdateType.REMOVED);
@@ -841,9 +849,7 @@ public class TopologyManagerImplTest {
         topoedgeupdateList.add(teu2);
         topoManagerImpl.edgeUpdate(topoedgeupdateList);
         Assert.assertTrue(topoManagerImpl.flushUpdateQueue(5000));
-        // Give TopologyManger time to update its edges DB.
-        Thread.sleep(1000);
-        Assert.assertEquals(0, topoManagerImpl.getEdges().size());
+        verifyEdgesSize(0);
         topoManagerImpl.notifyNodeConnector(nc1, UpdateType.REMOVED, propMap);
         topoManagerImpl.notifyNodeConnector(nc2, UpdateType.REMOVED, propMap);
 
@@ -870,14 +876,10 @@ public class TopologyManagerImplTest {
         swMgr.addNodeConnectors(nc2);
         topoManagerImpl.notifyNodeConnector(nc2, UpdateType.CHANGED, propMap);
         Assert.assertTrue(topoManagerImpl.flushUpdateQueue(5000));
-        // Give TopologyManger time to update its edges DB.
-        Thread.sleep(1000);
-        Assert.assertEquals(0, topoManagerImpl.getEdges().size());
+        verifyEdgesSize(0);
         topoManagerImpl.notifyNodeConnector(nc1, UpdateType.REMOVED, propMap);
         topoManagerImpl.notifyNodeConnector(nc2, UpdateType.REMOVED, propMap);
         Assert.assertTrue(topoManagerImpl.flushUpdateQueue(5000));
-        // Give TopologyManger time to update its edges DB.
-        Thread.sleep(1000);
-        Assert.assertEquals(0, topoManagerImpl.getEdges().size());
+        verifyEdgesSize(0);
     }
 }
index 06a43a6..b48e594 100644 (file)
@@ -76,6 +76,10 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker {
         Preconditions.checkArgument(cohorts != null, "Cohorts must not be null.");
         LOG.debug("Tx: {} is submitted for execution.", transaction.getIdentifier());
 
+        if(cohorts.isEmpty()){
+            return Futures.immediateCheckedFuture(null);
+        }
+
         final AsyncNotifyingSettableFuture clientSubmitFuture =
                 new AsyncNotifyingSettableFuture(clientFutureCallbackExecutor);
 
index 5531b5f..cf261cb 100644 (file)
@@ -112,7 +112,7 @@ public class TransactionChainProxy implements DOMStoreTransactionChain {
         currentState = CLOSED_STATE;
 
         // Send a close transaction chain request to each and every shard
-        actorContext.broadcast(new CloseTransactionChain(transactionChainId));
+        actorContext.broadcast(new CloseTransactionChain(transactionChainId).toSerializable());
     }
 
     private ChainedTransactionProxy allocateWriteTransaction(TransactionProxy.TransactionType type) {
index 80e25a1..f2536bf 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.controller.cluster.datastore;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -31,6 +32,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.SynchronousQueue;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
@@ -508,4 +510,23 @@ public class ConcurrentDOMDataBrokerTest {
         domDataWriteTransaction.put(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.builder().build(), mock(NormalizedNode.class));
     }
 
+    @Test
+    public void testEmptyTransactionSubmitSucceeds() throws ExecutionException, InterruptedException {
+        DOMStore domStore = mock(DOMStore.class);
+        ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(LogicalDatastoreType.OPERATIONAL,
+                domStore, LogicalDatastoreType.CONFIGURATION, domStore), futureExecutor);
+
+        CheckedFuture<Void, TransactionCommitFailedException> submit1 = dataBroker.newWriteOnlyTransaction().submit();
+
+        assertNotNull(submit1);
+
+        submit1.get();
+
+        CheckedFuture<Void, TransactionCommitFailedException> submit2 = dataBroker.newReadWriteTransaction().submit();
+
+        assertNotNull(submit2);
+
+        submit2.get();
+    }
+
 }
diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/util/InstanceIdToNodes.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/util/InstanceIdToNodes.java
deleted file mode 100644 (file)
index d0b9efc..0000000
+++ /dev/null
@@ -1,596 +0,0 @@
-/*
- * Copyright (c) 2015 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.connect.netconf.util;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-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.ConcurrentHashMap;
-import javax.xml.transform.dom.DOMSource;
-import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException;
-import org.opendaylight.yangtools.concepts.Identifiable;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.ModifyAction;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.schema.AnyXmlNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.AttributesBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
-import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
-import org.opendaylight.yangtools.yang.model.api.AugmentationTarget;
-import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
-import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-
-/**
- * Transforms an instance of yang instance identifier to a filter like structure in normalized node format. Can be also used to nest the edit-config rpc content.
- * For each argument of the id, a specific normalized node is created to ensure schema context conformance.
- */
-public abstract class InstanceIdToNodes<T extends PathArgument> implements Identifiable<T> {
-
-    private final T identifier;
-
-    @Override
-    public T getIdentifier() {
-        return identifier;
-    }
-
-    protected InstanceIdToNodes(final T identifier) {
-        this.identifier = identifier;
-    }
-
-    abstract InstanceIdToNodes<?> getChild(final PathArgument child) throws DataNormalizationException;
-
-    public abstract NormalizedNode<?, ?> create(YangInstanceIdentifier legacyData, Optional<NormalizedNode<?, ?>> deepestChild, Optional<ModifyAction> operation);
-
-    private static abstract class SimpleTypeNormalization<T extends PathArgument> extends InstanceIdToNodes<T> {
-
-        protected SimpleTypeNormalization(final T identifier) {
-            super(identifier);
-        }
-
-        @Override
-        public NormalizedNode<?, ?> create(final YangInstanceIdentifier id, final Optional<NormalizedNode<?, ?>> deepestChild, final Optional<ModifyAction> operation) {
-            checkNotNull(id);
-            final PathArgument pathArgument = Iterables.get(id.getPathArguments(), 0);
-            final NormalizedNodeAttrBuilder<? extends PathArgument, Object, ? extends NormalizedNode<? extends PathArgument, Object>> builder = getBuilder(pathArgument);
-
-            if(deepestChild.isPresent()) {
-                builder.withValue(deepestChild.get().getValue());
-            }
-
-            addModifyOpIfPresent(operation, builder);
-            return builder.build();
-        }
-
-        protected abstract NormalizedNodeAttrBuilder<? extends PathArgument, Object, ? extends NormalizedNode<? extends PathArgument, Object>> getBuilder(PathArgument node);
-
-        @Override
-        public InstanceIdToNodes<?> getChild(final PathArgument child) {
-            return null;
-        }
-    }
-
-
-    public void addModifyOpIfPresent(final Optional<ModifyAction> operation, final AttributesBuilder<?> builder) {
-        if(operation.isPresent()) {
-            builder.withAttributes(Collections.singletonMap(NetconfMessageTransformUtil.NETCONF_OPERATION_QNAME, NetconfMessageTransformUtil.modifyOperationToXmlString(operation.get())));
-        }
-    }
-
-    private static final class LeafNormalization extends SimpleTypeNormalization<NodeIdentifier> {
-
-        protected LeafNormalization(final LeafSchemaNode potential) {
-            super(new NodeIdentifier(potential.getQName()));
-        }
-
-        @Override
-        protected NormalizedNodeAttrBuilder<NodeIdentifier, Object, LeafNode<Object>> getBuilder(final PathArgument node) {
-            return Builders.leafBuilder().withNodeIdentifier(getIdentifier());
-        }
-    }
-
-    private static final class LeafListEntryNormalization extends SimpleTypeNormalization<NodeWithValue> {
-
-        public LeafListEntryNormalization(final LeafListSchemaNode potential) {
-            super(new NodeWithValue(potential.getQName(), null));
-        }
-
-        @Override
-        protected NormalizedNodeAttrBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> getBuilder(final PathArgument node) {
-            Preconditions.checkArgument(node instanceof NodeWithValue);
-            return Builders.leafSetEntryBuilder().withNodeIdentifier((NodeWithValue) node).withValue(((NodeWithValue) node).getValue());
-        }
-
-    }
-
-    private static abstract class CompositeNodeNormalizationOperation<T extends PathArgument> extends
-            InstanceIdToNodes<T> {
-
-        protected CompositeNodeNormalizationOperation(final T identifier) {
-            super(identifier);
-        }
-
-        @Override
-        @SuppressWarnings("unchecked")
-        public final NormalizedNode<?, ?> create(final YangInstanceIdentifier id, final Optional<NormalizedNode<?, ?>> lastChild, final Optional<ModifyAction> operation) {
-            checkNotNull(id);
-            final Iterator<PathArgument> iterator = id.getPathArguments().iterator();
-            final PathArgument legacyData = iterator.next();
-
-            if (!isMixin(this) && getIdentifier().getNodeType() != null) {
-                checkArgument(getIdentifier().getNodeType().equals(legacyData.getNodeType()),
-                        "Node QName must be %s was %s", getIdentifier().getNodeType(), legacyData.getNodeType());
-            }
-            final NormalizedNodeContainerBuilder builder = createBuilder(legacyData);
-
-            if (iterator.hasNext()) {
-                final PathArgument childPath = iterator.next();
-                final InstanceIdToNodes childOp = getChildOperation(childPath);
-
-                final YangInstanceIdentifier childId = YangInstanceIdentifier.create(Iterables.skip(id.getPathArguments(), 1));
-                builder.addChild(childOp.create(childId, lastChild, operation));
-            } else {
-                if(lastChild.isPresent()) {
-                    builder.withValue(Lists.newArrayList((Collection<?>) lastChild.get().getValue()));
-                }
-                if(operation.isPresent()) {
-                    Preconditions.checkArgument(builder instanceof AttributesBuilder<?>);
-                    addModifyOpIfPresent(operation, ((AttributesBuilder<?>) builder));
-                }
-            }
-
-            return builder.build();
-        }
-
-        private InstanceIdToNodes getChildOperation(final PathArgument childPath) {
-            final InstanceIdToNodes childOp;
-            try {
-                childOp = getChild(childPath);
-            } catch (final DataNormalizationException e) {
-                throw new IllegalArgumentException(String.format("Failed to process child node %s", childPath), e);
-            }
-            checkArgument(childOp != null, "Node %s is not allowed inside %s", childPath, getIdentifier());
-            return childOp;
-        }
-
-        @SuppressWarnings("rawtypes")
-        protected abstract NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final PathArgument compositeNode);
-    }
-
-    static boolean isMixin(final InstanceIdToNodes<?> op) {
-        return op instanceof MixinNormalizationOp;
-    }
-
-    private static abstract class DataContainerNormalizationOperation<T extends PathArgument> extends
-            CompositeNodeNormalizationOperation<T> {
-
-        private final DataNodeContainer schema;
-        private final Map<PathArgument, InstanceIdToNodes<?>> byArg;
-
-        protected DataContainerNormalizationOperation(final T identifier, final DataNodeContainer schema) {
-            super(identifier);
-            this.schema = schema;
-            this.byArg = new ConcurrentHashMap<>();
-        }
-
-        @Override
-        public InstanceIdToNodes<?> getChild(final PathArgument child) throws DataNormalizationException {
-            InstanceIdToNodes<?> potential = byArg.get(child);
-            if (potential != null) {
-                return potential;
-            }
-            potential = fromLocalSchema(child);
-            return register(potential);
-        }
-
-        private InstanceIdToNodes<?> fromLocalSchema(final PathArgument child) throws DataNormalizationException {
-            if (child instanceof AugmentationIdentifier) {
-                return fromSchemaAndQNameChecked(schema, ((AugmentationIdentifier) child).getPossibleChildNames()
-                        .iterator().next());
-            }
-            return fromSchemaAndQNameChecked(schema, child.getNodeType());
-        }
-
-        private InstanceIdToNodes<?> register(final InstanceIdToNodes<?> potential) {
-            if (potential != null) {
-                byArg.put(potential.getIdentifier(), potential);
-            }
-            return potential;
-        }
-    }
-
-    private static final class ListItemNormalization extends
-            DataContainerNormalizationOperation<NodeIdentifierWithPredicates> {
-
-        protected ListItemNormalization(final NodeIdentifierWithPredicates identifier, final ListSchemaNode schema) {
-            super(identifier, schema);
-        }
-
-        @Override
-        protected NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final PathArgument currentArg) {
-            final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> builder = Builders
-                    .mapEntryBuilder().withNodeIdentifier((NodeIdentifierWithPredicates) currentArg);
-            for (final Entry<QName, Object> keyValue : ((NodeIdentifierWithPredicates) currentArg).getKeyValues().entrySet()) {
-                builder.addChild(Builders.leafBuilder()
-                        //
-                        .withNodeIdentifier(new NodeIdentifier(keyValue.getKey())).withValue(keyValue.getValue())
-                        .build());
-            }
-            return builder;
-        }
-
-    }
-
-    private static final class UnkeyedListItemNormalization extends DataContainerNormalizationOperation<NodeIdentifier> {
-
-        protected UnkeyedListItemNormalization(final ListSchemaNode schema) {
-            super(new NodeIdentifier(schema.getQName()), schema);
-        }
-
-        @Override
-        protected NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final PathArgument compositeNode) {
-            return Builders.unkeyedListEntryBuilder().withNodeIdentifier(getIdentifier());
-        }
-
-    }
-
-    private static final class ContainerTransformation extends DataContainerNormalizationOperation<NodeIdentifier> {
-
-        protected ContainerTransformation(final ContainerSchemaNode schema) {
-            super(new NodeIdentifier(schema.getQName()), schema);
-        }
-
-        @Override
-        protected NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final PathArgument compositeNode) {
-            return Builders.containerBuilder().withNodeIdentifier(getIdentifier());
-        }
-    }
-
-    /**
-     * Marker interface for Mixin nodes normalization operations
-     */
-    private interface MixinNormalizationOp {}
-
-
-    private static final class OrderedLeafListMixinNormalization extends UnorderedLeafListMixinNormalization {
-
-
-        public OrderedLeafListMixinNormalization(final LeafListSchemaNode potential) {
-            super(potential);
-        }
-
-        @Override
-        protected NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final PathArgument compositeNode) {
-            return Builders.orderedLeafSetBuilder().withNodeIdentifier(getIdentifier());
-        }
-    }
-
-    private static class UnorderedLeafListMixinNormalization extends CompositeNodeNormalizationOperation<NodeIdentifier> implements MixinNormalizationOp {
-
-        private final InstanceIdToNodes<?> innerOp;
-
-        public UnorderedLeafListMixinNormalization(final LeafListSchemaNode potential) {
-            super(new NodeIdentifier(potential.getQName()));
-            innerOp = new LeafListEntryNormalization(potential);
-        }
-
-        @Override
-        protected NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final PathArgument compositeNode) {
-            return Builders.leafSetBuilder().withNodeIdentifier(getIdentifier());
-        }
-
-        @Override
-        public InstanceIdToNodes<?> getChild(final PathArgument child) {
-            if (child instanceof NodeWithValue) {
-                return innerOp;
-            }
-            return null;
-        }
-    }
-
-    private static final class AugmentationNormalization extends DataContainerNormalizationOperation<AugmentationIdentifier> implements MixinNormalizationOp {
-
-        public AugmentationNormalization(final AugmentationSchema augmentation, final DataNodeContainer schema) {
-            //super();
-            super(augmentationIdentifierFrom(augmentation), augmentationProxy(augmentation, schema));
-        }
-
-        @Override
-        protected NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final PathArgument compositeNode) {
-            return Builders.augmentationBuilder().withNodeIdentifier(getIdentifier());
-        }
-    }
-
-    private static class UnorderedMapMixinNormalization extends CompositeNodeNormalizationOperation<NodeIdentifier> implements MixinNormalizationOp {
-
-        private final ListItemNormalization innerNode;
-
-        public UnorderedMapMixinNormalization(final ListSchemaNode list) {
-            super(new NodeIdentifier(list.getQName()));
-            this.innerNode = new ListItemNormalization(new NodeIdentifierWithPredicates(list.getQName(),
-                    Collections.<QName, Object>emptyMap()), list);
-        }
-
-        @Override
-        protected NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final PathArgument compositeNode) {
-            return Builders.mapBuilder().withNodeIdentifier(getIdentifier());
-        }
-
-        @Override
-        public InstanceIdToNodes<?> getChild(final PathArgument child) {
-            if (child.getNodeType().equals(getIdentifier().getNodeType())) {
-                return innerNode;
-            }
-            return null;
-        }
-    }
-
-    private static class UnkeyedListMixinNormalization extends CompositeNodeNormalizationOperation<NodeIdentifier> implements MixinNormalizationOp {
-
-        private final UnkeyedListItemNormalization innerNode;
-
-        public UnkeyedListMixinNormalization(final ListSchemaNode list) {
-            super(new NodeIdentifier(list.getQName()));
-            this.innerNode = new UnkeyedListItemNormalization(list);
-        }
-
-        @Override
-        protected NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final PathArgument compositeNode) {
-            return Builders.unkeyedListBuilder().withNodeIdentifier(getIdentifier());
-        }
-
-        @Override
-        public InstanceIdToNodes<?> getChild(final PathArgument child) {
-            if (child.getNodeType().equals(getIdentifier().getNodeType())) {
-                return innerNode;
-            }
-            return null;
-        }
-
-    }
-
-    private static final class OrderedMapMixinNormalization extends UnorderedMapMixinNormalization {
-
-        public OrderedMapMixinNormalization(final ListSchemaNode list) {
-            super(list);
-        }
-
-        @Override
-        protected NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final PathArgument compositeNode) {
-            return Builders.orderedMapBuilder().withNodeIdentifier(getIdentifier());
-        }
-
-    }
-
-    private static class ChoiceNodeNormalization extends CompositeNodeNormalizationOperation<NodeIdentifier> implements MixinNormalizationOp {
-
-        private final ImmutableMap<PathArgument, InstanceIdToNodes<?>> byArg;
-
-        protected ChoiceNodeNormalization(final ChoiceSchemaNode schema) {
-            super(new NodeIdentifier(schema.getQName()));
-            final ImmutableMap.Builder<PathArgument, InstanceIdToNodes<?>> byArgBuilder = ImmutableMap.builder();
-
-            for (final ChoiceCaseNode caze : schema.getCases()) {
-                for (final DataSchemaNode cazeChild : caze.getChildNodes()) {
-                    final InstanceIdToNodes<?> childOp = fromDataSchemaNode(cazeChild);
-                    byArgBuilder.put(childOp.getIdentifier(), childOp);
-                }
-            }
-            byArg = byArgBuilder.build();
-        }
-
-        @Override
-        public InstanceIdToNodes<?> getChild(final PathArgument child) {
-            return byArg.get(child);
-        }
-
-        @Override
-        protected NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final PathArgument compositeNode) {
-            return Builders.choiceBuilder().withNodeIdentifier(getIdentifier());
-        }
-    }
-
-    private static class AnyXmlNormalization extends InstanceIdToNodes<NodeIdentifier> {
-
-        protected AnyXmlNormalization(final AnyXmlSchemaNode schema) {
-            super(new NodeIdentifier(schema.getQName()));
-        }
-
-        @Override
-        public InstanceIdToNodes<?> getChild(final PathArgument child) throws DataNormalizationException {
-            return null;
-        }
-
-        @Override
-        public NormalizedNode<?, ?> create(final YangInstanceIdentifier legacyData, final Optional<NormalizedNode<?, ?>> deepestChild, final Optional<ModifyAction> operation) {
-            if(deepestChild.isPresent()) {
-                Preconditions.checkState(deepestChild instanceof AnyXmlNode);
-                final NormalizedNodeAttrBuilder<NodeIdentifier, DOMSource, AnyXmlNode> anyXmlBuilder =
-                        Builders.anyXmlBuilder().withNodeIdentifier(getIdentifier()).withValue(((AnyXmlNode) deepestChild).getValue());
-                addModifyOpIfPresent(operation, anyXmlBuilder);
-                return anyXmlBuilder.build();
-            }
-
-            final NormalizedNodeAttrBuilder<NodeIdentifier, DOMSource, AnyXmlNode> builder =
-                    Builders.anyXmlBuilder().withNodeIdentifier(getIdentifier());
-            addModifyOpIfPresent(operation, builder);
-            return builder.build();
-        }
-
-    }
-
-    private static Optional<DataSchemaNode> findChildSchemaNode(final DataNodeContainer parent, final QName child) {
-        DataSchemaNode potential = parent.getDataChildByName(child);
-        if (potential == null) {
-            final Iterable<ChoiceSchemaNode> choices = FluentIterable.from(parent.getChildNodes()).filter(ChoiceSchemaNode.class);
-            potential = findChoice(choices, child);
-        }
-        return Optional.fromNullable(potential);
-    }
-
-    private static InstanceIdToNodes<?> fromSchemaAndQNameChecked(final DataNodeContainer schema, final QName child) throws DataNormalizationException {
-        final Optional<DataSchemaNode> potential = findChildSchemaNode(schema, child);
-        if (!potential.isPresent()) {
-            throw new DataNormalizationException(String.format("Supplied QName %s is not valid according to schema %s, potential children nodes: %s", child, schema, schema.getChildNodes()));
-        }
-
-        final DataSchemaNode result = potential.get();
-        // We try to look up if this node was added by augmentation
-        if ((schema instanceof DataSchemaNode) && result.isAugmenting()) {
-            return fromAugmentation(schema, (AugmentationTarget) schema, result);
-        }
-        return fromDataSchemaNode(result);
-    }
-
-    private static ChoiceSchemaNode findChoice(final Iterable<ChoiceSchemaNode> choices, final QName child) {
-        org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode foundChoice = null;
-        choiceLoop:
-        for (final ChoiceSchemaNode choice : choices) {
-            for (final ChoiceCaseNode caze : choice.getCases()) {
-                if (findChildSchemaNode(caze, child).isPresent()) {
-                    foundChoice = choice;
-                    break choiceLoop;
-                }
-            }
-        }
-        return foundChoice;
-    }
-
-    private static AugmentationIdentifier augmentationIdentifierFrom(final AugmentationSchema augmentation) {
-        final ImmutableSet.Builder<QName> potentialChildren = ImmutableSet.builder();
-        for (final DataSchemaNode child : augmentation.getChildNodes()) {
-            potentialChildren.add(child.getQName());
-        }
-        return new AugmentationIdentifier(potentialChildren.build());
-    }
-
-    private static DataNodeContainer augmentationProxy(final AugmentationSchema augmentation, final DataNodeContainer schema) {
-        final Set<DataSchemaNode> children = new HashSet<>();
-        for (final DataSchemaNode augNode : augmentation.getChildNodes()) {
-            children.add(schema.getDataChildByName(augNode.getQName()));
-        }
-        return new NodeContainerProxy(null, children);
-    }
-
-    /**
-     * Returns a SchemaPathUtil for provided child node
-     * <p/>
-     * If supplied child is added by Augmentation this operation returns
-     * a SchemaPathUtil for augmentation,
-     * otherwise returns a SchemaPathUtil for child as
-     * call for {@link #fromDataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode)}.
-     */
-    private static InstanceIdToNodes<?> fromAugmentation(final DataNodeContainer parent,
-                                                          final AugmentationTarget parentAug, final DataSchemaNode child) {
-        AugmentationSchema augmentation = null;
-        for (final AugmentationSchema aug : parentAug.getAvailableAugmentations()) {
-            final DataSchemaNode potential = aug.getDataChildByName(child.getQName());
-            if (potential != null) {
-                augmentation = aug;
-                break;
-            }
-
-        }
-        if (augmentation != null) {
-            return new AugmentationNormalization(augmentation, parent);
-        } else {
-            return fromDataSchemaNode(child);
-        }
-    }
-
-    private static InstanceIdToNodes<?> fromDataSchemaNode(final DataSchemaNode potential) {
-        if (potential instanceof ContainerSchemaNode) {
-            return new ContainerTransformation((ContainerSchemaNode) potential);
-        } else if (potential instanceof ListSchemaNode) {
-            return fromListSchemaNode((ListSchemaNode) potential);
-        } else if (potential instanceof LeafSchemaNode) {
-            return new LeafNormalization((LeafSchemaNode) potential);
-        } else if (potential instanceof ChoiceSchemaNode) {
-            return new ChoiceNodeNormalization((ChoiceSchemaNode) potential);
-        } else if (potential instanceof LeafListSchemaNode) {
-            return fromLeafListSchemaNode((LeafListSchemaNode) potential);
-        } else if (potential instanceof AnyXmlSchemaNode) {
-            return new AnyXmlNormalization((AnyXmlSchemaNode) potential);
-        }
-        return null;
-    }
-
-    private static InstanceIdToNodes<?> fromListSchemaNode(final ListSchemaNode potential) {
-        final List<QName> keyDefinition = potential.getKeyDefinition();
-        if (keyDefinition == null || keyDefinition.isEmpty()) {
-            return new UnkeyedListMixinNormalization(potential);
-        }
-        if (potential.isUserOrdered()) {
-            return new OrderedMapMixinNormalization(potential);
-        }
-        return new UnorderedMapMixinNormalization(potential);
-    }
-
-    private static InstanceIdToNodes<?> fromLeafListSchemaNode(final LeafListSchemaNode potential) {
-        if (potential.isUserOrdered()) {
-            return new OrderedLeafListMixinNormalization(potential);
-        }
-        return new UnorderedLeafListMixinNormalization(potential);
-    }
-
-    public static NormalizedNode<?, ?> serialize(final SchemaContext ctx, final YangInstanceIdentifier id) {
-        return serialize(ctx, id, Optional.<NormalizedNode<?, ?>>absent(), Optional.<ModifyAction>absent());
-    }
-
-    public static NormalizedNode<?, ?> serialize(final SchemaContext ctx, final YangInstanceIdentifier id, final NormalizedNode<?, ?> deepestElement) {
-        return serialize(ctx, id, Optional.<NormalizedNode<?, ?>>of(deepestElement), Optional.<ModifyAction>absent());
-    }
-
-    public static NormalizedNode<?, ?> serialize(final SchemaContext ctx, final YangInstanceIdentifier id, final Optional<NormalizedNode<?, ?>> deepestElement, final Optional<ModifyAction> operation) {
-        Preconditions.checkNotNull(ctx);
-        Preconditions.checkNotNull(id);
-        final PathArgument topLevelElement = id.getPathArguments().iterator().next();
-        final DataSchemaNode dataChildByName = ctx.getDataChildByName(topLevelElement.getNodeType());
-        Preconditions.checkNotNull(dataChildByName, "Cannot find %s node in schema context. Instance identifier has to start from root", topLevelElement);
-        try {
-            final InstanceIdToNodes<?> instanceIdToNodes = fromSchemaAndQNameChecked(ctx, topLevelElement.getNodeType());
-            return instanceIdToNodes.create(id, deepestElement, operation);
-        } catch (final DataNormalizationException e) {
-            throw new IllegalArgumentException("Unable to serialize: " + id, e);
-        }
-    }
-}
index c19bb48..bf432d3 100644 (file)
@@ -235,7 +235,8 @@ public final class NetconfBaseOps {
 
         // Default operation
         if(defaultOperation.isPresent()) {
-            editBuilder.withChild(Builders.leafBuilder().withNodeIdentifier(toId(NETCONF_DEFAULT_OPERATION_QNAME)).withValue(NetconfMessageTransformUtil.modifyOperationToXmlString(defaultOperation.get())).build());
+            final String opString = defaultOperation.get().name().toLowerCase();
+            editBuilder.withChild(Builders.leafBuilder().withNodeIdentifier(toId(NETCONF_DEFAULT_OPERATION_QNAME)).withValue(opString).build());
         }
 
         // Error option
index dc1c8c7..1da39cf 100644 (file)
@@ -14,6 +14,7 @@ import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 import java.io.IOException;
 import java.net.URI;
+import java.util.AbstractMap;
 import java.util.Collections;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -44,6 +45,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStre
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
 import org.opendaylight.yangtools.yang.data.impl.codec.xml.XMLStreamNormalizedNodeStreamWriter;
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
@@ -145,7 +147,7 @@ public class NetconfMessageTransformUtil {
         final NormalizedNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, DOMSource, AnyXmlNode> anyXmlBuilder = Builders.anyXmlBuilder().withNodeIdentifier(toId(NETCONF_FILTER_QNAME));
         anyXmlBuilder.withAttributes(Collections.singletonMap(NETCONF_TYPE_QNAME, SUBTREE));
 
-        final NormalizedNode<?, ?> filterContent = InstanceIdToNodes.serialize(ctx, identifier);
+        final NormalizedNode<?, ?> filterContent = ImmutableNodes.fromInstanceId(ctx, identifier);
 
         final Element element = XmlUtil.createElement(BLANK_DOCUMENT, NETCONF_FILTER_QNAME.getLocalName(), Optional.of(NETCONF_FILTER_QNAME.getNamespace().toString()));
         element.setAttributeNS(NETCONF_FILTER_QNAME.getNamespace().toString(), NETCONF_TYPE_QNAME.getLocalName(), "subtree");
@@ -268,7 +270,9 @@ public class NetconfMessageTransformUtil {
                     "Data has to be either container or a list node when creating structure for top level element, but was: %s", lastChildOverride.get());
             configContent = lastChildOverride.get();
         } else {
-            configContent = InstanceIdToNodes.serialize(ctx, dataPath, lastChildOverride, operation);
+            final Entry<QName, ModifyAction> modifyOperation =
+                    operation.isPresent() ? new AbstractMap.SimpleEntry<>(NETCONF_OPERATION_QNAME, operation.get()) : null;
+            configContent = ImmutableNodes.fromInstanceId(ctx, dataPath, lastChildOverride, Optional.fromNullable(modifyOperation));
         }
 
         final Element element = XmlUtil.createElement(BLANK_DOCUMENT, NETCONF_CONFIG_QNAME.getLocalName(), Optional.of(NETCONF_CONFIG_QNAME.getNamespace().toString()));
@@ -287,10 +291,6 @@ public class NetconfMessageTransformUtil {
         return SchemaPath.create(true, rpc);
     }
 
-    public static String modifyOperationToXmlString(final ModifyAction operation) {
-        return operation.name().toLowerCase();
-    }
-
     // FIXME similar code is in netconf-notifications-impl , DRY
     public static void writeNormalizedNode(final NormalizedNode<?, ?> normalized, final DOMResult result, final SchemaPath schemaPath, final SchemaContext context)
             throws IOException, XMLStreamException {
index b499bd8..23e2137 100644 (file)
@@ -28,7 +28,10 @@ import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.UsesNode;
 
-class NodeContainerProxy implements ContainerSchemaNode {
+/**
+ * Simple proxy for container like schema nodes, where user provides a collection of children schema nodes
+ */
+public final class NodeContainerProxy implements ContainerSchemaNode {
 
     private final Map<QName, DataSchemaNode> childNodes;
     private final QName qName;
@@ -146,4 +149,4 @@ class NodeContainerProxy implements ContainerSchemaNode {
     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
         return Collections.emptyList();
     }
-}
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-netconf-connector/src/test/java/org/opendaylight/controller/sal/connect/netconf/util/InstanceIdToNodesTest.java b/opendaylight/md-sal/sal-netconf-connector/src/test/java/org/opendaylight/controller/sal/connect/netconf/util/InstanceIdToNodesTest.java
deleted file mode 100644 (file)
index 39a8f42..0000000
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Copyright (c) 2015 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.connect.netconf.util;
-
-import static org.junit.Assert.assertEquals;
-
-import com.google.common.base.Function;
-import com.google.common.collect.Collections2;
-import com.google.common.io.ByteSource;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collections;
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
-import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
-
-public class InstanceIdToNodesTest {
-
-    private static final String NS = "urn:opendaylight:params:xml:ns:yang:controller:md:sal:normalization:test";
-    private static final String REVISION = "2014-03-13";
-    private static final QName ID = QName.create(NS, REVISION, "id");
-    private SchemaContext ctx;
-
-    private final YangInstanceIdentifier.NodeIdentifier rootContainer = new YangInstanceIdentifier.NodeIdentifier(QName.create(NS, REVISION, "test"));
-    private final YangInstanceIdentifier.NodeIdentifier outerContainer = new YangInstanceIdentifier.NodeIdentifier(QName.create(NS, REVISION, "outer-container"));
-    private final YangInstanceIdentifier.NodeIdentifier augmentedLeaf = new YangInstanceIdentifier.NodeIdentifier(QName.create(NS, REVISION, "augmented-leaf"));
-    private final YangInstanceIdentifier.AugmentationIdentifier augmentation = new YangInstanceIdentifier.AugmentationIdentifier(Collections.singleton(augmentedLeaf.getNodeType()));
-
-    private final YangInstanceIdentifier.NodeIdentifier outerList = new YangInstanceIdentifier.NodeIdentifier(QName.create(NS, REVISION, "outer-list"));
-    private final YangInstanceIdentifier.NodeIdentifierWithPredicates outerListWithKey = new YangInstanceIdentifier.NodeIdentifierWithPredicates(QName.create(NS, REVISION, "outer-list"), ID, 1);
-    private final YangInstanceIdentifier.NodeIdentifier choice = new YangInstanceIdentifier.NodeIdentifier(QName.create(NS, REVISION, "outer-choice"));
-    private final YangInstanceIdentifier.NodeIdentifier leafFromCase = new YangInstanceIdentifier.NodeIdentifier(QName.create(NS, REVISION, "one"));
-
-    private final YangInstanceIdentifier.NodeIdentifier leafList = new YangInstanceIdentifier.NodeIdentifier(QName.create(NS, REVISION, "ordered-leaf-list"));
-    private final YangInstanceIdentifier.NodeWithValue leafListWithValue = new YangInstanceIdentifier.NodeWithValue(leafList.getNodeType(), "abcd");
-
-    static SchemaContext createTestContext() throws IOException, YangSyntaxErrorException {
-        final YangParserImpl parser = new YangParserImpl();
-        return parser.parseSources(Collections2.transform(Collections.singletonList("/schemas/filter-test.yang"), new Function<String, ByteSource>() {
-            @Override
-            public ByteSource apply(final String input) {
-                return new ByteSource() {
-                    @Override
-                    public InputStream openStream() throws IOException {
-                        return InstanceIdToNodesTest.class.getResourceAsStream(input);
-                    }
-                };
-            }
-        }));
-    }
-
-    @Before
-    public void setUp() throws Exception {
-        ctx = createTestContext();
-
-    }
-
-    @Test
-    public void testInAugment() throws Exception {
-        final ContainerNode expectedFilter = Builders.containerBuilder().withNodeIdentifier(rootContainer).withChild(
-                Builders.containerBuilder().withNodeIdentifier(outerContainer).withChild(
-                        Builders.augmentationBuilder().withNodeIdentifier(augmentation).withChild(
-                                Builders.leafBuilder().withNodeIdentifier(augmentedLeaf).build()
-                        ).build()
-                ).build()
-        ).build();
-
-        final NormalizedNode<?, ?> filter = InstanceIdToNodes.serialize(ctx, YangInstanceIdentifier.create(rootContainer, outerContainer, augmentation, augmentedLeaf));
-        assertEquals(expectedFilter, filter);
-    }
-
-    @Test
-    public void testInAugmentLeafOverride() throws Exception {
-        final LeafNode<Object> lastLeaf = Builders.leafBuilder().withNodeIdentifier(augmentedLeaf).withValue("randomValue").build();
-
-        final ContainerNode expectedFilter = Builders.containerBuilder().withNodeIdentifier(rootContainer).withChild(
-                Builders.containerBuilder().withNodeIdentifier(outerContainer).withChild(
-                        Builders.augmentationBuilder().withNodeIdentifier(augmentation).withChild(
-                                lastLeaf
-                        ).build()
-                ).build()
-        ).build();
-
-        final NormalizedNode<?, ?> filter = InstanceIdToNodes.serialize(ctx, YangInstanceIdentifier.create(rootContainer, outerContainer, augmentation, augmentedLeaf), lastLeaf);
-        assertEquals(expectedFilter, filter);
-    }
-
-    @Test
-    public void testListChoice() throws Exception {
-        final ContainerNode expectedFilter = Builders.containerBuilder().withNodeIdentifier(rootContainer).withChild(
-                Builders.mapBuilder().withNodeIdentifier(outerList).withChild(
-                        Builders.mapEntryBuilder().withNodeIdentifier(outerListWithKey).withChild(
-                                Builders.leafBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(ID)).withValue(1).build()
-                        ).withChild(
-                                Builders.choiceBuilder().withNodeIdentifier(choice).withChild(
-                                        Builders.leafBuilder().withNodeIdentifier(leafFromCase).build()
-                                ).build()
-                        ).build()
-                ).build()
-        ).build();
-
-        final NormalizedNode<?, ?> filter = InstanceIdToNodes.serialize(ctx, YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey, choice, leafFromCase));
-        assertEquals(expectedFilter, filter);
-    }
-
-    @Test
-    public void testTopContainerLastChildOverride() throws Exception {
-        final ContainerNode expectedStructure = Builders.containerBuilder().withNodeIdentifier(rootContainer).withChild(
-                Builders.mapBuilder().withNodeIdentifier(outerList).withChild(
-                        Builders.mapEntryBuilder().withNodeIdentifier(outerListWithKey).withChild(
-                                Builders.leafBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(ID)).withValue(1).build()
-                        ).withChild(
-                                Builders.choiceBuilder().withNodeIdentifier(choice).withChild(
-                                        Builders.leafBuilder().withNodeIdentifier(leafFromCase).build()
-                                ).build()
-                        ).build()
-                ).build()
-        ).build();
-
-        final NormalizedNode<?, ?> filter = InstanceIdToNodes.serialize(ctx, YangInstanceIdentifier.create(rootContainer), expectedStructure);
-        assertEquals(expectedStructure, filter);
-    }
-
-    @Test
-    public void testListLastChildOverride() throws Exception {
-        final MapEntryNode outerListEntry = Builders.mapEntryBuilder().withNodeIdentifier(outerListWithKey).withChild(
-                Builders.leafBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(ID)).withValue(1).build()
-        ).build();
-        final MapNode lastChild = Builders.mapBuilder().withNodeIdentifier(this.outerList).withChild(
-                outerListEntry
-        ).build();
-        final ContainerNode expectedStructure = Builders.containerBuilder().withNodeIdentifier(rootContainer).withChild(
-                lastChild
-        ).build();
-
-        NormalizedNode<?, ?> filter = InstanceIdToNodes.serialize(ctx, YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey), outerListEntry);
-        assertEquals(expectedStructure, filter);
-        filter = InstanceIdToNodes.serialize(ctx, YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey));
-        assertEquals(expectedStructure, filter);
-    }
-
-    @Test
-    public void testLeafList() throws Exception {
-        final ContainerNode expectedFilter = Builders.containerBuilder().withNodeIdentifier(rootContainer).withChild(
-                Builders.orderedLeafSetBuilder().withNodeIdentifier(leafList).withChild(
-                        Builders.leafSetEntryBuilder().withNodeIdentifier(leafListWithValue).withValue(leafListWithValue.getValue()).build()
-                ).build()
-        ).build();
-
-        final NormalizedNode<?, ?> filter = InstanceIdToNodes.serialize(ctx, YangInstanceIdentifier.create(rootContainer, leafList, leafListWithValue));
-        assertEquals(expectedFilter, filter);
-    }
-}
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-netconf-connector/src/test/resources/schemas/filter-test.yang b/opendaylight/md-sal/sal-netconf-connector/src/test/resources/schemas/filter-test.yang
deleted file mode 100644 (file)
index 6df5306..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-module normalization-test {
-    yang-version 1;
-    namespace "urn:opendaylight:params:xml:ns:yang:controller:md:sal:normalization:test";
-    prefix "norm-test";
-
-    revision "2014-03-13" {
-        description "Initial revision.";
-    }
-
-    grouping outer-grouping {
-    }
-
-    container test {
-        list outer-list {
-            key id;
-            leaf id {
-                type uint16;
-            }
-            choice outer-choice {
-                case one {
-                    leaf one {
-                        type string;
-                    }
-                }
-                case two-three {
-                    leaf two {
-                        type string;
-                    }
-                    leaf three {
-                        type string;
-                    }
-               }
-           }
-           list inner-list {
-                key name;
-                ordered-by user;
-
-                leaf name {
-                    type string;
-                }
-                leaf value {
-                    type string;
-                }
-            }
-        }
-
-        list unkeyed-list {
-            leaf name {
-                type string;
-            }
-        }
-
-        leaf-list unordered-leaf-list {
-            type string;
-        }
-
-        leaf-list ordered-leaf-list {
-            ordered-by user;
-            type string;
-        }
-
-        container outer-container {
-        }
-
-        anyxml any-xml-data;
-    }
-
-    augment /norm-test:test/norm-test:outer-container {
-
-        leaf augmented-leaf {
-           type string;
-        }
-    }
-}
\ No newline at end of file
index cb03516..2961662 100644 (file)
@@ -137,12 +137,15 @@ public class YangStoreService implements YangStoreContext {
     }
 
     public AutoCloseable registerCapabilityListener(final CapabilityListener listener) {
-        if(ref.get() == null || ref.get().get() == null) {
-            getYangStoreSnapshot();
+        final SoftReference<YangStoreSnapshot> yangStoreSnapshotSoftReference = ref.get();
+
+        YangStoreContext ret = yangStoreSnapshotSoftReference != null ? yangStoreSnapshotSoftReference.get() : null;
+        if(ret == null) {
+            ret = getYangStoreSnapshot();
         }
 
         this.listeners.add(listener);
-        listener.onCapabilitiesAdded(NetconfOperationServiceFactoryImpl.setupCapabilities(ref.get().get()));
+        listener.onCapabilitiesAdded(NetconfOperationServiceFactoryImpl.setupCapabilities(ret));
 
         return new AutoCloseable() {
             @Override
index 878c378..d58bd54 100644 (file)
           <artifactId>xmlunit</artifactId>
           <scope>test</scope>
       </dependency>
-      <dependency>
-          <!--TODO remove this dependency on sal-netconf-connector - move InstanceIdToNodes to netconf-util,
-          remove odl-yangtools-models, sal-netconf-connector, model-inventory dependency from the odl-netconf-mdsal feature in mdsal features with this-->
-          <groupId>org.opendaylight.controller</groupId>
-          <artifactId>sal-netconf-connector</artifactId>
-      </dependency>
-
   </dependencies>
 
   <build>
index 9a66ceb..d028a89 100644 (file)
@@ -31,7 +31,6 @@ import org.opendaylight.controller.netconf.mdsal.connector.CurrentSchemaContext;
 import org.opendaylight.controller.netconf.mdsal.connector.ops.Datastore;
 import org.opendaylight.controller.netconf.util.mapping.AbstractSingletonNetconfOperation;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
-import org.opendaylight.controller.sal.connect.netconf.util.InstanceIdToNodes;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@@ -42,6 +41,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
 import org.opendaylight.yangtools.yang.data.impl.codec.xml.XMLStreamNormalizedNodeStreamWriter;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.DomUtils;
 import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.parser.DomToNormalizedNodeParserFactory;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
@@ -151,7 +151,7 @@ public abstract class AbstractGet extends AbstractSingletonNetconfOperation {
     protected Element serializeNodeWithParentStructure(Document document, YangInstanceIdentifier dataRoot, NormalizedNode node) {
         if (!dataRoot.equals(ROOT)) {
             return (Element) transformNormalizedNode(document,
-                    InstanceIdToNodes.serialize(schemaContext.getCurrentContext(), dataRoot, node),
+                    ImmutableNodes.fromInstanceId(schemaContext.getCurrentContext(), dataRoot, node),
                     ROOT);
         }
         return  (Element) transformNormalizedNode(document, node, ROOT);
index 4529f81..3d46bf6 100644 (file)
@@ -143,8 +143,9 @@ public final class XmlElement {
     }
 
     public String getName() {
-        if (element.getLocalName()!=null && !element.getLocalName().equals(DEFAULT_NAMESPACE_PREFIX)){
-            return element.getLocalName();
+        final String localName = element.getLocalName();
+        if (!Strings.isNullOrEmpty(localName)){
+            return localName;
         }
         return element.getTagName();
     }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.