Merge "Bump yangtools artifacts to reflect their uptodate versions"
authorGiovanni Meo <gmeo@cisco.com>
Wed, 22 Jan 2014 21:24:11 +0000 (21:24 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 22 Jan 2014 21:24:11 +0000 (21:24 +0000)
28 files changed:
opendaylight/arphandler/src/test/java/org/opendaylight/controller/arphandler/internal/ArphandlerTest.java
opendaylight/clustering/test/src/test/java/org/opendaylight/controller/clustering/test/internal/TestClusteringTest.java
opendaylight/hosttracker/api/src/test/java/org/opendaylight/controller/hosttracker/hostAware/HostNodeConnectorTest.java
opendaylight/hosttracker/implementation/src/test/java/org/opendaylight/controller/hosttracker/internal/HostTrackerTest.java
opendaylight/hosttracker_new/api/src/test/java/org/opendaylight/controller/hosttracker/hostAware/HostNodeConnectorTest.java
opendaylight/logging/bridge/src/main/java/org/opendaylight/controller/logging/bridge/internal/Activator.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/MountPointManagerImpl.xtend
opendaylight/netconf/config-persister-impl/pom.xml
opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPusher.java
opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/Util.java
opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/SSHNetconfClientLiveTest.java [new file with mode: 0644]
opendaylight/netconf/netconf-client/src/test/resources/get_schema.xml [new file with mode: 0644]
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionNegotiatorFactory.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/util/NetconfUtil.java [deleted file]
opendaylight/netconf/netconf-util/pom.xml
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/NetconfUtil.java [new file with mode: 0644]
opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/NetconfUtilTest.java [moved from opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationHandlerTest.java with 75% similarity]
opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/conflictingversion/conflictingVersionResponse.xml [moved from opendaylight/netconf/config-persister-impl/src/test/resources/conflictingVersionResponse.xml with 100% similarity]
opendaylight/northbound/commons/src/test/java/org/opendaylight/controller/northbound/commons/CommonsNorthboundTest.java
opendaylight/northbound/commons/src/test/java/org/opendaylight/controller/northbound/commons/exception/CommonsNorthboundExceptionTest.java
opendaylight/northbound/controllermanager/src/test/java/org/opendaylight/controller/controllermanager/northbound/ControllerManagerNorthboundTest.java
opendaylight/northbound/staticrouting/src/test/java/org/opendaylight/controller/forwarding/staticrouting/northbound/StaticRoutingNorthboundTest.java
opendaylight/northbound/statistics/src/test/java/org/opendaylight/controller/statistics/northbound/StatisticsNorthboundTest.java
opendaylight/northbound/switchmanager/src/test/java/org/opendaylight/controller/switchmanager/northbound/SwitchManagerNorthboundTest.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/Match.java
opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/match/MatchTest.java
opendaylight/samples/loadbalancer/src/test/java/org/opendaylight/controller/samples/loadbalancer/internal/LoadBalancerTest.java
opendaylight/topologymanager/implementation/src/main/java/org/opendaylight/controller/topologymanager/internal/TopologyManagerImpl.java

index 19c8b4d35bd39f8a1c4ad516911ad149cfc5d9a0..892a0bc370a53e9dd930f089d24040106fb44eb5 100644 (file)
 package org.opendaylight.controller.arphandler.internal;\r
 \r
 \r
-import junit.framework.TestCase;\r
-\r
 import org.junit.Assert;\r
 import org.junit.Test;\r
 \r
-public class ArphandlerTest extends TestCase {\r
+public class ArphandlerTest  {\r
 \r
         @Test\r
         public void testArphandlerCreation() {\r
index 1142909f8562844075b3cbbf475b2a65d016738e..d143a5171a9ffbc4d907cf2aa32dc80fd83ccc50 100644 (file)
@@ -13,9 +13,7 @@ package org.opendaylight.controller.clustering.test.internal;
 import org.junit.Assert;\r
 import org.junit.Test;\r
 \r
-import junit.framework.TestCase;\r
-\r
-public class TestClusteringTest extends TestCase {\r
+public class TestClusteringTest {\r
 \r
         @Test\r
         public void testComplexClass() {\r
index bdccc99c9c52d29801bf43c7a7ebff602a207c65..96cf308983c1444ea8e68b17fe94685af5c7baa7 100644 (file)
@@ -13,19 +13,14 @@ import java.net.UnknownHostException;
 \r
 import org.junit.Assert;\r
 import org.junit.Test;\r
-\r
 import org.opendaylight.controller.sal.core.ConstructionException;\r
 import org.opendaylight.controller.sal.core.Node;\r
-\r
-import junit.framework.TestCase;\r
-\r
+import org.opendaylight.controller.sal.core.NodeConnector;\r
 import org.opendaylight.controller.sal.packet.address.EthernetAddress;\r
-\r
 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;\r
-import org.opendaylight.controller.sal.core.NodeConnector;\r
 import org.opendaylight.controller.sal.utils.NodeCreator;\r
 \r
-public class HostNodeConnectorTest extends TestCase {\r
+public class HostNodeConnectorTest {\r
 \r
     @Test\r
     public void testHostNodeConnector() throws UnknownHostException {\r
index e222fcd7e42cdb23b5a0850f6b55fd6834deba8a..984d5d3000303865dd44465a32600fc03c9c7feb 100644 (file)
@@ -11,14 +11,12 @@ package org.opendaylight.controller.hosttracker.internal;
 import java.net.InetAddress;\r
 import java.net.UnknownHostException;\r
 \r
-import junit.framework.TestCase;\r
-\r
 import org.junit.Assert;\r
 import org.junit.Test;\r
 import org.opendaylight.controller.hosttracker.IHostId;\r
 import org.opendaylight.controller.hosttracker.IPHostId;\r
 \r
-public class HostTrackerTest extends TestCase {\r
+public class HostTrackerTest {\r
 \r
     @Test\r
     public void testHostTrackerCallable() throws UnknownHostException {\r
index 430d133ad7724024814dc232856f7c365dbd42a1..4248c6dfd0a93de3cb5ceb313e8927d8bc0de8ef 100644 (file)
@@ -13,19 +13,14 @@ import java.net.UnknownHostException;
 \r
 import org.junit.Assert;\r
 import org.junit.Test;\r
-\r
 import org.opendaylight.controller.sal.core.ConstructionException;\r
 import org.opendaylight.controller.sal.core.Node;\r
-\r
-import junit.framework.TestCase;\r
-\r
+import org.opendaylight.controller.sal.core.NodeConnector;\r
 import org.opendaylight.controller.sal.packet.address.EthernetAddress;\r
-\r
 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;\r
-import org.opendaylight.controller.sal.core.NodeConnector;\r
 import org.opendaylight.controller.sal.utils.NodeCreator;\r
 \r
-public class HostNodeConnectorTest extends TestCase {\r
+public class HostNodeConnectorTest {\r
 \r
     @Test\r
     public void testHostNodeConnector() throws UnknownHostException {\r
index b231faf15307b558cebc629524ee185c12c89a97..75990c7c518ca9e679e2838ab4469cf04757950c 100644 (file)
@@ -50,14 +50,15 @@ public class Activator implements BundleActivator {
                 if (reader == null) {
                     this.log.error("Cannot register the LogListener because "
                             + "cannot retrieve LogReaderService");
-                }
-                reader.addLogListener(this.listener);
-                // Now lets walk all the exiting messages
-                Enumeration<LogEntry> entries = reader.getLog();
-                if (entries != null) {
-                    while (entries.hasMoreElements()) {
-                        LogEntry entry = (LogEntry) entries.nextElement();
-                        this.listener.logged(entry);
+                } else {
+                    reader.addLogListener(this.listener);
+                    // Now lets walk all the exiting messages
+                    Enumeration<LogEntry> entries = reader.getLog();
+                    if (entries != null) {
+                        while (entries.hasMoreElements()) {
+                            LogEntry entry = entries.nextElement();
+                            this.listener.logged(entry);
+                        }
                     }
                 }
 
@@ -98,10 +99,10 @@ public class Activator implements BundleActivator {
 
     @Override
     public void stop(BundleContext context) {
-        ServiceReference service = null;
-        service = context.getServiceReference(LogReaderService.class.getName());
-        if (service != null) {
-            LogReaderService reader = (LogReaderService) service;
+        ServiceReference serviceRef = context.getServiceReference(
+                LogReaderService.class.getName());
+        if (serviceRef != null) {
+            LogReaderService reader = (LogReaderService) context.getService(serviceRef);
             reader.removeLogListener(this.listener);
         }
         if (this.shutdownHandler != null) {
index 5d441bddbd0f23e263c452695da13afe9ecacc3e..c3bc88ed5e4acc55a85cc3829e743ed107150174 100644 (file)
@@ -35,8 +35,8 @@ class MountPointManagerImpl implements MountProvisionService {
     }
     
     def registerMountPoint(MountPointImpl impl) {
-        dataBroker?.registerConfigurationReader(impl.mountPath,impl.readWrapper);
-        dataBroker?.registerOperationalReader(impl.mountPath,impl.readWrapper);
+        //dataBroker?.registerConfigurationReader(impl.mountPath,impl.readWrapper);
+        //dataBroker?.registerOperationalReader(impl.mountPath,impl.readWrapper);
         
     }
     
index 30215318d9d4a301b172c06b9ab4f584b5f8f83c..fc00177c507748f170bdad72ca214961dc43ba17 100644 (file)
@@ -98,7 +98,8 @@
                             org.xml.sax,
                             javax.xml.namespace,
                             javax.xml.xpath,
-                            org.opendaylight.controller.config.api
+                            org.opendaylight.controller.config.api,
+                            org.opendaylight.controller.netconf.util
                         </Import-Package>
                         <Export-Package>
                         </Export-Package>
index 0b623baaa480dde170d6866d7fe1564242ed704e..a47d6dd842e43a911891920cbf99317961080836 100644 (file)
@@ -8,23 +8,15 @@
 
 package org.opendaylight.controller.netconf.persist.impl;
 
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
 import io.netty.channel.EventLoopGroup;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.InetSocketAddress;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.annotation.concurrent.Immutable;
-
 import org.opendaylight.controller.config.api.ConflictingVersionException;
 import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
 import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.netconf.client.NetconfClient;
 import org.opendaylight.controller.netconf.client.NetconfClientDispatcher;
+import org.opendaylight.controller.netconf.util.NetconfUtil;
 import org.opendaylight.controller.netconf.util.messages.NetconfMessageAdditionalHeader;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
@@ -35,8 +27,14 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.xml.sax.SAXException;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
+import javax.annotation.concurrent.Immutable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 @Immutable
 public class ConfigPusher {
@@ -84,8 +82,7 @@ public class ConfigPusher {
         int maxAttempts = 30;
         for(int i = 0 ; i < maxAttempts; i++) {
             NetconfClient netconfClient = makeNetconfConnection(configSnapshotHolder.getCapabilities(), oldClientForPossibleReuse);
-            final String configSnapshot = configSnapshotHolder.getConfigSnapshot();
-            logger.trace("Pushing following xml to netconf {}", configSnapshot);
+            logger.trace("Pushing following xml to netconf {}", configSnapshotHolder);
             try {
                 pushLastConfig(configSnapshotHolder, netconfClient);
                 return netconfClient;
@@ -173,26 +170,19 @@ public class ConfigPusher {
         logger.info("Pushing last configuration to netconf: {}", configSnapshotHolder);
         StringBuilder response = new StringBuilder("editConfig response = {");
 
-
         NetconfMessage message = createEditConfigMessage(xmlToBePersisted, "/netconfOp/editConfig.xml");
 
         // sending message to netconf
         NetconfMessage responseMessage = getResponse(message, netconfClient);
 
-        XmlElement element = XmlElement.fromDomDocument(responseMessage.getDocument());
-        Preconditions.checkState(element.getName().equals(XmlNetconfConstants.RPC_REPLY_KEY));
-        element = element.getOnlyChildElement();
-
-        Util.checkIsOk(element, responseMessage);
+        NetconfUtil.checkIsMessageOk(responseMessage);
         response.append(XmlUtil.toString(responseMessage.getDocument()));
         response.append("}");
         responseMessage = getResponse(getNetconfMessageFromResource("/netconfOp/commit.xml"), netconfClient);
 
-        element = XmlElement.fromDomDocument(responseMessage.getDocument());
-        Preconditions.checkState(element.getName().equals(XmlNetconfConstants.RPC_REPLY_KEY));
-        element = element.getOnlyChildElement();
 
-        Util.checkIsOk(element, responseMessage);
+
+        NetconfUtil.checkIsMessageOk(responseMessage);
         response.append("commit response = {");
         response.append(XmlUtil.toString(responseMessage.getDocument()));
         response.append("}");
index 86a024a240db6b97ba45cb493dba36b8fe1d1d62..322a9b753b123c006a4298b3209163b9ea82e9ed 100644 (file)
@@ -8,19 +8,11 @@
 
 package org.opendaylight.controller.netconf.persist.impl;
 
-import org.opendaylight.controller.config.api.ConflictingVersionException;
-import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.netconf.client.NetconfClient;
 import org.opendaylight.controller.netconf.client.NetconfClientDispatcher;
-import org.opendaylight.controller.netconf.util.xml.XMLNetconfUtil;
-import org.opendaylight.controller.netconf.util.xml.XmlElement;
-import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
-import org.opendaylight.controller.netconf.util.xml.XmlUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpression;
 import java.util.Set;
 
 public final class Util {
@@ -58,27 +50,4 @@ public final class Util {
             }
         }
     }
-
-
-    public static void checkIsOk(XmlElement element, NetconfMessage responseMessage) throws ConflictingVersionException {
-        if (element.getName().equals(XmlNetconfConstants.OK)) {
-            return;
-        }
-
-        if (element.getName().equals(XmlNetconfConstants.RPC_ERROR)) {
-            logger.warn("Can not load last configuration, operation failed");
-            // is it ConflictingVersionException ?
-            XPathExpression xPathExpression = XMLNetconfUtil.compileXPath("/netconf:rpc-reply/netconf:rpc-error/netconf:error-info/netconf:error");
-            String error = (String) XmlUtil.evaluateXPath(xPathExpression, element.getDomElement(), XPathConstants.STRING);
-            if (error!=null && error.contains(ConflictingVersionException.class.getCanonicalName())) {
-                throw new ConflictingVersionException(error);
-            }
-            throw new IllegalStateException("Can not load last configuration, operation failed: "
-                    + XmlUtil.toString(responseMessage.getDocument()));
-        }
-
-        logger.warn("Can not load last configuration. Operation failed.");
-        throw new IllegalStateException("Can not load last configuration. Operation failed: "
-                + XmlUtil.toString(responseMessage.getDocument()));
-    }
 }
diff --git a/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/SSHNetconfClientLiveTest.java b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/SSHNetconfClientLiveTest.java
new file mode 100644 (file)
index 0000000..7f1d289
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2013 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.netconf.client;
+
+import io.netty.channel.nio.NioEventLoopGroup;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.opendaylight.controller.netconf.api.NetconfMessage;
+import org.opendaylight.controller.netconf.util.NetconfUtil;
+import org.opendaylight.controller.netconf.util.handler.ssh.authentication.LoginPassword;
+
+import java.net.InetSocketAddress;
+
+@Ignore
+public class SSHNetconfClientLiveTest {
+
+    NioEventLoopGroup nettyThreadgroup;
+    NetconfSshClientDispatcher netconfClientDispatcher;
+
+    @Before
+    public void setUp() {
+        nettyThreadgroup = new NioEventLoopGroup();
+        netconfClientDispatcher = new NetconfSshClientDispatcher(new LoginPassword(
+                System.getProperty("username"), System.getProperty("password")),
+                nettyThreadgroup, nettyThreadgroup);
+    }
+
+    @Test
+    public void test() throws Exception {
+        InetSocketAddress address = new InetSocketAddress(System.getProperty("host"), 830);
+        int connectionAttempts = 10, attemptMsTimeout = 1000;
+
+        NetconfClient netconfClient = new NetconfClient("client", address, connectionAttempts,
+            attemptMsTimeout, netconfClientDispatcher);
+
+        netconfClient.getCapabilities();
+
+        NetconfMessage netconfMessage = NetconfUtil.createMessage(getClass().getResourceAsStream("/get_schema.xml"));
+        NetconfMessage response = netconfClient.sendMessage(netconfMessage);
+        NetconfUtil.checkIsMessageOk(response);
+    }
+}
diff --git a/opendaylight/netconf/netconf-client/src/test/resources/get_schema.xml b/opendaylight/netconf/netconf-client/src/test/resources/get_schema.xml
new file mode 100644 (file)
index 0000000..3bc5200
--- /dev/null
@@ -0,0 +1,9 @@
+<rpc message-id="2"
+     xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
+    <get-schema xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">
+        <identifier>ietf-netconf-monitoring</identifier>
+        <format
+                xmlns:ncm="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">ncm:yang
+        </format>
+    </get-schema>
+</rpc>
\ No newline at end of file
index 91734beacbf57f3e164411b6832dcfda1ac93a02..3c14d5124f395f54182ce125e1a9bed4ccf03d93 100644 (file)
@@ -16,7 +16,7 @@ import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.netconf.api.NetconfServerSessionPreferences;
 import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListener;
-import org.opendaylight.controller.netconf.impl.util.NetconfUtil;
+import org.opendaylight.controller.netconf.util.NetconfUtil;
 import org.opendaylight.controller.netconf.util.xml.XMLNetconfUtil;
 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/util/NetconfUtil.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/util/NetconfUtil.java
deleted file mode 100644 (file)
index 621c8ea..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2013 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.netconf.impl.util;
-
-import com.google.common.base.Preconditions;
-import org.opendaylight.controller.netconf.api.NetconfMessage;
-import org.opendaylight.controller.netconf.util.xml.XmlUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-import org.xml.sax.SAXException;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-
-public class NetconfUtil {
-
-    private static final Logger logger = LoggerFactory.getLogger(NetconfUtil.class);
-
-    public static NetconfMessage createMessage(final File f) {
-        Preconditions.checkNotNull(f, "File parameter was null");
-        try {
-            return createMessage(new FileInputStream(f));
-        } catch (final FileNotFoundException e) {
-            logger.warn("File {} not found.", f, e);
-        }
-        return null;
-    }
-
-    public static NetconfMessage createMessage(final InputStream is) {
-        Preconditions.checkNotNull(is, "InputStream parameter was null");
-        Document doc = null;
-        try {
-            doc = XmlUtil.readXmlToDocument(is);
-        } catch (final IOException e) {
-            logger.warn("Error ocurred while parsing stream.", e);
-        } catch (final SAXException e) {
-            logger.warn("Error ocurred while final parsing stream.", e);
-        }
-        return (doc == null) ? null : new NetconfMessage(doc);
-    }
-}
index 9078d7de9df01128b4c627dd041a16705d1ec85e..71b7fa6eac991d0274c4ff1da12cbc28c2aabf02 100644 (file)
                             com.siemens.ct.exi.exceptions,
                             com.siemens.ct.exi.api.dom,
                             org.xml.sax.helpers,
+                            org.opendaylight.controller.config.api,
                         </Import-Package>
                     </instructions>
                 </configuration>
diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/NetconfUtil.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/NetconfUtil.java
new file mode 100644 (file)
index 0000000..aae2f71
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2013 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.netconf.util;
+
+import com.google.common.base.Preconditions;
+import org.opendaylight.controller.config.api.ConflictingVersionException;
+import org.opendaylight.controller.netconf.api.NetconfMessage;
+import org.opendaylight.controller.netconf.util.xml.XMLNetconfUtil;
+import org.opendaylight.controller.netconf.util.xml.XmlElement;
+import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
+import org.opendaylight.controller.netconf.util.xml.XmlUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+
+public class NetconfUtil {
+
+    private static final Logger logger = LoggerFactory.getLogger(NetconfUtil.class);
+
+    public static NetconfMessage createMessage(final File f) {
+        Preconditions.checkNotNull(f, "File parameter was null");
+        try {
+            return createMessage(new FileInputStream(f));
+        } catch (final FileNotFoundException e) {
+            logger.warn("File {} not found.", f, e);
+        }
+        return null;
+    }
+
+    public static NetconfMessage createMessage(final InputStream is) {
+        Preconditions.checkNotNull(is, "InputStream parameter was null");
+        Document doc = null;
+        try {
+            doc = XmlUtil.readXmlToDocument(is);
+        } catch (final IOException e) {
+            logger.warn("Error ocurred while parsing stream.", e);
+        } catch (final SAXException e) {
+            logger.warn("Error ocurred while final parsing stream.", e);
+        }
+        return (doc == null) ? null : new NetconfMessage(doc);
+    }
+
+    public static void checkIsMessageOk(NetconfMessage responseMessage) throws ConflictingVersionException {
+        XmlElement element = XmlElement.fromDomDocument(responseMessage.getDocument());
+        Preconditions.checkState(element.getName().equals(XmlNetconfConstants.RPC_REPLY_KEY));
+        element = element.getOnlyChildElement();
+
+        if (element.getName().equals(XmlNetconfConstants.OK)) {
+            return;
+        }
+
+        if (element.getName().equals(XmlNetconfConstants.RPC_ERROR)) {
+            logger.warn("Can not load last configuration, operation failed");
+            // is it ConflictingVersionException ?
+            XPathExpression xPathExpression = XMLNetconfUtil.compileXPath("/netconf:rpc-reply/netconf:rpc-error/netconf:error-info/netconf:error");
+            String error = (String) XmlUtil.evaluateXPath(xPathExpression, element.getDomElement(), XPathConstants.STRING);
+            if (error!=null && error.contains(ConflictingVersionException.class.getCanonicalName())) {
+                throw new ConflictingVersionException(error);
+            }
+            throw new IllegalStateException("Can not load last configuration, operation failed: "
+                    + XmlUtil.toString(responseMessage.getDocument()));
+        }
+
+        logger.warn("Can not load last configuration. Operation failed.");
+        throw new IllegalStateException("Can not load last configuration. Operation failed: "
+                + XmlUtil.toString(responseMessage.getDocument()));
+    }
+}
@@ -5,12 +5,11 @@
  * 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.netconf.persist.impl;
+package org.opendaylight.controller.netconf.util;
 
 import org.junit.Test;
 import org.opendaylight.controller.config.api.ConflictingVersionException;
 import org.opendaylight.controller.netconf.api.NetconfMessage;
-import org.opendaylight.controller.netconf.util.xml.XmlElement;
 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
 import org.w3c.dom.Document;
 
@@ -18,17 +17,16 @@ import static org.junit.Assert.assertThat;
 import static org.junit.Assert.fail;
 import static org.junit.matchers.JUnitMatchers.containsString;
 
-public class ConfigPersisterNotificationHandlerTest {
+public class NetconfUtilTest {
 
     @Test
     public void testConflictingVersionDetection() throws Exception {
-        Document document = XmlUtil.readXmlToDocument(getClass().getResourceAsStream("/conflictingVersionResponse.xml"));
+        Document document = XmlUtil.readXmlToDocument(getClass().getResourceAsStream("/netconfMessages/conflictingversion/conflictingVersionResponse.xml"));
         try{
-            Util.checkIsOk(XmlElement.fromDomDocument(document).getOnlyChildElement(), new NetconfMessage(document));
+            NetconfUtil.checkIsMessageOk(new NetconfMessage(document));
             fail();
         }catch(ConflictingVersionException e){
             assertThat(e.getMessage(), containsString("Optimistic lock failed. Expected parent version 21, was 18"));
         }
     }
-
 }
index 9dba530c341237763c96cab63ac0c50e54e88364..1e910d18fb98ac50e719a09703ad6e4343d57798 100644 (file)
@@ -3,9 +3,7 @@ package org.opendaylight.controller.northbound.commons;
 import org.junit.Assert;
 import org.junit.Test;
 
-import junit.framework.TestCase;
-
-public class CommonsNorthboundTest extends TestCase {
+public class CommonsNorthboundTest {
 
     @Test
     public void testRestMessages() {
index 0a282b9b28b8c3c68ca31e3419a39b0f607105c2..c3296441109b00e5335dde7af1984fbfc4ff3001 100644 (file)
@@ -5,9 +5,7 @@ import javax.ws.rs.core.Response;
 import org.junit.Assert;
 import org.junit.Test;
 
-import junit.framework.TestCase;
-
-public class CommonsNorthboundExceptionTest extends TestCase {
+public class CommonsNorthboundExceptionTest {
 
     @Test
     public void testMethodNotAllowed() {
index a57e615618a8b0854e9ed07721c6df1d2857b247..7f8b0b43bfc0ad227f6ac98b7929bdb35ff3d75a 100644 (file)
@@ -3,13 +3,11 @@ package org.opendaylight.controller.controllermanager.northbound;
 import java.util.HashSet;
 import java.util.Set;
 
-import junit.framework.TestCase;
-
 import org.junit.Assert;
 import org.junit.Test;
 import org.opendaylight.controller.sal.core.Property;
 
-public class ControllerManagerNorthboundTest extends TestCase {
+public class ControllerManagerNorthboundTest {
 
     @Test
     public void testControllerProperties() {
index 2023d5256109f734668de07265bac6b01906489f..ac15a91f43a6caa0c2b4480057a9fe4150f2e034 100644 (file)
@@ -6,9 +6,7 @@ import java.util.List;
 import org.junit.Assert;
 import org.junit.Test;
 
-import junit.framework.TestCase;
-
-public class StaticRoutingNorthboundTest extends TestCase {
+public class StaticRoutingNorthboundTest {
 
     @Test
     public void testStaticRoute() {
index 0764c0b0077d25f9d33e2d173079a16e2bae9078..d09ff04574095a9d771ff08c655f993ded13a0b5 100644 (file)
@@ -12,8 +12,6 @@ package org.opendaylight.controller.statistics.northbound;
 import java.util.ArrayList;
 import java.util.List;
 
-import junit.framework.TestCase;
-
 import org.junit.Assert;
 import org.junit.Test;
 import org.opendaylight.controller.sal.core.Node;
@@ -22,7 +20,7 @@ import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
 import org.opendaylight.controller.sal.reader.NodeTableStatistics;
 import org.opendaylight.controller.sal.utils.NodeCreator;
 
-public class StatisticsNorthboundTest extends TestCase {
+public class StatisticsNorthboundTest {
 
     @Test
     public void testFlowStatistics() {
index 5386d4142fd55f0d3c7c79a5254aaa4faa70710b..f9a88d2e28526a35cbc0c149bd8008887c4ff622 100644 (file)
@@ -1,22 +1,20 @@
 package org.opendaylight.controller.switchmanager.northbound;
 
 
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
-import java.util.ArrayList;
 
 import org.junit.Assert;
 import org.junit.Test;
-import junit.framework.TestCase;
-
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.NodeConnector;
 import org.opendaylight.controller.sal.core.Property;
 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
 import org.opendaylight.controller.sal.utils.NodeCreator;
 
-public class SwitchManagerNorthboundTest extends TestCase {
+public class SwitchManagerNorthboundTest {
 
         @Test
         public void testNodes() {
index 2c3cfb8303736229e6c86b618642f6bd72b12aaa..910695c1e9cbc0ebcfb121b621fb7187305aff37 100644 (file)
@@ -20,6 +20,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.TreeMap;
 
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
@@ -444,13 +445,16 @@ public class Match implements Cloneable, Serializable {
         if (this.fields == null) {
             result = prime * result;
         } else {
-            int sum = 0;
-            for (MatchType field : this.fields.keySet()) {
-                MatchField f = this.fields.get(field);
-                sum = sum + ((field==null ? 0 : field.calculateConsistentHashCode()) ^
-                             (f==null ? 0 : f.hashCode()));
+            // use a tree map as the order of hashMap is not guaranteed.
+            // 2 Match objects with fields in different order are still equal.
+            // Hence the hashCode should be the same too.
+            TreeMap<MatchType, MatchField> tm = new TreeMap<MatchType, MatchField>(this.fields);
+            for (MatchType field : tm.keySet()) {
+                MatchField f = tm.get(field);
+                int fieldHashCode = (field==null ? 0 : field.calculateConsistentHashCode()) ^
+                             (f==null ? 0 : f.hashCode());
+                result = prime * result + fieldHashCode;
             }
-            result = prime * result + sum;
         }
         result = prime * result + matches;
         return result;
index 30d49cfd9dcc5b5abb90bafd659ac314e855f99a..b88ae034d9aa713c96f4ce3ef633f977d5a223b3 100644 (file)
@@ -337,6 +337,21 @@ public class MatchTest {
         Assert.assertTrue(match1.equals(match2));
     }
 
+    @Test
+    public void testHashCodeWithReverseMatch() throws Exception {
+        InetAddress srcIP1 = InetAddress.getByName("1.1.1.1");
+        InetAddress ipMask1 = InetAddress.getByName("255.255.255.255");
+        InetAddress srcIP2 = InetAddress.getByName("2.2.2.2");
+        InetAddress ipMask2 = InetAddress.getByName("255.255.255.255");
+        MatchField field1 = new MatchField(MatchType.NW_SRC, srcIP1, ipMask1);
+        MatchField field2 = new MatchField(MatchType.NW_DST, srcIP2, ipMask2);
+        Match match1 = new Match();
+        match1.setField(field1);
+        match1.setField(field2);
+        Match match2 = match1.reverse();
+        Assert.assertFalse(match1.hashCode() == match2.hashCode());
+    }
+
     @Test
     public void testHashCode() throws Exception {
         byte srcMac1[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a, (byte) 0xbc };
index 4fd3f4a32de5964fe7f2b0df20c4125497e71eb6..cfffb7e73aa8c83e0bca5ec2af19b11d6ebb5c97 100644 (file)
@@ -17,14 +17,12 @@ import org.opendaylight.controller.samples.loadbalancer.entities.PoolMember;
 import org.opendaylight.controller.samples.loadbalancer.entities.VIP;\r
 import org.opendaylight.controller.samples.loadbalancer.policies.RoundRobinLBPolicy;\r
 \r
-import junit.framework.TestCase;\r
-\r
 /**\r
  *\r
  * Class to unit test the load balancing policies.\r
  *\r
  */\r
-public class LoadBalancerTest extends TestCase {\r
+public class LoadBalancerTest {\r
     @Test\r
     public void testRoundRobinPolicy() {\r
         ConfigManager cm = null;\r
@@ -65,4 +63,4 @@ public class LoadBalancerTest extends TestCase {
         c1 = new Client("10.0.0.1","TCP",(short)5003);\r
         Assert.assertTrue(rrp.getPoolMemberForClient(c1, vip).equals(host4.getIp()));\r
     }\r
-}
\ No newline at end of file
+}
index 45a8a5880b70982d83748a3e3d2392dd3e93de1f..b0570fb7f9b6eed29384ac4c0280202df1fd4a5f 100644 (file)
@@ -574,36 +574,38 @@ public class TopologyManagerImpl implements
     private TopoEdgeUpdate edgeUpdate(Edge e, UpdateType type, Set<Property> props) {
         switch (type) {
         case ADDED:
-            // Avoid redundant update as notifications trigger expensive tasks
-            if (edgesDB.containsKey(e)) {
-                log.trace("Skipping redundant edge addition: {}", e);
-                return null;
-            }
-
-            // Ensure that head node connector exists
-            if (!headNodeConnectorExist(e)) {
-                log.warn("Ignore edge that contains invalid node connector: {}", e);
-                return null;
-            }
-
-            // Check if nodeConnectors of the edge were correctly categorized
-            // by OF plugin
-            crossCheckNodeConnectors(e);
 
-            // Make sure the props are non-null
+            // Make sure the props are non-null or create a copy
             if (props == null) {
                 props = new HashSet<Property>();
             } else {
                 props = new HashSet<Property>(props);
             }
 
-            //in case of node switch-over to a different cluster controller,
-            //let's retain edge props
             Set<Property> currentProps = this.edgesDB.get(e);
-            if (currentProps != null){
+            if (currentProps != null) {
+
+                if (currentProps.equals(props)) {
+                    // Avoid redundant updates as notifications trigger expensive tasks
+                    log.trace("Skipping redundant edge addition: {}", e);
+                    return null;
+                }
+
+                // In case of node switch-over to a different cluster controller,
+                // let's retain edge props (e.g. creation time)
                 props.addAll(currentProps);
             }
 
+            // Ensure that head node connector exists
+            if (!headNodeConnectorExist(e)) {
+                log.warn("Ignore edge that contains invalid node connector: {}", e);
+                return null;
+            }
+
+            // Check if nodeConnectors of the edge were correctly categorized
+            // by protocol plugin
+            crossCheckNodeConnectors(e);
+
             // Now make sure there is the creation timestamp for the
             // edge, if not there, stamp with the first update
             boolean found_create = false;