X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fnetconf%2Fconfig-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fconfignetconfconnector%2Foperations%2Fgetconfig%2FGetConfig.java;h=11d3e32edf6748fe811a9a25174330afae5b1d28;hb=d7a972ac145d9f0ac8870dac2d7835520e92c02a;hp=d75cfd5d6f049d9d586ac856fa0ccd7b70b3c00c;hpb=cf000a86e871a4acf98cf15ba31ce140e6c0f262;p=controller.git diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/getconfig/GetConfig.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/getconfig/GetConfig.java index d75cfd5d6f..11d3e32edf 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/getconfig/GetConfig.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/getconfig/GetConfig.java @@ -9,32 +9,28 @@ package org.opendaylight.controller.netconf.confignetconfconnector.operations.getconfig; import com.google.common.base.Optional; -import com.google.common.collect.Maps; 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.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.confignetconfconnector.mapping.config.Config; -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.Services; +import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.ServiceRegistryWrapper; 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.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.opendaylight.controller.netconf.util.xml.XmlUtil; 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.HashMap; -import java.util.Map; import java.util.Set; public class GetConfig extends AbstractConfigNetconfOperation { @@ -57,7 +53,8 @@ public class GetConfig extends AbstractConfigNetconfOperation { this.transactionProvider = transactionProvider; } - public static Datastore fromXml(XmlElement xml) { + public static Datastore fromXml(XmlElement xml) throws UnexpectedNamespaceException, UnexpectedElementException, MissingNameSpaceException, NetconfDocumentedException { + xml.checkName(GET_CONFIG); xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); @@ -79,75 +76,34 @@ public class GetConfig extends AbstractConfigNetconfOperation { private Element getResponseInternal(final Document document, final ConfigRegistryClient configRegistryClient, final Datastore source) throws NetconfDocumentedException { - Element dataElement = document.createElement(XmlNetconfConstants.DATA_KEY); + Element dataElement = XmlUtil.createElement(document, XmlNetconfConstants.DATA_KEY, Optional.absent()); final Set instances = Datastore.getInstanceQueryStrategy(source, this.transactionProvider) .queryInstances(configRegistryClient); - final Config configMapping = new Config(transform(configRegistryClient, + final Config configMapping = new Config(EditConfig.transformMbeToModuleConfigs(configRegistryClient, yangStoreSnapshot.getModuleMXBeanEntryMap())); ObjectName on = transactionProvider.getOrCreateTransaction(); ConfigTransactionClient ta = configRegistryClient.getConfigTransactionClient(on); - Services serviceTracker = new Services(ta); + ServiceRegistryWrapper serviceTracker = new ServiceRegistryWrapper(ta); dataElement = configMapping.toXml(instances, this.maybeNamespace, document, dataElement, serviceTracker); - logger.info("{} operation successful", GET_CONFIG); + logger.trace("{} operation successful", GET_CONFIG); return dataElement; } - // TODO refactor ... duplicate code - public static Map> transform(final ConfigRegistryClient configRegistryClient, - Map> mBeanEntries) { - return Maps.transformEntries(mBeanEntries, - new Maps.EntryTransformer, Map>() { - - @Override - public Map transformEntry(String arg0, Map arg1) { - return Maps.transformEntries(arg1, - new Maps.EntryTransformer() { - - @Override - public ModuleConfig transformEntry(String key, ModuleMXBeanEntry value) { - return new ModuleConfig(key, new InstanceConfig(configRegistryClient, value - .getAttributes()), value.getProvidedServices().values()); - } - }); - } - }); - } - @Override protected String getOperationName() { return GET_CONFIG; } @Override - public Element handle(Document document, XmlElement xml) throws NetconfDocumentedException { + public Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws NetconfDocumentedException { Datastore source; - try { - source = fromXml(xml); - } catch (final IllegalArgumentException e) { - logger.warn("Rpc error: {}", ErrorTag.bad_attribute, 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 IllegalStateException e) { - logger.warn("Rpc error: {}", ErrorTag.missing_attribute, e); - final Map errorInfo = new HashMap<>(); - errorInfo.put(ErrorTag.missing_attribute.name(), "Missing datasource attribute value"); - throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.rpc, ErrorTag.missing_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); - } + source = fromXml(xml); return getResponseInternal(document, configRegistryClient, source); } }