brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjcorb...@apache.org
Subject [3/5] incubator-brooklyn git commit: Fix sharded-mongodb, with CoLocatedMongoDbRouter
Date Tue, 09 Dec 2014 10:45:32 GMT
Fix sharded-mongodb, with CoLocatedMongoDbRouter

- was getting NPE in CoLocatedMongoDbRouter.init, while trying to
  resolve config set in yam that pointed at another entity.


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

Branch: refs/heads/master
Commit: a46391e1671bd37460eaa5676badb87c4ba48463
Parents: 7051e6c
Author: Aled Sage <aled.sage@gmail.com>
Authored: Tue Nov 18 22:05:26 2014 +0000
Committer: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Committed: Tue Dec 9 10:38:23 2014 +0000

----------------------------------------------------------------------
 .../sharding/CoLocatedMongoDBRouterImpl.java    | 33 ++++++++++++++++----
 1 file changed, 27 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a46391e1/software/nosql/src/main/java/brooklyn/entity/nosql/mongodb/sharding/CoLocatedMongoDBRouterImpl.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/mongodb/sharding/CoLocatedMongoDBRouterImpl.java
b/software/nosql/src/main/java/brooklyn/entity/nosql/mongodb/sharding/CoLocatedMongoDBRouterImpl.java
index d61478f..a8bec4e 100644
--- a/software/nosql/src/main/java/brooklyn/entity/nosql/mongodb/sharding/CoLocatedMongoDBRouterImpl.java
+++ b/software/nosql/src/main/java/brooklyn/entity/nosql/mongodb/sharding/CoLocatedMongoDBRouterImpl.java
@@ -21,12 +21,16 @@ package brooklyn.entity.nosql.mongodb.sharding;
 import java.util.Collection;
 
 import brooklyn.enricher.Enrichers;
+import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.SameServerEntityImpl;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.entity.trait.Startable;
 import brooklyn.event.basic.DependentConfiguration;
 import brooklyn.location.Location;
 
+import com.google.common.base.Predicates;
+import com.google.common.collect.Iterables;
+
 public class CoLocatedMongoDBRouterImpl extends SameServerEntityImpl implements CoLocatedMongoDBRouter
{
     @Override
     public void init() {
@@ -35,15 +39,32 @@ public class CoLocatedMongoDBRouterImpl extends SameServerEntityImpl implements
         for (EntitySpec<?> siblingSpec : getConfig(CoLocatedMongoDBRouter.SIBLING_SPECS))
{
             addChild(siblingSpec);
         }
-        setAttribute(ROUTER, addChild(EntitySpec.create(MongoDBRouter.class)
-                .configure(MongoDBRouter.CONFIG_SERVERS,
-                        DependentConfiguration.attributeWhenReady(getConfig(CoLocatedMongoDBRouter.SHARDED_DEPLOYMENT),
MongoDBConfigServerCluster.CONFIG_SERVER_ADDRESSES))));
-        addEnricher(Enrichers.builder().propagating(MongoDBRouter.PORT).from(getAttribute(ROUTER)).build());
     }
-    
+
     @Override
     protected void doStart(Collection<? extends Location> locations) {
-        super.start(locations);
+        // TODO Changed to create the router child after init as a workaround.
+        // When we use `mongo-sharded.yaml`, and we call 
+        // `getConfig(CoLocatedMongoDBRouter.SHARDED_DEPLOYMENT)`,
+        // the value is `$brooklyn:component("shardeddeployment")`.
+        // To look up the component, it tries to do `entity().getApplication()` to
+        // search the entities for one with the correct id. However if being done
+        // during `init()`, then this (which is returned by `entity()`) has not had its parent
+        // set, so `entity().getApplication()` returns null.
+        //
+        // We should move this code back to `init()` once we have a solution for that.
+        // We can also remove the call to Entities.manage() once this is in init() again.
+        
+        MongoDBRouter router = addChild(EntitySpec.create(MongoDBRouter.class)
+                .configure(MongoDBRouter.CONFIG_SERVERS,
+                        DependentConfiguration.attributeWhenReady(
+                                getConfig(CoLocatedMongoDBRouter.SHARDED_DEPLOYMENT), 
+                                MongoDBConfigServerCluster.CONFIG_SERVER_ADDRESSES)));
+        Entities.manage(router);
+        setAttribute(ROUTER, (MongoDBRouter) Iterables.tryFind(getChildren(), Predicates.instanceOf(MongoDBRouter.class)).get());
+        addEnricher(Enrichers.builder().propagating(MongoDBRouter.PORT).from(router).build());
+        
+        super.doStart(locations);
         setAttribute(Startable.SERVICE_UP, true);
     }
 }


Mime
View raw message