brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjcorb...@apache.org
Subject [4/7] incubator-brooklyn git commit: addresses PR review comments
Date Thu, 17 Sep 2015 13:27:56 GMT
addresses PR review comments


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

Branch: refs/heads/master
Commit: e4067e58bb293fea00ad9a60da52b1da1f2667cf
Parents: 3bb9cfc
Author: Robert Moss <robertgmoss@gmail.com>
Authored: Wed Sep 16 15:04:42 2015 +0100
Committer: Robert Moss <robertgmoss@gmail.com>
Committed: Wed Sep 16 15:35:29 2015 +0100

----------------------------------------------------------------------
 .../nosql/mongodb/MongoDBReplicaSetImpl.java    | 60 +++++++++++---------
 1 file changed, 32 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e4067e58/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/mongodb/MongoDBReplicaSetImpl.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/mongodb/MongoDBReplicaSetImpl.java
b/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/mongodb/MongoDBReplicaSetImpl.java
index 59e6524..2c95d02 100644
--- a/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/mongodb/MongoDBReplicaSetImpl.java
+++ b/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/mongodb/MongoDBReplicaSetImpl.java
@@ -54,7 +54,7 @@ import org.apache.brooklyn.util.text.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.api.client.util.Sets;
+import com.google.common.collect.Sets;
 import com.google.common.base.Function;
 import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
@@ -142,15 +142,17 @@ public class MongoDBReplicaSetImpl extends DynamicClusterImpl implements
MongoDB
                 .publishing(MongoDBAuthenticationMixins.ROOT_USERNAME)
                 .fromMembers()
                 .valueToReportIfNoSensors(null)
-                .computing(new Function<Collection<String>, String>() {
-                        @Override
-                        public String apply(Collection<String> input) {
-                            if (input==null || input.isEmpty()) return null;
-                            // when authentication is used all members have the same value
-                            return Iterables.getFirst(input, null);
-                        }})
+                .computing(new RootUsernameReducer())
                 .build());
-    };
+    }
+
+    public static class RootUsernameReducer implements Function<Collection<String>,
String>{
+        @Override
+        public String apply(Collection<String> input) {
+            // when authentication is used all members have the same value
+            return (input == null || input.isEmpty()) ? null : Iterables.getFirst(input,
null);
+        };
+    }
 
     /** @return {@link #NON_PRIMARY_REMOVAL_STRATEGY} */
     @Override
@@ -397,26 +399,9 @@ public class MongoDBReplicaSetImpl extends DynamicClusterImpl implements
MongoDB
                 .build());
         
         addEnricher(Enrichers.builder()
-                .aggregating(MongoDBServer.MONGO_SERVER_ENDPOINT)
+                .transforming(REPLICA_SET_ENDPOINTS)
                 .publishing(DATASTORE_URL)
-                .fromMembers()
-                .valueToReportIfNoSensors(null)
-                .computing(new Function<Collection<String>, String>() {
-                        @Override
-                        public String apply(Collection<String> input) {
-                            Set<String> endpoints = Sets.newHashSet();
-                            for (String endpoint: input) {
-                                if (!Strings.isBlank(endpoint)) {
-                                    
-                                    endpoints.add(endpoint);
-                                }
-                            }
-                            String credentials = MongoDBAuthenticationUtils.usesAuthentication(MongoDBReplicaSetImpl.this)
? 
-                                    String.format("%s:%s@", 
-                                            config().get(MongoDBAuthenticationMixins.ROOT_USERNAME),

-                                            config().get(MongoDBAuthenticationMixins.ROOT_PASSWORD))
: "";
-                            return String.format("mongodb://%s%s", credentials, Strings.join(endpoints,
","));
-                        }})
+                .computing(new EndpointsToDatastoreUrlMapper(this))
                 .build());
 
         subscribeToMembers(this, MongoDBServer.IS_PRIMARY_FOR_REPLICA_SET, new SensorEventListener<Boolean>()
{
@@ -427,6 +412,25 @@ public class MongoDBReplicaSetImpl extends DynamicClusterImpl implements
MongoDB
         });
 
     }
+    
+    public static class EndpointsToDatastoreUrlMapper implements Function<Collection<String>,
String> {
+        
+        private Entity entity;
+
+        public EndpointsToDatastoreUrlMapper(Entity entity) {
+            this.entity = entity;
+        }
+        
+        @Override
+        public String apply(Collection<String> input) {
+            String credentials = MongoDBAuthenticationUtils.usesAuthentication(entity) 
+                    ? String.format("%s:%s@", 
+                            entity.config().get(MongoDBAuthenticationMixins.ROOT_USERNAME),

+                            entity.config().get(MongoDBAuthenticationMixins.ROOT_PASSWORD))

+                    : "";
+            return String.format("mongodb://%s%s", credentials, Strings.join(input, ","));
+        }
+    }
 
     @Override
     public void stop() {


Mime
View raw message