Merge "Add service reference binding to config registry."
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / operations / get / Get.java
index b93843d28e65a09aa62c9c5518209a5b0f772712..7ee13aeb589c713351f760464f19a4aff48647d3 100644 (file)
@@ -18,10 +18,13 @@ import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorS
 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.runtime.InstanceRuntime;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.runtime.ModuleRuntime;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.runtime.Runtime;
 import org.opendaylight.controller.netconf.confignetconfconnector.operations.AbstractConfigNetconfOperation;
+import org.opendaylight.controller.netconf.confignetconfconnector.operations.Datastore;
+import org.opendaylight.controller.netconf.confignetconfconnector.operations.getconfig.GetConfig;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
 import org.slf4j.Logger;
@@ -37,8 +40,6 @@ import java.util.Set;
 
 public class Get extends AbstractConfigNetconfOperation {
 
-    public static final String GET = "get";
-
     private final YangStoreSnapshot yangStoreSnapshot;
     private static final Logger logger = LoggerFactory.getLogger(Get.class);
 
@@ -99,17 +100,17 @@ public class Get extends AbstractConfigNetconfOperation {
     }
 
     private static void checkXml(XmlElement xml) {
-        xml.checkName(GET);
+        xml.checkName(XmlNetconfConstants.GET);
         xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
 
         // Filter option - unsupported
         if (xml.getChildElements(XmlNetconfConstants.FILTER).size() != 0)
-            throw new UnsupportedOperationException("Unsupported option " + XmlNetconfConstants.FILTER + " for " + GET);
+            throw new UnsupportedOperationException("Unsupported option " + XmlNetconfConstants.FILTER + " for " + XmlNetconfConstants.GET);
     }
 
     @Override
     protected String getOperationName() {
-        return GET;
+        return XmlNetconfConstants.GET;
     }
 
     @Override
@@ -129,14 +130,23 @@ public class Get extends AbstractConfigNetconfOperation {
             throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.application,
                     ErrorTag.operation_not_supported, ErrorSeverity.error, errorInfo);
         }
+
         final Set<ObjectName> runtimeBeans = configRegistryClient.lookupRuntimeBeans();
-        final Map<String, Map<String, ModuleRuntime>> moduleMappings = createModuleRuntimes(configRegistryClient,
+
+        //Transaction provider required only for candidate datastore
+        final Set<ObjectName> configBeans = Datastore.getInstanceQueryStrategy(Datastore.running, null)
+                .queryInstances(configRegistryClient);
+
+        final Map<String, Map<String, ModuleRuntime>> moduleRuntimes = createModuleRuntimes(configRegistryClient,
+                yangStoreSnapshot.getModuleMXBeanEntryMap());
+        final Map<String, Map<String, ModuleConfig>> moduleConfigs = GetConfig.transform(configRegistryClient,
                 yangStoreSnapshot.getModuleMXBeanEntryMap());
-        final Runtime runtime = new Runtime(moduleMappings);
 
-        final Element element = runtime.toXml(runtimeBeans, document);
+        final Runtime runtime = new Runtime(moduleRuntimes, moduleConfigs);
+
+        final Element element = runtime.toXml(runtimeBeans, configBeans, document);
 
-        logger.info("{} operation successful", GET);
+        logger.info("{} operation successful", XmlNetconfConstants.GET);
 
         return element;
     }