Merge "removed config-util from pax-exam minimum bundles as this is not a bundle"
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / mapping / config / Config.java
index 2242101f5b12ab1cbdf940576dc6a60d530a7c25..f33a32271fd189dd39a61b7403069d765e4d1615 100644 (file)
@@ -52,21 +52,24 @@ public class Config {
         this.moduleNamesToConfigs = Collections.unmodifiableMap(moduleNamesToConfigs);
     }
 
-    private Map<String, Map<String, Collection<ObjectName>>> getMappedInstances(Set<ObjectName> instancesToMap,
-            Services serviceTracker) {
+    public static Map<String, Map<String, Collection<ObjectName>>> getMappedInstances(Set<ObjectName> instancesToMap,
+                                                                                Services serviceTracker, Map<String, Map<String, ModuleConfig>> configs) {
         Multimap<String, ObjectName> moduleToInstances = mapInstancesToModules(instancesToMap);
 
         Map<String, Map<String, Collection<ObjectName>>> retVal = Maps.newLinkedHashMap();
 
-        for (String namespace : moduleConfigs.keySet()) {
+        for (String namespace : configs.keySet()) {
 
             Map<String, Collection<ObjectName>> innerRetVal = Maps.newHashMap();
 
-            for (Entry<String, ModuleConfig> mbeEntry : moduleConfigs.get(namespace).entrySet()) {
+            for (Entry<String, ModuleConfig> mbeEntry : configs.get(namespace).entrySet()) {
 
                 String moduleName = mbeEntry.getKey();
                 Collection<ObjectName> instances = moduleToInstances.get(moduleName);
 
+                // TODO, this code does not support same module names from different namespaces
+                // Namespace should be present in ObjectName
+
                 if (instances == null)
                     continue;
 
@@ -86,10 +89,10 @@ public class Config {
         return retVal;
     }
 
-    private void addServices(Services serviceTracker, Collection<ObjectName> instances,
-            Map<String, String> providedServices) {
+    private static void addServices(Services serviceTracker, Collection<ObjectName> instances,
+            Multimap<String, String> providedServices) {
         for (ObjectName instanceOn : instances) {
-            for (Entry<String, String> serviceName : providedServices.entrySet()) {
+            for (Entry<String, String> serviceName : providedServices.entries()) {
                 serviceTracker.addServiceEntry(serviceName.getKey(), serviceName.getValue(), instanceOn);
             }
         }
@@ -115,7 +118,7 @@ public class Config {
         Services serviceTracker = new Services();
 
         Map<String, Map<String, Collection<ObjectName>>> moduleToInstances = getMappedInstances(instancesToMap,
-                serviceTracker);
+                serviceTracker, moduleConfigs);
 
         Element root = dataElement;
         if (maybeNamespace.isPresent()) {
@@ -243,7 +246,7 @@ public class Config {
 
             checkState(moduleConfig != null, "Cannot find ModuleConfig with name " + factoryName + " in " + moduleNamesToConfigs);
             // Set<String> services = ;
-            for (Entry<String, String> serviceName : moduleConfig.getProvidedServices().entrySet()) {
+            for (Entry<String, String> serviceName : moduleConfig.getProvidedServices().entries()) {
 
                 services.addServiceEntry(serviceName.getKey(), serviceName.getValue(), existingON);
             }