brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [4/9] git commit: Avoid NPE in MongoDBShardClusterImpl
Date Tue, 28 Oct 2014 17:55:37 GMT
Avoid NPE in MongoDBShardClusterImpl


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

Branch: refs/heads/master
Commit: 7157b6d3d2d8ce0720a45d16ddb0e30052c0b2dc
Parents: 28fc278
Author: Aled Sage <aled.sage@gmail.com>
Authored: Tue Oct 28 15:40:17 2014 +0000
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Tue Oct 28 17:03:17 2014 +0000

----------------------------------------------------------------------
 .../mongodb/sharding/MongoDBShardClusterImpl.java     | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7157b6d3/software/nosql/src/main/java/brooklyn/entity/nosql/mongodb/sharding/MongoDBShardClusterImpl.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/mongodb/sharding/MongoDBShardClusterImpl.java
b/software/nosql/src/main/java/brooklyn/entity/nosql/mongodb/sharding/MongoDBShardClusterImpl.java
index 1d68728..5b465ca 100644
--- a/software/nosql/src/main/java/brooklyn/entity/nosql/mongodb/sharding/MongoDBShardClusterImpl.java
+++ b/software/nosql/src/main/java/brooklyn/entity/nosql/mongodb/sharding/MongoDBShardClusterImpl.java
@@ -89,11 +89,15 @@ public class MongoDBShardClusterImpl extends DynamicClusterImpl implements
Mongo
         for (Entity member : this.getMembers()) {
             if (member.getAttribute(Startable.SERVICE_UP) && !addedMembers.contains(member))
{
                 MongoDBServer primary = member.getAttribute(MongoDBReplicaSet.PRIMARY_ENTITY);
-                String addr = Strings.removeFromStart(primary.getAttribute(MongoDBServer.MONGO_SERVER_ENDPOINT),
"http://");
-                String replicaSetURL = ((MongoDBReplicaSet) member).getName() + "/" + addr;
-                LOG.info("Using {} to add shard URL {}...", router, replicaSetURL);
-                client.addShardToRouter(replicaSetURL);
-                addedMembers.add(member);
+                if (primary != null) {
+                    String addr = Strings.removeFromStart(primary.getAttribute(MongoDBServer.MONGO_SERVER_ENDPOINT),
"http://");
+                    String replicaSetURL = ((MongoDBReplicaSet) member).getName() + "/" +
addr;
+                    LOG.info("Using {} to add shard URL {}...", router, replicaSetURL);
+                    client.addShardToRouter(replicaSetURL);
+                    addedMembers.add(member);
+                } else {
+                    LOG.debug("{} not set for member {}); not adding shart to router {}",
new Object[] {MongoDBReplicaSet.PRIMARY_ENTITY, member, router});
+                }
             }
         }
     }


Mime
View raw message