X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fconfig-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fconfignetconfconnector%2Foperations%2Fget%2FGet.java;h=fc95046dfdbef94e3e139480cae950c7010a83f9;hp=73f9ecd6fa56a3a161bc7e9ca2795640e252e74c;hb=c7ec8db7f107b5e265f4e8b2fe3dd0f7b1163b64;hpb=d651368d83292f7226a4e91adb55de98036c228f 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 73f9ecd6fa..fc95046dfd 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 @@ -8,7 +8,8 @@ package org.opendaylight.controller.netconf.confignetconfconnector.operations.get; -import java.util.HashMap; +import com.google.common.collect.Maps; + import java.util.List; import java.util.Map; import java.util.Set; @@ -16,44 +17,37 @@ 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.yang.store.api.YangStoreSnapshot; 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.NetconfDocumentedException.ErrorSeverity; -import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorTag; -import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorType; +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.transactions.TransactionProvider; +import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreSnapshot; +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 com.google.common.collect.Maps; - public class Get extends AbstractConfigNetconfOperation { private final YangStoreSnapshot yangStoreSnapshot; private static final Logger logger = LoggerFactory.getLogger(Get.class); - private final TransactionProvider transactionProvider; public Get(YangStoreSnapshot yangStoreSnapshot, ConfigRegistryClient configRegistryClient, - String netconfSessionIdForReporting, TransactionProvider transactionProvider) { + String netconfSessionIdForReporting) { super(configRegistryClient, netconfSessionIdForReporting); this.yangStoreSnapshot = yangStoreSnapshot; - this.transactionProvider = transactionProvider; } private Map> createModuleRuntimes(ConfigRegistryClient configRegistryClient, @@ -71,16 +65,18 @@ public class Get extends AbstractConfigNetconfOperation { Map cache = Maps.newHashMap(); RuntimeBeanEntry root = null; for (RuntimeBeanEntry rbe : mbe.getRuntimeBeans()) { - cache.put(rbe, new InstanceConfig(configRegistryClient, rbe.getYangPropertiesToTypesMap())); - if (rbe.isRoot()) + cache.put(rbe, new InstanceConfig(configRegistryClient, rbe.getYangPropertiesToTypesMap(), mbe.getNullableDummyContainerName())); + if (rbe.isRoot()){ root = rbe; + } } - if (root == null) + if (root == null){ continue; + } InstanceRuntime rootInstanceRuntime = createInstanceRuntime(root, cache); - ModuleRuntime moduleRuntime = new ModuleRuntime(module, rootInstanceRuntime); + ModuleRuntime moduleRuntime = new ModuleRuntime(rootInstanceRuntime); innerMap.put(module, moduleRuntime); } @@ -106,13 +102,11 @@ public class Get extends AbstractConfigNetconfOperation { return jmxToYangNamesForChildRbe; } - private static void checkXml(XmlElement xml) { + private static void checkXml(XmlElement xml) throws UnexpectedElementException, UnexpectedNamespaceException, MissingNameSpaceException { 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 @@ -122,38 +116,22 @@ public class Get extends AbstractConfigNetconfOperation { @Override protected Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws NetconfDocumentedException { - try { - checkXml(xml); - } catch (final IllegalArgumentException e) { - logger.warn("Error parsing xml", e); - final Map errorInfo = new HashMap<>(); - errorInfo.put(ErrorTag.bad_attribute.name(), e.getMessage()); - throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.rpc, ErrorTag.bad_attribute, - ErrorSeverity.error, errorInfo); - } catch (final UnsupportedOperationException e) { - logger.warn("Unsupported", e); - final Map errorInfo = new HashMap<>(); - errorInfo.put(ErrorTag.operation_not_supported.name(), "Unsupported option for 'get'"); - throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.application, - ErrorTag.operation_not_supported, ErrorSeverity.error, errorInfo); - } + checkXml(xml); - final Set runtimeBeans = configRegistryClient.lookupRuntimeBeans(); + final Set runtimeBeans = getConfigRegistryClient().lookupRuntimeBeans(); //Transaction provider required only for candidate datastore final Set configBeans = Datastore.getInstanceQueryStrategy(Datastore.running, null) - .queryInstances(configRegistryClient); + .queryInstances(getConfigRegistryClient()); - final Map> moduleRuntimes = createModuleRuntimes(configRegistryClient, + final Map> moduleRuntimes = createModuleRuntimes(getConfigRegistryClient(), yangStoreSnapshot.getModuleMXBeanEntryMap()); final Map> moduleConfigs = EditConfig.transformMbeToModuleConfigs( - configRegistryClient, yangStoreSnapshot.getModuleMXBeanEntryMap()); + getConfigRegistryClient(), yangStoreSnapshot.getModuleMXBeanEntryMap()); final Runtime runtime = new Runtime(moduleRuntimes, moduleConfigs); - ObjectName txOn = transactionProvider.getOrCreateTransaction(); - ConfigTransactionClient ta = configRegistryClient.getConfigTransactionClient(txOn); - final Element element = runtime.toXml(runtimeBeans, configBeans, document, new ServiceRegistryWrapper(ta)); + final Element element = runtime.toXml(runtimeBeans, configBeans, document); logger.trace("{} operation successful", XmlNetconfConstants.GET);