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%2FServices.java;h=74655f938fdcacf58417fe3e6a8efca79b517e59;hp=eb5c018cf3db0af76ced902576543861b732a4f6;hb=b38840f0ca28b5968bf3841e7bde37d8904ca878;hpb=dc1a275c3c1ea8949dd3a607e08ee4624e758511 diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/Services.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/Services.java index eb5c018cf3..74655f938f 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/Services.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/Services.java @@ -11,24 +11,25 @@ package org.opendaylight.controller.netconf.confignetconfconnector.mapping.confi import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.collect.Maps; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import javax.management.ObjectName; import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; import org.opendaylight.controller.netconf.api.NetconfDocumentedException; +import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants; import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.ObjectNameAttributeReadingStrategy; 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.opendaylight.yangtools.yang.data.api.ModifyAction; 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.Map.Entry; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - public final class Services { + private static final String EMPTY_PROVIDER = ""; private static final String PROVIDER_KEY = "provider"; private static final String NAME_KEY = "name"; public static final String TYPE_KEY = "type"; @@ -69,9 +70,11 @@ public final class Services { } String refName = refEntry.getKey(); - - ServiceInstance serviceInstance = ServiceInstance.fromString(refEntry.getValue()); - refNameToInstance.put(refName, serviceInstance); + //we want to compare reference not value of the provider + refNameToInstance.put(refName, refEntry.getValue() == EMPTY_PROVIDER + //provider name cannot be EMPTY_PROVIDER instance unless we are executing delete + ? ServiceInstance.EMPTY_SERVICE_INSTANCE + : ServiceInstance.fromString(refEntry.getValue())); } } @@ -102,8 +105,11 @@ public final class Services { String serviceName = ObjectNameAttributeReadingStrategy.checkPrefixAndExtractServiceName(typeElement, prefixNamespace); - Map innerMap = Maps.newHashMap(); - namespaceToServices.put(serviceName, innerMap); + Map innerMap = namespaceToServices.get(serviceName); + if (innerMap == null) { + innerMap = Maps.newHashMap(); + namespaceToServices.put(serviceName, innerMap); + } List instances = service.getChildElements(XmlNetconfConstants.INSTANCE_KEY); service.checkUnrecognisedElements(instances, typeElement); @@ -112,12 +118,21 @@ public final class Services { XmlElement nameElement = instance.getOnlyChildElement(NAME_KEY); String refName = nameElement.getTextContent(); - XmlElement providerElement = instance.getOnlyChildElement(PROVIDER_KEY); - String providerName = providerElement.getTextContent(); + if (!ModifyAction.DELETE.toString().toLowerCase().equals( + instance.getAttribute( + XmlNetconfConstants.OPERATION_ATTR_KEY, + XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0))) + { + XmlElement providerElement = instance.getOnlyChildElement(PROVIDER_KEY); + String providerName = providerElement.getTextContent(); - instance.checkUnrecognisedElements(nameElement, providerElement); + instance.checkUnrecognisedElements(nameElement, providerElement); - innerMap.put(refName, providerName); + innerMap.put(refName, providerName); + } else { + //since this is a delete we dont have a provider name - we want empty service instance + innerMap.put(refName, EMPTY_PROVIDER); + } } } @@ -128,14 +143,18 @@ public final class Services { Element root = XmlUtil.createElement(document, XmlNetconfConstants.SERVICES_KEY, Optional.of(XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG)); Map>> mappedServices = serviceRegistryWrapper.getMappedServices(); - for (String namespace : mappedServices.keySet()) { + for (Entry>> namespaceToRefEntry : mappedServices.entrySet()) { - for (Entry> serviceEntry : mappedServices.get(namespace).entrySet()) { + for (Entry> serviceEntry : namespaceToRefEntry.getValue().entrySet()) { + // service belongs to config.yang namespace Element serviceElement = XmlUtil.createElement(document, SERVICE_KEY, Optional.absent()); root.appendChild(serviceElement); - Element typeElement = XmlUtil.createPrefixedTextElement(document, XmlUtil.createPrefixedValue(XmlNetconfConstants.PREFIX, TYPE_KEY), XmlNetconfConstants.PREFIX, - serviceEntry.getKey(), Optional.of(namespace)); + // type belongs to config.yang namespace + String serviceType = serviceEntry.getKey(); + Element typeElement = XmlUtil.createTextElementWithNamespacedContent(document, XmlNetconfConstants.TYPE_KEY, + XmlNetconfConstants.PREFIX, namespaceToRefEntry.getKey(), serviceType); + serviceElement.appendChild(typeElement); for (Entry instanceEntry : serviceEntry.getValue().entrySet()) { @@ -155,6 +174,8 @@ public final class Services { } public static final class ServiceInstance { + public static final ServiceInstance EMPTY_SERVICE_INSTANCE = new ServiceInstance("", ""); + public ServiceInstance(String moduleName, String instanceName) { this.moduleName = moduleName; this.instanceName = instanceName;