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%2Fmapping%2Fconfig%2FInstanceConfig.java;h=cf9b4c159746e15434be1096d0caf946e2417ec3;hp=b8870e51ce8bd0907655054a0b9c4566e1343cf4;hb=8720a3f3498bbc6fab675431f4200d26641a8ec8;hpb=662465381994f266eb32aa3dceba426e747df678 diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/InstanceConfig.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/InstanceConfig.java index b8870e51ce..cf9b4c1597 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/InstanceConfig.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/InstanceConfig.java @@ -9,13 +9,18 @@ package org.opendaylight.controller.netconf.confignetconfconnector.mapping.config; import com.google.common.base.Optional; -import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.google.common.collect.Multimap; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import javax.management.ObjectName; +import javax.management.openmbean.OpenType; import org.opendaylight.controller.config.util.ConfigRegistryClient; import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry; import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc; +import org.opendaylight.controller.netconf.api.NetconfDocumentedException; import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.AttributeConfigElement; import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.AttributeReadingStrategy; import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.ObjectXmlReader; @@ -25,6 +30,7 @@ import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attrib import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.resolving.ObjectResolver; import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.toxml.AttributeWritingStrategy; import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.toxml.ObjectXmlWriter; +import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfig; import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditStrategyType; import org.opendaylight.controller.netconf.util.xml.XmlElement; import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants; @@ -33,12 +39,6 @@ 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.List; -import java.util.Map; -import java.util.Map.Entry; - public final class InstanceConfig { private static final Logger logger = LoggerFactory.getLogger(InstanceConfig.class); @@ -52,56 +52,52 @@ public final class InstanceConfig { this.configRegistryClient = configRegistryClient; } - private Map getMappedConfiguration(ObjectName on, ServiceRegistryWrapper depTracker) { + private Map getMappedConfiguration(ObjectName on) { // TODO make field, mappingStrategies can be instantiated only once - Map>> mappingStrategies = new ObjectMapper(depTracker) + Map>> mappingStrategies = new ObjectMapper() .prepareMapping(jmxToAttrConfig); Map toXml = Maps.newHashMap(); for (Entry configDefEntry : jmxToAttrConfig.entrySet()) { - // Skip children runtime beans as they are mapped by InstanceRuntime - if (configDefEntry.getValue() instanceof RuntimeBeanEntry) + if (configDefEntry.getValue() instanceof RuntimeBeanEntry){ continue; - + } Object value = configRegistryClient.getAttributeCurrentValue(on, configDefEntry.getKey()); try { AttributeMappingStrategy> attributeMappingStrategy = mappingStrategies .get(configDefEntry.getKey()); Optional a = attributeMappingStrategy.mapAttribute(value); - if (a.isPresent() == false) + if (!a.isPresent()){ continue; - + } toXml.put(configDefEntry.getValue().getAttributeYangName(), a.get()); } catch (Exception e) { throw new IllegalStateException("Unable to map value " + value + " to attribute " + configDefEntry.getKey(), e); } } - return toXml; } - public Element toXml(ObjectName on, ServiceRegistryWrapper depTracker, String namespace, Document document, Element rootElement) { - - Element cfgElement = rootElement; + public Element toXml(ObjectName on, String namespace, Document document, Element rootElement) { Map strats = new ObjectXmlWriter().prepareWriting(yangToAttrConfig, document); - Map mappedConfig = getMappedConfiguration(on, depTracker); + Map mappedConfig = getMappedConfiguration(on); for (Entry mappingEntry : mappedConfig.entrySet()) { try { - strats.get(mappingEntry.getKey()).writeElement(cfgElement, namespace, mappingEntry.getValue()); + strats.get(mappingEntry.getKey()).writeElement(rootElement, namespace, mappingEntry.getValue()); } catch (Exception e) { throw new IllegalStateException("Unable to write value " + mappingEntry.getValue() + " for attribute " + mappingEntry.getValue(), e); } } - return cfgElement; + return rootElement; } private void resolveConfiguration(InstanceConfigElementResolved mappedConfig, ServiceRegistryWrapper depTracker) { @@ -129,14 +125,17 @@ public final class InstanceConfig { } public InstanceConfigElementResolved fromXml(XmlElement moduleElement, ServiceRegistryWrapper services, String moduleNamespace, - EditStrategyType defaultStrategy, Multimap providedServices) { + EditStrategyType defaultStrategy, + Map> identityMap) throws NetconfDocumentedException { Map retVal = Maps.newHashMap(); - Map strats = new ObjectXmlReader().prepareReading(yangToAttrConfig); + Map strats = new ObjectXmlReader().prepareReading(yangToAttrConfig, identityMap); List recognisedChildren = Lists.newArrayList(); - XmlElement type = moduleElement.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.TYPE_KEY); - XmlElement name = moduleElement.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.NAME_KEY); + XmlElement type; + XmlElement name; + type = moduleElement.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.TYPE_KEY); + name = moduleElement.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.NAME_KEY); List typeAndName = Lists.newArrayList(type, name); for (Entry readStratEntry : strats.entrySet()) { @@ -154,14 +153,14 @@ public final class InstanceConfig { XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); InstanceConfigElementResolved instanceConfigElementResolved = perInstanceEditStrategy.equals("") ? new InstanceConfigElementResolved( - retVal, defaultStrategy, providedServices) : new InstanceConfigElementResolved(perInstanceEditStrategy, retVal, defaultStrategy, providedServices); + retVal, defaultStrategy) : new InstanceConfigElementResolved(perInstanceEditStrategy, retVal, defaultStrategy); resolveConfiguration(instanceConfigElementResolved, services); return instanceConfigElementResolved; } private List getConfigNodes(XmlElement moduleElement, String moduleNamespace, String name, - List recognisedChildren, List typeAndName) { + List recognisedChildren, List typeAndName) throws NetconfDocumentedException { List foundConfigNodes = moduleElement.getChildElementsWithinNamespace(name, moduleNamespace); if (foundConfigNodes.isEmpty()) { logger.debug("No config nodes {}:{} found in {}", moduleNamespace, name, moduleElement); @@ -179,9 +178,13 @@ public final class InstanceConfig { List foundWithoutNamespaceNodes = moduleElement.getChildElementsWithinNamespace(name, XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG); foundWithoutNamespaceNodes.removeAll(typeAndName); - Preconditions.checkState(foundWithoutNamespaceNodes.isEmpty(), - "Element %s present multiple times with different namespaces: %s, %s", name, foundConfigNodes, - foundWithoutNamespaceNodes); + if (!foundWithoutNamespaceNodes.isEmpty()){ + throw new NetconfDocumentedException(String.format("Element %s present multiple times with different namespaces: %s, %s", name, foundConfigNodes, + foundWithoutNamespaceNodes), + NetconfDocumentedException.ErrorType.application, + NetconfDocumentedException.ErrorTag.invalid_value, + NetconfDocumentedException.ErrorSeverity.error); + } } recognisedChildren.addAll(foundConfigNodes);