From: Maros Marsalek Date: Fri, 22 Nov 2013 13:08:30 +0000 (+0100) Subject: Fix no response from netconf server if no operation is available to handle message. X-Git-Tag: jenkins-controller-bulk-release-prepare-only-2-1~343^2~1 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=863cbb7b2c20ff4ef2d0b97c64d2887e49a9ca4f;p=controller.git Fix no response from netconf server if no operation is available to handle message. Change-Id: Ia3e319ee6b9d224a92def7652ed50f4ae7021b4a Signed-off-by: Maros Marsalek --- diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/runtimerpc/RuntimeRpc.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/runtimerpc/RuntimeRpc.java index f838c6f9f5..7463bdd429 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/runtimerpc/RuntimeRpc.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/runtimerpc/RuntimeRpc.java @@ -127,6 +127,7 @@ public class RuntimeRpc extends AbstractConfigNetconfOperation { if (contextInstanceElement.isPresent() == false) return HandlingPriority.CANNOT_HANDLE; + // FIXME update xpath to instance to conform to config-api yang final RuntimeRpcElementResolved id = RuntimeRpcElementResolved.fromXpath(contextInstanceElement.get() .getTextContent(), netconfOperationName, netconfOperationNamespace); diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java index 3dd6e6803b..54deb91837 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java @@ -7,14 +7,9 @@ */ package org.opendaylight.controller.netconf.impl.osgi; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Set; -import java.util.TreeMap; -import java.util.TreeSet; - +import com.google.common.base.Preconditions; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import org.opendaylight.controller.netconf.api.NetconfDocumentedException; import org.opendaylight.controller.netconf.api.NetconfOperationRouter; import org.opendaylight.controller.netconf.api.NetconfSession; @@ -36,9 +31,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; -import com.google.common.base.Preconditions; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; public class NetconfOperationRouterImpl implements NetconfOperationRouter { @@ -116,9 +116,33 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { @Override public synchronized Document onNetconfMessage(Document message, NetconfSession session) throws NetconfDocumentedException { - NetconfOperationExecution netconfOperationExecution = getNetconfOperationWithHighestPriority( - message, session); - logger.debug("Forwarding netconf message {} to {}", XmlUtil.toString(message), + NetconfOperationExecution netconfOperationExecution = null; + + String messageAsString = XmlUtil.toString(message); + + try { + netconfOperationExecution = getNetconfOperationWithHighestPriority( + message, session); + } catch (IllegalArgumentException | IllegalStateException e) { + logger.warn("Unable to handle rpc {} on session {}", messageAsString, session, e); + + String errorMessage = String.format("Unable to handle rpc %s on session %s", messageAsString, session); + Map errorInfo = Maps.newHashMap(); + + NetconfDocumentedException.ErrorTag tag = null; + if (e instanceof IllegalArgumentException) { + errorInfo.put(NetconfDocumentedException.ErrorTag.operation_not_supported.toString(), e.getMessage()); + tag = NetconfDocumentedException.ErrorTag.operation_not_supported; + } else if (e instanceof IllegalStateException) { + errorInfo.put(NetconfDocumentedException.ErrorTag.operation_failed.toString(), e.getMessage()); + tag = NetconfDocumentedException.ErrorTag.operation_failed; + } + + throw new NetconfDocumentedException(errorMessage, e, NetconfDocumentedException.ErrorType.application, + tag, NetconfDocumentedException.ErrorSeverity.error, errorInfo); + } + + logger.debug("Forwarding netconf message {} to {}", messageAsString, netconfOperationExecution.operationWithHighestPriority); final LinkedList chain = new LinkedList<>(); @@ -147,7 +171,7 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { TreeMap> sortedPriority = getSortedNetconfOperationsWithCanHandle( message, session); - Preconditions.checkState(sortedPriority.isEmpty() == false, "No %s available to handle message %s", + Preconditions.checkArgument(sortedPriority.isEmpty() == false, "No %s available to handle message %s", NetconfOperation.class.getName(), XmlUtil.toString(message)); HandlingPriority highestFoundPriority = sortedPriority.lastKey();