Merge changes I4ba7cf7d,Ia3e319ee
authorEd Warnicke <eaw@cisco.com>
Mon, 25 Nov 2013 17:48:58 +0000 (17:48 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 25 Nov 2013 17:48:58 +0000 (17:48 +0000)
* changes:
  Allow multiple services provided from same namespace parsed from netconf message
  Fix no response from netconf server if no operation is available to handle message.

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/ModuleConfig.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/runtimerpc/RuntimeRpc.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java

index 2242101f5b12ab1cbdf940576dc6a60d530a7c25..f96b3acf20c0f2d518ed042f9191fe33b7de798a 100644 (file)
@@ -87,9 +87,9 @@ public class Config {
     }
 
     private void addServices(Services serviceTracker, Collection<ObjectName> instances,
-            Map<String, String> providedServices) {
+            Multimap<String, String> providedServices) {
         for (ObjectName instanceOn : instances) {
-            for (Entry<String, String> serviceName : providedServices.entrySet()) {
+            for (Entry<String, String> serviceName : providedServices.entries()) {
                 serviceTracker.addServiceEntry(serviceName.getKey(), serviceName.getValue(), instanceOn);
             }
         }
@@ -243,7 +243,7 @@ public class Config {
 
             checkState(moduleConfig != null, "Cannot find ModuleConfig with name " + factoryName + " in " + moduleNamesToConfigs);
             // Set<String> services = ;
-            for (Entry<String, String> serviceName : moduleConfig.getProvidedServices().entrySet()) {
+            for (Entry<String, String> serviceName : moduleConfig.getProvidedServices().entries()) {
 
                 services.addServiceEntry(serviceName.getKey(), serviceName.getValue(), existingON);
             }
index 064cd9fe6f332cb01124c7243a3e25430b8be6a9..2e2a26400f19899b3f172e80f0de00f7c46ce1c6 100644 (file)
@@ -8,8 +8,8 @@
 
 package org.opendaylight.controller.netconf.confignetconfconnector.mapping.config;
 
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditStrategyType;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
@@ -21,15 +21,12 @@ import org.w3c.dom.Element;
 
 import javax.management.ObjectName;
 import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
 
 public class ModuleConfig {
 
     private final String moduleName;
     private final InstanceConfig instanceConfig;
-    // TODO 2 services from same namespace ?
-    private final Map<String, String> providedServices;
+    private final Multimap<String, String> providedServices;
 
     public ModuleConfig(String moduleName, InstanceConfig mbeanMapping, Collection<QName> providedServices) {
         this.moduleName = moduleName;
@@ -37,12 +34,11 @@ public class ModuleConfig {
         this.providedServices = mapServices(providedServices);
     }
 
-    private Map<String, String> mapServices(Collection<QName> providedServices) {
-        HashMap<String, String> mapped = Maps.newHashMap();
+    private Multimap<String, String> mapServices(Collection<QName> providedServices) {
+        Multimap<String, String> mapped = HashMultimap.create();
 
         for (QName providedService : providedServices) {
             String key = providedService.getNamespace().toString();
-            Preconditions.checkState(mapped.containsKey(key) == false);
             mapped.put(key, providedService.getLocalName());
         }
 
@@ -53,7 +49,7 @@ public class ModuleConfig {
         return instanceConfig;
     }
 
-    public Map<String, String> getProvidedServices() {
+    public Multimap<String, String> getProvidedServices() {
         return providedServices;
     }
 
index f838c6f9f5e69160b4c889d799f7e42ed2c7338c..7463bdd429e4dc9552dfc390d59bcaba32fe5e5b 100644 (file)
@@ -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);
 
index 3dd6e6803bda9662b7e54a95849db368931a8452..54deb91837b002b76a7c7f80a6d01ef5ee56e9cc 100644 (file)
@@ -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<String, String> 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<NetconfOperationFilterChain> chain = new LinkedList<>();
@@ -147,7 +171,7 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
         TreeMap<HandlingPriority, Set<NetconfOperation>> 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();