*/
package org.opendaylight.controller.config.yangjmxgenerator;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-import static java.lang.String.format;
-import static org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants.createConfigQName;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.Sets;
import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc;
import org.opendaylight.controller.config.yangjmxgenerator.attribute.DependencyAttribute;
import org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.Sets;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+import static java.lang.String.format;
+import static org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants.createConfigQName;
/**
* Represents part of yang model that describes a module.
private final String nullableDescription, packageName, javaNamePrefix,
namespace;
- private final Map<String /* java fully qualified name */, String/* identity local name */> providedServices;
+ private final Map<String, QName> providedServices;
private Collection<RuntimeBeanEntry> runtimeBeans;
public ModuleMXBeanEntry(IdentitySchemaNode id,
Map<String, AttributeIfc> yangToAttributes, String packageName,
- Map<String, String> providedServices2, String javaNamePrefix,
+ Map<String, QName> providedServices2, String javaNamePrefix,
String namespace, Collection<RuntimeBeanEntry> runtimeBeans) {
this.globallyUniqueName = id.getQName().getLocalName();
this.yangToAttributes = yangToAttributes;
* @return services implemented by this module. Keys are fully qualified java names of generated
* ServiceInterface classes, values are identity local names.
*/
- public Map<String, String> getProvidedServices() {
+ public Map<String, QName> getProvidedServices() {
return providedServices;
}
checkState(moduleIdentity != null, "Cannot find identity "
+ moduleLocalNameFromXPath
+ " matching augmentation " + augmentation);
- Map<String, String> providedServices = findProvidedServices(
+ Map<String, QName> providedServices = findProvidedServices(
moduleIdentity, currentModule, qNamesToSIEs,
schemaContext);
return yangToAttributes;
}
- private static Map<String, String> findProvidedServices(
+ private static Map<String, QName> findProvidedServices(
IdentitySchemaNode moduleIdentity, Module currentModule,
Map<QName, ServiceInterfaceEntry> qNamesToSIEs,
SchemaContext schemaContext) {
- Map<String, String> result = new HashMap<>();
+ Map<String, QName> result = new HashMap<>();
for (UnknownSchemaNode unknownNode : moduleIdentity
.getUnknownSchemaNodes()) {
if (ConfigConstants.PROVIDED_SERVICE_EXTENSION_QNAME
.getNodeParameter();
ServiceInterfaceEntry sie = findSIE(prefixAndIdentityLocalName,
currentModule, qNamesToSIEs, schemaContext);
- result.put(sie.getFullyQualifiedName(), sie.getQName()
- .getLocalName());
+ result.put(sie.getFullyQualifiedName(), sie.getQName());
}
}
return result;
import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
import java.util.List;
+import java.util.Map;
public class ObjectNameAttributeReadingStrategy extends AbstractAttributeReadingStrategy<AttributeIfc> {
+ private static final Object PREFIX_SEPARATOR = ":";
+
public ObjectNameAttributeReadingStrategy(DependencyAttribute attributeIfc) {
super(attributeIfc);
}
private ObjectNameAttributeMappingStrategy.MappedDependency resolve(XmlElement firstChild) {
XmlElement typeElement = firstChild.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.TYPE_KEY);
- String serviceName = typeElement.getTextContent();
+ Map.Entry<String, String> prefixNamespace = typeElement.findNamespaceOfTextContent();
+
+ String serviceName = checkPrefixAndExtractServiceName(typeElement, prefixNamespace);
+
XmlElement nameElement = firstChild.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.NAME_KEY);
String dependencyName = nameElement.getTextContent();
- return new ObjectNameAttributeMappingStrategy.MappedDependency(serviceName, dependencyName);
+ return new ObjectNameAttributeMappingStrategy.MappedDependency(prefixNamespace.getValue(), serviceName,
+ dependencyName);
+ }
+
+ public static String checkPrefixAndExtractServiceName(XmlElement typeElement, Map.Entry<String, String> prefixNamespace) {
+ String serviceName = typeElement.getTextContent();
+
+ Preconditions.checkState(prefixNamespace.equals("") == false, "Service %s value not prefixed with namespace",
+ XmlNetconfConstants.TYPE_KEY);
+ String prefix = prefixNamespace.getKey() + PREFIX_SEPARATOR;
+ Preconditions.checkState(serviceName.startsWith(prefix),
+ "Service %s not correctly prefixed, expected %s, but was %s", XmlNetconfConstants.TYPE_KEY, prefix,
+ serviceName);
+ serviceName = serviceName.substring(prefix.length());
+ return serviceName;
}
}
protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseDependencyAttribute(
DependencyAttribute attributeIfc) {
String serviceName = attributeIfc.getDependency().getSie().getQName().getLocalName();
+ String namespace = attributeIfc.getDependency().getSie().getQName().getNamespace().toString();
return new ObjectNameAttributeMappingStrategy((SimpleType<?>) attributeIfc.getOpenType(), dependencyTracker,
- serviceName);
+ serviceName, namespace);
}
@Override
private final Services tracker;
private final String serviceName;
+ private final String namespace;
- public ObjectNameAttributeMappingStrategy(SimpleType<?> openType, Services dependencyTracker, String serviceName) {
+ public ObjectNameAttributeMappingStrategy(SimpleType<?> openType, Services dependencyTracker, String serviceName, String namespace) {
super(openType);
this.tracker = dependencyTracker;
this.serviceName = serviceName;
+ this.namespace = namespace;
}
@Override
Util.checkType(value, ObjectName.class);
ObjectName on = (ObjectName) value;
- String refName = tracker.addServiceEntry(serviceName, on);
+ String refName = tracker.addServiceEntry(namespace, serviceName, on);
- return Optional.of(new MappedDependency(serviceName, refName));
+ return Optional.of(new MappedDependency(namespace, serviceName, refName));
}
public static class MappedDependency {
- private final String serviceName, refName;
+ private final String namespace, serviceName, refName;
- public MappedDependency(String serviceName, String refName) {
+ public MappedDependency(String namespace, String serviceName, String refName) {
this.serviceName = serviceName;
this.refName = refName;
+ this.namespace = namespace;
}
public String getServiceName() {
return refName;
}
+ public String getNamespace() {
+ return namespace;
+ }
+
@Override
public String toString() {
final StringBuffer sb = new StringBuffer("MappedDependency{");
- sb.append("serviceName='").append(serviceName).append('\'');
+ sb.append("namespace='").append(namespace).append('\'');
+ sb.append(", serviceName='").append(serviceName).append('\'');
sb.append(", refName='").append(refName).append('\'');
sb.append('}');
return sb.toString();
ObjectNameAttributeMappingStrategy.MappedDependency mappedDep = (ObjectNameAttributeMappingStrategy.MappedDependency) value;
String serviceName = mappedDep.getServiceName();
- if (serviceName.contains(":")) {
- // hack for yuma
- serviceName = serviceName.substring(serviceName.indexOf(":") + 1);
- }
String refName = mappedDep.getRefName();
- logger.trace("Getting service instance by service name {} and ref name {}", serviceName, refName);
- ServiceInstance byRefName = serviceTracker.getByServiceAndRefName(serviceName, refName);
+ String namespace = mappedDep.getNamespace();
+ logger.trace("Getting service instance by service name {} : {} and ref name {}", namespace, serviceName, refName);
+
+ ServiceInstance byRefName = serviceTracker.getByServiceAndRefName(namespace, serviceName, refName);
ObjectName on = ObjectNameUtil.createReadOnlyModuleON(byRefName.getModuleName(), byRefName.getInstanceName());
logger.debug("Attribute {} : {} parsed to type {}", attrName, value, getOpenType());
return Optional.of(on);
String moduleName = ((ObjectNameAttributeMappingStrategy.MappedDependency) value).getServiceName();
String refName = ((ObjectNameAttributeMappingStrategy.MappedDependency) value).getRefName();
+ String namespaceForType = ((ObjectNameAttributeMappingStrategy.MappedDependency) value).getNamespace();
- final Element typeElement = XmlUtil.createTextElement(document, XmlNetconfConstants.TYPE_KEY, moduleName);
+ Element typeElement = XmlUtil.createPrefixedTextElement(document, XmlNetconfConstants.TYPE_KEY, XmlNetconfConstants.PREFIX,
+ moduleName);
+ XmlUtil.addPrefixedNamespaceAttr(typeElement, XmlNetconfConstants.PREFIX, namespaceForType);
innerNode.appendChild(typeElement);
final Element nameElement = XmlUtil.createTextElement(document, XmlNetconfConstants.NAME_KEY, refName);
}
private void addServices(Services serviceTracker, Collection<ObjectName> instances,
- Collection<String> providedServices) {
+ Map<String, String> providedServices) {
for (ObjectName instanceOn : instances) {
- for (String serviceName : providedServices) {
- serviceTracker.addServiceEntry(serviceName, instanceOn);
+ for (Entry<String, String> serviceName : providedServices.entrySet()) {
+ serviceTracker.addServiceEntry(serviceName.getKey(), serviceName.getValue(), instanceOn);
}
}
}
return root;
}
+ // TODO remove commented modules from output
private void addEmptyModulesCommented(Document document, Element root, String moduleNamespace,
Entry<String, Collection<ObjectName>> moduleMappingEntry) {
Element emptyModule = document.createElement(XmlNetconfConstants.MODULE_KEY);
Optional<XmlElement> servicesElement = xml.getOnlyChildElementOptionally(XmlNetconfConstants.SERVICES_KEY,
XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
- Map<String, Map<String, String>> mappedServices;
+ Map<String, Map<String, Map<String, String>>> mappedServices;
if (servicesElement.isPresent()) {
mappedServices = Services.fromXml(servicesElement.get());
recognisedChildren.add(servicesElement.get());
checkState(moduleConfig != null, "Cannot find ModuleConfig with name " + factoryName + " in " + moduleNamesToConfigs);
// Set<String> services = ;
- for (String serviceName : moduleConfig.getProvidedServices()) {
- services.addServiceEntry(serviceName, existingON);
+ for (Entry<String, String> serviceName : moduleConfig.getProvidedServices().entrySet()) {
+
+ services.addServiceEntry(serviceName.getKey(), serviceName.getValue(), existingON);
}
}
package org.opendaylight.controller.netconf.confignetconfconnector.mapping.config;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
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;
import org.opendaylight.controller.netconf.util.xml.XmlUtil;
+import org.opendaylight.yangtools.yang.common.QName;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import javax.management.ObjectName;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
public class ModuleConfig {
private final String moduleName;
private final InstanceConfig instanceConfig;
- private final Collection<String> providedServices;
+ // TODO 2 services from same namespace ?
+ private final Map<String, String> providedServices;
- public ModuleConfig(String moduleName, InstanceConfig mbeanMapping, Collection<String> providedServices) {
+ public ModuleConfig(String moduleName, InstanceConfig mbeanMapping, Collection<QName> providedServices) {
this.moduleName = moduleName;
this.instanceConfig = mbeanMapping;
- this.providedServices = providedServices;
+ this.providedServices = mapServices(providedServices);
+ }
+
+ private Map<String, String> mapServices(Collection<QName> providedServices) {
+ HashMap<String, String> mapped = Maps.newHashMap();
+
+ for (QName providedService : providedServices) {
+ String key = providedService.getNamespace().toString();
+ Preconditions.checkState(mapped.containsKey(key) == false);
+ mapped.put(key, providedService.getLocalName());
+ }
+
+ return mapped;
}
public InstanceConfig getMbeanMapping() {
return instanceConfig;
}
- public Collection<String> getProvidedServices() {
+ public Map<String, String> getProvidedServices() {
return providedServices;
}
private String getPrefix(String namespace) {
// if(namespace.contains(":")==false)
- return "prefix";
+ return XmlNetconfConstants.PREFIX;
// return namespace.substring(namespace.lastIndexOf(':') + 1,
// namespace.length());
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
+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;
private long suffix = 1;
private final Map<ServiceInstance, String> instanceToRef = Maps.newHashMap();
- private final Map<String/* ServiceName */, Map<String/* refName */, ServiceInstance>> serviceNameToRefNameToInstance = Maps
+ private final Map<String /*Namespace*/, Map<String/* ServiceName */, Map<String/* refName */, ServiceInstance>>> namespaceToServiceNameToRefNameToInstance = Maps
.newHashMap();
- public String addServiceEntry(String serviceName, ObjectName on) {
+ public String addServiceEntry(String namespace, String serviceName, ObjectName on) {
String moduleName = on.getKeyProperty("moduleFactoryName");
String instanceName = on.getKeyProperty("instanceName");
- String refName = addServiceEntry(serviceName, moduleName, instanceName);
+ String refName = addServiceEntry(namespace, serviceName, moduleName, instanceName);
logger.trace("Added service entry to tracker. Service name {}, ref name {}, module name {}, instance name {}",
serviceName, refName, moduleName, instanceName);
return refName;
}
@VisibleForTesting
- public String addServiceEntry(String serviceName, String moduleName, String instanceName) {
+ public String addServiceEntry(String namespace, String serviceName, String moduleName, String instanceName) {
ServiceInstance serviceInstance = new ServiceInstance(moduleName, instanceName);
serviceInstance.setServiceName(serviceName);
String refName = instanceToRef.get(serviceInstance);
+ Map<String, Map<String, ServiceInstance>> serviceNameToRefNameToInstance = namespaceToServiceNameToRefNameToInstance.get(namespace);
+ if (serviceNameToRefNameToInstance == null) {
+ serviceNameToRefNameToInstance = Maps.newHashMap();
+ namespaceToServiceNameToRefNameToInstance.put(namespace, serviceNameToRefNameToInstance);
+ }
+
Map<String, ServiceInstance> refNameToInstance = serviceNameToRefNameToInstance.get(serviceName);
if (refNameToInstance == null) {
refNameToInstance = Maps.newHashMap();
return refNamesAsSet;
}
- public ServiceInstance getByServiceAndRefName(String serviceName, String refName) {
+ public ServiceInstance getByServiceAndRefName(String namespace, String serviceName, String refName) {
+ Map<String, Map<String, ServiceInstance>> serviceNameToRefNameToInstance = namespaceToServiceNameToRefNameToInstance.get(namespace);
+ Preconditions.checkArgument(serviceNameToRefNameToInstance != null, "No serviceInstances mapped to " + namespace + " , "
+ + serviceNameToRefNameToInstance.keySet());
+
Map<String, ServiceInstance> refNameToInstance = serviceNameToRefNameToInstance.get(serviceName);
Preconditions.checkArgument(refNameToInstance != null, "No serviceInstances mapped to " + serviceName + " , "
+ serviceNameToRefNameToInstance.keySet());
// TODO hide getMappedServices, call it explicitly in toXml
- public Map<String, Map<String, String>> getMappedServices() {
- Map<String, Map<String, String>> retVal = Maps.newHashMap();
+ public Map<String, Map<String, Map<String, String>>> getMappedServices() {
+ Map<String, Map<String, Map<String, String>>> retVal = Maps.newHashMap();
+
+ for (String namespace : namespaceToServiceNameToRefNameToInstance.keySet()) {
- for (String serviceName : serviceNameToRefNameToInstance.keySet()) {
+ Map<String, Map<String, ServiceInstance>> serviceNameToRefNameToInstance = namespaceToServiceNameToRefNameToInstance
+ .get(namespace);
+ Map<String, Map<String, String>> innerRetVal = Maps.newHashMap();
- Map<String, String> innerRetVal = Maps.transformValues(serviceNameToRefNameToInstance.get(serviceName),
- new Function<ServiceInstance, String>() {
- @Nullable
- @Override
- public String apply(@Nullable ServiceInstance serviceInstance) {
- return serviceInstance.toString();
- }
- });
- retVal.put(serviceName, innerRetVal);
+ for (String serviceName : serviceNameToRefNameToInstance.keySet()) {
+
+ Map<String, String> innerInnerRetVal = Maps.transformValues(
+ serviceNameToRefNameToInstance.get(serviceName), new Function<ServiceInstance, String>() {
+ @Nullable
+ @Override
+ public String apply(@Nullable ServiceInstance serviceInstance) {
+ return serviceInstance.toString();
+ }
+ });
+ innerRetVal.put(serviceName, innerInnerRetVal);
+ }
+ retVal.put(namespace, innerRetVal);
}
return retVal;
// TODO hide resolveServices, call it explicitly in fromXml
- public static Services resolveServices(Map<String, Map<String, String>> mappedServices) {
+ public static Services resolveServices(Map<String, Map<String, Map<String, String>>> mappedServices) {
Services tracker = new Services();
- for (Entry<String, Map<String, String>> serviceEntry : mappedServices.entrySet()) {
+ for (Entry<String, Map<String, Map<String, String>>> namespaceEntry : mappedServices.entrySet()) {
+ String namespace = namespaceEntry.getKey();
- String serviceName = serviceEntry.getKey();
- for (Entry<String, String> refEntry : serviceEntry.getValue().entrySet()) {
+ for (Entry<String, Map<String, String>> serviceEntry : namespaceEntry.getValue().entrySet()) {
- Map<String, ServiceInstance> refNameToInstance = tracker.serviceNameToRefNameToInstance
- .get(serviceName);
- if (refNameToInstance == null) {
- refNameToInstance = Maps.newHashMap();
- tracker.serviceNameToRefNameToInstance.put(serviceName, refNameToInstance);
- }
+ String serviceName = serviceEntry.getKey();
+ for (Entry<String, String> refEntry : serviceEntry.getValue().entrySet()) {
- String refName = refEntry.getKey();
- Preconditions.checkState(false == refNameToInstance.containsKey(refName),
- "Duplicate reference name to service " + refName + " under service " + serviceName);
- ServiceInstance serviceInstance = ServiceInstance.fromString(refEntry.getValue());
- refNameToInstance.put(refName, serviceInstance);
+ Map<String, Map<String, ServiceInstance>> namespaceToServices = tracker.namespaceToServiceNameToRefNameToInstance.get(namespace);
+ if (namespaceToServices == null) {
+ namespaceToServices = Maps.newHashMap();
+ tracker.namespaceToServiceNameToRefNameToInstance.put(namespace, namespaceToServices);
+ }
+
+ Map<String, ServiceInstance> refNameToInstance = namespaceToServices
+ .get(serviceName);
+ if (refNameToInstance == null) {
+ refNameToInstance = Maps.newHashMap();
+ namespaceToServices.put(serviceName, refNameToInstance);
+ }
- tracker.instanceToRef.put(serviceInstance, refEntry.getKey());
+ String refName = refEntry.getKey();
+ Preconditions.checkState(false == refNameToInstance.containsKey(refName),
+ "Duplicate reference name to service " + refName + " under service " + serviceName);
+ ServiceInstance serviceInstance = ServiceInstance.fromString(refEntry.getValue());
+ refNameToInstance.put(refName, serviceInstance);
+
+ tracker.instanceToRef.put(serviceInstance, refEntry.getKey());
+ }
}
}
return tracker;
}
- public static Map<String, Map<String, String>> fromXml(XmlElement xml) {
- Map<String, Map<String, String>> retVal = Maps.newHashMap();
+ public static Map<String, Map<String, Map<String, String>>> fromXml(XmlElement xml) {
+ Map<String, Map<String, Map<String, String>>> retVal = Maps.newHashMap();
List<XmlElement> services = xml.getChildElements(SERVICE_KEY);
xml.checkUnrecognisedElements(services);
for (XmlElement service : services) {
XmlElement typeElement = service.getOnlyChildElement(TYPE_KEY);
- String serviceName = typeElement.getTextContent();
+ Entry<String, String> prefixNamespace = typeElement.findNamespaceOfTextContent();
+
+ Preconditions.checkState(prefixNamespace.getKey()!=null && prefixNamespace.getKey().equals("") == false, "Type attribute was not prefixed");
+
+ Map<String, Map<String, String>> namespaceToServices = retVal.get(prefixNamespace.getValue());
+ if(namespaceToServices == null) {
+ namespaceToServices = Maps.newHashMap();
+ retVal.put(prefixNamespace.getValue(), namespaceToServices);
+ }
+
+ String serviceName = ObjectNameAttributeReadingStrategy.checkPrefixAndExtractServiceName(typeElement, prefixNamespace);
Map<String, String> innerMap = Maps.newHashMap();
- retVal.put(serviceName, innerMap);
+ namespaceToServices.put(serviceName, innerMap);
List<XmlElement> instances = service.getChildElements(XmlNetconfConstants.INSTANCE_KEY);
service.checkUnrecognisedElements(instances, typeElement);
}
}
- public Element toXml(Map<String, Map<String, String>> mappedServices, Document document) {
+ public Element toXml(Map<String, Map<String, Map<String, String>>> mappedServices, Document document) {
Element root = document.createElement(XmlNetconfConstants.SERVICES_KEY);
XmlUtil.addNamespaceAttr(root, XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
- for (Entry<String, Map<String, String>> serviceEntry : mappedServices.entrySet()) {
- Element serviceElement = document.createElement(SERVICE_KEY);
- root.appendChild(serviceElement);
+ for (String namespace : mappedServices.keySet()) {
+
+ for (Entry<String, Map<String, String>> serviceEntry : mappedServices.get(namespace).entrySet()) {
+ Element serviceElement = document.createElement(SERVICE_KEY);
+ root.appendChild(serviceElement);
- Element typeElement = XmlUtil.createTextElement(document, TYPE_KEY, serviceEntry.getKey());
- serviceElement.appendChild(typeElement);
+ Element typeElement = XmlUtil.createPrefixedTextElement(document, TYPE_KEY, XmlNetconfConstants.PREFIX,
+ serviceEntry.getKey());
+ XmlUtil.addPrefixedNamespaceAttr(typeElement, XmlNetconfConstants.PREFIX, namespace);
+ serviceElement.appendChild(typeElement);
- for (Entry<String, String> instanceEntry : serviceEntry.getValue().entrySet()) {
- Element instanceElement = document.createElement(XmlNetconfConstants.INSTANCE_KEY);
- serviceElement.appendChild(instanceElement);
+ for (Entry<String, String> instanceEntry : serviceEntry.getValue().entrySet()) {
+ Element instanceElement = document.createElement(XmlNetconfConstants.INSTANCE_KEY);
+ serviceElement.appendChild(instanceElement);
- Element nameElement = XmlUtil.createTextElement(document, NAME_KEY, instanceEntry.getKey());
- instanceElement.appendChild(nameElement);
+ Element nameElement = XmlUtil.createTextElement(document, NAME_KEY, instanceEntry.getKey());
+ instanceElement.appendChild(nameElement);
- Element providerElement = XmlUtil.createTextElement(document, PROVIDER_KEY, instanceEntry.getValue());
- instanceElement.appendChild(providerElement);
+ Element providerElement = XmlUtil.createTextElement(document, PROVIDER_KEY, instanceEntry.getValue());
+ instanceElement.appendChild(providerElement);
+ }
}
- }
+ }
return root;
}
Map<String/* Namespace from yang file */,
Map<String /* Name of module entry from yang file */, ModuleMXBeanEntry>> mBeanEntries) {
Map<String, Map<String, ModuleConfig>> factories = transform(configRegistryClient, mBeanEntries);
+
return new Config(factories);
}
Element dataElement = document.createElement(XmlNetconfConstants.DATA_KEY);
final Set<ObjectName> instances = Datastore.getInstanceQueryStrategy(source, this.transactionProvider)
.queryInstances(configRegistryClient);
+
final Config configMapping = new Config(transform(configRegistryClient,
yangStoreSnapshot.getModuleMXBeanEntryMap()));
dataElement = configMapping.toXml(instances, this.maybeNamespace, document, dataElement);
edit("netconfMessages/editConfig.xml");
checkBinaryLeafEdited(getConfigCandidate());
+
// default-operation:none, should not affect binary leaf
edit("netconfMessages/editConfig_none.xml");
checkBinaryLeafEdited(getConfigCandidate());
// check after edit
commit();
Element response = getConfigRunning();
- // System.out.println(Xml.toString(response));
checkBinaryLeafEdited(response);
checkTypeConfigAttribute(response);
/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
+* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+*
+* This program and the accompanying materials are made available under the
+* terms of the Eclipse Public License v1.0 which accompanies this distribution,
+* and is available at http://www.eclipse.org/legal/epl-v10.html
+*/
package org.opendaylight.controller.netconf.confignetconfconnector;
@Test
public void testOneInstanceMultipleServices() {
Services services = new Services();
- services.addServiceEntry("s1", "module", "instance");
+ services.addServiceEntry("nm", "s1", "module", "instance");
assertEquals(1, services.getMappedServices().size());
- services.addServiceEntry("s2", "module", "instance");
+ services.addServiceEntry("nm2", "s2", "module", "instance");
assertEquals(2, services.getMappedServices().size());
}
@Test
public void testMultipleInstancesOneName() throws Exception {
Services services = new Services();
- services.addServiceEntry("s1", "module", "instance");
+ services.addServiceEntry("nm", "s1", "module", "instance");
assertEquals(1, services.getMappedServices().size());
- services.addServiceEntry("s1", "module2", "instance");
+ services.addServiceEntry("nm", "s1", "module2", "instance");
assertEquals(1, services.getMappedServices().size());
- assertEquals(2, services.getMappedServices().get("s1").size());
- assertTrue(services.getMappedServices().get("s1").containsKey("ref_instance"));
- assertTrue(services.getMappedServices().get("s1").containsKey("ref_instance_1"));
+ assertEquals(2, services.getMappedServices().get("nm").get("s1").size());
+ assertTrue(services.getMappedServices().get("nm").get("s1").containsKey("ref_instance"));
+ assertTrue(services.getMappedServices().get("nm").get("s1").containsKey("ref_instance_1"));
}
@Test
public void testMultipleInstancesOneName2() throws Exception {
Services services = new Services();
- services.addServiceEntry("s1", "module", "instance_1");
-
- services.addServiceEntry("s2", "module2", "instance");
- services.addServiceEntry("s2", "module3", "instance");
- services.addServiceEntry("s1", "module3", "instance");
-
- assertEquals(2, services.getMappedServices().get("s1").size());
- assertEquals(2, services.getMappedServices().get("s2").size());
- assertTrue(services.getMappedServices().get("s1").containsKey("ref_instance_2"));
- assertTrue(services.getMappedServices().get("s1").containsKey("ref_instance_1"));
- assertTrue(services.getMappedServices().get("s2").containsKey("ref_instance"));
- assertTrue(services.getMappedServices().get("s2").containsKey("ref_instance_2"));
+ services.addServiceEntry("nm", "s1", "module", "instance_1");
+
+ services.addServiceEntry("nm2", "s2", "module2", "instance");
+ services.addServiceEntry("nm2", "s2", "module3", "instance");
+ services.addServiceEntry("nm", "s1", "module3", "instance");
+
+ assertEquals(2, services.getMappedServices().get("nm").get("s1").size());
+ assertEquals(2, services.getMappedServices().get("nm2").get("s2").size());
+ assertTrue(services.getMappedServices().get("nm").get("s1").containsKey("ref_instance_2"));
+ assertTrue(services.getMappedServices().get("nm").get("s1").containsKey("ref_instance_1"));
+ assertTrue(services.getMappedServices().get("nm2").get("s2").containsKey("ref_instance"));
+ assertTrue(services.getMappedServices().get("nm2").get("s2").containsKey("ref_instance_2"));
}
}
prefix = "";
}
if (namespaces.containsKey(prefix) == false) {
- throw new IllegalArgumentException("Cannot find namespace for " + element + ". Prefix from content is "
+ throw new IllegalArgumentException("Cannot find namespace for " + XmlUtil.toString(element) + ". Prefix from content is "
+ prefix + ". Found namespaces " + namespaces);
}
return Maps.immutableEntry(prefix, namespaces.get(prefix));
public static final String NAME_KEY = "name";
public static final String NOTIFICATION_ELEMENT_NAME = "notification";
+ public static final String PREFIX = "prefix";
+
//
//
public static final String RFC4741_TARGET_NAMESPACE = "urn:ietf:params:xml:ns:netconf:base:1.0";
<core-size>44</core-size>
</peers>
<testing-dep>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<name>ref_dep</name>
</testing-dep>
</module>
</type>
<name>test2</name>
<testing-dep>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<name>ref_dep</name>
</testing-dep>
</module>
<services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
<service>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<instance>
<name>ref_dep</name>
<provider>/config/modules/module[name='impl-dep']/instance[name='dep']
<core-size>44</core-size>
</peers>
<testing-dep>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<name>ref_dep</name>
</testing-dep>
</module>
</type>
<name>test2</name>
<testing-dep>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<name>ref_dep</name>
</testing-dep>
</module>
</modules>
<services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
<service>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<instance>
<name>ref_dep</name>
<provider>/config/modules/module[name='impl-dep']/instance[name='dep']
<core-size>44</core-size>
</peers>
<testing-dep>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<name>ref_dep</name>
</testing-dep>
</module>
</type>
<name>test2</name>
<testing-dep>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<name>ref_dep</name>
</testing-dep>
</module>
<services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
<service>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<instance>
<name>ref_dep</name>
<provider>/config/modules/module[name='impl-dep']/instance[name='dep']
<core-size>44</core-size>
</peers>
<testing-dep>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<name>ref_dep</name>
</testing-dep>
</module>
</type>
<name>test2</name>
<testing-dep>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<name>ref_dep</name>
</testing-dep>
</module>
<services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
<service>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<instance>
<name>ref_dep</name>
<provider>/config/modules/module[name='impl-dep']/instance[name='dep']
<core-size>44</core-size>
</peers>
<testing-dep>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<name>ref_dep</name>
</testing-dep>
</module>
</type>
<name>test2</name>
<testing-dep>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<name>ref_dep</name>
</testing-dep>
</module>
<services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
<service>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<instance>
<name>ref_dep</name>
<provider>/config/modules/module[name='impl-dep']/instance[name='dep']
<core-size>44</core-size>
</peers>
<testing-dep>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<name>ref_dep</name>
</testing-dep>
</module>
</type>
<name>test2</name>
<testing-dep>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<name>ref_dep</name>
</testing-dep>
</module>
<services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
<service>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<instance>
<name>ref_dep</name>
<provider>/config/modules/module[name='impl-dep']/instance[name='dep']
<services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
<service>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<instance>
<name>ref_dep</name>
<provider>/config/modules/module[name='impl-dep']/instance[name='dep']
<services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
<service>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<instance>
<name>ref_dep</name>
<provider>/config/modules/module[name='impl-dep']/instance[name='dep']
<unknownAttribute>error</unknownAttribute>
l
<service>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<instance>
<name>ref_dep</name>
<provider>/config/modules/module[name='impl-dep']/instance[name='dep']
<services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
l
<service>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<unknownAttribute>error</unknownAttribute>
<instance>
<services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
l
<service>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<instance>
<name>ref_dep</name>
<services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
<service>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<instance>
<name>ref_dep</name>
<provider>/config/modules/module[name='impl-dep']/instance[name='dep']
<core-size>44</core-size>
</peers>
<testing-dep>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<name>ref_dep</name>
</testing-dep>
</module>
</type>
<name>test2</name>
<testing-dep>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<name>ref_dep</name>
</testing-dep>
</module>
<services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
<service>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<instance>
<name>ref_dep</name>
<provider>/config/modules/module[name='impl-dep']/instance[name='dep']
<unknownAttribute>error</unknownAttribute>
</peers>
<testing-dep>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<name>ref_dep</name>
</testing-dep>
</module>
</type>
<name>test2</name>
<testing-dep>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<name>ref_dep</name>
</testing-dep>
</module>
<services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
<service>
- <type>testing</type>
+ <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
<instance>
<name>ref_dep</name>
<provider>/config/modules/module[name='impl-dep']/instance[name='dep']