Merge "Cleaned Commons POM prerequisites for Karaf distribution"
authorGiovanni Meo <gmeo@cisco.com>
Mon, 28 Apr 2014 10:10:35 +0000 (10:10 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 28 Apr 2014 10:10:35 +0000 (10:10 +0000)
74 files changed:
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModuleFactory.java [new file with mode: 0644]
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/IdentityTestModuleFactory.java [new file with mode: 0644]
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleFactory.java [new file with mode: 0644]
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModuleFactory.java [new file with mode: 0644]
opendaylight/distribution/opendaylight/src/main/resources/configuration/initial/00-netty.xml
opendaylight/distribution/opendaylight/src/main/resources/configuration/initial/02-clustering.xml
opendaylight/distribution/opendaylight/src/main/resources/configuration/initial/03-toaster-sample.xml
opendaylight/distribution/opendaylight/src/main/resources/configuration/initial/04-netconf-connector.xml [new file with mode: 0644]
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDeviceListener.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfMapping.java
opendaylight/netconf/config-netconf-connector/pom.xml
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/exception/NetconfConfigHandlingException.java [new file with mode: 0644]
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/exception/NoTransactionFoundException.java [new file with mode: 0644]
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/exception/OperationNotPermittedException.java [new file with mode: 0644]
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/fromxml/AbstractAttributeReadingStrategy.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/fromxml/ArrayAttributeReadingStrategy.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/fromxml/AttributeReadingStrategy.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/fromxml/CompositeAttributeReadingStrategy.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/fromxml/ObjectNameAttributeReadingStrategy.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/fromxml/SimpleAttributeReadingStrategy.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/fromxml/SimpleIdentityRefAttributeReadingStrategy.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/Config.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/InstanceConfig.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/InstanceConfigElementResolved.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/ModuleConfig.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/ModuleElementDefinition.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/Services.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/rpc/InstanceRuntimeRpc.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/Commit.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/DiscardChanges.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/Validate.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/editconfig/AbstractEditConfigStrategy.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/editconfig/DeleteEditConfigStrategy.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/editconfig/EditConfig.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/editconfig/EditConfigStrategy.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/editconfig/EditConfigXmlParser.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/editconfig/EditStrategyType.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/editconfig/MergeEditConfigStrategy.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/editconfig/MissingInstanceHandlingStrategy.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/editconfig/ReplaceEditConfigStrategy.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/get/Get.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/getconfig/GetConfig.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/runtimerpc/RuntimeRpc.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/transactions/TransactionProvider.java
opendaylight/netconf/config-netconf-connector/src/test/java/org/opendaylight/controller/netconf/confignetconfconnector/NetconfMappingTest.java
opendaylight/netconf/config-netconf-connector/src/test/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/editconfig/EditConfigTest.java
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/osgi/ConfigPersisterActivator.java
opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/NetconfDocumentedException.java
opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiator.java
opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiatorFactory.java
opendaylight/netconf/netconf-impl/pom.xml
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/mapping/operations/DefaultCommit.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultGetSchema.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java
opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITTest.java
opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperation.java
opendaylight/netconf/netconf-monitoring/pom.xml
opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/Get.java
opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/NetconfSSHServer.java
opendaylight/netconf/netconf-util/pom.xml
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractNetconfSessionNegotiator.java
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/NetconfUtil.java
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/exception/MissingNameSpaceException.java [new file with mode: 0644]
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/exception/UnexpectedElementException.java [new file with mode: 0644]
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/exception/UnexpectedNamespaceException.java [new file with mode: 0644]
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/mapping/AbstractLastNetconfOperation.java
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/mapping/AbstractNetconfOperation.java
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/messages/NetconfHelloMessage.java
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/messages/NetconfMessageUtil.java
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/xml/XmlElement.java
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/xml/XmlNetconfConstants.java
opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/NetconfUtilTest.java

diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModuleFactory.java b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModuleFactory.java
new file mode 100644 (file)
index 0000000..330f804
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+* 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
+*/
+/*
+* Generated file
+*
+* Generated from: yang module name: config-test-impl yang module local name: impl-dep
+* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+* Generated at: Fri Apr 25 09:12:08 CEST 2014
+*
+* Do not modify this file unless it is present under src/main directory
+*/
+package org.opendaylight.controller.config.yang.test.impl;
+public class DepTestImplModuleFactory extends org.opendaylight.controller.config.yang.test.impl.AbstractDepTestImplModuleFactory {
+
+}
diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/IdentityTestModuleFactory.java b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/IdentityTestModuleFactory.java
new file mode 100644 (file)
index 0000000..b57d1dc
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+* 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
+*/
+/*
+* Generated file
+*
+* Generated from: yang module name: config-test-impl yang module local name: impl-identity-test
+* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+* Generated at: Fri Apr 25 09:12:08 CEST 2014
+*
+* Do not modify this file unless it is present under src/main directory
+*/
+package org.opendaylight.controller.config.yang.test.impl;
+public class IdentityTestModuleFactory extends org.opendaylight.controller.config.yang.test.impl.AbstractIdentityTestModuleFactory {
+
+}
diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleFactory.java b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleFactory.java
new file mode 100644 (file)
index 0000000..74a0549
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+* 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
+*/
+/*
+* Generated file
+*
+* Generated from: yang module name: config-test-impl yang module local name: impl-netconf
+* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+* Generated at: Fri Apr 25 09:12:08 CEST 2014
+*
+* Do not modify this file unless it is present under src/main directory
+*/
+package org.opendaylight.controller.config.yang.test.impl;
+public class NetconfTestImplModuleFactory extends org.opendaylight.controller.config.yang.test.impl.AbstractNetconfTestImplModuleFactory {
+
+}
diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModuleFactory.java b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModuleFactory.java
new file mode 100644 (file)
index 0000000..9680bff
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+* 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
+*/
+/*
+* Generated file
+*
+* Generated from: yang module name: config-test-impl yang module local name: impl
+* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+* Generated at: Fri Apr 25 09:12:08 CEST 2014
+*
+* Do not modify this file unless it is present under src/main directory
+*/
+package org.opendaylight.controller.config.yang.test.impl;
+public class TestImplModuleFactory extends org.opendaylight.controller.config.yang.test.impl.AbstractTestImplModuleFactory {
+
+}
index 2365c700f9fe085c762b6e91cbe8396522487acc..686d3631108d250f5dc56b825200e387536dd9c5 100644 (file)
@@ -1,3 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+ 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
+-->
 <snapshot>
     <required-capabilities>
         <capability>urn:opendaylight:params:xml:ns:yang:controller:netty?module=netty&amp;revision=2013-11-19</capability>
index 7853b8681b14f0d3cc4c2263357b320dac97f418..c5f99fd0c1278ee91011a0de6152627001f04c5a 100644 (file)
@@ -1,3 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+ 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
+-->
 <snapshot>
     <configuration>
         <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
index c481485c9237e01e8e92e7a41ad7f9ab5b01ec8c..6d5d0eb82633964f0eeca31cb084063136412298 100644 (file)
@@ -1,3 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+ 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
+-->
 <snapshot>
     <configuration>
         <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
diff --git a/opendaylight/distribution/opendaylight/src/main/resources/configuration/initial/04-netconf-connector.xml b/opendaylight/distribution/opendaylight/src/main/resources/configuration/initial/04-netconf-connector.xml
new file mode 100644 (file)
index 0000000..8143a38
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+ 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
+-->
+<snapshot>
+  <configuration>
+    <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
+      <modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
+    <module>
+      <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">prefix:sal-netconf-connector</type>
+      <name>controller-config</name>
+      <port xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">1830</port>
+      <username xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">admin</username>
+      <worker-thread-group xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
+        <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:netty">prefix:netty-threadgroup</type>
+        <name>global-worker-group</name>
+      </worker-thread-group>
+      <address xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">127.0.0.1</address>
+      <tcp-only xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">false</tcp-only>
+      <event-executor xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
+        <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:netty">prefix:netty-event-executor</type>
+        <name>global-event-executor</name>
+      </event-executor>
+      <password xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">admin</password>
+      <boss-thread-group xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
+        <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:netty">prefix:netty-threadgroup</type>
+        <name>global-boss-group</name>
+      </boss-thread-group>
+      <dom-registry xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
+        <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom">prefix:dom-broker-osgi-registry</type>
+        <name>dom-broker</name>
+      </dom-registry>
+    </module>
+      </modules>
+    </data>
+  </configuration>
+  <required-capabilities>
+      <capability>urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf?module=odl-sal-netconf-connector-cfg&amp;revision=2013-10-28</capability>
+  </required-capabilities>
+</snapshot>
index d6bf868b75dfaa55059e19f05bdb5bf924f08306..94f5e166a115e216cf839e52a044bc870c34c661 100644 (file)
@@ -18,6 +18,7 @@ import java.util.Iterator;
 import java.util.Queue;
 import java.util.Set;
 
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.netconf.api.NetconfTerminationReason;
 import org.opendaylight.controller.netconf.client.NetconfClientSession;
@@ -156,7 +157,7 @@ class NetconfDeviceListener implements NetconfClientSessionListener {
 
             try {
                 NetconfMapping.checkSuccessReply(message);
-            } catch (IllegalStateException e) {
+            } catch (NetconfDocumentedException | IllegalStateException e) {
                 LOG.warn("Error reply from remote device", e);
                 r.future.setException(e);
                 return;
index 3e729149eb99a485c3026cbd7868304c1a20d057..a6e6b3dfdf456d92711da924522d22de0aeea788 100644 (file)
@@ -7,6 +7,12 @@
  */
 package org.opendaylight.controller.sal.connect.netconf;
 
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -14,10 +20,9 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
-
 import javax.activation.UnsupportedDataTypeException;
 import javax.annotation.Nullable;
-
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.netconf.util.messages.NetconfMessageUtil;
 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
@@ -41,14 +46,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
 public class NetconfMapping {
 
     public static URI NETCONF_URI = URI.create("urn:ietf:params:xml:ns:netconf:base:1.0");
@@ -262,7 +259,7 @@ public class NetconfMapping {
         }
     }
 
-    public static void checkSuccessReply(NetconfMessage output) {
+    public static void checkSuccessReply(NetconfMessage output) throws NetconfDocumentedException {
         if(NetconfMessageUtil.isErrorMessage(output)) {
             throw new IllegalStateException(String.format("Response contains error: %s", XmlUtil.toString(output.getDocument())));
         }
index 2a0f0a97f7b1e5cbe051569dd5876f4ccb56c28c..c10f0a9089ed5341550d21a62ea68c3ac67c9a02 100644 (file)
                             org.opendaylight.controller.netconf.confignetconfconnector.transactions,
                             org.opendaylight.controller.netconf.confignetconfconnector.util,
                             org.opendaylight.controller.netconf.confignetconfconnector.osgi,
-                            org.opendaylight.controller.config.util,</Private-Package>
+                            org.opendaylight.controller.config.util,
+                            org.opendaylight.controller.netconf.confignetconfconnector.exception,</Private-Package>
             <Import-Package>com.google.common.base,
                             com.google.common.collect,
                             javax.annotation,
                             org.opendaylight.controller.netconf.mapping.api,
                             org.opendaylight.controller.netconf.util.mapping,
                             org.opendaylight.controller.netconf.util.xml,
+                            org.opendaylight.controller.netconf.util.exception,
                             org.opendaylight.yangtools.yang.common,
                             org.opendaylight.yangtools.yang.model.api,
                             org.osgi.framework,
                             com.google.common.io,
                             org.opendaylight.yangtools.yang.model.api.type,
                             org.opendaylight.yangtools.sal.binding.generator.spi,
-                            org.opendaylight.yangtools.sal.binding.yang.types</Import-Package>
+                            org.opendaylight.yangtools.sal.binding.yang.types,</Import-Package>
             <Export-Package></Export-Package>
           </instructions>
         </configuration>
diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/exception/NetconfConfigHandlingException.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/exception/NetconfConfigHandlingException.java
new file mode 100644 (file)
index 0000000..be44a71
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * 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.confignetconfconnector.exception;
+
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
+
+import java.util.Collections;
+import java.util.Map;
+
+public class NetconfConfigHandlingException extends NetconfDocumentedException {
+
+    public NetconfConfigHandlingException(final String message, final ErrorType errorType, final ErrorTag errorTag,
+                                          final ErrorSeverity errorSeverity) {
+        this(message, errorType, errorTag, errorSeverity, Collections.<String, String>emptyMap());
+    }
+
+    public NetconfConfigHandlingException(final String message, final ErrorType errorType, final ErrorTag errorTag,
+                                          final ErrorSeverity errorSeverity, final Map<String, String> errorInfo){
+        super(message,errorType,errorTag,errorSeverity,errorInfo);
+    }
+}
diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/exception/NoTransactionFoundException.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/exception/NoTransactionFoundException.java
new file mode 100644 (file)
index 0000000..ebb8054
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * 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.confignetconfconnector.exception;
+
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
+
+import java.util.Collections;
+import java.util.Map;
+
+public class NoTransactionFoundException extends NetconfDocumentedException {
+
+    public NoTransactionFoundException(final String message, final ErrorType errorType, final ErrorTag errorTag,
+                                          final ErrorSeverity errorSeverity) {
+        this(message, errorType, errorTag, errorSeverity, Collections.<String, String> emptyMap());
+    }
+
+    public NoTransactionFoundException(final String message, final ErrorType errorType, final ErrorTag errorTag,
+                                          final ErrorSeverity errorSeverity, final Map<String, String> errorInfo){
+        super(message,errorType,errorTag,errorSeverity,errorInfo);
+    }
+
+}
diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/exception/OperationNotPermittedException.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/exception/OperationNotPermittedException.java
new file mode 100644 (file)
index 0000000..e0d63c1
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * 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.confignetconfconnector.exception;
+
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
+
+import java.util.Collections;
+import java.util.Map;
+
+public class OperationNotPermittedException extends NetconfDocumentedException {
+
+    public OperationNotPermittedException(final String message, final ErrorType errorType, final ErrorTag errorTag,
+                                       final ErrorSeverity errorSeverity) {
+        this(message, errorType, errorTag, errorSeverity, Collections.<String, String> emptyMap());
+    }
+
+    public OperationNotPermittedException(final String message, final ErrorType errorType, final ErrorTag errorTag,
+                                       final ErrorSeverity errorSeverity, final Map<String, String> errorInfo){
+        super(message,errorType,errorTag,errorSeverity,errorInfo);
+    }
+}
index 793911262810f826f332f84c75bb642bb1d7fe6e..701e96ecd95b8853fcee8ccf75b98a9ac6cb1b47 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml;
 
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 
 import java.util.List;
@@ -25,14 +26,14 @@ public abstract class AbstractAttributeReadingStrategy implements AttributeReadi
     }
 
     @Override
-    public AttributeConfigElement readElement(List<XmlElement> configNodes) {
-        if (configNodes.size() == 0)
+    public AttributeConfigElement readElement(List<XmlElement> configNodes) throws NetconfDocumentedException {
+        if (configNodes.size() == 0){
             return AttributeConfigElement.createNullValue(postprocessNullableDefault(nullableDefault));
-
+        }
         return readElementHook(configNodes);
     }
 
-    abstract AttributeConfigElement readElementHook(List<XmlElement> configNodes);
+    abstract AttributeConfigElement readElementHook(List<XmlElement> configNodes) throws NetconfDocumentedException;
 
     protected Object postprocessNullableDefault(String nullableDefault) {
         return nullableDefault;
index 8f569619001c0d8c60697a92d160e730740ba567..442c504cce28ebc96b26e7bba589563ee3bef1d4 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml;
 
 import com.google.common.collect.Lists;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 
 import java.util.List;
@@ -27,7 +28,7 @@ public class ArrayAttributeReadingStrategy extends AbstractAttributeReadingStrat
     }
 
     @Override
-    AttributeConfigElement readElementHook(List<XmlElement> configNodes) {
+    AttributeConfigElement readElementHook(List<XmlElement> configNodes) throws NetconfDocumentedException {
         List<Object> innerList = Lists.newArrayList();
         for (int i = 0; i < configNodes.size(); i++) {
             innerList.add(innerStrategy.readElement(Lists.newArrayList(configNodes.get(i))).getValue());
index 6dae839148fff303aaeaf400430aaf4889de1658..4e78370c931340a0f2411cbfa272ead0a0133e15 100644 (file)
@@ -10,10 +10,11 @@ package org.opendaylight.controller.netconf.confignetconfconnector.mapping.attri
 
 import java.util.List;
 
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 
 public interface AttributeReadingStrategy {
 
-    public abstract AttributeConfigElement readElement(List<XmlElement> element);
+    public abstract AttributeConfigElement readElement(List<XmlElement> element) throws NetconfDocumentedException;
 
 }
index fdbfb98e1ca7e9f57c6421eda42f0c3bbd2d93c7..792fb28027245d92c30e1bbd3d84ee99e22beced 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.controller.netconf.confignetconfconnector.mapping.attri
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 
 import java.util.List;
@@ -28,7 +29,7 @@ public class CompositeAttributeReadingStrategy extends AbstractAttributeReadingS
     }
 
     @Override
-    AttributeConfigElement readElementHook(List<XmlElement> configNodes) {
+    AttributeConfigElement readElementHook(List<XmlElement> configNodes) throws NetconfDocumentedException {
 
         Preconditions.checkState(configNodes.size() == 1, "This element should be present only once %s", configNodes);
 
@@ -38,7 +39,8 @@ public class CompositeAttributeReadingStrategy extends AbstractAttributeReadingS
 
         List<XmlElement> recognisedChildren = Lists.newArrayList();
         for (Entry<String, AttributeReadingStrategy> innerAttrEntry : innerStrategies.entrySet()) {
-            List<XmlElement> childItem = complexElement.getChildElementsWithSameNamespace(innerAttrEntry.getKey());
+            List<XmlElement> childItem = null;
+            childItem = complexElement.getChildElementsWithSameNamespace(innerAttrEntry.getKey());
             recognisedChildren.addAll(childItem);
 
             AttributeConfigElement resolvedInner = innerAttrEntry.getValue().readElement(childItem);
index 7a4ba31255ac08e0099dab72830fe7cdbb2a48a3..5f44c16dcaefb754f7732143c41f59968cea9fda 100644 (file)
@@ -8,9 +8,12 @@
 package org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml;
 
 import com.google.common.base.Preconditions;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.mapping.ObjectNameAttributeMappingStrategy;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.List;
 import java.util.Map;
@@ -18,13 +21,14 @@ import java.util.Map;
 public class ObjectNameAttributeReadingStrategy extends AbstractAttributeReadingStrategy {
 
     private static final Object PREFIX_SEPARATOR = ":";
+    private static final Logger logger = LoggerFactory.getLogger(ObjectNameAttributeReadingStrategy.class);
 
     public ObjectNameAttributeReadingStrategy(String nullableDefault) {
         super(nullableDefault);
     }
 
     @Override
-    AttributeConfigElement readElementHook(List<XmlElement> configNodes) {
+    AttributeConfigElement readElementHook(List<XmlElement> configNodes) throws NetconfDocumentedException {
 
         XmlElement firstChild = configNodes.get(0);
         Preconditions.checkState(configNodes.size() == 1, "This element should be present only once " + firstChild
@@ -34,8 +38,9 @@ public class ObjectNameAttributeReadingStrategy extends AbstractAttributeReading
         return AttributeConfigElement.create(getNullableDefault(), resolve(firstChild));
     }
 
-    private ObjectNameAttributeMappingStrategy.MappedDependency resolve(XmlElement firstChild) {
-        XmlElement typeElement = firstChild.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.TYPE_KEY);
+    private ObjectNameAttributeMappingStrategy.MappedDependency resolve(XmlElement firstChild) throws NetconfDocumentedException{
+        XmlElement typeElement = null;
+        typeElement = firstChild.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.TYPE_KEY);
         Map.Entry<String, String> prefixNamespace = typeElement.findNamespaceOfTextContent();
 
         String serviceName = checkPrefixAndExtractServiceName(typeElement, prefixNamespace);
@@ -47,7 +52,7 @@ public class ObjectNameAttributeReadingStrategy extends AbstractAttributeReading
                 dependencyName);
     }
 
-    public static String checkPrefixAndExtractServiceName(XmlElement typeElement, Map.Entry<String, String> prefixNamespace) {
+    public static String checkPrefixAndExtractServiceName(XmlElement typeElement, Map.Entry<String, String> prefixNamespace) throws NetconfDocumentedException {
         String serviceName = typeElement.getTextContent();
 
         Preconditions.checkState(prefixNamespace.equals("") == false, "Service %s value not prefixed with namespace",
index 3765a135080adbd7e5a4af7742bd069bf6b5b2c7..cb8f66081b7dee8b0205b34132ed0b131dac98c6 100644 (file)
@@ -9,12 +9,12 @@
 package org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml;
 
 import com.google.common.base.Preconditions;
+import java.util.List;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.List;
-
 public class SimpleAttributeReadingStrategy extends AbstractAttributeReadingStrategy {
     private static final Logger logger = LoggerFactory.getLogger(SimpleAttributeReadingStrategy.class);
 
@@ -24,7 +24,7 @@ public class SimpleAttributeReadingStrategy extends AbstractAttributeReadingStra
     }
 
     @Override
-    AttributeConfigElement readElementHook(List<XmlElement> configNodes) {
+    AttributeConfigElement readElementHook(List<XmlElement> configNodes) throws NetconfDocumentedException {
         XmlElement xmlElement = configNodes.get(0);
         Preconditions.checkState(configNodes.size() == 1, "This element should be present only once " + xmlElement
                 + " but was " + configNodes.size());
@@ -37,12 +37,17 @@ public class SimpleAttributeReadingStrategy extends AbstractAttributeReadingStra
             logger.warn("Ignoring exception caused by failure to read text element", e);
         }
 
-        Preconditions.checkNotNull(textContent, "This element should contain text %s", xmlElement);
+        if (null == textContent){
+            throw new NetconfDocumentedException(String.format("This element should contain text %s", xmlElement),
+                    NetconfDocumentedException.ErrorType.application,
+                    NetconfDocumentedException.ErrorTag.invalid_value,
+                    NetconfDocumentedException.ErrorSeverity.error);
+        }
         return AttributeConfigElement.create(postprocessNullableDefault(getNullableDefault()),
                 postprocessParsedValue(textContent));
     }
 
-    protected String readElementContent(XmlElement xmlElement) {
+    protected String readElementContent(XmlElement xmlElement) throws NetconfDocumentedException {
         return xmlElement.getTextContent();
     }
 
index 120559712552d4a963c8a90c411e99c9f4b0b96a..58f91a7deec8c9ce7522f426bb4428b2dee3d691 100644 (file)
@@ -15,6 +15,7 @@ import java.util.Map;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Maps;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfig;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -32,7 +33,7 @@ public class SimpleIdentityRefAttributeReadingStrategy extends SimpleAttributeRe
     }
 
     @Override
-    protected String readElementContent(XmlElement xmlElement) {
+    protected String readElementContent(XmlElement xmlElement) throws NetconfDocumentedException {
         // TODO test
         Map.Entry<String, String> namespaceOfTextContent = xmlElement.findNamespaceOfTextContent();
         String content = xmlElement.getTextContent();
index decb091f866f085ae36034d21c7ee4908685170b..bb5a67cb9ce9051570b6ea736cc83d5e89cd1977 100644 (file)
@@ -23,6 +23,7 @@ import java.util.Set;
 import javax.management.ObjectName;
 
 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfig;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditStrategyType;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
@@ -147,7 +148,7 @@ public class Config {
     // TODO refactor, replace Map->Multimap with e.g. ConfigElementResolved
     // class
 
-    public Map<String, Multimap<String, ModuleElementResolved>> fromXmlModulesResolved(XmlElement xml, EditStrategyType defaultEditStrategyType, ServiceRegistryWrapper serviceTracker) {
+    public Map<String, Multimap<String, ModuleElementResolved>> fromXmlModulesResolved(XmlElement xml, EditStrategyType defaultEditStrategyType, ServiceRegistryWrapper serviceTracker) throws NetconfDocumentedException {
         Optional<XmlElement> modulesElement = getModulesElement(xml);
         List<XmlElement> moduleElements = getModulesElementList(modulesElement);
 
@@ -156,7 +157,7 @@ public class Config {
         for (XmlElement moduleElement : moduleElements) {
             ResolvingStrategy<ModuleElementResolved> resolvingStrategy = new ResolvingStrategy<ModuleElementResolved>() {
                 @Override
-                public ModuleElementResolved resolveElement(ModuleConfig moduleMapping, XmlElement moduleElement, ServiceRegistryWrapper serviceTracker, String instanceName, String moduleNamespace, EditStrategyType defaultStrategy) {
+                public ModuleElementResolved resolveElement(ModuleConfig moduleMapping, XmlElement moduleElement, ServiceRegistryWrapper serviceTracker, String instanceName, String moduleNamespace, EditStrategyType defaultStrategy) throws NetconfDocumentedException {
                     return moduleMapping.fromXml(moduleElement, serviceTracker,
                             instanceName, moduleNamespace, defaultStrategy, identityMap);
                 }
@@ -171,7 +172,7 @@ public class Config {
      * return a map containing namespace -> moduleName -> instanceName map. Attribute parsing is omitted.
      */
     public Map<String, Multimap<String, ModuleElementDefinition>> fromXmlModulesMap(XmlElement xml,
-            EditStrategyType defaultEditStrategyType, ServiceRegistryWrapper serviceTracker) {
+            EditStrategyType defaultEditStrategyType, ServiceRegistryWrapper serviceTracker) throws NetconfDocumentedException {
         Optional<XmlElement> modulesElement = getModulesElement(xml);
         List<XmlElement> moduleElements = getModulesElementList(modulesElement);
 
@@ -201,7 +202,7 @@ public class Config {
                     XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
     }
 
-    private List<XmlElement> getModulesElementList(Optional<XmlElement> modulesElement) {
+    private List<XmlElement> getModulesElementList(Optional<XmlElement> modulesElement) throws NetconfDocumentedException {
         List<XmlElement> moduleElements;
 
         if (modulesElement.isPresent()) {
@@ -214,11 +215,13 @@ public class Config {
     }
 
     private <T> void resolveModule(Map<String, Multimap<String, T>> retVal, ServiceRegistryWrapper serviceTracker,
-            XmlElement moduleElement, EditStrategyType defaultStrategy, ResolvingStrategy<T> resolvingStrategy) {
-        XmlElement typeElement = moduleElement.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.TYPE_KEY);
+            XmlElement moduleElement, EditStrategyType defaultStrategy, ResolvingStrategy<T> resolvingStrategy) throws NetconfDocumentedException {
+        XmlElement typeElement = null;
+        typeElement = moduleElement.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.TYPE_KEY);
         Entry<String, String> prefixToNamespace = typeElement.findNamespaceOfTextContent();
         String moduleNamespace = prefixToNamespace.getValue();
-        XmlElement nameElement = moduleElement.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.NAME_KEY);
+        XmlElement nameElement = null;
+        nameElement = moduleElement.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.NAME_KEY);
         String instanceName = nameElement.getTextContent();
         String factoryNameWithPrefix = typeElement.getTextContent();
         String prefixOrEmptyString = prefixToNamespace.getKey();
@@ -238,7 +241,7 @@ public class Config {
         innerMap.put(factoryName, resolvedElement);
     }
 
-    public Services fromXmlServices(XmlElement xml) {
+    public Services fromXmlServices(XmlElement xml) throws NetconfDocumentedException {
         Optional<XmlElement> servicesElement = getServicesElement(xml);
 
         Services services;
@@ -256,7 +259,7 @@ public class Config {
                     XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
     }
 
-    public static void checkUnrecognisedChildren(XmlElement parent) {
+    public static void checkUnrecognisedChildren(XmlElement parent) throws NetconfDocumentedException {
         Optional<XmlElement> servicesOpt = getServicesElement(parent);
         Optional<XmlElement> modulesOpt = getModulesElement(parent);
 
@@ -298,6 +301,6 @@ public class Config {
 
     private interface ResolvingStrategy<T> {
         public T resolveElement(ModuleConfig moduleMapping, XmlElement moduleElement, ServiceRegistryWrapper serviceTracker,
-                String instanceName, String moduleNamespace, EditStrategyType defaultStrategy);
+                String instanceName, String moduleNamespace, EditStrategyType defaultStrategy) throws NetconfDocumentedException;
     }
 }
index a940be7e77f0cb71ea8d41253048f6818dff8a73..1da9fabdb38390dd0a153b37f4f30a3560fdd03d 100644 (file)
@@ -9,13 +9,13 @@
 package org.opendaylight.controller.netconf.confignetconfconnector.mapping.config;
 
 import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Multimap;
 import org.opendaylight.controller.config.util.ConfigRegistryClient;
 import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry;
 import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.AttributeConfigElement;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.AttributeReadingStrategy;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.ObjectXmlReader;
@@ -131,14 +131,16 @@ public final class InstanceConfig {
     }
 
     public InstanceConfigElementResolved fromXml(XmlElement moduleElement, ServiceRegistryWrapper services, String moduleNamespace,
-                                                 EditStrategyType defaultStrategy, Multimap<String, String> providedServices, Map<String, Map<Date,EditConfig.IdentityMapping>> identityMap) {
+                                                 EditStrategyType defaultStrategy, Multimap<String, String> providedServices, Map<String, Map<Date,EditConfig.IdentityMapping>> identityMap) throws NetconfDocumentedException {
         Map<String, AttributeConfigElement> retVal = Maps.newHashMap();
 
         Map<String, AttributeReadingStrategy> strats = new ObjectXmlReader().prepareReading(yangToAttrConfig, identityMap);
         List<XmlElement> recognisedChildren = Lists.newArrayList();
 
-        XmlElement type = moduleElement.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.TYPE_KEY);
-        XmlElement name = moduleElement.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.NAME_KEY);
+        XmlElement type = null;
+        XmlElement name = null;
+        type = moduleElement.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.TYPE_KEY);
+        name = moduleElement.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.NAME_KEY);
         List<XmlElement> typeAndName = Lists.newArrayList(type, name);
 
         for (Entry<String, AttributeReadingStrategy> readStratEntry : strats.entrySet()) {
@@ -163,7 +165,7 @@ public final class InstanceConfig {
     }
 
     private List<XmlElement> getConfigNodes(XmlElement moduleElement, String moduleNamespace, String name,
-            List<XmlElement> recognisedChildren, List<XmlElement> typeAndName) {
+            List<XmlElement> recognisedChildren, List<XmlElement> typeAndName) throws NetconfDocumentedException {
         List<XmlElement> foundConfigNodes = moduleElement.getChildElementsWithinNamespace(name, moduleNamespace);
         if (foundConfigNodes.isEmpty()) {
             logger.debug("No config nodes {}:{} found in {}", moduleNamespace, name, moduleElement);
@@ -181,9 +183,13 @@ public final class InstanceConfig {
             List<XmlElement> foundWithoutNamespaceNodes = moduleElement.getChildElementsWithinNamespace(name,
                     XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
             foundWithoutNamespaceNodes.removeAll(typeAndName);
-            Preconditions.checkState(foundWithoutNamespaceNodes.isEmpty(),
-                    "Element %s present multiple times with different namespaces: %s, %s", name, foundConfigNodes,
-                    foundWithoutNamespaceNodes);
+            if (!foundWithoutNamespaceNodes.isEmpty()){
+                throw new NetconfDocumentedException(String.format("Element %s present multiple times with different namespaces: %s, %s", name, foundConfigNodes,
+                        foundWithoutNamespaceNodes),
+                        NetconfDocumentedException.ErrorType.application,
+                        NetconfDocumentedException.ErrorTag.invalid_value,
+                        NetconfDocumentedException.ErrorSeverity.error);
+            }
         }
 
         recognisedChildren.addAll(foundConfigNodes);
index 0bb4191bf2f33817d4bd395e3f29c0110139835b..c9605af5868db41a4910523d61347d2d83ae1729 100644 (file)
@@ -8,15 +8,14 @@
 
 package org.opendaylight.controller.netconf.confignetconfconnector.mapping.config;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Multimap;
+import java.util.Map;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
+import org.opendaylight.controller.netconf.confignetconfconnector.exception.OperationNotPermittedException;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.AttributeConfigElement;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfigStrategy;
-import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfigXmlParser;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditStrategyType;
 
-import java.util.Map;
-
 /**
  * Parsed xml element containing whole configuration for an instance of some
  * module. Contains preferred edit strategy type.
@@ -27,8 +26,9 @@ public class InstanceConfigElementResolved {
     private final Map<String, AttributeConfigElement> configuration;
     private final Multimap<String, String> providedServices;
 
-    public InstanceConfigElementResolved(String currentStrategy, Map<String, AttributeConfigElement> configuration, EditStrategyType defaultStrategy, Multimap<String, String> providedServices) {
-        EditStrategyType valueOf = parseStrategy(currentStrategy, defaultStrategy);
+    public InstanceConfigElementResolved(String currentStrategy, Map<String, AttributeConfigElement> configuration, EditStrategyType defaultStrategy, Multimap<String, String> providedServices) throws NetconfDocumentedException {
+        EditStrategyType valueOf = null;
+        valueOf = parseStrategy(currentStrategy, defaultStrategy);
         this.editStrategy = valueOf;
         this.configuration = configuration;
         this.providedServices = providedServices;
@@ -41,18 +41,9 @@ public class InstanceConfigElementResolved {
     }
 
 
-    static EditStrategyType parseStrategy(String currentStrategy, EditStrategyType defaultStrategy) {
+    static EditStrategyType parseStrategy(String currentStrategy, EditStrategyType defaultStrategy) throws OperationNotPermittedException {
         EditStrategyType parsedStrategy = EditStrategyType.valueOf(currentStrategy);
-        if (defaultStrategy.isEnforcing()) {
-            Preconditions
-                    .checkArgument(
-                            parsedStrategy == defaultStrategy,
-                            "With "
-                                    + defaultStrategy
-                                    + " as "
-                                    + EditConfigXmlParser.DEFAULT_OPERATION_KEY
-                                    + " operations on module elements are not permitted since the default option is restrictive");
-        }
+        EditStrategyType.compareParsedStrategyToDefaultEnforcing(parsedStrategy,defaultStrategy);
         return parsedStrategy;
     }
 
index dbaa7895d353d8c2217c97765f8b555f234402e7..f3d75d07bef7ec9dc33ac1d0a189f9e37d30e50d 100644 (file)
@@ -15,6 +15,7 @@ import java.util.Map;
 import javax.management.ObjectName;
 
 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfig;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditStrategyType;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
@@ -90,7 +91,7 @@ public class ModuleConfig {
     }
 
     public ModuleElementResolved fromXml(XmlElement moduleElement, ServiceRegistryWrapper depTracker, String instanceName,
-                                         String moduleNamespace, EditStrategyType defaultStrategy, Map<String, Map<Date,EditConfig.IdentityMapping>> identityMap) {
+                                         String moduleNamespace, EditStrategyType defaultStrategy, Map<String, Map<Date,EditConfig.IdentityMapping>> identityMap) throws NetconfDocumentedException {
 
         InstanceConfigElementResolved ice = instanceConfig.fromXml(moduleElement, depTracker, moduleNamespace, defaultStrategy, providedServices, identityMap);
         return new ModuleElementResolved(instanceName, ice);
index 9111701ba01d08e604d255da904846dae202839f..b772eee0d7a9f3b37a5c8854cfe6b9d1650270b2 100644 (file)
@@ -8,10 +8,13 @@
 
 package org.opendaylight.controller.netconf.confignetconfconnector.mapping.config;
 
+import org.opendaylight.controller.netconf.confignetconfconnector.exception.OperationNotPermittedException;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfigStrategy;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditStrategyType;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.MissingInstanceHandlingStrategy;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.NoneEditConfigStrategy;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ModuleElementDefinition {
 
@@ -20,13 +23,26 @@ public class ModuleElementDefinition {
 
     private final String instanceName;
     private final EditStrategyType editStrategy;
+    private static final Logger logger = LoggerFactory.getLogger(ModuleElementDefinition.class);
 
     public ModuleElementDefinition(String instanceName, String currentStrategy, EditStrategyType defaultStrategy) {
         this.instanceName = instanceName;
-        if (currentStrategy == null || currentStrategy.isEmpty())
+        if (currentStrategy == null || currentStrategy.isEmpty()) {
             this.editStrategy = defaultStrategy;
-        else
-            this.editStrategy = InstanceConfigElementResolved.parseStrategy(currentStrategy, defaultStrategy);
+        } else {
+            EditStrategyType _edStrategy = null;
+            try {
+                _edStrategy = InstanceConfigElementResolved.parseStrategy(currentStrategy, defaultStrategy);
+            } catch (OperationNotPermittedException e) {
+                _edStrategy = defaultStrategy;
+                logger.warn("Operation not permitted on current strategy {} while default strategy is {}. Element definition strategy set to default.",
+                        currentStrategy,
+                        defaultStrategy,
+                        e);
+            }
+            this.editStrategy = _edStrategy;
+        }
+
     }
 
     public String getInstanceName() {
index 9767b3f0560cdeae5f51927a1275dec0e7f8f29f..f9df71700870d12e7f14e7121c14e088cd5ce474 100644 (file)
@@ -17,6 +17,7 @@ import java.util.regex.Pattern;
 import javax.management.ObjectName;
 
 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.ObjectNameAttributeReadingStrategy;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
@@ -86,7 +87,7 @@ public final class Services {
 
     // TODO support edit strategies on services
 
-    public static Services fromXml(XmlElement xml) {
+    public static Services fromXml(XmlElement xml) throws NetconfDocumentedException {
         Map<String, Map<String, Map<String, String>>> retVal = Maps.newHashMap();
 
         List<XmlElement> services = xml.getChildElements(SERVICE_KEY);
index b7f5fc780bcc4c47a5428b00549629f39d9688b8..d63d8a139d92c3e6922989608907760e52d3cf28 100644 (file)
@@ -12,6 +12,7 @@ import com.google.common.collect.Maps;
 import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry.Rpc;
 import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc;
 import org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.AttributeConfigElement;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.AttributeReadingStrategy;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.ObjectXmlReader;
@@ -67,7 +68,7 @@ public final class InstanceRuntimeRpc {
         }
     }
 
-    public Map<String, AttributeConfigElement> fromXml(XmlElement configRootNode) {
+    public Map<String, AttributeConfigElement> fromXml(XmlElement configRootNode) throws NetconfDocumentedException {
         Map<String, AttributeConfigElement> retVal = Maps.newHashMap();
 
         // FIXME add identity map to runtime data
index 561aab9052f3ac5d040369fa89f799406a64d525..d49fe1a11629b0c5a9110b82973eac91ea25ba44 100644 (file)
@@ -8,17 +8,11 @@
 
 package org.opendaylight.controller.netconf.confignetconfconnector.operations;
 
-import java.util.HashMap;
-import java.util.Map;
-
 import org.opendaylight.controller.config.api.ConflictingVersionException;
 import org.opendaylight.controller.config.api.ValidationException;
 import org.opendaylight.controller.config.api.jmx.CommitStatus;
 import org.opendaylight.controller.config.util.ConfigRegistryClient;
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
-import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorSeverity;
-import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorTag;
-import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorType;
 import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
@@ -42,7 +36,7 @@ public class Commit extends AbstractConfigNetconfOperation {
         this.transactionProvider = transactionProvider;
     }
 
-    private static void checkXml(XmlElement xml) {
+    private static void checkXml(XmlElement xml) throws NetconfDocumentedException {
         xml.checkName(XmlNetconfConstants.COMMIT);
         xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
     }
@@ -54,25 +48,14 @@ public class Commit extends AbstractConfigNetconfOperation {
 
     @Override
     protected Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws NetconfDocumentedException {
-        checkXml(xml);
 
+        checkXml(xml);
         CommitStatus status;
         try {
             status = this.transactionProvider.commitTransaction();
-        } catch (final IllegalStateException e) {
-            // TODO Illegal state thrown when no transaction yet for user
-            // Throw other exception type, or create transaction automatically
-            logger.warn("Commit failed: ", e);
-            final Map<String, String> errorInfo = new HashMap<>();
-            errorInfo.put(ErrorTag.operation_failed.name(),
-                    "Operation failed. Use 'get-config' or 'edit-config' before triggering 'commit' operation");
-            throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.application, ErrorTag.operation_failed,
-                    ErrorSeverity.error, errorInfo);
-        } catch (ValidationException e) {
+            logger.trace("Datastore {} committed successfully: {}", Datastore.candidate, status);
+        } catch (ConflictingVersionException | ValidationException e) {
             throw NetconfDocumentedException.wrap(e);
-        } catch (ConflictingVersionException e) {
-            throw NetconfDocumentedException.wrap(e);
-
         }
         logger.trace("Datastore {} committed successfully: {}", Datastore.candidate, status);
 
index 639d4dac726d4d156659739bb5addaf54578d0ce..96a43b104d7d58a687f68744f79f6536b669f468 100644 (file)
@@ -6,11 +6,9 @@
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 
-package org.opendaylight.controller.netconf.confignetconfconnector.operations;
-
-import java.util.HashMap;
-import java.util.Map;
+    package org.opendaylight.controller.netconf.confignetconfconnector.operations;
 
+import com.google.common.base.Optional;
 import org.opendaylight.controller.config.util.ConfigRegistryClient;
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorSeverity;
@@ -25,7 +23,9 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import com.google.common.base.Optional;
+import java.util.HashMap;
+import java.util.Map;
+
 
 public class DiscardChanges extends AbstractConfigNetconfOperation {
 
@@ -41,7 +41,7 @@ public class DiscardChanges extends AbstractConfigNetconfOperation {
         this.transactionProvider = transactionProvider;
     }
 
-    private static void fromXml(XmlElement xml) {
+    private static void fromXml(XmlElement xml) throws NetconfDocumentedException {
         xml.checkName(DISCARD);
         xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
     }
@@ -53,21 +53,10 @@ public class DiscardChanges extends AbstractConfigNetconfOperation {
 
     @Override
     protected Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws NetconfDocumentedException {
-        try {
-            fromXml(xml);
-        } catch (final IllegalArgumentException e) {
-            //FIXME where can IllegalStateException  be thrown?
-            logger.warn("Rpc error: {}", ErrorTag.bad_attribute, e);
-            final Map<String, String> errorInfo = new HashMap<>();
-            errorInfo.put(ErrorTag.bad_attribute.name(), e.getMessage());
-            throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.rpc, ErrorTag.bad_attribute,
-                    ErrorSeverity.error, errorInfo);
-        }
-
+        fromXml(xml);
         try {
             this.transactionProvider.abortTransaction();
         } catch (final IllegalStateException e) {
-            //FIXME where can IllegalStateException  be thrown?
             logger.warn("Abort failed: ", e);
             final Map<String, String> errorInfo = new HashMap<>();
             errorInfo
@@ -78,6 +67,7 @@ public class DiscardChanges extends AbstractConfigNetconfOperation {
         }
         logger.trace("Changes discarded successfully from datastore {}", Datastore.candidate);
 
+
         return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
     }
 }
index 642c4456a8cc79dea6b884dc84c575d4af6bd664..1a7d50e5fabbc91f1359a3295a80f3f0418d6340 100644 (file)
@@ -8,9 +8,7 @@
 
 package org.opendaylight.controller.netconf.confignetconfconnector.operations;
 
-import java.util.HashMap;
-import java.util.Map;
-
+import com.google.common.base.Optional;
 import org.opendaylight.controller.config.api.ValidationException;
 import org.opendaylight.controller.config.util.ConfigRegistryClient;
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
@@ -26,8 +24,8 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
+import java.util.HashMap;
+import java.util.Map;
 
 public class Validate extends AbstractConfigNetconfOperation {
 
@@ -43,7 +41,7 @@ public class Validate extends AbstractConfigNetconfOperation {
         this.transactionProvider = transactionProvider;
     }
 
-    private void checkXml(XmlElement xml) {
+    private void checkXml(XmlElement xml) throws NetconfDocumentedException {
         xml.checkName(VALIDATE);
         xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
 
@@ -55,8 +53,10 @@ public class Validate extends AbstractConfigNetconfOperation {
         String datastoreValue = sourceChildNode.getName();
         Datastore sourceDatastore = Datastore.valueOf(datastoreValue);
 
-        Preconditions.checkState(sourceDatastore == Datastore.candidate, "Only " + Datastore.candidate
-                + " is supported as source for " + VALIDATE + " but was " + datastoreValue);
+        if (sourceDatastore != Datastore.candidate){
+            throw new NetconfDocumentedException( "Only " + Datastore.candidate
+                    + " is supported as source for " + VALIDATE + " but was " + datastoreValue,ErrorType.application,ErrorTag.data_missing,ErrorSeverity.error);
+        }
     }
 
     @Override
@@ -66,24 +66,7 @@ public class Validate extends AbstractConfigNetconfOperation {
 
     @Override
     protected Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws NetconfDocumentedException {
-        try {
-            checkXml(xml);
-        } catch (IllegalStateException e) {
-            //FIXME where can IllegalStateException  be thrown? I see precondition that guards for programming bugs..
-            logger.warn("Rpc error: {}", ErrorTag.missing_attribute, e);
-            final Map<String, String> errorInfo = new HashMap<>();
-            errorInfo.put(ErrorTag.missing_attribute.name(), "Missing value of datastore attribute");
-            throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.rpc, ErrorTag.missing_attribute,
-                    ErrorSeverity.error, errorInfo);
-        } catch (final IllegalArgumentException e) {
-            // FIXME use checked exception if it has domain meaning
-            logger.warn("Rpc error: {}", ErrorTag.bad_attribute, e);
-            final Map<String, String> errorInfo = new HashMap<>();
-            errorInfo.put(ErrorTag.bad_attribute.name(), e.getMessage());
-            throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.rpc, ErrorTag.bad_attribute,
-                    ErrorSeverity.error, errorInfo);
-        }
-
+        checkXml(xml);
         try {
             transactionProvider.validateTransaction();
         } catch (ValidationException e) {
index 1d37fcd49378de3d577db338b034f987634f9518..820f8ff7723237cb45a798faa6831bcfb7523d76 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig;
 
 import org.opendaylight.controller.config.util.ConfigTransactionClient;
+import org.opendaylight.controller.netconf.confignetconfconnector.exception.NetconfConfigHandlingException;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.AttributeConfigElement;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.ServiceRegistryWrapper;
 import org.slf4j.Logger;
@@ -24,7 +25,7 @@ public abstract class AbstractEditConfigStrategy implements EditConfigStrategy {
 
     @Override
     public void executeConfiguration(String module, String instance, Map<String, AttributeConfigElement> configuration,
-                                     ConfigTransactionClient ta, ServiceRegistryWrapper services) {
+                                     ConfigTransactionClient ta, ServiceRegistryWrapper services) throws NetconfConfigHandlingException {
 
         try {
             ObjectName on = ta.lookupConfigBean(module, instance);
@@ -40,9 +41,9 @@ public abstract class AbstractEditConfigStrategy implements EditConfigStrategy {
     // edit configs should not handle missing
 
     abstract void handleMissingInstance(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta,
-                                        String module, String instance, ServiceRegistryWrapper services);
+                                        String module, String instance, ServiceRegistryWrapper services) throws NetconfConfigHandlingException;
 
     abstract void executeStrategy(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta,
-                                  ObjectName objectName, ServiceRegistryWrapper services);
+                                  ObjectName objectName, ServiceRegistryWrapper services) throws NetconfConfigHandlingException;
 
 }
index 13e8c30211539485e0ac91ca1eb0ec06704e8409..e88863c685ace15c486c9b5c263345a81ace9a44 100644 (file)
@@ -11,6 +11,8 @@ package org.opendaylight.controller.netconf.confignetconfconnector.operations.ed
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.Multimap;
 import org.opendaylight.controller.config.util.ConfigTransactionClient;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
+import org.opendaylight.controller.netconf.confignetconfconnector.exception.NetconfConfigHandlingException;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.AttributeConfigElement;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.ServiceRegistryWrapper;
 import org.slf4j.Logger;
@@ -36,17 +38,24 @@ public class DeleteEditConfigStrategy extends AbstractEditConfigStrategy {
 
     @Override
     void handleMissingInstance(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta,
-                               String module, String instance, ServiceRegistryWrapper services) {
-        throw new IllegalStateException("Unable to delete " + module + ":" + instance + " , ServiceInstance not found");
+                               String module, String instance, ServiceRegistryWrapper services) throws NetconfConfigHandlingException {
+        throw new NetconfConfigHandlingException(String.format("Unable to delete %s : %s , ServiceInstance not found", module ,instance),
+                NetconfDocumentedException.ErrorType.application,
+                NetconfDocumentedException.ErrorTag.operation_failed,
+                NetconfDocumentedException.ErrorSeverity.error);
     }
 
     @Override
-    void executeStrategy(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta, ObjectName on, ServiceRegistryWrapper services) {
+    void executeStrategy(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta, ObjectName on, ServiceRegistryWrapper services) throws NetconfConfigHandlingException {
         try {
             ta.destroyModule(on);
             logger.debug("ServiceInstance {} deleted successfully", on);
         } catch (InstanceNotFoundException e) {
-            throw new IllegalStateException("Unable to delete " + on, e);
+            throw new NetconfConfigHandlingException(
+                    String.format("Unable to delete %s because of exception %s" + on, e.getMessage()),
+                    NetconfDocumentedException.ErrorType.application,
+                    NetconfDocumentedException.ErrorTag.operation_failed,
+                    NetconfDocumentedException.ErrorSeverity.error);
         }
     }
 }
index 0cc9d1153f7711ec0aa3c8320b32cc45cd7d67ae..428ddb3b740dfbb5e34e62bff86035d0e9464b03 100644 (file)
@@ -8,15 +8,11 @@
 
 package org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig;
 
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import javax.management.InstanceNotFoundException;
-import javax.management.ObjectName;
-
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Multimap;
 import org.opendaylight.controller.config.api.ValidationException;
 import org.opendaylight.controller.config.util.ConfigRegistryClient;
 import org.opendaylight.controller.config.util.ConfigTransactionClient;
@@ -25,6 +21,7 @@ import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorSeverity;
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorTag;
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorType;
+import org.opendaylight.controller.netconf.confignetconfconnector.exception.NetconfConfigHandlingException;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.Config;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.InstanceConfig;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.InstanceConfigElementResolved;
@@ -46,11 +43,12 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Multimap;
+import javax.management.InstanceNotFoundException;
+import javax.management.ObjectName;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
 
 public class EditConfig extends AbstractConfigNetconfOperation {
 
@@ -71,7 +69,7 @@ public class EditConfig extends AbstractConfigNetconfOperation {
 
     @VisibleForTesting
     Element getResponseInternal(final Document document,
-            final EditConfigXmlParser.EditConfigExecution editConfigExecution) throws NetconfDocumentedException {
+            final EditConfigXmlParser.EditConfigExecution editConfigExecution) throws NetconfDocumentedException, NetconfConfigHandlingException {
 
         if (editConfigExecution.shouldTest()) {
             executeTests(configRegistryClient, editConfigExecution);
@@ -88,19 +86,7 @@ public class EditConfig extends AbstractConfigNetconfOperation {
 
     private void executeSet(ConfigRegistryClient configRegistryClient,
             EditConfigXmlParser.EditConfigExecution editConfigExecution) throws NetconfDocumentedException {
-        try {
-            set(configRegistryClient, editConfigExecution);
-
-        } catch (IllegalStateException e) {
-            //FIXME: when can IllegalStateException be thrown?
-            // JmxAttributeValidationException is wrapped in DynamicWritableWrapper with ValidationException
-            // ValidationException is not thrown until validate or commit is issued
-            logger.warn("Set phase for {} failed", EditConfigXmlParser.EDIT_CONFIG, e);
-            final Map<String, String> errorInfo = new HashMap<>();
-            errorInfo.put(ErrorTag.operation_failed.name(), e.getMessage());
-            throw new NetconfDocumentedException("Test phase: " + e.getMessage(), e, ErrorType.application,
-                    ErrorTag.operation_failed, ErrorSeverity.error, errorInfo);
-        }
+        set(configRegistryClient, editConfigExecution);
         logger.debug("Set phase for {} operation successful", EditConfigXmlParser.EDIT_CONFIG);
     }
 
@@ -108,8 +94,7 @@ public class EditConfig extends AbstractConfigNetconfOperation {
             EditConfigExecution editConfigExecution) throws NetconfDocumentedException {
         try {
             test(configRegistryClient, editConfigExecution, editConfigExecution.getDefaultStrategy());
-        } catch (IllegalStateException | ValidationException e) {
-            //FIXME: when can IllegalStateException be thrown?
+        } catch (final ValidationException e) {
             logger.warn("Test phase for {} failed", EditConfigXmlParser.EDIT_CONFIG, e);
             final Map<String, String> errorInfo = new HashMap<>();
             errorInfo.put(ErrorTag.operation_failed.name(), e.getMessage());
@@ -120,10 +105,9 @@ public class EditConfig extends AbstractConfigNetconfOperation {
     }
 
     private void test(ConfigRegistryClient configRegistryClient, EditConfigExecution execution,
-            EditStrategyType editStrategyType) throws ValidationException {
+            EditStrategyType editStrategyType) throws ValidationException, NetconfDocumentedException {
         ObjectName taON = transactionProvider.getTestTransaction();
         try {
-
             // default strategy = replace wipes config
             if (editStrategyType == EditStrategyType.replace) {
                 transactionProvider.wipeTestTransaction(taON);
@@ -141,7 +125,7 @@ public class EditConfig extends AbstractConfigNetconfOperation {
     }
 
     private void set(ConfigRegistryClient configRegistryClient,
-            EditConfigXmlParser.EditConfigExecution editConfigExecution) {
+            EditConfigXmlParser.EditConfigExecution editConfigExecution) throws NetconfDocumentedException {
         ObjectName taON = transactionProvider.getOrCreateTransaction();
 
         // default strategy = replace wipes config
@@ -156,7 +140,7 @@ public class EditConfig extends AbstractConfigNetconfOperation {
         setOnTransaction(ta, editConfigExecution);
     }
 
-    private void setServicesOnTransaction(ConfigTransactionClient ta, EditConfigExecution execution) {
+    private void setServicesOnTransaction(ConfigTransactionClient ta, EditConfigExecution execution) throws NetconfDocumentedException {
 
         Services services = execution.getServices();
 
@@ -177,7 +161,10 @@ public class EditConfig extends AbstractConfigNetconfOperation {
                         logger.debug("Saving service {} with on {} under name {} with service on {}", qnameOfService,
                                 on, refName, saved);
                     } catch (InstanceNotFoundException e) {
-                        throw new IllegalStateException("Unable to save ref name " + refName + " for instance " + on, e);
+                        throw new NetconfDocumentedException(String.format("Unable to save ref name " + refName + " for instance " + on, e),
+                                ErrorType.application,
+                                ErrorTag.operation_failed,
+                                ErrorSeverity.error);
                     }
                 }
             }
@@ -188,11 +175,11 @@ public class EditConfig extends AbstractConfigNetconfOperation {
         return ta.getServiceInterfaceName(namespace, serviceName);
     }
 
-    private void setOnTransaction(ConfigTransactionClient ta, EditConfigExecution execution) {
+    private void setOnTransaction(ConfigTransactionClient ta, EditConfigExecution execution) throws NetconfDocumentedException {
 
         for (Multimap<String, ModuleElementResolved> modulesToResolved : execution.getResolvedXmlElements(ta).values()) {
 
-            for (Entry<String, ModuleElementResolved> moduleToResolved : modulesToResolved.entries()) {
+            for (Map.Entry<String, ModuleElementResolved> moduleToResolved : modulesToResolved.entries()) {
                 String moduleName = moduleToResolved.getKey();
 
                 ModuleElementResolved moduleElementResolved = moduleToResolved.getValue();
@@ -206,10 +193,10 @@ public class EditConfig extends AbstractConfigNetconfOperation {
     }
 
     private void handleMisssingInstancesOnTransaction(ConfigTransactionClient ta,
-            EditConfigExecution execution) {
+            EditConfigExecution execution) throws NetconfDocumentedException {
 
         for (Multimap<String,ModuleElementDefinition> modulesToResolved : execution.getModulesDefinition(ta).values()) {
-            for (Entry<String, ModuleElementDefinition> moduleToResolved : modulesToResolved.entries()) {
+            for (Map.Entry<String, ModuleElementDefinition> moduleToResolved : modulesToResolved.entries()) {
                 String moduleName = moduleToResolved.getKey();
 
                 ModuleElementDefinition moduleElementDefinition = moduleToResolved.getValue();
@@ -289,7 +276,7 @@ public class EditConfig extends AbstractConfigNetconfOperation {
         Map<String, Map<String, ModuleConfig>> namespaceToModuleNameToModuleConfig = Maps.newHashMap();
 
         for (String namespace : mBeanEntries.keySet()) {
-            for (Entry<String, ModuleMXBeanEntry> moduleNameToMbe : mBeanEntries.get(namespace).entrySet()) {
+            for (Map.Entry<String, ModuleMXBeanEntry> moduleNameToMbe : mBeanEntries.get(namespace).entrySet()) {
                 String moduleName = moduleNameToMbe.getKey();
                 ModuleMXBeanEntry moduleMXBeanEntry = moduleNameToMbe.getValue();
 
@@ -320,29 +307,11 @@ public class EditConfig extends AbstractConfigNetconfOperation {
 
         EditConfigXmlParser.EditConfigExecution editConfigExecution;
         Config cfg = getConfigMapping(configRegistryClient, yangStoreSnapshot);
-        try {
-            editConfigExecution = editConfigXmlParser.fromXml(xml, cfg, transactionProvider, configRegistryClient);
-        } catch (IllegalStateException e) {
-            logger.warn("Error parsing xml", e);
-            final Map<String, String> errorInfo = new HashMap<>();
-            errorInfo.put(ErrorTag.missing_attribute.name(), "Error parsing xml: " + e.getMessage());
-            throw new NetconfDocumentedException(e.getMessage(), ErrorType.rpc, ErrorTag.missing_attribute,
-                    ErrorSeverity.error, errorInfo);
-        } catch (final IllegalArgumentException e) {
-            logger.warn("Error parsing xml", e);
-            final Map<String, String> errorInfo = new HashMap<>();
-            errorInfo.put(ErrorTag.bad_attribute.name(), e.getMessage());
-            throw new NetconfDocumentedException(e.getMessage(), ErrorType.rpc, ErrorTag.bad_attribute,
-                    ErrorSeverity.error, errorInfo);
-        } catch (final UnsupportedOperationException e) {
-            logger.warn("Unsupported", e);
-            final Map<String, String> errorInfo = new HashMap<>();
-            errorInfo.put(ErrorTag.operation_not_supported.name(), "Unsupported option for 'edit-config'");
-            throw new NetconfDocumentedException(e.getMessage(), ErrorType.application,
-                    ErrorTag.operation_not_supported, ErrorSeverity.error, errorInfo);
-        }
+        editConfigExecution = editConfigXmlParser.fromXml(xml, cfg, transactionProvider, configRegistryClient);
 
-        return getResponseInternal(document, editConfigExecution);
+        Element responseInternal;
+        responseInternal = getResponseInternal(document, editConfigExecution);
+        return responseInternal;
     }
 
 }
index cebcb0239bc81cda1d7ef6a83bc0f15b8c3bdd90..8538e40bcd0e04f060f46dd0029109fa70fa1e4a 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig;
 
 import org.opendaylight.controller.config.util.ConfigTransactionClient;
+import org.opendaylight.controller.netconf.confignetconfconnector.exception.NetconfConfigHandlingException;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.AttributeConfigElement;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.ServiceRegistryWrapper;
 
@@ -17,6 +18,6 @@ import java.util.Map;
 public interface EditConfigStrategy {
 
     void executeConfiguration(String module, String instance, Map<String, AttributeConfigElement> configuration,
-                              ConfigTransactionClient ta, ServiceRegistryWrapper services);
+                              ConfigTransactionClient ta, ServiceRegistryWrapper services) throws NetconfConfigHandlingException;
 
 }
index e481bbe57f68bf4d043a8365362ce2c90ab46893..de6979565e3fe225fc7150dbbe645d4042decdc0 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.controller.netconf.confignetconfconnector.operations.ed
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Multimap;
 import org.opendaylight.controller.config.api.ServiceReferenceReadableRegistry;
 import org.opendaylight.controller.config.util.ConfigRegistryClient;
@@ -22,6 +21,8 @@ import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.Services;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.Datastore;
 import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider;
+import org.opendaylight.controller.netconf.util.exception.MissingNameSpaceException;
+import org.opendaylight.controller.netconf.util.exception.UnexpectedNamespaceException;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
 import org.slf4j.Logger;
@@ -55,15 +56,30 @@ public class EditConfigXmlParser {
         xml.checkName(EditConfigXmlParser.EDIT_CONFIG);
         xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
 
-        XmlElement targetElement = xml.getOnlyChildElementWithSameNamespace(EditConfigXmlParser.TARGET_KEY);
-        XmlElement targetChildNode = targetElement.getOnlyChildElementWithSameNamespace();
+
+        XmlElement targetElement = null;
+        XmlElement targetChildNode = null;
+        try {
+            targetElement  = xml.getOnlyChildElementWithSameNamespace(EditConfigXmlParser.TARGET_KEY);
+            targetChildNode = targetElement.getOnlyChildElementWithSameNamespace();
+        } catch (final MissingNameSpaceException | UnexpectedNamespaceException e) {
+            logger.trace("Can't get only child element with same namespace due to {}",e);
+            throw NetconfDocumentedException.wrap(e);
+        }
         String datastoreValue = targetChildNode.getName();
         Datastore targetDatastore = Datastore.valueOf(datastoreValue);
         logger.debug("Setting {} to '{}'", EditConfigXmlParser.TARGET_KEY, targetDatastore);
 
         // check target
-        Preconditions.checkArgument(targetDatastore == Datastore.candidate,
-                "Only %s datastore supported for edit config but was: %s", Datastore.candidate, targetDatastore);
+        if (targetDatastore != Datastore.candidate){
+            throw new NetconfDocumentedException(String.format(
+                    "Only %s datastore supported for edit config but was: %s",
+                    Datastore.candidate,
+                    targetDatastore),
+                    NetconfDocumentedException.ErrorType.application,
+                    NetconfDocumentedException.ErrorTag.invalid_value,
+                    NetconfDocumentedException.ErrorSeverity.error);
+        }
 
         // Test option
         TestOption testOption;
@@ -96,7 +112,13 @@ public class EditConfigXmlParser {
             editStrategyType = EditStrategyType.valueOf(mergeStrategyString);
         }
 
-        XmlElement configElement = xml.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.CONFIG_KEY);
+        XmlElement configElement = null;
+        try {
+            configElement = xml.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.CONFIG_KEY);
+        } catch (MissingNameSpaceException e) {
+            logger.trace("Can't get only child element with same namespace due to {}",e);
+            throw NetconfDocumentedException.wrap(e);
+        }
 
         return new EditConfigXmlParser.EditConfigExecution(cfgMapping, configElement, testOption, editStrategyType);
     }
@@ -134,7 +156,7 @@ public class EditConfigXmlParser {
         private final Config configResolver;
         private final XmlElement configElement;
 
-        EditConfigExecution(Config configResolver, XmlElement configElement, TestOption testOption, EditStrategyType defaultStrategy) {
+        EditConfigExecution(Config configResolver, XmlElement configElement, TestOption testOption, EditStrategyType defaultStrategy) throws NetconfDocumentedException {
             Config.checkUnrecognisedChildren(configElement);
             this.configResolver = configResolver;
             this.configElement = configElement;
@@ -151,7 +173,7 @@ public class EditConfigXmlParser {
             return testOption == TestOption.set || testOption == TestOption.testThenSet;
         }
 
-        Map<String, Multimap<String, ModuleElementResolved>> getResolvedXmlElements(ServiceReferenceReadableRegistry serviceRegistry) {
+        Map<String, Multimap<String, ModuleElementResolved>> getResolvedXmlElements(ServiceReferenceReadableRegistry serviceRegistry) throws NetconfDocumentedException {
             return configResolver.fromXmlModulesResolved(configElement, defaultEditStrategyType, getServiceRegistryWrapper(serviceRegistry));
         }
 
@@ -160,7 +182,7 @@ public class EditConfigXmlParser {
             return new ServiceRegistryWrapper(serviceRegistry);
         }
 
-        Map<String, Multimap<String,ModuleElementDefinition>> getModulesDefinition(ServiceReferenceReadableRegistry serviceRegistry) {
+        Map<String, Multimap<String,ModuleElementDefinition>> getModulesDefinition(ServiceReferenceReadableRegistry serviceRegistry) throws NetconfDocumentedException {
             return configResolver.fromXmlModulesMap(configElement, defaultEditStrategyType, getServiceRegistryWrapper(serviceRegistry));
         }
 
index 06560b2d2724d2efb7996736649a2d90219e168c..2f41defac8ff880a9733e21513f6a3dd96d914f5 100644 (file)
@@ -9,6 +9,8 @@
 package org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig;
 
 import com.google.common.collect.Multimap;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
+import org.opendaylight.controller.netconf.confignetconfconnector.exception.OperationNotPermittedException;
 
 import java.util.EnumSet;
 import java.util.Set;
@@ -40,7 +42,22 @@ public enum EditStrategyType {
                     + this);
         }
     }
+    public static void compareParsedStrategyToDefaultEnforcing(EditStrategyType parsedStrategy,
+                                                                  EditStrategyType defaultStrategy) throws OperationNotPermittedException {
+        if (defaultStrategy.isEnforcing()) {
+            if (parsedStrategy != defaultStrategy){
+                throw new OperationNotPermittedException(String.format("With "
+                        + defaultStrategy
+                        + " as "
+                        + EditConfigXmlParser.DEFAULT_OPERATION_KEY
+                        + " operations on module elements are not permitted since the default option is restrictive"),
+                        NetconfDocumentedException.ErrorType.application,
+                        NetconfDocumentedException.ErrorTag.operation_failed,
+                        NetconfDocumentedException.ErrorSeverity.error);
+            }
+        }
 
+    }
     public EditConfigStrategy getFittingStrategy(Multimap<String, String> providedServices) {
         switch (this) {
         case merge:
index f2e2b193a8f1b7d90380c3cee6916a1a9b0514c1..0a72547d78454cc242756a5a683045ad2f034fa0 100644 (file)
@@ -12,6 +12,8 @@ import com.google.common.collect.HashMultimap;
 import com.google.common.collect.Multimap;
 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
 import org.opendaylight.controller.config.util.ConfigTransactionClient;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
+import org.opendaylight.controller.netconf.confignetconfconnector.exception.NetconfConfigHandlingException;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.AttributeConfigElement;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.ServiceRegistryWrapper;
 import org.slf4j.Logger;
@@ -38,10 +40,14 @@ public class MergeEditConfigStrategy extends AbstractEditConfigStrategy {
 
     @Override
     void handleMissingInstance(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta,
-            String module, String instance, ServiceRegistryWrapper services) {
-        throw new IllegalStateException(
-                "Unable to handle missing instance, no missing instances should appear at this point, missing: "
-                        + module + ":" + instance);
+            String module, String instance, ServiceRegistryWrapper services) throws NetconfConfigHandlingException {
+        throw new NetconfConfigHandlingException(
+                String.format("Unable to handle missing instance, no missing instances should appear at this point, missing: %s : %s ",
+                        module,
+                        instance),
+                NetconfDocumentedException.ErrorType.application,
+                NetconfDocumentedException.ErrorTag.operation_failed,
+                NetconfDocumentedException.ErrorSeverity.error);
     }
 
     private void addRefNames(ServiceRegistryWrapper services, Multimap<String, String> providedServices, ConfigTransactionClient ta, ObjectName on) throws InstanceNotFoundException {
@@ -59,11 +65,14 @@ public class MergeEditConfigStrategy extends AbstractEditConfigStrategy {
     }
 
     @Override
-    void executeStrategy(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta, ObjectName on, ServiceRegistryWrapper services) {
+    void executeStrategy(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta, ObjectName on, ServiceRegistryWrapper services) throws NetconfConfigHandlingException {
         try {
             addRefNames(services, providedServices, ta, on);
         } catch (InstanceNotFoundException e) {
-            throw new IllegalStateException("Unable to save default ref name for instance " + on, e);
+            throw new NetconfConfigHandlingException(String.format("Unable to save default ref name for instance %s. Instance was not found.",e),
+                    NetconfDocumentedException.ErrorType.application,
+                    NetconfDocumentedException.ErrorTag.operation_failed,
+                    NetconfDocumentedException.ErrorSeverity.error);
         }
 
         for (Entry<String, AttributeConfigElement> configAttributeEntry : configuration.entrySet()) {
@@ -79,8 +88,13 @@ public class MergeEditConfigStrategy extends AbstractEditConfigStrategy {
                 ta.setAttribute(on, ace.getJmxName(), new Attribute(ace.getJmxName(), value));
                 logger.debug("Attribute {} set to {} for {}", configAttributeEntry.getKey(), value, on);
             } catch (Exception e) {
-                throw new IllegalStateException("Unable to set attributes for " + on + ", Error with attribute "
-                        + configAttributeEntry.getKey() + ":" + configAttributeEntry.getValue(), e);
+                throw new NetconfConfigHandlingException(String.format("Unable to set attributes for %s, Error with attribute %s : %s ",
+                        on,
+                        configAttributeEntry.getKey(),
+                        configAttributeEntry.getValue()),
+                        NetconfDocumentedException.ErrorType.application,
+                        NetconfDocumentedException.ErrorTag.operation_failed,
+                        NetconfDocumentedException.ErrorSeverity.error);
             }
         }
     }
index 92e30f1617d755f8524905c81f2ba99659023186..c431766c4c5a61ebbf53928a529b63ea933d4f2b 100644 (file)
@@ -9,6 +9,8 @@
 package org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig;
 
 import org.opendaylight.controller.config.util.ConfigTransactionClient;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
+import org.opendaylight.controller.netconf.confignetconfconnector.exception.NetconfConfigHandlingException;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.AttributeConfigElement;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.ServiceRegistryWrapper;
 import org.slf4j.Logger;
@@ -24,13 +26,16 @@ public class MissingInstanceHandlingStrategy extends AbstractEditConfigStrategy
 
     @Override
     void handleMissingInstance(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta,
-            String module, String instance, ServiceRegistryWrapper services) {
+            String module, String instance, ServiceRegistryWrapper services) throws NetconfConfigHandlingException {
         ObjectName on = null;
         try {
             on = ta.createModule(module, instance);
             logger.trace("New instance for {} {} created under name {}", module, instance, on);
         } catch (InstanceAlreadyExistsException e1) {
-            throw new IllegalStateException("Unable to create instance for " + module + " : " + instance);
+            throw new NetconfConfigHandlingException(String.format("Unable to create instance for %s : %s.", module, instance),
+                    NetconfDocumentedException.ErrorType.application,
+                    NetconfDocumentedException.ErrorTag.operation_failed,
+                    NetconfDocumentedException.ErrorSeverity.error);
         }
     }
 
index 4976244eae57cb6eadfec806620a10f43a2387d4..b61fcbadc07cd3caaa6582538f734077c79839ba 100644 (file)
@@ -12,6 +12,8 @@ import com.google.common.collect.HashMultimap;
 import com.google.common.collect.Multimap;
 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
 import org.opendaylight.controller.config.util.ConfigTransactionClient;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
+import org.opendaylight.controller.netconf.confignetconfconnector.exception.NetconfConfigHandlingException;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.AttributeConfigElement;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.ServiceRegistryWrapper;
 import org.slf4j.Logger;
@@ -39,10 +41,14 @@ public class ReplaceEditConfigStrategy extends AbstractEditConfigStrategy {
 
     @Override
     void handleMissingInstance(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta,
-                               String module, String instance, ServiceRegistryWrapper services) {
-        throw new IllegalStateException(
-                "Unable to handle missing instance, no missing instances should appear at this point, missing: "
-                        + module + ":" + instance);
+                               String module, String instance, ServiceRegistryWrapper services) throws NetconfConfigHandlingException {
+        throw new NetconfConfigHandlingException(
+                String.format("Unable to handle missing instance, no missing instances should appear at this point, missing: %s : %s ",
+                        module,
+                        instance),
+                NetconfDocumentedException.ErrorType.application,
+                NetconfDocumentedException.ErrorTag.operation_failed,
+                NetconfDocumentedException.ErrorSeverity.error);
     }
 
     private void addRefNames(ServiceRegistryWrapper services, Multimap<String, String> providedServices, ConfigTransactionClient ta, ObjectName on) throws InstanceNotFoundException {
@@ -60,11 +66,14 @@ public class ReplaceEditConfigStrategy extends AbstractEditConfigStrategy {
     }
 
     @Override
-    void executeStrategy(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta, ObjectName on, ServiceRegistryWrapper services) {
+    void executeStrategy(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta, ObjectName on, ServiceRegistryWrapper services) throws NetconfConfigHandlingException {
         try {
             addRefNames(services, providedServices, ta, on);
         } catch (InstanceNotFoundException e) {
-            throw new IllegalStateException("Unable to save default ref name for instance " + on, e);
+            throw new NetconfConfigHandlingException(String.format("Unable to save default ref name for instance %s. Instance not found. ",on),
+                    NetconfDocumentedException.ErrorType.application,
+                    NetconfDocumentedException.ErrorTag.operation_failed,
+                    NetconfDocumentedException.ErrorSeverity.error);
         }
 
         for (Entry<String, AttributeConfigElement> configAttributeEntry : configuration.entrySet()) {
index f7fc029fcc8f363dd38dc6e8aaad565963654f6d..dd0e53b1bbb42f8fb2b91fb8b1eb1cc97671aa52 100644 (file)
@@ -8,22 +8,12 @@
 
 package org.opendaylight.controller.netconf.confignetconfconnector.operations.get;
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.management.ObjectName;
-
+import com.google.common.collect.Maps;
 import org.opendaylight.controller.config.util.ConfigRegistryClient;
 import org.opendaylight.controller.config.util.ConfigTransactionClient;
-import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreSnapshot;
 import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
 import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry;
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
-import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorSeverity;
-import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorTag;
-import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorType;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.InstanceConfig;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.ModuleConfig;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.ServiceRegistryWrapper;
@@ -33,7 +23,11 @@ import org.opendaylight.controller.netconf.confignetconfconnector.mapping.runtim
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.AbstractConfigNetconfOperation;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.Datastore;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfig;
+import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreSnapshot;
 import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider;
+import org.opendaylight.controller.netconf.util.exception.MissingNameSpaceException;
+import org.opendaylight.controller.netconf.util.exception.UnexpectedElementException;
+import org.opendaylight.controller.netconf.util.exception.UnexpectedNamespaceException;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
 import org.slf4j.Logger;
@@ -41,7 +35,10 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import com.google.common.collect.Maps;
+import javax.management.ObjectName;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 public class Get extends AbstractConfigNetconfOperation {
 
@@ -106,7 +103,7 @@ public class Get extends AbstractConfigNetconfOperation {
         return jmxToYangNamesForChildRbe;
     }
 
-    private static void checkXml(XmlElement xml) {
+    private static void checkXml(XmlElement xml) throws UnexpectedElementException, UnexpectedNamespaceException, MissingNameSpaceException {
         xml.checkName(XmlNetconfConstants.GET);
         xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
 
@@ -122,21 +119,7 @@ public class Get extends AbstractConfigNetconfOperation {
 
     @Override
     protected Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws NetconfDocumentedException {
-        try {
-            checkXml(xml);
-        } catch (final IllegalArgumentException e) {
-            logger.warn("Error parsing xml", e);
-            final Map<String, String> errorInfo = new HashMap<>();
-            errorInfo.put(ErrorTag.bad_attribute.name(), e.getMessage());
-            throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.rpc, ErrorTag.bad_attribute,
-                    ErrorSeverity.error, errorInfo);
-        } catch (final UnsupportedOperationException e) {
-            logger.warn("Unsupported", e);
-            final Map<String, String> errorInfo = new HashMap<>();
-            errorInfo.put(ErrorTag.operation_not_supported.name(), "Unsupported option for 'get'");
-            throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.application,
-                    ErrorTag.operation_not_supported, ErrorSeverity.error, errorInfo);
-        }
+        checkXml(xml);
 
         final Set<ObjectName> runtimeBeans = configRegistryClient.lookupRuntimeBeans();
 
index 05bba56611a1137e0bfb60c69b198df82ae2aa7d..11d3e32edf6748fe811a9a25174330afae5b1d28 100644 (file)
@@ -8,18 +8,10 @@
 
 package org.opendaylight.controller.netconf.confignetconfconnector.operations.getconfig;
 
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import javax.management.ObjectName;
-
+import com.google.common.base.Optional;
 import org.opendaylight.controller.config.util.ConfigRegistryClient;
 import org.opendaylight.controller.config.util.ConfigTransactionClient;
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
-import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorSeverity;
-import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorTag;
-import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorType;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.Config;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.ServiceRegistryWrapper;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.AbstractConfigNetconfOperation;
@@ -27,6 +19,9 @@ import org.opendaylight.controller.netconf.confignetconfconnector.operations.Dat
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfig;
 import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreSnapshot;
 import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider;
+import org.opendaylight.controller.netconf.util.exception.MissingNameSpaceException;
+import org.opendaylight.controller.netconf.util.exception.UnexpectedElementException;
+import org.opendaylight.controller.netconf.util.exception.UnexpectedNamespaceException;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
@@ -35,7 +30,8 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import com.google.common.base.Optional;
+import javax.management.ObjectName;
+import java.util.Set;
 
 public class GetConfig extends AbstractConfigNetconfOperation {
 
@@ -57,7 +53,8 @@ public class GetConfig extends AbstractConfigNetconfOperation {
         this.transactionProvider = transactionProvider;
     }
 
-    public static Datastore fromXml(XmlElement xml) {
+    public static Datastore fromXml(XmlElement xml) throws UnexpectedNamespaceException, UnexpectedElementException, MissingNameSpaceException, NetconfDocumentedException {
+
         xml.checkName(GET_CONFIG);
         xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
 
@@ -106,27 +103,7 @@ public class GetConfig extends AbstractConfigNetconfOperation {
     @Override
     public Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws NetconfDocumentedException {
         Datastore source;
-        try {
-            source = fromXml(xml);
-        } catch (final IllegalArgumentException e) {
-            logger.warn("Rpc error: {}", ErrorTag.bad_attribute, e);
-            final Map<String, String> errorInfo = new HashMap<>();
-            errorInfo.put(ErrorTag.bad_attribute.name(), e.getMessage());
-            throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.rpc, ErrorTag.bad_attribute,
-                    ErrorSeverity.error, errorInfo);
-        } catch (final IllegalStateException e) {
-            logger.warn("Rpc error: {}", ErrorTag.missing_attribute, e);
-            final Map<String, String> errorInfo = new HashMap<>();
-            errorInfo.put(ErrorTag.missing_attribute.name(), "Missing datasource attribute value");
-            throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.rpc, ErrorTag.missing_attribute,
-                    ErrorSeverity.error, errorInfo);
-        } catch (final UnsupportedOperationException e) {
-            logger.warn("Unsupported", e);
-            final Map<String, String> errorInfo = new HashMap<>();
-            errorInfo.put(ErrorTag.operation_not_supported.name(), "Unsupported option for get");
-            throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.application,
-                    ErrorTag.operation_not_supported, ErrorSeverity.error, errorInfo);
-        }
+        source = fromXml(xml);
         return getResponseInternal(document, configRegistryClient, source);
     }
 }
index 8accbd591f6f2098904560b9097f0ccf2f3ad6b3..5a30fc8352600f524f86224c88ff09a6c5365a68 100644 (file)
@@ -8,11 +8,9 @@
 
 package org.opendaylight.controller.netconf.confignetconfconnector.operations.runtimerpc;
 
-import java.util.Map;
-
-import javax.management.ObjectName;
-import javax.management.openmbean.OpenType;
-
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
 import org.opendaylight.controller.config.util.ConfigRegistryClient;
 import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
 import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry;
@@ -31,6 +29,7 @@ import org.opendaylight.controller.netconf.confignetconfconnector.operations.Abs
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.Commit;
 import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreSnapshot;
 import org.opendaylight.controller.netconf.mapping.api.HandlingPriority;
+import org.opendaylight.controller.netconf.util.exception.MissingNameSpaceException;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
@@ -39,9 +38,9 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
+import javax.management.ObjectName;
+import javax.management.openmbean.OpenType;
+import java.util.Map;
 
 public class RuntimeRpc extends AbstractConfigNetconfOperation {
 
@@ -56,7 +55,7 @@ public class RuntimeRpc extends AbstractConfigNetconfOperation {
         this.yangStoreSnapshot = yangStoreSnapshot;
     }
 
-    private Element toXml(Document doc, Object result, AttributeIfc returnType, String namespace, String elementName) {
+    private Element toXml(Document doc, Object result, AttributeIfc returnType, String namespace, String elementName) throws NetconfDocumentedException {
         AttributeMappingStrategy<?, ? extends OpenType<?>> mappingStrategy = new ObjectMapper(null).prepareStrategy(returnType);
         Optional<?> mappedAttributeOpt = mappingStrategy.mapAttribute(result);
         Preconditions.checkState(mappedAttributeOpt.isPresent(), "Unable to map return value %s as %s", result, returnType.getOpenType());
@@ -94,7 +93,13 @@ public class RuntimeRpc extends AbstractConfigNetconfOperation {
     }
 
     public NetconfOperationExecution fromXml(final XmlElement xml) throws NetconfDocumentedException {
-        final String namespace = xml.getNamespace();
+        final String namespace;
+        try {
+            namespace = xml.getNamespace();
+        } catch (MissingNameSpaceException e) {
+            logger.trace("Can't get namespace from xml element due to {}",e);
+            throw NetconfDocumentedException.wrap(e);
+        }
         final XmlElement contextInstanceElement = xml.getOnlyChildElement(CONTEXT_INSTANCE);
         final String operationName = xml.getName();
 
@@ -117,12 +122,19 @@ public class RuntimeRpc extends AbstractConfigNetconfOperation {
     }
 
     @Override
-    public HandlingPriority canHandle(Document message) {
-        XmlElement requestElement = getRequestElementWithCheck(message);
+    public HandlingPriority canHandle(Document message) throws NetconfDocumentedException {
+        XmlElement requestElement = null;
+        requestElement = getRequestElementWithCheck(message);
 
         XmlElement operationElement = requestElement.getOnlyChildElement();
         final String netconfOperationName = operationElement.getName();
-        final String netconfOperationNamespace = operationElement.getNamespace();
+        final String netconfOperationNamespace;
+        try {
+            netconfOperationNamespace = operationElement.getNamespace();
+        } catch (MissingNameSpaceException e) {
+            logger.debug("Cannot retrieve netconf operation namespace from message due to {}", e);
+            return HandlingPriority.CANNOT_HANDLE;
+        }
 
         final Optional<XmlElement> contextInstanceElement = operationElement
                 .getOnlyChildElementOptionally(CONTEXT_INSTANCE);
@@ -165,10 +177,7 @@ public class RuntimeRpc extends AbstractConfigNetconfOperation {
 
     @Override
     protected Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws NetconfDocumentedException {
-
-        // TODO exception handling
         // TODO check for namespaces and unknown elements
-
         final NetconfOperationExecution execution = fromXml(xml);
 
         logger.debug("Invoking operation {} on {} with arguments {}", execution.operationName, execution.on,
index d7cbf6680db5a06b311898f1464c99def0768dee..756a38ed940be7e910dc82a90523bbf3cbf48b50 100644 (file)
@@ -15,6 +15,8 @@ import org.opendaylight.controller.config.api.ValidationException;
 import org.opendaylight.controller.config.api.jmx.CommitStatus;
 import org.opendaylight.controller.config.util.ConfigRegistryClient;
 import org.opendaylight.controller.config.util.ConfigTransactionClient;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
+import org.opendaylight.controller.netconf.confignetconfconnector.exception.NoTransactionFoundException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -94,9 +96,14 @@ public class TransactionProvider implements AutoCloseable {
     /**
      * Commit and notification send must be atomic
      */
-    public synchronized CommitStatus commitTransaction() throws ValidationException, ConflictingVersionException {
+    public synchronized CommitStatus commitTransaction() throws ValidationException, ConflictingVersionException, NoTransactionFoundException {
+        if (!getTransaction().isPresent()){
+            throw new NoTransactionFoundException("No transaction found for session " + netconfSessionIdForReporting,
+                    NetconfDocumentedException.ErrorType.application,
+                    NetconfDocumentedException.ErrorTag.operation_failed,
+                    NetconfDocumentedException.ErrorSeverity.error);
+        }
         final Optional<ObjectName> maybeTaON = getTransaction();
-        Preconditions.checkState(maybeTaON.isPresent(), "No transaction found for session " + netconfSessionIdForReporting);
         ObjectName taON = maybeTaON.get();
         try {
             CommitStatus status = configRegistryClient.commitConfig(taON);
index cd38d3babef700c8cb5b55529bbac71fb5e4c943..f151949abc3c859018e02daca7620d25b2d1b34e 100644 (file)
@@ -8,39 +8,11 @@
 
 package org.opendaylight.controller.netconf.confignetconfconnector;
 
-import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.opendaylight.controller.netconf.util.test.XmlUnitUtil.assertContainsElement;
-import static org.opendaylight.controller.netconf.util.test.XmlUnitUtil.assertContainsElementWithText;
-import static org.opendaylight.controller.netconf.util.xml.XmlUtil.readXmlToElement;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.math.BigInteger;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.InstanceNotFoundException;
-import javax.management.ObjectName;
-import javax.xml.parsers.ParserConfigurationException;
-
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
 import org.custommonkey.xmlunit.AbstractNodeTester;
 import org.custommonkey.xmlunit.NodeTest;
 import org.custommonkey.xmlunit.NodeTestException;
@@ -74,7 +46,6 @@ import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleMX
 import org.opendaylight.controller.config.yang.test.impl.Peers;
 import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
-import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationRouter;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.Commit;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.DiscardChanges;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfig;
@@ -85,6 +56,7 @@ import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStore
 import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreSnapshot;
 import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider;
 import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultCloseSession;
+import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationRouter;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceSnapshotImpl;
 import org.opendaylight.controller.netconf.mapping.api.HandlingPriority;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperation;
@@ -111,11 +83,37 @@ import org.w3c.dom.Text;
 import org.w3c.dom.traversal.DocumentTraversal;
 import org.xml.sax.SAXException;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
+import javax.management.ObjectName;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.math.BigInteger;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.opendaylight.controller.netconf.util.test.XmlUnitUtil.assertContainsElement;
+import static org.opendaylight.controller.netconf.util.test.XmlUnitUtil.assertContainsElementWithText;
+import static org.opendaylight.controller.netconf.util.xml.XmlUtil.readXmlToElement;
 
 
 public class NetconfMappingTest extends AbstractConfigTest {
@@ -567,7 +565,7 @@ public class NetconfMappingTest extends AbstractConfigTest {
         assertThat(string, JUnitMatchers.containsString(substring));
     }
 
-    private void checkEnum(final Document response) {
+    private void checkEnum(final Document response) throws NetconfDocumentedException {
         XmlElement modulesElement = XmlElement.fromDomElement(response.getDocumentElement()).getOnlyChildElement("data")
                 .getOnlyChildElement("modules");
 
@@ -591,7 +589,7 @@ public class NetconfMappingTest extends AbstractConfigTest {
         assertEquals(2, testingDepsSize);
     }
 
-    private void checkTypeConfigAttribute(Document response) {
+    private void checkTypeConfigAttribute(Document response) throws NetconfDocumentedException {
 
         XmlElement modulesElement = XmlElement.fromDomElement(response.getDocumentElement()).getOnlyChildElement("data")
                 .getOnlyChildElement("modules");
index ae5a9930d2a3c3d66aaf29a56f626adb3f44c04d..4d9935eafbf77897cc54b7734e9fb4de62bfe348 100644 (file)
@@ -20,7 +20,6 @@ import org.opendaylight.controller.config.api.ServiceReferenceReadableRegistry;
 import org.opendaylight.controller.config.api.ValidationException;
 import org.opendaylight.controller.config.util.ConfigRegistryClient;
 import org.opendaylight.controller.config.util.ConfigTransactionClient;
-import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreSnapshot;
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.AttributeConfigElement;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.InstanceConfigElementResolved;
@@ -30,6 +29,7 @@ import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.Services;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.ValidateTest;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfigXmlParser.EditConfigExecution;
+import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreSnapshot;
 import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider;
 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
 
@@ -104,7 +104,7 @@ public class EditConfigTest {
                 any(ConfigTransactionClient.class), any(ServiceRegistryWrapper.class));
     }
 
-    private EditConfigExecution mockExecution(EditConfigStrategy editStrat) {
+    private EditConfigExecution mockExecution(EditConfigStrategy editStrat) throws NetconfDocumentedException {
         EditConfigExecution mock = mock(EditConfigExecution.class);
         doReturn(getMapping(editStrat)).when(mock).getResolvedXmlElements(any(ConfigTransactionClient.class));
         doReturn(getMappingDefinition(editStrat)).when(mock).getModulesDefinition(any(ConfigTransactionClient.class));
index ed5a3a97a4c67809e75857ba77409eb695e00535..44e90270e7e31e5d691756ef421122d4418f0287 100644 (file)
@@ -59,7 +59,7 @@ public class ConfigPusher {
         this.conflictingVersionTimeoutMillis = conflictingVersionTimeoutMillis;
     }
 
-    public synchronized LinkedHashMap<ConfigSnapshotHolder, EditAndCommitResponse> pushConfigs(List<ConfigSnapshotHolder> configs) {
+    public synchronized LinkedHashMap<ConfigSnapshotHolder, EditAndCommitResponse> pushConfigs(List<ConfigSnapshotHolder> configs) throws NetconfDocumentedException {
         logger.debug("Last config snapshots to be pushed to netconf: {}", configs);
         LinkedHashMap<ConfigSnapshotHolder, EditAndCommitResponse> result = new LinkedHashMap<>();
         // start pushing snapshots:
@@ -78,7 +78,7 @@ public class ConfigPusher {
      * is caught, whole process is retried - new service instance need to be obtained from the factory. Closes
      * {@link NetconfOperationService} after each use.
      */
-    private synchronized EditAndCommitResponse pushConfigWithConflictingVersionRetries(ConfigSnapshotHolder configSnapshotHolder) {
+    private synchronized EditAndCommitResponse pushConfigWithConflictingVersionRetries(ConfigSnapshotHolder configSnapshotHolder) throws NetconfDocumentedException {
         ConflictingVersionException lastException;
         Stopwatch stopwatch = new Stopwatch().start();
         do {
@@ -139,7 +139,7 @@ public class ConfigPusher {
         } else {
             serviceCandidate.close();
             logger.trace("Netconf server did not provide required capabilities for {} " +
-                            "Expected but not found: {}, all expected {}, current {}",
+                    "Expected but not found: {}, all expected {}, current {}",
                     idForReporting, notFoundDiff, expectedCapabilities, serviceCandidate.getCapabilities()
             );
             throw new NotEnoughCapabilitiesException("Not enough capabilities for " + idForReporting + ". Expected but not found: " + notFoundDiff);
@@ -177,7 +177,7 @@ public class ConfigPusher {
      * @throws java.lang.RuntimeException  if edit-config or commit fails otherwise
      */
     private synchronized EditAndCommitResponse pushConfig(ConfigSnapshotHolder configSnapshotHolder, NetconfOperationService operationService)
-            throws ConflictingVersionException {
+            throws ConflictingVersionException, NetconfDocumentedException {
 
         Element xmlToBePersisted;
         try {
@@ -209,7 +209,7 @@ public class ConfigPusher {
         return new EditAndCommitResponse(editResponseMessage, commitResponseMessage);
     }
 
-    private NetconfOperation findOperation(NetconfMessage request, NetconfOperationService operationService) {
+    private NetconfOperation findOperation(NetconfMessage request, NetconfOperationService operationService) throws NetconfDocumentedException {
         TreeMap<HandlingPriority, NetconfOperation> allOperations = new TreeMap<>();
         Set<NetconfOperation> netconfOperations = operationService.getNetconfOperations();
         if (netconfOperations.isEmpty()) {
@@ -228,7 +228,7 @@ public class ConfigPusher {
 
     private Document sendRequestGetResponseCheckIsOK(NetconfMessage request, NetconfOperationService operationService,
                                                      String operationNameForReporting, String configIdForReporting)
-            throws ConflictingVersionException {
+            throws ConflictingVersionException, NetconfDocumentedException {
 
         NetconfOperation operation = findOperation(request, operationService);
         Document response;
@@ -245,7 +245,7 @@ public class ConfigPusher {
     }
 
     // load editConfig.xml template, populate /rpc/edit-config/config with parameter
-    private static NetconfMessage createEditConfigMessage(Element dataElement) {
+    private static NetconfMessage createEditConfigMessage(Element dataElement) throws NetconfDocumentedException {
         String editConfigResourcePath = "/netconfOp/editConfig.xml";
         try (InputStream stream = ConfigPersisterNotificationHandler.class.getResourceAsStream(editConfigResourcePath)) {
             Preconditions.checkNotNull(stream, "Unable to load resource " + editConfigResourcePath);
index 0cc55719e12875ece51220073657867fc3a9c21f..1a261da32342525c1eeaf52aca44e33803692a7c 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.controller.netconf.persist.impl.osgi;
 
 import com.google.common.annotations.VisibleForTesting;
 import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
 import org.opendaylight.controller.netconf.persist.impl.ConfigPersisterNotificationHandler;
@@ -151,7 +152,12 @@ public class ConfigPersisterActivator implements BundleActivator {
             final Thread pushingThread = new Thread(new Runnable() {
                 @Override
                 public void run() {
-                    configPusher.pushConfigs(configs);
+                    try {
+                        configPusher.pushConfigs(configs);
+                    } catch (NetconfDocumentedException e) {
+                        logger.error("Error pushing configs {}",configs);
+                        throw new IllegalStateException(e);
+                    }
                     logger.info("Configuration Persister initialization completed.");
                     ConfigPersisterNotificationHandler jmxNotificationHandler = new ConfigPersisterNotificationHandler(platformMBeanServer, persisterAggregator);
                     synchronized (ConfigPersisterActivator.this) {
index ceeca51defdff65016a842faaa97bfcdc165d6ae..57bd3dd6209d3248dc7c7b969ccaf6f5a33fbbf7 100644 (file)
@@ -90,6 +90,12 @@ public class NetconfDocumentedException extends Exception {
         this.errorInfo = errorInfo;
     }
 
+    public static <E extends Exception> NetconfDocumentedException wrap(E exception) throws NetconfDocumentedException {
+        final Map<String, String> errorInfo = new HashMap<>();
+        errorInfo.put(ErrorTag.operation_failed.name(), "Exception thrown");
+        throw new NetconfDocumentedException(exception.getMessage(), exception, ErrorType.application, ErrorTag.operation_failed,
+                ErrorSeverity.error, errorInfo);
+    }
     public static NetconfDocumentedException wrap(ValidationException e) throws NetconfDocumentedException {
         final Map<String, String> errorInfo = new HashMap<>();
         errorInfo.put(ErrorTag.operation_failed.name(), "Validation failed");
index 83f49b2635a5d0699d2b31615fc3c20927d4f878..f8f73fc8e5296b9534e0759bc43f24bbf493521e 100644 (file)
@@ -8,10 +8,15 @@
 
 package org.opendaylight.controller.netconf.client;
 
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpression;
-
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelFutureListener;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.util.Timer;
+import io.netty.util.concurrent.Promise;
 import org.opendaylight.controller.netconf.api.NetconfClientSessionPreferences;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.netconf.util.AbstractChannelInitializer;
 import org.opendaylight.controller.netconf.util.AbstractNetconfSessionNegotiator;
@@ -26,13 +31,8 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
-import io.netty.channel.Channel;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.ChannelFutureListener;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInboundHandlerAdapter;
-import io.netty.util.Timer;
-import io.netty.util.concurrent.Promise;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
 
 public class NetconfClientSessionNegotiator extends
         AbstractNetconfSessionNegotiator<NetconfClientSessionPreferences, NetconfClientSession, NetconfClientSessionListener>
@@ -54,14 +54,14 @@ public class NetconfClientSessionNegotiator extends
     }
 
     @Override
-    protected void handleMessage(NetconfHelloMessage netconfMessage) {
+    protected void handleMessage(NetconfHelloMessage netconfMessage) throws NetconfDocumentedException {
         NetconfClientSession session = super.getSessionForHelloMessage(netconfMessage);
 
         if (shouldUseExi(netconfMessage.getDocument())){
-            logger.info("Netconf session: {} should use exi.", session);
+            logger.debug("Netconf session: {} should use exi.", session);
             tryToStartExi(session);
         } else {
-            logger.info("Netconf session {} isn't capable using exi.", session);
+            logger.debug("Netconf session {} isn't capable using exi.", session);
             negotiationSuccessful(session);
         }
     }
@@ -109,7 +109,7 @@ public class NetconfClientSessionNegotiator extends
     }
 
     @Override
-    protected NetconfClientSession getSession(NetconfClientSessionListener sessionListener, Channel channel, NetconfHelloMessage message) {
+    protected NetconfClientSession getSession(NetconfClientSessionListener sessionListener, Channel channel, NetconfHelloMessage message) throws NetconfDocumentedException {
         return new NetconfClientSession(sessionListener, channel, extractSessionId(message.getDocument()),
                 NetconfMessageUtil.extractCapabilitiesFromHello(message.getDocument()));
     }
index 07e088e117d636502be739aabff6952eeac62fb9..9e15b49a843c677cdc12ae6bee2a927a2f891df7 100644 (file)
@@ -8,7 +8,14 @@
 
 package org.opendaylight.controller.netconf.client;
 
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Sets;
+import io.netty.channel.Channel;
+import io.netty.util.Timer;
+import io.netty.util.concurrent.Promise;
 import org.opendaylight.controller.netconf.api.NetconfClientSessionPreferences;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessage;
 import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader;
@@ -20,14 +27,8 @@ import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
 import org.openexi.proc.common.AlignmentType;
 import org.openexi.proc.common.EXIOptions;
 import org.openexi.proc.common.EXIOptionsException;
-
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Sets;
-
-import io.netty.channel.Channel;
-import io.netty.util.Timer;
-import io.netty.util.concurrent.Promise;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class NetconfClientSessionNegotiatorFactory implements SessionNegotiatorFactory<NetconfMessage, NetconfClientSession, NetconfClientSessionListener> {
 
@@ -42,6 +43,7 @@ public class NetconfClientSessionNegotiatorFactory implements SessionNegotiatorF
     private final long connectionTimeoutMillis;
     private final Timer timer;
     private final EXIOptions options;
+    private static final Logger logger = LoggerFactory.getLogger(NetconfClientSessionNegotiatorFactory.class);
 
     public NetconfClientSessionNegotiatorFactory(Timer timer,
                                                  Optional<NetconfHelloMessageAdditionalHeader> additionalHeader,
@@ -64,7 +66,13 @@ public class NetconfClientSessionNegotiatorFactory implements SessionNegotiatorF
             Promise<NetconfClientSession> promise) {
 
         NetconfMessage startExiMessage = NetconfStartExiMessage.create(options, START_EXI_MESSAGE_ID);
-        NetconfHelloMessage helloMessage = NetconfHelloMessage.createClientHello(CLIENT_CAPABILITIES, additionalHeader);
+        NetconfHelloMessage helloMessage = null;
+        try {
+            helloMessage = NetconfHelloMessage.createClientHello(CLIENT_CAPABILITIES, additionalHeader);
+        } catch (NetconfDocumentedException e) {
+            logger.error("Unable to create client hello message with capabilities {} and additional handler {}",CLIENT_CAPABILITIES,additionalHeader);
+            throw new IllegalStateException(e);
+        }
 
         NetconfClientSessionPreferences proposal = new NetconfClientSessionPreferences(helloMessage,startExiMessage);
         return new NetconfClientSessionNegotiator(proposal, promise, channel, timer,
index 9694a90c49ad79ebce01b14971fb3605a9a1195e..c62a85aae68d796030d27e954f901c029eb1b1e2 100644 (file)
                             org.opendaylight.controller.netconf.util.mapping,
                             org.opendaylight.controller.netconf.util.osgi,
                             org.opendaylight.controller.netconf.util.xml,
+                            org.opendaylight.controller.netconf.util.exception,
                             org.opendaylight.controller.netconf.util.handler,
                             org.opendaylight.protocol.framework,
                             org.osgi.framework,
index 9106b6ad85ef68ec00e4cbb037c82e1b93047b03..9d958660615c27c27e86fee68e669f7e17c6a1b1 100644 (file)
@@ -8,10 +8,11 @@
 
 package org.opendaylight.controller.netconf.impl;
 
-import static org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider.NetconfOperationProviderUtil.getNetconfSessionIdForReporting;
-
-import java.util.Set;
-
+import com.google.common.collect.Sets;
+import io.netty.channel.Channel;
+import io.netty.util.Timer;
+import io.netty.util.concurrent.Promise;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.api.NetconfServerSessionPreferences;
 import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider;
 import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService;
@@ -22,12 +23,12 @@ import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
 import org.opendaylight.protocol.framework.SessionListenerFactory;
 import org.opendaylight.protocol.framework.SessionNegotiator;
 import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-import com.google.common.collect.Sets;
+import java.util.Set;
 
-import io.netty.channel.Channel;
-import io.netty.util.Timer;
-import io.netty.util.concurrent.Promise;
+import static org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider.NetconfOperationProviderUtil.getNetconfSessionIdForReporting;
 
 public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorFactory<NetconfHelloMessage, NetconfServerSession, NetconfServerSessionListener> {
 
@@ -42,6 +43,7 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF
     private final long connectionTimeoutMillis;
     private final DefaultCommitNotificationProducer commitNotificationProducer;
     private final SessionMonitoringService monitoringService;
+    private static final Logger logger = LoggerFactory.getLogger(NetconfServerSessionNegotiatorFactory.class);
 
     public NetconfServerSessionNegotiatorFactory(Timer timer, NetconfOperationProvider netconfOperationProvider,
                                                  SessionIdProvider idProvider, long connectionTimeoutMillis,
@@ -71,8 +73,14 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF
                 getNetconfSessionIdForReporting(sessionId));
         CapabilityProvider capabilityProvider = new CapabilityProviderImpl(netconfOperationServiceSnapshot);
 
-        NetconfServerSessionPreferences proposal = new NetconfServerSessionPreferences(
-                createHelloMessage(sessionId, capabilityProvider), sessionId);
+        NetconfServerSessionPreferences proposal = null;
+        try {
+            proposal = new NetconfServerSessionPreferences(
+                    createHelloMessage(sessionId, capabilityProvider), sessionId);
+        } catch (NetconfDocumentedException e) {
+            logger.error("Unable to create hello mesage for session {} with capability provider {}", sessionId,capabilityProvider);
+            throw new IllegalStateException(e);
+        }
 
         NetconfServerSessionListenerFactory sessionListenerFactory = new NetconfServerSessionListenerFactory(
                 commitNotificationProducer, monitoringService,
@@ -82,7 +90,7 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF
                 sessionListenerFactory.getSessionListener(), connectionTimeoutMillis);
     }
 
-    private NetconfHelloMessage createHelloMessage(long sessionId, CapabilityProvider capabilityProvider) {
+    private NetconfHelloMessage createHelloMessage(long sessionId, CapabilityProvider capabilityProvider) throws NetconfDocumentedException {
         return NetconfHelloMessage.createServerHello(Sets.union(capabilityProvider.getCapabilities(), DEFAULT_CAPABILITIES), sessionId);
     }
 
index 1a9f5d7393ad469f5e1c8d1cc0862589e65fe185..d6940a1a453fcaaf14f4e6e30292f8dbc427256d 100644 (file)
@@ -8,9 +8,7 @@
 
 package org.opendaylight.controller.netconf.impl.mapping.operations;
 
-import java.io.InputStream;
-import java.util.Map;
-
+import com.google.common.base.Preconditions;
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationRouter;
 import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer;
@@ -26,8 +24,7 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
+import java.io.InputStream;
 
 public class DefaultCommit extends AbstractNetconfOperation {
 
@@ -100,8 +97,14 @@ public class DefaultCommit extends AbstractNetconfOperation {
     }
 
     private boolean isCommitWithoutNotification(Document message) {
-        XmlElement xmlElement = XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
-                XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
+        XmlElement xmlElement = null;
+        try {
+            xmlElement = XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
+                    XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
+        } catch (NetconfDocumentedException e) {
+            logger.trace("Commit operation is not valid due to  {}",e);
+            return false;
+        }
 
         String attr = xmlElement.getAttribute(NOTIFY_ATTR);
 
@@ -120,20 +123,9 @@ public class DefaultCommit extends AbstractNetconfOperation {
                 getConfigMessage, null);
 
         XmlElement dataElement;
-        try {
-            XmlElement xmlElement = XmlElement.fromDomElementWithExpected(responseDocument.getDocumentElement(),
-                    XmlNetconfConstants.RPC_REPLY_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
-            dataElement = xmlElement.getOnlyChildElement(XmlNetconfConstants.DATA_KEY);
-        } catch (IllegalArgumentException e) {
-            final String msg = "Unexpected response from get-config operation";
-            logger.warn(msg, e);
-            Map<String, String> info = Maps.newHashMap();
-            info.put(NetconfDocumentedException.ErrorTag.operation_failed.toString(), e.getMessage());
-            throw new NetconfDocumentedException(msg, e, NetconfDocumentedException.ErrorType.application,
-                    NetconfDocumentedException.ErrorTag.operation_failed,
-                    NetconfDocumentedException.ErrorSeverity.error, info);
-        }
-
+        XmlElement xmlElement = XmlElement.fromDomElementWithExpected(responseDocument.getDocumentElement(),
+                XmlNetconfConstants.RPC_REPLY_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
+        dataElement = xmlElement.getOnlyChildElement(XmlNetconfConstants.DATA_KEY);
         return dataElement.getDomElement();
     }
 
index f50dd3e706e40f60e22457c9f243a489061c4cab..beceb8d008cb6e6b61662cf16f6ea32bd31981ed 100644 (file)
@@ -8,11 +8,11 @@
 
 package org.opendaylight.controller.netconf.impl.mapping.operations;
 
-import java.util.HashMap;
-import java.util.Map;
-
+import com.google.common.base.Optional;
+import com.google.common.collect.Maps;
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider;
+import org.opendaylight.controller.netconf.util.exception.MissingNameSpaceException;
 import org.opendaylight.controller.netconf.util.mapping.AbstractLastNetconfOperation;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
@@ -22,8 +22,7 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import com.google.common.base.Optional;
-import com.google.common.collect.Maps;
+import java.util.Map;
 
 public final class DefaultGetSchema extends AbstractLastNetconfOperation {
     public static final String GET_SCHEMA = "get-schema";
@@ -52,23 +51,7 @@ public final class DefaultGetSchema extends AbstractLastNetconfOperation {
     protected Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws NetconfDocumentedException {
         GetSchemaEntry entry;
 
-        try {
-            entry = new GetSchemaEntry(xml);
-        } catch (final IllegalArgumentException e) {
-            logger.warn("Error parsing xml", e);
-            final Map<String, String> errorInfo = new HashMap<>();
-            errorInfo.put(NetconfDocumentedException.ErrorTag.bad_attribute.name(), e.getMessage());
-            throw new NetconfDocumentedException(e.getMessage(), e, NetconfDocumentedException.ErrorType.rpc,
-                    NetconfDocumentedException.ErrorTag.bad_attribute, NetconfDocumentedException.ErrorSeverity.error,
-                    errorInfo);
-        } catch (final IllegalStateException e) {
-            logger.warn("Error parsing xml", e);
-            final Map<String, String> errorInfo = new HashMap<>();
-            errorInfo.put(NetconfDocumentedException.ErrorTag.bad_attribute.name(), e.getMessage());
-            throw new NetconfDocumentedException(e.getMessage(), e, NetconfDocumentedException.ErrorType.rpc,
-                    NetconfDocumentedException.ErrorTag.bad_attribute, NetconfDocumentedException.ErrorSeverity.error,
-                    errorInfo);
-        }
+        entry = new GetSchemaEntry(xml);
 
         String schema;
         try {
@@ -94,11 +77,17 @@ public final class DefaultGetSchema extends AbstractLastNetconfOperation {
         private final String identifier;
         private final Optional<String> version;
 
-        GetSchemaEntry(XmlElement getSchemaElement) {
+        GetSchemaEntry(XmlElement getSchemaElement) throws NetconfDocumentedException {
             getSchemaElement.checkName(GET_SCHEMA);
             getSchemaElement.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_YANG_IETF_NETCONF_MONITORING);
 
-            XmlElement identifierElement = getSchemaElement.getOnlyChildElementWithSameNamespace(IDENTIFIER);
+            XmlElement identifierElement = null;
+            try {
+                identifierElement = getSchemaElement.getOnlyChildElementWithSameNamespace(IDENTIFIER);
+            } catch (MissingNameSpaceException e) {
+                logger.trace("Can't get identifier element as only child element with same namespace due to {}",e);
+                throw NetconfDocumentedException.wrap(e);
+            }
             identifier = identifierElement.getTextContent();
             Optional<XmlElement> versionElement = getSchemaElement
                     .getOnlyChildElementWithSameNamespaceOptionally(VERSION);
index bb4c76a4b89d327879e637a58a9ea4d919d26878..c2ab36f2c68ac8478d89fc14b02b6729e0ccf072 100644 (file)
@@ -153,7 +153,7 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
     }
 
     private NetconfOperationExecution getNetconfOperationWithHighestPriority(
-            Document message, NetconfServerSession session) {
+            Document message, NetconfServerSession session) throws NetconfDocumentedException {
 
         TreeMap<HandlingPriority, NetconfOperation> sortedByPriority = getSortedNetconfOperationsWithCanHandle(
                 message, session);
@@ -166,7 +166,7 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
     }
 
     private TreeMap<HandlingPriority, NetconfOperation> getSortedNetconfOperationsWithCanHandle(Document message,
-            NetconfServerSession session) {
+            NetconfServerSession session) throws NetconfDocumentedException {
         TreeMap<HandlingPriority, NetconfOperation> sortedPriority = Maps.newTreeMap();
 
         for (NetconfOperation netconfOperation : allNetconfOperations) {
@@ -185,6 +185,21 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
         return sortedPriority;
     }
 
+    public static final NetconfOperationChainedExecution EXECUTION_TERMINATION_POINT = new NetconfOperationChainedExecution() {
+        @Override
+        public boolean isExecutionTermination() {
+            return true;
+        }
+
+        @Override
+        public Document execute(Document requestMessage) throws NetconfDocumentedException {
+            throw new NetconfDocumentedException("This execution represents the termination point in operation execution and cannot be executed itself",
+                    NetconfDocumentedException.ErrorType.application,
+                    NetconfDocumentedException.ErrorTag.operation_failed,
+                    NetconfDocumentedException.ErrorSeverity.error);
+        }
+    };
+
     private static class NetconfOperationExecution implements NetconfOperationChainedExecution {
         private final NetconfOperation netconfOperation;
         private NetconfOperationChainedExecution subsequentExecution;
index d169858d35ff90a720d039f8d8ecc0fa85aa60e3..634a18f852a05184a861fc1ab8ce1eb7073e893b 100644 (file)
@@ -22,16 +22,17 @@ import org.junit.Test;
 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
 import org.opendaylight.controller.config.spi.ModuleFactory;
 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
-import org.opendaylight.controller.netconf.client.test.TestingNetconfClient;
-import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreException;
 import org.opendaylight.controller.config.yang.test.impl.DepTestImplModuleFactory;
 import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleFactory;
 import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleMXBean;
 import org.opendaylight.controller.config.yang.test.impl.TestImplModuleFactory;
 import org.opendaylight.controller.netconf.StubUserManager;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.netconf.client.NetconfClientDispatcher;
+import org.opendaylight.controller.netconf.client.test.TestingNetconfClient;
 import org.opendaylight.controller.netconf.confignetconfconnector.osgi.NetconfOperationServiceFactoryImpl;
+import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreException;
 import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer;
 import org.opendaylight.controller.netconf.impl.NetconfServerDispatcher;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfMonitoringServiceImpl;
@@ -321,17 +322,17 @@ public class NetconfITTest extends AbstractNetconfConfigTest {
         }
     }
 
-    private void assertIsOK(final Document rpcReply) {
+    private void assertIsOK(final Document rpcReply) throws NetconfDocumentedException {
         assertEquals("rpc-reply", rpcReply.getDocumentElement().getLocalName());
         assertEquals("ok", XmlElement.fromDomDocument(rpcReply).getOnlyChildElement().getName());
     }
 
-    private Document assertGetConfigWorks(final TestingNetconfClient netconfClient) throws InterruptedException, ExecutionException, TimeoutException {
+    private Document assertGetConfigWorks(final TestingNetconfClient netconfClient) throws InterruptedException, ExecutionException, TimeoutException, NetconfDocumentedException {
         return assertGetConfigWorks(netconfClient, this.getConfig);
     }
 
     private Document assertGetConfigWorks(final TestingNetconfClient netconfClient, final NetconfMessage getConfigMessage)
-            throws InterruptedException, ExecutionException, TimeoutException {
+            throws InterruptedException, ExecutionException, TimeoutException, NetconfDocumentedException {
         final NetconfMessage rpcReply = netconfClient.sendMessage(getConfigMessage);
         assertNotNull(rpcReply);
         assertEquals("data", XmlElement.fromDomDocument(rpcReply.getDocument()).getOnlyChildElement().getName());
index b70f8dbd39ac9d489b0cb3c1f5cbe8f5f688e054..c7298cbf1e4ae42e91976868cc93851c77bf8f7b 100644 (file)
@@ -33,7 +33,7 @@ public interface NetconfOperation {
      * @param requestMessage
      * @return
      */
-    HandlingPriority canHandle(Document requestMessage);
+    HandlingPriority canHandle(Document message) throws NetconfDocumentedException;
 
     /**
      * Execute current netconf operation and trigger execution of subsequent
index 6730ccbb54f576b32036a28a3536c2710690f87a..03193b84923d98e69e7f6262d5e2e135eb45ab92 100644 (file)
@@ -58,6 +58,7 @@
                             org.opendaylight.controller.netconf.api,
                             org.opendaylight.controller.netconf.mapping.api,
                             org.opendaylight.controller.netconf.util.mapping,
+                            org.opendaylight.controller.netconf.util.exception,
                             org.osgi.framework,
                             org.slf4j,
                             org.w3c.dom,
index 08da36148fa235cf20e8b006c052f985342e4dbf..6449c3e05fa39a6510e27d59ed69664e243e29b2 100644 (file)
@@ -7,8 +7,8 @@
  */
 package org.opendaylight.controller.netconf.monitoring;
 
-import java.util.Map;
-
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService;
 import org.opendaylight.controller.netconf.mapping.api.HandlingPriority;
@@ -24,8 +24,7 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
+import java.util.Map;
 
 public class Get extends AbstractNetconfOperation {
 
@@ -37,10 +36,11 @@ public class Get extends AbstractNetconfOperation {
         this.netconfMonitor = netconfMonitor;
     }
 
-    private Element getPlaceholder(Document innerResult) {
+    private Element getPlaceholder(Document innerResult) throws NetconfDocumentedException {
         try {
-            XmlElement rootElement = XmlElement.fromDomElementWithExpected(innerResult.getDocumentElement(),
-                    XmlNetconfConstants.RPC_REPLY_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
+            XmlElement rootElement = null;
+            rootElement = XmlElement.fromDomElementWithExpected(innerResult.getDocumentElement(),
+                    XmlNetconfConstants.RPC_REPLY_KEY, XmlNetconfConstants.RFC4741_TARGET_NAMESPACE);
             return rootElement.getOnlyChildElement(XmlNetconfConstants.DATA_KEY).getDomElement();
         } catch (RuntimeException e) {
             throw new IllegalArgumentException(String.format(
index 45807a83334f8e655b268c00bcb9c9e163ccf88f..c2d067915516b27efb44bd5a7644f942744a13d2 100644 (file)
@@ -7,17 +7,18 @@
  */
 package org.opendaylight.controller.netconf.ssh;
 
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.util.concurrent.atomic.AtomicLong;
-import javax.annotation.concurrent.ThreadSafe;
 import org.opendaylight.controller.netconf.ssh.authentication.AuthProvider;
 import org.opendaylight.controller.netconf.ssh.threads.SocketThread;
 import org.opendaylight.controller.usermanager.IUserManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.annotation.concurrent.ThreadSafe;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.util.concurrent.atomic.AtomicLong;
+
 @ThreadSafe
 public class NetconfSSHServer implements Runnable {
 
@@ -69,7 +70,7 @@ public class NetconfSSHServer implements Runnable {
             try {
                SocketThread.start(ss.accept(), clientAddress, sesssionId.incrementAndGet(),authProvider);
             } catch (IOException e) {
-                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+                logger.error("Exception occurred during socket thread initialization {}",e);
             }
         }
     }
index 25db5f3f426c03959b32f4f7575b5dc99193de22..65d2954afd9d0f2e1cd607acb170b2b444928cb7 100644 (file)
@@ -77,7 +77,8 @@
                             org.opendaylight.controller.netconf.util.mapping,
                             org.opendaylight.controller.netconf.util.messages,
                             org.opendaylight.controller.netconf.util.handler,
-                            org.opendaylight.controller.netconf.util.handler.*,</Export-Package>
+                            org.opendaylight.controller.netconf.util.handler.*,
+                            org.opendaylight.controller.netconf.util.exception,</Export-Package>
             <Import-Package>com.google.common.base,
                             com.google.common.collect,
                             ch.ethz.ssh2,
index 724b45bc08d867f6702ae75a11aece291fefd484..5521e28818b20fcb9291089ced8867cce787e2e6 100644 (file)
@@ -21,6 +21,7 @@ import io.netty.util.TimerTask;
 import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.GenericFutureListener;
 import io.netty.util.concurrent.Promise;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.netconf.api.NetconfSessionListener;
 import org.opendaylight.controller.netconf.api.NetconfSessionPreferences;
@@ -133,12 +134,12 @@ extends AbstractSessionNegotiator<NetconfHelloMessage, S> {
     }
 
     @Override
-    protected void handleMessage(NetconfHelloMessage netconfMessage) {
-        S session = getSessionForHelloMessage(netconfMessage);
+    protected void handleMessage(NetconfHelloMessage netconfMessage) throws NetconfDocumentedException {
+        S session = getSessionForHelloMessage(netconfMessage)   ;
         negotiationSuccessful(session);
     }
 
-    protected final S getSessionForHelloMessage(NetconfHelloMessage netconfMessage) {
+    protected final S getSessionForHelloMessage(NetconfHelloMessage netconfMessage) throws NetconfDocumentedException {
         Preconditions.checkNotNull(netconfMessage, "netconfMessage");
 
         final Document doc = netconfMessage.getDocument();
@@ -180,7 +181,7 @@ extends AbstractSessionNegotiator<NetconfHelloMessage, S> {
         return channel.pipeline().replace(handlerKey, handlerKey, decoder);
     }
 
-    protected abstract S getSession(L sessionListener, Channel channel, NetconfHelloMessage message);
+    protected abstract S getSession(L sessionListener, Channel channel, NetconfHelloMessage message) throws NetconfDocumentedException;
 
     protected synchronized void changeState(final State newState) {
         logger.debug("Changing state from : {} to : {}", state, newState);
index 29f40ce6242e7fcada70574b774a56ff1a5fab99..9443f93f920f9720e13908c6319a139f4be0f6b0 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.controller.netconf.util;
 
 import com.google.common.base.Preconditions;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
@@ -52,11 +53,7 @@ public final class NetconfUtil {
         return (doc == null) ? null : new NetconfMessage(doc);
     }
 
-    public static Document checkIsMessageOk(NetconfMessage responseMessage) {
-        return checkIsMessageOk(responseMessage.getDocument());
-    }
-
-    public static Document checkIsMessageOk(Document response) {
+    public static Document checkIsMessageOk(Document response) throws NetconfDocumentedException {
         XmlElement element = XmlElement.fromDomDocument(response);
         Preconditions.checkState(element.getName().equals(XmlNetconfConstants.RPC_REPLY_KEY));
         element = element.getOnlyChildElement();
diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/exception/MissingNameSpaceException.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/exception/MissingNameSpaceException.java
new file mode 100644 (file)
index 0000000..0a3e0b3
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * 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.exception;
+
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
+
+import java.util.Collections;
+import java.util.Map;
+
+public class MissingNameSpaceException extends NetconfDocumentedException {
+
+    public MissingNameSpaceException(final String message, final ErrorType errorType, final ErrorTag errorTag,
+                                      final ErrorSeverity errorSeverity) {
+        this(message, errorType, errorTag, errorSeverity, Collections.<String, String> emptyMap());
+    }
+
+    public MissingNameSpaceException(final String message, final ErrorType errorType, final ErrorTag errorTag,
+                                      final ErrorSeverity errorSeverity, final Map<String, String> errorInfo){
+        super(message,errorType,errorTag,errorSeverity,errorInfo);
+    }
+}
diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/exception/UnexpectedElementException.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/exception/UnexpectedElementException.java
new file mode 100644 (file)
index 0000000..b470ce1
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * 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.exception;
+
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
+
+import java.util.Collections;
+import java.util.Map;
+
+public class UnexpectedElementException extends NetconfDocumentedException {
+
+    public UnexpectedElementException(final String message, final ErrorType errorType, final ErrorTag errorTag,
+                                        final ErrorSeverity errorSeverity) {
+        this(message, errorType, errorTag, errorSeverity, Collections.<String, String> emptyMap());
+    }
+
+    public UnexpectedElementException(final String message, final ErrorType errorType, final ErrorTag errorTag,
+                                        final ErrorSeverity errorSeverity, final Map<String, String> errorInfo){
+        super(message,errorType,errorTag,errorSeverity,errorInfo);
+    }
+}
diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/exception/UnexpectedNamespaceException.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/exception/UnexpectedNamespaceException.java
new file mode 100644 (file)
index 0000000..50d7670
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * 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.exception;
+
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
+
+import java.util.Collections;
+import java.util.Map;
+
+public class UnexpectedNamespaceException extends NetconfDocumentedException {
+
+    public UnexpectedNamespaceException(final String message, final ErrorType errorType, final ErrorTag errorTag,
+                                          final ErrorSeverity errorSeverity) {
+        this(message, errorType, errorTag, errorSeverity, Collections.<String, String> emptyMap());
+    }
+
+    public UnexpectedNamespaceException(final String message, final ErrorType errorType, final ErrorTag errorTag,
+                                          final ErrorSeverity errorSeverity, final Map<String, String> errorInfo){
+        super(message,errorType,errorTag,errorSeverity,errorInfo);
+    }
+}
index d6d57c50aceabf543bcc367bb8022ccc79b1ec72..c40bf3909a029e275467ce7c987fa6fe05063e2c 100644 (file)
@@ -14,8 +14,6 @@ import org.opendaylight.controller.netconf.util.xml.XmlElement;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import com.google.common.base.Preconditions;
-
 public abstract class AbstractLastNetconfOperation extends AbstractNetconfOperation {
 
     protected AbstractLastNetconfOperation(String netconfSessionIdForReporting) {
@@ -25,8 +23,12 @@ public abstract class AbstractLastNetconfOperation extends AbstractNetconfOperat
     @Override
     protected Element handle(Document document, XmlElement operationElement,
             NetconfOperationChainedExecution subsequentOperation) throws NetconfDocumentedException {
-        Preconditions.checkArgument(subsequentOperation.isExecutionTermination(),
-                "No netconf operation expected to be subsequent to %s, but is %s", this, subsequentOperation);
+        if (!subsequentOperation.isExecutionTermination()){
+            throw new NetconfDocumentedException(String.format("No netconf operation expected to be subsequent to %s, but is %s", this, subsequentOperation),
+                    NetconfDocumentedException.ErrorType.application,
+                    NetconfDocumentedException.ErrorTag.malformed_message,
+                    NetconfDocumentedException.ErrorSeverity.error);
+        }
 
         return handleWithNoSubsequentOperations(document, operationElement);
     }
index b7bbd3c6a70199cac0915d412568aae7d796d594..65ca1b7c4b5118b00653aa5daf9d0416342532ef 100644 (file)
@@ -17,6 +17,8 @@ import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedEx
 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.Attr;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -26,6 +28,7 @@ import com.google.common.base.Optional;
 
 public abstract class AbstractNetconfOperation implements NetconfOperation {
     private final String netconfSessionIdForReporting;
+    private static final Logger logger = LoggerFactory.getLogger(AbstractNetconfOperation.class);
 
     protected AbstractNetconfOperation(String netconfSessionIdForReporting) {
         this.netconfSessionIdForReporting = netconfSessionIdForReporting;
@@ -36,16 +39,18 @@ public abstract class AbstractNetconfOperation implements NetconfOperation {
     }
 
     @Override
-    public HandlingPriority canHandle(Document message) {
-        OperationNameAndNamespace operationNameAndNamespace = new OperationNameAndNamespace(message);
+    public HandlingPriority canHandle(Document message) throws NetconfDocumentedException {
+        OperationNameAndNamespace operationNameAndNamespace = null;
+        operationNameAndNamespace = new OperationNameAndNamespace(message);
         return canHandle(operationNameAndNamespace.getOperationName(), operationNameAndNamespace.getNamespace());
     }
 
     public static final class OperationNameAndNamespace {
         private final String operationName, namespace;
 
-        public OperationNameAndNamespace(Document message) {
-            XmlElement requestElement = getRequestElementWithCheck(message);
+        public OperationNameAndNamespace(Document message) throws NetconfDocumentedException {
+            XmlElement requestElement = null;
+            requestElement = getRequestElementWithCheck(message);
 
             XmlElement operationElement = requestElement.getOnlyChildElement();
             operationName = operationElement.getName();
@@ -61,7 +66,7 @@ public abstract class AbstractNetconfOperation implements NetconfOperation {
         }
     }
 
-    protected static XmlElement getRequestElementWithCheck(Document message) {
+    protected static XmlElement getRequestElementWithCheck(Document message) throws NetconfDocumentedException {
         return XmlElement.fromDomElementWithExpected(message.getDocumentElement(), XmlNetconfConstants.RPC_KEY,
                 XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
     }
index e3eb45070453f038240faebebe584e6ad742d977..3fd25e814d697d37e607e1e0ade520db254e83a8 100644 (file)
@@ -8,8 +8,9 @@
 
 package org.opendaylight.controller.netconf.util.messages;
 
-import java.util.Set;
-
+import com.google.common.base.Optional;
+import com.google.common.collect.Sets;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
@@ -17,8 +18,7 @@ import org.opendaylight.controller.netconf.util.xml.XmlUtil;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import com.google.common.base.Optional;
-import com.google.common.collect.Sets;
+import java.util.Set;
 
 /**
  * NetconfMessage that can carry additional header with session metadata. See {@link org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader}
@@ -29,13 +29,13 @@ public final class NetconfHelloMessage extends NetconfMessage {
 
     private final NetconfHelloMessageAdditionalHeader additionalHeader;
 
-    public NetconfHelloMessage(Document doc, NetconfHelloMessageAdditionalHeader additionalHeader) {
+    public NetconfHelloMessage(Document doc, NetconfHelloMessageAdditionalHeader additionalHeader) throws NetconfDocumentedException {
         super(doc);
         checkHelloMessage(doc);
         this.additionalHeader = additionalHeader;
     }
 
-    public NetconfHelloMessage(Document doc) {
+    public NetconfHelloMessage(Document doc) throws NetconfDocumentedException {
         this(doc, null);
     }
 
@@ -43,20 +43,14 @@ public final class NetconfHelloMessage extends NetconfMessage {
         return additionalHeader== null ? Optional.<NetconfHelloMessageAdditionalHeader>absent() : Optional.of(additionalHeader);
     }
 
-    private static void checkHelloMessage(Document doc) {
-        try {
-            XmlElement.fromDomElementWithExpected(doc.getDocumentElement(), HELLO_TAG,
-                    XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
+    private static void checkHelloMessage(Document doc) throws NetconfDocumentedException {
+        XmlElement.fromDomElementWithExpected(doc.getDocumentElement(), HELLO_TAG,
+                XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
 
-        } catch (IllegalArgumentException | IllegalStateException e) {
-            throw new IllegalArgumentException(String.format(
-                    "Hello message invalid format, should contain %s tag from namespace %s, but is: %s", HELLO_TAG,
-                    XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, XmlUtil.toString(doc)), e);
-        }
     }
 
     public static NetconfHelloMessage createClientHello(Iterable<String> capabilities,
-                                                        Optional<NetconfHelloMessageAdditionalHeader> additionalHeaderOptional) {
+                                                        Optional<NetconfHelloMessageAdditionalHeader> additionalHeaderOptional) throws NetconfDocumentedException {
         Document doc = createHelloMessageDoc(capabilities);
         return additionalHeaderOptional.isPresent() ? new NetconfHelloMessage(doc, additionalHeaderOptional.get())
                 : new NetconfHelloMessage(doc);
@@ -80,7 +74,7 @@ public final class NetconfHelloMessage extends NetconfMessage {
         return doc;
     }
 
-    public static NetconfHelloMessage createServerHello(Set<String> capabilities, long sessionId) {
+    public static NetconfHelloMessage createServerHello(Set<String> capabilities, long sessionId) throws NetconfDocumentedException {
         Document doc = createHelloMessageDoc(capabilities);
         Element sessionIdElement = doc.createElement(XmlNetconfConstants.SESSION_ID);
         sessionIdElement.setTextContent(Long.toString(sessionId));
index e4d97cf65af4ef805b6ecf9cff3133a65cf964ab..49395d53d21225a20b6d47491db0e05fd03626eb 100644 (file)
@@ -10,9 +10,12 @@ package org.opendaylight.controller.netconf.util.messages;
 
 import com.google.common.base.Function;
 import com.google.common.collect.Collections2;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 
 import javax.annotation.Nullable;
@@ -21,39 +24,41 @@ import java.util.List;
 
 public final class NetconfMessageUtil {
 
+    private static final Logger logger = LoggerFactory.getLogger(NetconfMessageUtil.class);
+
     private NetconfMessageUtil() {}
 
-    public static boolean isOKMessage(NetconfMessage message) {
+    public static boolean isOKMessage(NetconfMessage message) throws NetconfDocumentedException {
         return isOKMessage(message.getDocument());
     }
 
-    public static boolean isOKMessage(Document document) {
+    public static boolean isOKMessage(Document document) throws NetconfDocumentedException {
         return isOKMessage(XmlElement.fromDomDocument(document));
     }
 
-    public static boolean isOKMessage(XmlElement xmlElement) {
+    public static boolean isOKMessage(XmlElement xmlElement) throws NetconfDocumentedException {
         if(xmlElement.getChildElements().size() != 1) {
             return false;
         }
         return xmlElement.getOnlyChildElement().getName().equals(XmlNetconfConstants.OK);
     }
 
-    public static boolean isErrorMessage(NetconfMessage message) {
+    public static boolean isErrorMessage(NetconfMessage message) throws NetconfDocumentedException {
         return isErrorMessage(message.getDocument());
     }
 
-    public static boolean isErrorMessage(Document document) {
+    public static boolean isErrorMessage(Document document) throws NetconfDocumentedException {
         return isErrorMessage(XmlElement.fromDomDocument(document));
     }
 
-    public static boolean isErrorMessage(XmlElement xmlElement) {
+    public static boolean isErrorMessage(XmlElement xmlElement) throws NetconfDocumentedException {
         if(xmlElement.getChildElements().size() != 1) {
             return false;
         }
         return xmlElement.getOnlyChildElement().getName().equals(XmlNetconfConstants.RPC_ERROR);
     }
 
-    public static Collection<String> extractCapabilitiesFromHello(Document doc) {
+    public static Collection<String> extractCapabilitiesFromHello(Document doc) throws NetconfDocumentedException {
         XmlElement responseElement = XmlElement.fromDomDocument(doc);
         XmlElement capabilitiesElement = responseElement
                 .getOnlyChildElementWithSameNamespace(XmlNetconfConstants.CAPABILITIES);
@@ -64,7 +69,12 @@ public final class NetconfMessageUtil {
             @Override
             public String apply(@Nullable XmlElement input) {
                 // Trim possible leading/tailing whitespace
-                return input.getTextContent().trim();
+                try {
+                    return input.getTextContent().trim();
+                } catch (NetconfDocumentedException e) {
+                    logger.trace("Error fetching inpit text content becauese {}",e);
+                    return null;
+                }
             }
         });
 
index 1fbae1ee2d6e52c404742655ccd059e9038fd803..17ea3740fca77cd6124daad71050de6383970dc5 100644 (file)
@@ -9,11 +9,16 @@
 package org.opendaylight.controller.netconf.util.xml;
 
 import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
 import com.google.common.base.Predicate;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
+import org.opendaylight.controller.netconf.util.exception.MissingNameSpaceException;
+import org.opendaylight.controller.netconf.util.exception.UnexpectedElementException;
+import org.opendaylight.controller.netconf.util.exception.UnexpectedNamespaceException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -34,6 +39,7 @@ import java.util.Map;
 public final class XmlElement {
 
     private final Element element;
+    private static final Logger logger = LoggerFactory.getLogger(XmlElement.class);
 
     private XmlElement(Element element) {
         this.element = element;
@@ -47,27 +53,27 @@ public final class XmlElement {
         return new XmlElement(xml.getDocumentElement());
     }
 
-    public static XmlElement fromString(String s) {
+    public static XmlElement fromString(String s) throws NetconfDocumentedException {
         try {
             return new XmlElement(XmlUtil.readXmlToElement(s));
         } catch (IOException | SAXException e) {
-            throw new IllegalArgumentException("Unable to create from " + s, e);
+            throw NetconfDocumentedException.wrap(e);
         }
     }
 
-    public static XmlElement fromDomElementWithExpected(Element element, String expectedName) {
+    public static XmlElement fromDomElementWithExpected(Element element, String expectedName) throws NetconfDocumentedException {
         XmlElement xmlElement = XmlElement.fromDomElement(element);
         xmlElement.checkName(expectedName);
         return xmlElement;
     }
 
-    public static XmlElement fromDomElementWithExpected(Element element, String expectedName, String expectedNamespace) {
+    public static XmlElement fromDomElementWithExpected(Element element, String expectedName, String expectedNamespace) throws NetconfDocumentedException {
         XmlElement xmlElement = XmlElement.fromDomElementWithExpected(element, expectedName);
         xmlElement.checkNamespace(expectedNamespace);
         return xmlElement;
     }
 
-    private static Map<String, String> extractNamespaces(Element typeElement) {
+    private static Map<String, String> extractNamespaces(Element typeElement) throws NetconfDocumentedException {
         Map<String, String> namespaces = new HashMap<>();
         NamedNodeMap attributes = typeElement.getAttributes();
         for (int i = 0; i < attributes.getLength(); i++) {
@@ -78,7 +84,12 @@ public final class XmlElement {
                 if (attribKey.equals(XmlUtil.XMLNS_ATTRIBUTE_KEY)) {
                     prefix = "";
                 } else {
-                    Preconditions.checkState(attribKey.startsWith(XmlUtil.XMLNS_ATTRIBUTE_KEY + ":"));
+                    if (!attribKey.startsWith(XmlUtil.XMLNS_ATTRIBUTE_KEY + ":")){
+                        throw new NetconfDocumentedException("Attribute doesn't start with :",
+                                NetconfDocumentedException.ErrorType.application,
+                                NetconfDocumentedException.ErrorTag.invalid_value,
+                                NetconfDocumentedException.ErrorSeverity.error);
+                    }
                     prefix = attribKey.substring(XmlUtil.XMLNS_ATTRIBUTE_KEY.length() + 1);
                 }
                 namespaces.put(prefix, attribute.getNodeValue());
@@ -87,19 +98,38 @@ public final class XmlElement {
         return namespaces;
     }
 
-    public void checkName(String expectedName) {
-        Preconditions.checkArgument(getName().equals(expectedName), "Expected %s xml element but was %s", expectedName,
-                getName());
+    public void checkName(String expectedName) throws UnexpectedElementException {
+        if (!getName().equals(expectedName)){
+            throw new UnexpectedElementException(String.format("Expected %s xml element but was %s", expectedName,
+                    getName()),
+                    NetconfDocumentedException.ErrorType.application,
+                    NetconfDocumentedException.ErrorTag.operation_failed,
+                    NetconfDocumentedException.ErrorSeverity.error);
+        }
     }
 
-    public void checkNamespaceAttribute(String expectedNamespace) {
-        Preconditions.checkArgument(getNamespaceAttribute().equals(expectedNamespace),
-                "Unexpected namespace %s for element %s, should be %s", getNamespaceAttribute(), expectedNamespace);
+    public void checkNamespaceAttribute(String expectedNamespace) throws UnexpectedNamespaceException, MissingNameSpaceException {
+        if (!getNamespaceAttribute().equals(expectedNamespace))
+        {
+            throw new UnexpectedNamespaceException(String.format("Unexpected namespace %s for element %s, should be %s",
+                    getNamespaceAttribute(),
+                    expectedNamespace),
+                    NetconfDocumentedException.ErrorType.application,
+                    NetconfDocumentedException.ErrorTag.operation_failed,
+                    NetconfDocumentedException.ErrorSeverity.error);
+        }
     }
 
-    public void checkNamespace(String expectedNamespace) {
-        Preconditions.checkArgument(getNamespace().equals(expectedNamespace),
-                "Unexpected namespace %s for element %s, should be %s", getNamespace(), expectedNamespace);
+    public void checkNamespace(String expectedNamespace) throws UnexpectedNamespaceException, MissingNameSpaceException {
+        if (!getNamespace().equals(expectedNamespace))
+       {
+            throw new UnexpectedNamespaceException(String.format("Unexpected namespace %s for element %s, should be %s",
+                    getNamespace(),
+                    expectedNamespace),
+                    NetconfDocumentedException.ErrorType.application,
+                    NetconfDocumentedException.ErrorTag.operation_failed,
+                    NetconfDocumentedException.ErrorSeverity.error);
+        }
     }
 
     public String getName() {
@@ -184,7 +214,11 @@ public final class XmlElement {
         return getChildElementsInternal(new ElementFilteringStrategy() {
             @Override
             public boolean accept(Element e) {
-                return XmlElement.fromDomElement(e).getNamespace().equals(namespace);
+                try {
+                    return XmlElement.fromDomElement(e).getNamespace().equals(namespace);
+                } catch (MissingNameSpaceException e1) {
+                    return false;
+                }
             }
 
         });
@@ -199,9 +233,14 @@ public final class XmlElement {
         });
     }
 
-    public XmlElement getOnlyChildElement(String childName) {
+    public XmlElement getOnlyChildElement(String childName) throws NetconfDocumentedException {
         List<XmlElement> nameElements = getChildElements(childName);
-        Preconditions.checkState(nameElements.size() == 1, "One element " + childName + " expected in " + toString());
+        if (nameElements.size() != 1){
+            throw new NetconfDocumentedException("One element " + childName + " expected in " + toString(),
+                    NetconfDocumentedException.ErrorType.application,
+                    NetconfDocumentedException.ErrorTag.invalid_value,
+                    NetconfDocumentedException.ErrorSeverity.error);
+        }
         return nameElements.get(0);
     }
 
@@ -221,7 +260,7 @@ public final class XmlElement {
         }
     }
 
-    public XmlElement getOnlyChildElementWithSameNamespace(String childName) {
+    public XmlElement getOnlyChildElementWithSameNamespace(String childName) throws  NetconfDocumentedException {
         return getOnlyChildElement(childName, getNamespace());
     }
 
@@ -233,7 +272,7 @@ public final class XmlElement {
         }
     }
 
-    public XmlElement getOnlyChildElementWithSameNamespace() {
+    public XmlElement getOnlyChildElementWithSameNamespace() throws NetconfDocumentedException {
         XmlElement childElement = getOnlyChildElement();
         childElement.checkNamespace(getNamespace());
         return childElement;
@@ -249,7 +288,7 @@ public final class XmlElement {
         }
     }
 
-    public XmlElement getOnlyChildElement(final String childName, String namespace) {
+    public XmlElement getOnlyChildElement(final String childName, String namespace) throws NetconfDocumentedException {
         List<XmlElement> children = getChildElementsWithinNamespace(namespace);
         children = Lists.newArrayList(Collections2.filter(children, new Predicate<XmlElement>() {
             @Override
@@ -257,38 +296,69 @@ public final class XmlElement {
                 return xmlElement.getName().equals(childName);
             }
         }));
-        Preconditions.checkState(children.size() == 1, "One element %s:%s expected in %s but was %s", namespace,
-                childName, toString(), children.size());
+        if (children.size() != 1){
+            throw new NetconfDocumentedException(String.format("One element %s:%s expected in %s but was %s", namespace,
+                    childName, toString(), children.size()),
+                    NetconfDocumentedException.ErrorType.application,
+                    NetconfDocumentedException.ErrorTag.invalid_value,
+                    NetconfDocumentedException.ErrorSeverity.error);
+        }
+
         return children.get(0);
     }
 
-    public XmlElement getOnlyChildElement() {
+    public XmlElement getOnlyChildElement() throws NetconfDocumentedException {
         List<XmlElement> children = getChildElements();
-        Preconditions.checkState(children.size() == 1, "One element expected in %s but was %s", toString(),
-                children.size());
+        if (children.size() != 1){
+            throw new NetconfDocumentedException(String.format( "One element expected in %s but was %s", toString(),
+                    children.size()),
+                    NetconfDocumentedException.ErrorType.application,
+                    NetconfDocumentedException.ErrorTag.invalid_value,
+                    NetconfDocumentedException.ErrorSeverity.error);
+        }
         return children.get(0);
     }
 
-    public String getTextContent() {
+    public String getTextContent() throws NetconfDocumentedException {
         Node textChild = element.getFirstChild();
-        Preconditions.checkNotNull(textChild, "Child node expected, got null for " + getName() + " : " + element);
-        Preconditions.checkState(textChild instanceof Text, getName() + " should contain text." +
-                Text.class.getName() + " expected, got " + textChild);
+        if (null == textChild){
+            throw new NetconfDocumentedException(String.format( "Child node expected, got null for " + getName() + " : " + element),
+                    NetconfDocumentedException.ErrorType.application,
+                    NetconfDocumentedException.ErrorTag.invalid_value,
+                    NetconfDocumentedException.ErrorSeverity.error);
+        }
+        if (!(textChild instanceof Text)){
+            throw new NetconfDocumentedException(String.format(getName() + " should contain text." +
+                    Text.class.getName() + " expected, got " + textChild),
+                    NetconfDocumentedException.ErrorType.application,
+                    NetconfDocumentedException.ErrorTag.invalid_value,
+                    NetconfDocumentedException.ErrorSeverity.error);
+        }
         String content = textChild.getTextContent();
         // Trim needed
         return content.trim();
     }
 
-    public String getNamespaceAttribute() {
+    public String getNamespaceAttribute() throws MissingNameSpaceException {
         String attribute = element.getAttribute(XmlUtil.XMLNS_ATTRIBUTE_KEY);
-        Preconditions.checkState(attribute != null && !attribute.equals(""), "Element %s must specify namespace",
-                toString());
+        if (attribute == null || attribute.equals("")){
+            throw new MissingNameSpaceException(String.format("Element %s must specify namespace",
+                    toString()),
+                    NetconfDocumentedException.ErrorType.application,
+                    NetconfDocumentedException.ErrorTag.operation_failed,
+                    NetconfDocumentedException.ErrorSeverity.error);
+        }
         return attribute;
     }
 
-    public String getNamespace() {
+    public String getNamespace() throws MissingNameSpaceException {
         String namespaceURI = element.getNamespaceURI();
-        Preconditions.checkState(namespaceURI != null, "No namespace defined for %s", this);
+        if (namespaceURI  == null || namespaceURI.equals("")){
+            throw new MissingNameSpaceException(String.format("No namespace defined for %s", this),
+                    NetconfDocumentedException.ErrorType.application,
+                    NetconfDocumentedException.ErrorTag.operation_failed,
+                    NetconfDocumentedException.ErrorSeverity.error);
+        }
         return namespaceURI;
     }
 
@@ -297,7 +367,11 @@ public final class XmlElement {
         final StringBuilder sb = new StringBuilder("XmlElement{");
         sb.append("name='").append(getName()).append('\'');
         if (element.getNamespaceURI() != null) {
-            sb.append(", namespace='").append(getNamespace()).append('\'');
+            try {
+                sb.append(", namespace='").append(getNamespace()).append('\'');
+            } catch (MissingNameSpaceException e) {
+                logger.trace("Missing namespace for element.");
+            }
         }
         sb.append('}');
         return sb.toString();
@@ -316,7 +390,7 @@ public final class XmlElement {
      * namespace is returned with empty string as key. If no default namespace
      * is found value will be null.
      */
-    public Map.Entry<String/* prefix */, String/* namespace */> findNamespaceOfTextContent() {
+    public Map.Entry<String/* prefix */, String/* namespace */> findNamespaceOfTextContent() throws NetconfDocumentedException {
         Map<String, String> namespaces = extractNamespaces(element);
         String textContent = getTextContent();
         int indexOfColon = textContent.indexOf(':');
@@ -333,7 +407,7 @@ public final class XmlElement {
         return Maps.immutableEntry(prefix, namespaces.get(prefix));
     }
 
-    public List<XmlElement> getChildElementsWithSameNamespace(final String childName) {
+    public List<XmlElement> getChildElementsWithSameNamespace(final String childName) throws MissingNameSpaceException {
         List<XmlElement> children = getChildElementsWithinNamespace(getNamespace());
         return Lists.newArrayList(Collections2.filter(children, new Predicate<XmlElement>() {
             @Override
@@ -344,17 +418,22 @@ public final class XmlElement {
     }
 
     public void checkUnrecognisedElements(List<XmlElement> recognisedElements,
-            XmlElement... additionalRecognisedElements) {
+            XmlElement... additionalRecognisedElements) throws NetconfDocumentedException {
         List<XmlElement> childElements = getChildElements();
         childElements.removeAll(recognisedElements);
         for (XmlElement additionalRecognisedElement : additionalRecognisedElements) {
             childElements.remove(additionalRecognisedElement);
         }
-        Preconditions.checkState(childElements.isEmpty(), "Unrecognised elements %s in %s", childElements, this);
+        if (!childElements.isEmpty()){
+            throw new NetconfDocumentedException(String.format("Unrecognised elements %s in %s", childElements, this),
+                    NetconfDocumentedException.ErrorType.application,
+                    NetconfDocumentedException.ErrorTag.invalid_value,
+                    NetconfDocumentedException.ErrorSeverity.error);
+        }
     }
 
-    public void checkUnrecognisedElements(XmlElement... additionalRecognisedElements) {
-        checkUnrecognisedElements(Collections.<XmlElement> emptyList(), additionalRecognisedElements);
+    public void checkUnrecognisedElements(XmlElement... additionalRecognisedElements) throws NetconfDocumentedException {
+        checkUnrecognisedElements(Collections.<XmlElement>emptyList(), additionalRecognisedElements);
     }
 
     @Override
@@ -383,10 +462,10 @@ public final class XmlElement {
     public boolean hasNamespace() {
         try {
             getNamespaceAttribute();
-        } catch (IllegalStateException e) {
+        } catch (MissingNameSpaceException e) {
             try {
                 getNamespace();
-            } catch (IllegalStateException e1) {
+            } catch (MissingNameSpaceException e1) {
                 return false;
             }
             return true;
index d0be73843b0aa3b9c3243e942e91f8aab5d2aa31..39a49544a576abe3bd65403c864aa1b4572fc898 100644 (file)
@@ -43,6 +43,8 @@ public final class XmlNetconfConstants {
     public static final String SESSION_ID = "session-id";
 
     //
+    // TODO duplicate
+    public static final String RFC4741_TARGET_NAMESPACE = "urn:ietf:params:xml:ns:netconf:base:1.0";
     public static final String URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0 = "urn:ietf:params:xml:ns:netconf:base:1.0";
     public static final String URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_1 = "urn:ietf:params:xml:ns:netconf:base:1.1";
     public static final String URN_IETF_PARAMS_XML_NS_NETCONF_EXI_1_0 = "urn:ietf:params:xml:ns:netconf:exi:1.0";
index 85eeb30a07339c3b379bd756328f7ed96926fbc2..b8605d823066330e2a4c0b0650a2024f12c063f6 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.controller.netconf.util;
 
 import org.junit.Test;
-import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
 import org.w3c.dom.Document;
 
@@ -22,7 +21,7 @@ public class NetconfUtilTest {
     public void testConflictingVersionDetection() throws Exception {
         Document document = XmlUtil.readXmlToDocument(getClass().getResourceAsStream("/netconfMessages/conflictingversion/conflictingVersionResponse.xml"));
         try{
-            NetconfUtil.checkIsMessageOk(new NetconfMessage(document));
+            NetconfUtil.checkIsMessageOk(document);
             fail();
         }catch(IllegalStateException e){
             assertThat(e.getMessage(), containsString("Optimistic lock failed. Expected parent version 21, was 18"));