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%2Fmapping%2Fconfig%2FInstanceConfig.java;h=0fe5fad29c1d4ad20e5cb67c3d8c21357e791f46;hb=803d525860fbb1974b65ba5605ba5a9dfe1928a4;hp=a940be7e77f0cb71ea8d41253048f6818dff8a73;hpb=20500c9eb46d1ceb99d742d1c110dcb7c558dc2b;p=controller.git 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 a940be7e77..0fe5fad29c 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,13 @@ 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 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; @@ -63,26 +63,24 @@ public final class InstanceConfig { 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; } @@ -131,14 +129,16 @@ public final class InstanceConfig { } public InstanceConfigElementResolved fromXml(XmlElement moduleElement, ServiceRegistryWrapper services, String moduleNamespace, - EditStrategyType defaultStrategy, Multimap providedServices, Map> identityMap) { + EditStrategyType defaultStrategy, Multimap providedServices, Map> identityMap) throws NetconfDocumentedException { Map retVal = Maps.newHashMap(); 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 = null; + XmlElement name = null; + type = moduleElement.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.TYPE_KEY); + name = moduleElement.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.NAME_KEY); List typeAndName = Lists.newArrayList(type, name); for (Entry readStratEntry : strats.entrySet()) { @@ -163,7 +163,7 @@ public final class InstanceConfig { } 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); @@ -181,9 +181,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);