brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rich...@apache.org
Subject [2/5] git commit: Automatically rebalance when node is added
Date Wed, 18 Jun 2014 16:45:14 GMT
Automatically rebalance when node is added


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

Branch: refs/heads/master
Commit: 02af3ebd6968617428c666ec040e9c392e4026c7
Parents: f5ccb4b
Author: Martin Harris <github@nakomis.com>
Authored: Wed Jun 18 12:08:58 2014 +0100
Committer: Martin Harris <github@nakomis.com>
Committed: Wed Jun 18 12:21:07 2014 +0100

----------------------------------------------------------------------
 .../nosql/couchbase/CouchbaseClusterImpl.java   | 31 +++++++-------------
 .../entity/nosql/couchbase/CouchbaseNode.java   |  7 ++++-
 .../nosql/couchbase/CouchbaseNodeDriver.java    |  2 ++
 .../nosql/couchbase/CouchbaseNodeImpl.java      |  9 +++++-
 .../nosql/couchbase/CouchbaseNodeSshDriver.java |  3 ++
 5 files changed, 30 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/02af3ebd/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseClusterImpl.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseClusterImpl.java
b/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseClusterImpl.java
index d277a03..70df568 100644
--- a/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseClusterImpl.java
+++ b/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseClusterImpl.java
@@ -33,6 +33,7 @@ import brooklyn.util.time.Time;
 
 import com.google.common.base.Function;
 import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
@@ -206,8 +207,6 @@ public class CouchbaseClusterImpl extends DynamicClusterImpl implements
Couchbas
                         if (isClusterInitialized()) {
                             addServer(member);
                         }
-                    } else {
-                        log.warn("Node already in cluster up nodes {}: {};", this, member);
                     }
                 } else {
                     Set<Entity> newNodes = Sets.newHashSet();
@@ -283,34 +282,26 @@ public class CouchbaseClusterImpl extends DynamicClusterImpl implements
Couchbas
     }
 
     protected void addServers(Set<Entity> serversToAdd) {
-        //FIXME: disambiguate between method names to differentiate between the stage phase
and commit phase.
-        log.info("adding the SERVICE_UP couchbase nodes to the cluster..");
-
-        if (!serversToAdd.isEmpty()) {
-            for (Entity e : serversToAdd) {
-                if (!isMemberInCluster(e)) {
-                    String hostname = e.getAttribute(Attributes.HOSTNAME) + ":" + e.getConfig(CouchbaseNode.COUCHBASE_WEB_ADMIN_PORT).iterator().next();
-                    String username = e.getConfig(CouchbaseNode.COUCHBASE_ADMIN_USERNAME);
-                    String password = e.getConfig(CouchbaseNode.COUCHBASE_ADMIN_PASSWORD);
-
-                    Entities.invokeEffectorWithArgs(this, getPrimaryNode(), CouchbaseNode.SERVER_ADD,
hostname, username, password);
-                    //FIXME check feedback of whether the server was added.
-                    ((EntityInternal) e).setAttribute(CouchbaseNode.IS_IN_CLUSTER, true);
-                }
+        Preconditions.checkNotNull(serversToAdd);
+        for (Entity e : serversToAdd) {
+            if (!isMemberInCluster(e)) {
+                addServer(e);
             }
-        } else {
-            log.warn("no servers to be added on the cluster: {}", this);
         }
     }
 
     protected void addServer(Entity serverToAdd) {
-
+        Preconditions.checkNotNull(serverToAdd);
         if (!isMemberInCluster(serverToAdd)) {
             String hostname = serverToAdd.getAttribute(Attributes.HOSTNAME) + ":" + serverToAdd.getConfig(CouchbaseNode.COUCHBASE_WEB_ADMIN_PORT).iterator().next();
             String username = serverToAdd.getConfig(CouchbaseNode.COUCHBASE_ADMIN_USERNAME);
             String password = serverToAdd.getConfig(CouchbaseNode.COUCHBASE_ADMIN_PASSWORD);
 
-            Entities.invokeEffectorWithArgs(this, getPrimaryNode(), CouchbaseNode.SERVER_ADD,
hostname, username, password);
+            if (isClusterInitialized()) {
+                Entities.invokeEffectorWithArgs(this, getPrimaryNode(), CouchbaseNode.SERVER_ADD_AND_REBALANCE,
hostname, username, password);
+            } else {
+                Entities.invokeEffectorWithArgs(this, getPrimaryNode(), CouchbaseNode.SERVER_ADD,
hostname, username, password);
+            }
             //FIXME check feedback of whether the server was added.
             ((EntityInternal) serverToAdd).setAttribute(CouchbaseNode.IS_IN_CLUSTER, true);
         }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/02af3ebd/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseNode.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseNode.java
b/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseNode.java
index 26cf369..b6d96df 100644
--- a/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseNode.java
+++ b/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseNode.java
@@ -80,7 +80,8 @@ public interface CouchbaseNode extends SoftwareProcess {
             "Retrieved from pools/nodes/<current node>/interestingStats/cmd_get");
     AttributeSensor<Long> CURR_ITEMS_TOT = Sensors.newLongSensor("couchbase.stats.curr.items.tot",

             "Retrieved from pools/nodes/<current node>/interestingStats/curr_items_tot");
-
+    AttributeSensor<String> REBALANCE_STATUS = Sensors.newStringSensor("couchbase.rebalance.status",

+            "Displays the current rebalance status from pools/nodes/rebalanceStatus");
     
     class RootUrl {
         public static final AttributeSensor<String> ROOT_URL = WebAppService.ROOT_URL;
@@ -101,10 +102,14 @@ public interface CouchbaseNode extends SoftwareProcess {
     AttributeSensor<String> ROOT_URL = RootUrl.ROOT_URL;
 
     MethodEffector<Void> SERVER_ADD = new MethodEffector<Void>(CouchbaseNode.class,
"serverAdd");
+    MethodEffector<Void> SERVER_ADD_AND_REBALANCE = new MethodEffector<Void>(CouchbaseNode.class,
"serverAddAndRebalance");
     MethodEffector<Void> REBALANCE = new MethodEffector<Void>(CouchbaseNode.class,
"rebalance");
 
     @Effector(description = "add a server to a cluster")
     public void serverAdd(@EffectorParam(name = "serverHostname") String serverToAdd, @EffectorParam(name
= "username") String username, @EffectorParam(name = "password") String password);
+    
+    @Effector(description = "add a server to a cluster, and immediately rebalances")
+    public void serverAddAndRebalance(@EffectorParam(name = "serverHostname") String serverToAdd,
@EffectorParam(name = "username") String username, @EffectorParam(name = "password") String
password);
 
     @Effector(description = "rebalance the couchbase cluster")
     public void rebalance();

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/02af3ebd/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseNodeDriver.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseNodeDriver.java
b/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseNodeDriver.java
index 2cf7773..0596b89 100644
--- a/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseNodeDriver.java
+++ b/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseNodeDriver.java
@@ -9,4 +9,6 @@ public interface CouchbaseNodeDriver extends SoftwareProcessDriver {
 
     public void rebalance();
 
+    public void serverAddAndRebalance(String serverToAdd, String username, String password);
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/02af3ebd/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseNodeImpl.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseNodeImpl.java
b/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseNodeImpl.java
index 06d9c18..e1050cf 100644
--- a/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseNodeImpl.java
+++ b/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseNodeImpl.java
@@ -88,6 +88,11 @@ public class CouchbaseNodeImpl extends SoftwareProcessImpl implements CouchbaseN
     }
 
     @Override
+    public void serverAddAndRebalance(String serverToAdd, String username, String password)
{
+        getDriver().serverAddAndRebalance(serverToAdd, username, password);
+    }
+
+    @Override
     public void rebalance() {
         getDriver().rebalance();
     }
@@ -144,6 +149,9 @@ public class CouchbaseNodeImpl extends SoftwareProcessImpl implements
CouchbaseN
             .poll(getSensorFromNodeStat(CouchbaseNode.GET_HITS, "get_hits"))
             .poll(getSensorFromNodeStat(CouchbaseNode.CMD_GET, "cmd_get"))
             .poll(getSensorFromNodeStat(CouchbaseNode.CURR_ITEMS_TOT, "curr_items_tot"))
+            .poll(new HttpPollConfig<String>(CouchbaseNode.REBALANCE_STATUS)
+                        .onSuccess(HttpValueFunctions.jsonContents("rebalanceStatus", String.class))
+                        .onFailureOrException(Functions.constant("Could not retrieve")))
             .build();
     }
 
@@ -155,5 +163,4 @@ public class CouchbaseNodeImpl extends SoftwareProcessImpl implements
CouchbaseN
         }
     }
 
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/02af3ebd/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseNodeSshDriver.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseNodeSshDriver.java
b/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseNodeSshDriver.java
index 246992d..20ba1ca 100644
--- a/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseNodeSshDriver.java
+++ b/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseNodeSshDriver.java
@@ -174,6 +174,7 @@ public class CouchbaseNodeSshDriver extends AbstractSoftwareProcessSshDriver
imp
                         getCouchbaseHostnameAndCredentials())
                 .failOnNonZeroResultCode()
                 .execute();
+        entity.setAttribute(CouchbaseNode.REBALANCE_STATUS, "Rebalance Started");
     }
 
     @Override
@@ -187,6 +188,7 @@ public class CouchbaseNodeSshDriver extends AbstractSoftwareProcessSshDriver
imp
                 .execute();
     }
 
+    @Override
     public void serverAddAndRebalance(String serverToAdd, String username, String password)
{
         newScript("serverAddAndRebalance").body.append(couchbaseCli("rebalance")
                 + getCouchbaseHostnameAndCredentials() +
@@ -195,6 +197,7 @@ public class CouchbaseNodeSshDriver extends AbstractSoftwareProcessSshDriver
imp
                 " --server-add-password=" + password)
                 .failOnNonZeroResultCode()
                 .execute();
+        entity.setAttribute(CouchbaseNode.REBALANCE_STATUS, "Rebalance Started");
     }
 
 }


Mime
View raw message