X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fconfig-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fconfignetconfconnector%2Foperations%2Fget%2FGet.java;h=40592ea64b50ef0a1bb4f37c7c9c54c38b18c6b9;hb=1a43f55c49d91816751cec1825c40d0a90f8bd8b;hp=4665c2cc89cf23d9f5efbb876b532b377ef22896;hpb=84248dac9ed8aa37e996e39429c8aa8ece473eaf;p=controller.git diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/get/Get.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/get/Get.java index 4665c2cc89..40592ea64b 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/get/Get.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/get/Get.java @@ -9,66 +9,64 @@ package org.opendaylight.controller.netconf.confignetconfconnector.operations.get; import com.google.common.collect.Maps; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.management.ObjectName; import org.opendaylight.controller.config.util.ConfigRegistryClient; import org.opendaylight.controller.config.util.ConfigTransactionClient; 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.xml.XmlNetconfConstants; 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; 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.editconfig.EditConfig; -import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreSnapshot; +import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreContext; 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; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; -import javax.management.ObjectName; -import java.util.List; -import java.util.Map; -import java.util.Set; - public class Get extends AbstractConfigNetconfOperation { - private final YangStoreSnapshot yangStoreSnapshot; - private static final Logger logger = LoggerFactory.getLogger(Get.class); private final TransactionProvider transactionProvider; + private final YangStoreContext yangStoreSnapshot; + private static final Logger LOG = LoggerFactory.getLogger(Get.class); - public Get(YangStoreSnapshot yangStoreSnapshot, ConfigRegistryClient configRegistryClient, - String netconfSessionIdForReporting, TransactionProvider transactionProvider) { + public Get(final TransactionProvider transactionProvider, YangStoreContext yangStoreSnapshot, ConfigRegistryClient configRegistryClient, + String netconfSessionIdForReporting) { super(configRegistryClient, netconfSessionIdForReporting); - this.yangStoreSnapshot = yangStoreSnapshot; this.transactionProvider = transactionProvider; + this.yangStoreSnapshot = yangStoreSnapshot; } private Map> createModuleRuntimes(ConfigRegistryClient configRegistryClient, Map> mBeanEntries) { Map> retVal = Maps.newHashMap(); - for (String namespace : mBeanEntries.keySet()) { + for (Map.Entry> namespaceToModuleEntry : mBeanEntries.entrySet()) { Map innerMap = Maps.newHashMap(); - Map entriesFromNamespace = mBeanEntries.get(namespace); - for (String module : entriesFromNamespace.keySet()) { + Map entriesFromNamespace = namespaceToModuleEntry.getValue(); + for (Map.Entry moduleToMXEntry : entriesFromNamespace.entrySet()) { - ModuleMXBeanEntry mbe = entriesFromNamespace.get(module); + ModuleMXBeanEntry mbe = moduleToMXEntry.getValue(); Map cache = Maps.newHashMap(); RuntimeBeanEntry root = null; for (RuntimeBeanEntry rbe : mbe.getRuntimeBeans()) { - cache.put(rbe, new InstanceConfig(configRegistryClient, rbe.getYangPropertiesToTypesMap())); + cache.put(rbe, new InstanceConfig(configRegistryClient, rbe.getYangPropertiesToTypesMap(), mbe.getNullableDummyContainerName())); if (rbe.isRoot()){ root = rbe; } @@ -79,11 +77,11 @@ public class Get extends AbstractConfigNetconfOperation { } InstanceRuntime rootInstanceRuntime = createInstanceRuntime(root, cache); - ModuleRuntime moduleRuntime = new ModuleRuntime(module, rootInstanceRuntime); - innerMap.put(module, moduleRuntime); + ModuleRuntime moduleRuntime = new ModuleRuntime(rootInstanceRuntime); + innerMap.put(moduleToMXEntry.getKey(), moduleRuntime); } - retVal.put(namespace, innerMap); + retVal.put(namespaceToModuleEntry.getKey(), innerMap); } return retVal; } @@ -109,10 +107,7 @@ public class Get extends AbstractConfigNetconfOperation { 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 " + XmlNetconfConstants.GET); - } + // Filter option: ignore for now, TODO only load modules specified by the filter } @Override @@ -124,25 +119,30 @@ public class Get extends AbstractConfigNetconfOperation { protected Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws NetconfDocumentedException { checkXml(xml); - final Set runtimeBeans = getConfigRegistryClient().lookupRuntimeBeans(); + final ObjectName testTransaction = transactionProvider.getOrCreateReadTransaction(); + final ConfigTransactionClient registryClient = getConfigRegistryClient().getConfigTransactionClient(testTransaction); + + try { + // Runtime beans are not parts of transactions and have to be queried against the central registry + final Set runtimeBeans = getConfigRegistryClient().lookupRuntimeBeans(); - //Transaction provider required only for candidate datastore - final Set configBeans = Datastore.getInstanceQueryStrategy(Datastore.running, null) - .queryInstances(getConfigRegistryClient()); + final Set configBeans = Datastore.getInstanceQueryStrategy(Datastore.running, transactionProvider) + .queryInstances(getConfigRegistryClient()); - final Map> moduleRuntimes = createModuleRuntimes(getConfigRegistryClient(), - yangStoreSnapshot.getModuleMXBeanEntryMap()); - final Map> moduleConfigs = EditConfig.transformMbeToModuleConfigs( - getConfigRegistryClient(), yangStoreSnapshot.getModuleMXBeanEntryMap()); + final Map> moduleRuntimes = createModuleRuntimes(getConfigRegistryClient(), + yangStoreSnapshot.getModuleMXBeanEntryMap()); + final Map> moduleConfigs = EditConfig.transformMbeToModuleConfigs( + registryClient, yangStoreSnapshot.getModuleMXBeanEntryMap()); - final Runtime runtime = new Runtime(moduleRuntimes, moduleConfigs); + final Runtime runtime = new Runtime(moduleRuntimes, moduleConfigs); - ObjectName txOn = transactionProvider.getOrCreateTransaction(); - ConfigTransactionClient ta = getConfigRegistryClient().getConfigTransactionClient(txOn); - final Element element = runtime.toXml(runtimeBeans, configBeans, document, new ServiceRegistryWrapper(ta)); + final Element element = runtime.toXml(runtimeBeans, configBeans, document, yangStoreSnapshot.getEnumResolver()); - logger.trace("{} operation successful", XmlNetconfConstants.GET); + LOG.trace("{} operation successful", XmlNetconfConstants.GET); - return element; + return element; + } finally { + transactionProvider.closeReadTransaction(); + } } }