BUG-2453 (De)Serialize enum values as defined in yang
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / operations / runtimerpc / RuntimeRpc.java
index 0d9c61bad7b17b961294ce3562a7abca56f4d851..f7d28b789e30d7f631f053249f46f09407901932 100644 (file)
@@ -11,7 +11,9 @@ package org.opendaylight.controller.netconf.confignetconfconnector.operations.ru
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Maps;
-
+import java.util.Map;
+import javax.management.ObjectName;
+import javax.management.openmbean.OpenType;
 import org.opendaylight.controller.config.util.ConfigRegistryClient;
 import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
 import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry;
@@ -28,8 +30,8 @@ import org.opendaylight.controller.netconf.confignetconfconnector.mapping.rpc.In
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.rpc.ModuleRpcs;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.rpc.Rpcs;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.AbstractConfigNetconfOperation;
-import org.opendaylight.controller.netconf.confignetconfconnector.operations.Commit;
-import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreSnapshot;
+import org.opendaylight.controller.netconf.confignetconfconnector.osgi.EnumResolver;
+import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreContext;
 import org.opendaylight.controller.netconf.mapping.api.HandlingPriority;
 import org.opendaylight.controller.netconf.util.exception.MissingNameSpaceException;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
@@ -39,19 +41,14 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import javax.management.ObjectName;
-import javax.management.openmbean.OpenType;
-
-import java.util.Map;
-
 public class RuntimeRpc extends AbstractConfigNetconfOperation {
 
-    private static final Logger logger = LoggerFactory.getLogger(Commit.class);
+    private static final Logger LOG = LoggerFactory.getLogger(RuntimeRpc.class);
     public static final String CONTEXT_INSTANCE = "context-instance";
 
-    private final YangStoreSnapshot yangStoreSnapshot;
+    private final YangStoreContext yangStoreSnapshot;
 
-    public RuntimeRpc(final YangStoreSnapshot yangStoreSnapshot, ConfigRegistryClient configRegistryClient,
+    public RuntimeRpc(final YangStoreContext yangStoreSnapshot, ConfigRegistryClient configRegistryClient,
             String netconfSessionIdForReporting) {
         super(configRegistryClient, netconfSessionIdForReporting);
         this.yangStoreSnapshot = yangStoreSnapshot;
@@ -98,7 +95,7 @@ public class RuntimeRpc extends AbstractConfigNetconfOperation {
         try {
             namespace = xml.getNamespace();
         } catch (MissingNameSpaceException e) {
-            logger.trace("Can't get namespace from xml element due to {}",e);
+            LOG.trace("Can't get namespace from xml element due to ",e);
             throw NetconfDocumentedException.wrap(e);
         }
         final XmlElement contextInstanceElement = xml.getOnlyChildElement(CONTEXT_INSTANCE);
@@ -107,7 +104,7 @@ public class RuntimeRpc extends AbstractConfigNetconfOperation {
         final RuntimeRpcElementResolved id = RuntimeRpcElementResolved.fromXpath(
                 contextInstanceElement.getTextContent(), operationName, namespace);
 
-        final Rpcs rpcs = mapRpcs(yangStoreSnapshot.getModuleMXBeanEntryMap());
+        final Rpcs rpcs = mapRpcs(yangStoreSnapshot.getModuleMXBeanEntryMap(), yangStoreSnapshot.getEnumResolver());
 
         final ModuleRpcs rpcMapping = rpcs.getRpcMapping(id);
         final InstanceRuntimeRpc instanceRuntimeRpc = rpcMapping.getRpc(id.getRuntimeBeanName(), operationName);
@@ -133,7 +130,7 @@ public class RuntimeRpc extends AbstractConfigNetconfOperation {
         try {
             netconfOperationNamespace = operationElement.getNamespace();
         } catch (MissingNameSpaceException e) {
-            logger.debug("Cannot retrieve netconf operation namespace from message due to {}", e);
+            LOG.debug("Cannot retrieve netconf operation namespace from message due to ", e);
             return HandlingPriority.CANNOT_HANDLE;
         }
 
@@ -148,7 +145,7 @@ public class RuntimeRpc extends AbstractConfigNetconfOperation {
                 .getTextContent(), netconfOperationName, netconfOperationNamespace);
 
         // TODO reuse rpcs instance in fromXml method
-        final Rpcs rpcs = mapRpcs(yangStoreSnapshot.getModuleMXBeanEntryMap());
+        final Rpcs rpcs = mapRpcs(yangStoreSnapshot.getModuleMXBeanEntryMap(), yangStoreSnapshot.getEnumResolver());
 
         try {
 
@@ -159,7 +156,7 @@ public class RuntimeRpc extends AbstractConfigNetconfOperation {
                     netconfOperationName);
 
         } catch (IllegalStateException e) {
-            logger.debug("Cannot handle runtime operation {}:{}", netconfOperationNamespace, netconfOperationName, e);
+            LOG.debug("Cannot handle runtime operation {}:{}", netconfOperationNamespace, netconfOperationName, e);
             return HandlingPriority.CANNOT_HANDLE;
         }
 
@@ -182,12 +179,12 @@ public class RuntimeRpc extends AbstractConfigNetconfOperation {
         // TODO check for namespaces and unknown elements
         final NetconfOperationExecution execution = fromXml(xml);
 
-        logger.debug("Invoking operation {} on {} with arguments {}", execution.operationName, execution.on,
+        LOG.debug("Invoking operation {} on {} with arguments {}", execution.operationName, execution.on,
                 execution.attributes);
         final Object result = executeOperation(getConfigRegistryClient(), execution.on, execution.operationName,
                 execution.attributes);
 
-        logger.trace("Operation {} called successfully on {} with arguments {} with result {}", execution.operationName,
+        LOG.trace("Operation {} called successfully on {} with arguments {} with result {}", execution.operationName,
                 execution.on, execution.attributes, result);
 
         if (execution.isVoid()) {
@@ -243,7 +240,7 @@ public class RuntimeRpc extends AbstractConfigNetconfOperation {
         return sorted;
     }
 
-    private static Rpcs mapRpcs(final Map<String, Map<String, ModuleMXBeanEntry>> mBeanEntries) {
+    private static Rpcs mapRpcs(final Map<String, Map<String, ModuleMXBeanEntry>> mBeanEntries, final EnumResolver enumResolver) {
 
         final Map<String, Map<String, ModuleRpcs>> map = Maps.newHashMap();
 
@@ -259,7 +256,7 @@ public class RuntimeRpc extends AbstractConfigNetconfOperation {
 
                 ModuleRpcs rpcMapping = namespaceToModules.get(moduleEntry.getKey());
                 if (rpcMapping == null) {
-                    rpcMapping = new ModuleRpcs();
+                    rpcMapping = new ModuleRpcs(enumResolver);
                     namespaceToModules.put(moduleEntry.getKey(), rpcMapping);
                 }