You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by hu...@apache.org on 2012/10/22 11:14:00 UTC

git commit: The adapterlist needs to be merged instead of overwritten in ComponentLocator.

Updated Branches:
  refs/heads/master d04bfc340 -> 5b2e1f42b


The adapterlist needs to be merged instead of overwritten in
ComponentLocator.

When using the extend option in the components-nonoss.xml the adapter
lsit was overwritten (putAll on the map), but it should be merged
instead. This prevented adapters from the parent to be loaded.

Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/5b2e1f42
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/5b2e1f42
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/5b2e1f42

Branch: refs/heads/master
Commit: 5b2e1f42b74d497c8ead6f697b66cea18d2844b4
Parents: d04bfc3
Author: Hugo Trippaers <ht...@schubergphilis.com>
Authored: Mon Oct 22 11:13:34 2012 +0200
Committer: Hugo Trippaers <ht...@schubergphilis.com>
Committed: Mon Oct 22 11:13:34 2012 +0200

----------------------------------------------------------------------
 .../cloud/utils/component/ComponentLocator.java    |   29 +++++++++++++--
 1 files changed, 26 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5b2e1f42/utils/src/com/cloud/utils/component/ComponentLocator.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/component/ComponentLocator.java b/utils/src/com/cloud/utils/component/ComponentLocator.java
index dea34d9..2f76f15 100755
--- a/utils/src/com/cloud/utils/component/ComponentLocator.java
+++ b/utils/src/com/cloud/utils/component/ComponentLocator.java
@@ -32,6 +32,7 @@ import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Properties;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
@@ -199,17 +200,38 @@ public class ComponentLocator implements ComponentLocatorMBean {
                 library = (ComponentLibrary)clazz.newInstance();
                 _daoMap.putAll(library.getDaos());
                 _managerMap.putAll(library.getManagers());
-                adapters.putAll(library.getAdapters());
                 _factories.putAll(library.getFactories());
                 _pluginsMap.putAll(library.getPluggableServices());
+
+                // putAll overwrites existing keys, so merge instead
+                for (Entry<String, List<ComponentInfo<Adapter>>> e : handler.adapters.entrySet()) {
+                	if (adapters.containsKey(e.getKey())) {
+                		s_logger.debug("Merge needed for " + e.getKey());
+                		adapters.get(e.getKey()).addAll(e.getValue());
+                	}
+                	else {
+                		adapters.put(e.getKey(), e.getValue());
+                	}
+                }
             }
 
             _daoMap.putAll(handler.daos);
             _managerMap.putAll(handler.managers);
             _checkerMap.putAll(handler.checkers);
-            adapters.putAll(handler.adapters);
             _pluginsMap.putAll(handler.pluggableServices);
-
+            
+            // putAll overwrites existing keys, so merge instead
+            for (Entry<String, List<ComponentInfo<Adapter>>> e : handler.adapters.entrySet()) {
+            	if (adapters.containsKey(e.getKey())) {
+            		s_logger.debug("Merge needed for " + e.getKey());
+            		adapters.get(e.getKey()).addAll(e.getValue());
+            	}
+            	else {
+            		adapters.put(e.getKey(), e.getValue());
+            	}
+            }
+            
+            
             return new Pair<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>>(handler, adapters);
         } catch (ParserConfigurationException e) {
             s_logger.error("Unable to load " + _serverName + " due to errors while parsing " + filename, e);
@@ -1261,4 +1283,5 @@ public class ComponentLocator implements ComponentLocatorMBean {
             return index;
         }
     }
+    
 }