Merge "BUG-1568 Remove ganymed Ssh client adapter"
authorEd Warnicke <eaw@cisco.com>
Mon, 25 Aug 2014 11:15:10 +0000 (11:15 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 25 Aug 2014 11:15:10 +0000 (11:15 +0000)
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/NormalizedNodeToNodeCodec.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/NormalizedNodeGetter.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/PathUtils.java
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/NormalizedNodeToNodeCodecTest.java
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/PathUtilsTest.java [new file with mode: 0644]
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java
opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfStateSchemas.java
opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/FlowCapableTopologyExporter.java

index 17bdb36e569612ef513a787e010aeb8583167984..d1ae264c3b912839a4332fc74766076859b754db 100644 (file)
@@ -32,7 +32,7 @@ public class NormalizedNodeToNodeCodec {
         String parentPath = "";
 
         if(id != null){
-            parentPath = PathUtils.getParentPath(id.toString());
+            parentPath = PathUtils.getParentPath(PathUtils.toString(id));
         }
 
 
index 31e6521a2861e65f1412b99818d4d47684e04c7b..32f3be82fcd0648e35796c5e3c835332825a20e9 100644 (file)
@@ -25,7 +25,7 @@ public class NormalizedNodeGetter implements
 
     @Override
     public void visitNode(int level, String parentPath, NormalizedNode normalizedNode) {
-        String nodePath = parentPath + "/"+ normalizedNode.getIdentifier().toString();
+        String nodePath = parentPath + "/"+ PathUtils.toString(normalizedNode.getIdentifier());
 
         if(nodePath.toString().equals(path)){
             output = normalizedNode;
index 1dd0f3b8278407752b91afbb24548eb857385cbc..25b65f01681ac4b9dcaa6354ec001c85bc531981 100644 (file)
 
 package org.opendaylight.controller.cluster.datastore.node.utils;
 
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
 public class PathUtils {
+
     public static String getParentPath(String currentElementPath){
         StringBuilder parentPath = new StringBuilder();
 
@@ -27,4 +36,86 @@ public class PathUtils {
         }
         return parentPath.toString();
     }
+
+    /**
+     * Given a YangInstanceIdentifier return a serialized version of the same
+     * as a String
+     *
+     * @param path
+     * @return
+     */
+    public static String toString(YangInstanceIdentifier path){
+        StringBuilder sb = new StringBuilder();
+        Iterator<YangInstanceIdentifier.PathArgument> iterator =
+            path.getPathArguments().iterator();
+
+        while(iterator.hasNext()){
+            sb.append(toString(iterator.next()));
+            if(iterator.hasNext()){
+                sb.append("/");
+            }
+        }
+        return sb.toString();
+    }
+
+    /**
+     * Given a YangInstanceIdentifier.PathArgument return a serialized version
+     * of the same as a String
+     *
+     * @param pathArgument
+     * @return
+     */
+    public static String toString(YangInstanceIdentifier.PathArgument pathArgument){
+        if(pathArgument instanceof YangInstanceIdentifier.NodeIdentifier){
+            return toString((YangInstanceIdentifier.NodeIdentifier) pathArgument);
+        } else if(pathArgument instanceof YangInstanceIdentifier.AugmentationIdentifier){
+            return toString((YangInstanceIdentifier.AugmentationIdentifier) pathArgument);
+        } else if(pathArgument instanceof YangInstanceIdentifier.NodeWithValue){
+            return toString((YangInstanceIdentifier.NodeWithValue) pathArgument);
+        } else if(pathArgument instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates){
+            return toString((YangInstanceIdentifier.NodeIdentifierWithPredicates) pathArgument);
+        }
+
+        return pathArgument.toString();
+    }
+
+    /**
+     * Given a serialized string version of a YangInstanceIdentifier convert
+     * to a YangInstanceIdentifier
+     *
+     * @param path
+     * @return
+     */
+    public static YangInstanceIdentifier toYangInstanceIdentifier(String path){
+        String[] segments = path.split("/");
+
+        List<YangInstanceIdentifier.PathArgument> pathArguments = new ArrayList<>();
+        for (String segment : segments) {
+            if (!"".equals(segment)) {
+                pathArguments.add(NodeIdentifierFactory.getArgument(segment));
+            }
+        }
+        return YangInstanceIdentifier.create(pathArguments);
+    }
+
+    private static String toString(YangInstanceIdentifier.NodeIdentifier pathArgument){
+        return pathArgument.getNodeType().toString();
+    }
+
+    private static String toString(YangInstanceIdentifier.AugmentationIdentifier pathArgument){
+        Set<QName> childNames = pathArgument.getPossibleChildNames();
+        final StringBuilder sb = new StringBuilder("AugmentationIdentifier{");
+        sb.append("childNames=").append(childNames).append('}');
+        return sb.toString();
+
+    }
+
+    private static String toString(YangInstanceIdentifier.NodeWithValue pathArgument){
+        return pathArgument.getNodeType().toString() + "[" + pathArgument.getValue() + "]";
+    }
+
+    private static String toString(YangInstanceIdentifier.NodeIdentifierWithPredicates pathArgument){
+        return pathArgument.getNodeType().toString() + '[' + pathArgument.getKeyValues() + ']';
+    }
+
 }
index bdad86ddc1e8fb5521607fbb91a575a99e677d38..c42865c659192e0584ebe93a147fee655ab284c4 100644 (file)
@@ -13,9 +13,9 @@ package org.opendaylight.controller.cluster.datastore.node;
 import junit.framework.Assert;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.controller.cluster.datastore.node.utils.NodeIdentifierFactory;
 import org.opendaylight.controller.cluster.datastore.node.utils.NormalizedNodeGetter;
 import org.opendaylight.controller.cluster.datastore.node.utils.NormalizedNodeNavigator;
+import org.opendaylight.controller.cluster.datastore.node.utils.PathUtils;
 import org.opendaylight.controller.cluster.datastore.util.TestModel;
 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages.Container;
 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages.Node;
@@ -24,7 +24,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
-import java.util.ArrayList;
 import java.util.List;
 
 import static junit.framework.Assert.assertEquals;
@@ -43,21 +42,9 @@ public class NormalizedNodeToNodeCodecTest {
   }
 
   private YangInstanceIdentifier instanceIdentifierFromString(String s) {
-
-    String[] ids = s.split("/");
-
-    List<YangInstanceIdentifier.PathArgument> pathArguments = new ArrayList<>();
-    for (String nodeId : ids) {
-      if (!"".equals(nodeId)) {
-        pathArguments.add(NodeIdentifierFactory.getArgument(nodeId));
-      }
-    }
-    final YangInstanceIdentifier instanceIdentifier =
-        YangInstanceIdentifier.create(pathArguments);
-    return instanceIdentifier;
+      return PathUtils.toYangInstanceIdentifier(s);
   }
 
-
   @Test
   public void testNormalizeNodeAttributesToProtoBuffNode() {
     final NormalizedNode<?, ?> documentOne = TestModel.createTestContainer();
@@ -69,7 +56,7 @@ public class NormalizedNodeToNodeCodecTest {
 
     NormalizedNodeGetter normalizedNodeGetter = new NormalizedNodeGetter(id);
     new NormalizedNodeNavigator(normalizedNodeGetter).navigate(
-        YangInstanceIdentifier.builder().build().toString(), documentOne);
+        PathUtils.toString(YangInstanceIdentifier.builder().build()), documentOne);
 
     // Validate the value of id can be retrieved from the normalized node
     NormalizedNode output = normalizedNodeGetter.getOutput();
diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/PathUtilsTest.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/PathUtilsTest.java
new file mode 100644 (file)
index 0000000..ffa8a10
--- /dev/null
@@ -0,0 +1,121 @@
+package org.opendaylight.controller.cluster.datastore.node.utils;
+
+import org.junit.Test;
+import org.opendaylight.controller.cluster.datastore.util.TestModel;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import static junit.framework.TestCase.assertEquals;
+
+public class PathUtilsTest {
+
+    @Test
+    public void getParentPath(){
+        assertEquals("", PathUtils.getParentPath("foobar"));
+        assertEquals("", PathUtils.getParentPath("/a"));
+        assertEquals("/a", PathUtils.getParentPath("/a/b"));
+        assertEquals("/a/b", PathUtils.getParentPath("/a/b/c"));
+        assertEquals("/a/b", PathUtils.getParentPath("a/b/c"));
+    }
+
+    @Test
+    public void toStringNodeIdentifier(){
+        YangInstanceIdentifier.PathArgument pathArgument = nodeIdentifier();
+
+        String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test";
+
+        assertEquals(expected , PathUtils.toString(pathArgument));
+    }
+
+    @Test
+    public void toStringAugmentationIdentifier(){
+        String expected = "AugmentationIdentifier{childNames=[(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics]}";
+
+        YangInstanceIdentifier.PathArgument pathArgument = augmentationIdentifier();
+
+        assertEquals(expected, PathUtils.toString(pathArgument));
+    }
+
+    @Test
+    public void toStringNodeWithValue(){
+
+        YangInstanceIdentifier.PathArgument pathArgument = nodeWithValue();
+
+        String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[100]";
+
+        assertEquals(expected, PathUtils.toString(pathArgument));
+    }
+
+
+    @Test
+    public void toStringNodeIdentifierWithPredicates(){
+
+        YangInstanceIdentifier.PathArgument pathArgument = nodeIdentifierWithPredicates();
+
+        String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[{(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)id=100}]";
+
+        assertEquals(expected, PathUtils.toString(pathArgument));
+    }
+
+    @Test
+    public void toStringYangInstanceIdentifier(){
+
+        YangInstanceIdentifier path =
+            YangInstanceIdentifier.create(nodeIdentifier())
+                .node(nodeIdentifierWithPredicates())
+                .node(augmentationIdentifier()).node(nodeWithValue());
+
+
+        String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test/" +
+            "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[{(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)id=100}]/" +
+            "AugmentationIdentifier{childNames=[(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics]}/" +
+            "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[100]";
+
+        assertEquals(expected, PathUtils.toString(path));
+
+    }
+
+    @Test
+    public void toYangInstanceIdentifier(){
+        String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test/" +
+            "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[{(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)id=100}]/" +
+            "AugmentationIdentifier{childNames=[(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics]}/" +
+            "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[100]";
+
+        YangInstanceIdentifier yangInstanceIdentifier =
+            PathUtils.toYangInstanceIdentifier(expected);
+
+        String actual = PathUtils.toString(yangInstanceIdentifier);
+
+        assertEquals(expected, actual);
+
+    }
+
+    private YangInstanceIdentifier.NodeIdentifier nodeIdentifier(){
+        return new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME);
+    }
+
+    private YangInstanceIdentifier.AugmentationIdentifier augmentationIdentifier(){
+        Set<QName> childNames = new HashSet();
+        childNames.add(QNameFactory.create("(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics"));
+
+        return new YangInstanceIdentifier.AugmentationIdentifier(childNames);
+    }
+
+    private YangInstanceIdentifier.NodeWithValue nodeWithValue(){
+        return new YangInstanceIdentifier.NodeWithValue(TestModel.TEST_QNAME, Integer.valueOf(100));
+    }
+
+    private YangInstanceIdentifier.NodeIdentifierWithPredicates nodeIdentifierWithPredicates(){
+        Map<QName, Object> keys = new HashMap<>();
+
+        keys.put(TestModel.ID_QNAME, Integer.valueOf(100));
+
+        return new YangInstanceIdentifier.NodeIdentifierWithPredicates(TestModel.TEST_QNAME, keys);
+    }
+}
index 5b5b1296af08e42c2278b6db80ac05cbf08329c6..6183c489c4cdbc56a1ba9ac0c3c3939963277edb 100644 (file)
@@ -99,7 +99,7 @@ public class TransactionProxy implements DOMStoreReadWriteTransaction {
         this.identifier = TransactionIdentifier.builder().memberName(memberName).counter(
                 counter.getAndIncrement()).build();
 
-        LOG.debug("Created txn {}", identifier);
+        LOG.debug("Created txn {} of type {}", identifier, transactionType);
 
     }
 
index 129013378ea57c713304793248e1cdc2f2c0a6ce..7ad3b8201e182cff9b3820a9e029f697e4cdb950 100644 (file)
@@ -191,7 +191,7 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable<String>, Sch
     }
 
     @Override
-    public synchronized DOMStoreThreePhaseCommitCohort ready(final SnapshotBackedWriteTransaction writeTx) {
+    public DOMStoreThreePhaseCommitCohort ready(final SnapshotBackedWriteTransaction writeTx) {
         LOG.debug("Tx: {} is submitted. Modifications: {}", writeTx.getIdentifier(), writeTx.getMutatedView());
         return new ThreePhaseCommitImpl(writeTx);
     }
index d6bfc0c3b69152fd560afd545f11ddfd0773862a..23b039c2542540fe39d7af70b8ea0b0129e11aa3 100644 (file)
@@ -115,6 +115,11 @@ public final class NetconfStateSchemas {
 
         final CompositeNode schemasNode =
                 (CompositeNode) NetconfMessageTransformUtil.findNode(schemasNodeResult.getResult(), DATA_STATE_SCHEMAS_IDENTIFIER);
+        if(schemasNode == null) {
+            logger.warn("{}: Unable to detect available schemas, get to {} was empty", id, STATE_SCHEMAS_IDENTIFIER);
+            return EMPTY;
+        }
+
         return create(id, schemasNode);
     }
 
index 451cad48169ea81869ef11047895010715f0e30f..10aec4ca2e85038cdc7ff21dd0ebd4dc4b6cddf6 100644 (file)
@@ -15,11 +15,9 @@ import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMap
 import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMapping.toTopologyNode;
 import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMapping.toTopologyNodeId;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.CheckedFuture;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
+import java.util.Collections;
+import java.util.List;
+
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
@@ -50,6 +48,12 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+
 class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, OpendaylightInventoryListener {
 
     private final Logger LOG = LoggerFactory.getLogger(FlowCapableTopologyExporter.class);
@@ -193,8 +197,9 @@ class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, Open
                     @Override
                     public void onSuccess(Optional<Topology> topologyOptional) {
                         if (topologyOptional.isPresent()) {
-                            Topology topologyData = topologyOptional.get();
-                            for (Link link : topologyData.getLink()) {
+                            List<Link> linkList = topologyOptional.get().getLink() != null
+                                    ? topologyOptional.get().getLink() : Collections.<Link> emptyList();
+                            for (Link link : linkList) {
                                 if (id.equals(link.getSource().getSourceNode()) || id.equals(link.getDestination().getDestNode())) {
                                     transaction.delete(LogicalDatastoreType.OPERATIONAL, linkPath(link));
                                 }
@@ -220,8 +225,9 @@ class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, Open
                     @Override
                     public void onSuccess(Optional<Topology> topologyOptional) {
                         if (topologyOptional.isPresent()) {
-                            Topology topologyData = topologyOptional.get();
-                            for (Link link : topologyData.getLink()) {
+                            List<Link> linkList = topologyOptional.get().getLink() != null
+                                    ? topologyOptional.get().getLink() : Collections.<Link> emptyList();
+                            for (Link link : linkList) {
                                 if (id.equals(link.getSource().getSourceTp()) || id.equals(link.getDestination().getDestTp())) {
                                     transaction.delete(LogicalDatastoreType.OPERATIONAL, linkPath(link));
                                 }