Repository: incubator-brooklyn Updated Branches: refs/heads/master 0c74027ad -> fd22cc070
set IS_IN_CLUSTER on couchbase primary node, fix problem noticed in #427 Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/d26acd87 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/d26acd87 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/d26acd87 Branch: refs/heads/master Commit: d26acd87c8dc8f995c94bf4f2deb1e8f8f2a018e Parents: beeb4d8 Author: Alex Heneveld <[email protected]> Authored: Thu Jan 29 12:26:08 2015 +0000 Committer: Alex Heneveld <[email protected]> Committed: Thu Jan 29 12:26:08 2015 +0000 ---------------------------------------------------------------------- .../nosql/couchbase/CouchbaseClusterImpl.java | 9 +++++-- .../entity/nosql/couchbase/CouchbaseNode.java | 3 ++- .../CouchbaseSyncGatewaySshDriver.java | 25 +++++++------------- 3 files changed, 17 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d26acd87/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 7552928..0eb2586 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 @@ -229,8 +229,13 @@ public class CouchbaseClusterImpl extends DynamicClusterImpl implements Couchbas } ((CouchbaseNode)getPrimaryNode()).rebalance(); - } else if (getQuorumSize()>1) { - log.warn(this+" is not quorate; will likely fail later, but proceeding for now"); + } else { + if (getQuorumSize()>1) { + log.warn(this+" is not quorate; will likely fail later, but proceeding for now"); + } + if (!serversToAdd.isEmpty()) { + ((EntityInternal) Iterables.getOnlyElement(serversToAdd)).setAttribute(CouchbaseNode.IS_IN_CLUSTER, true); + } } if (getConfig(CREATE_BUCKETS)!=null) { http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d26acd87/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 f09114d..cb9f264 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 { PortAttributeSensorAndConfigKey NODE_DATA_EXCHANGE_PORT_RANGE_END = new PortAttributeSensorAndConfigKey("couchbase.nodeDataExchangePortRangeEnd", "Node data exchange Port Range End", "21199+"); AttributeSensor<Boolean> IS_PRIMARY_NODE = Sensors.newBooleanSensor("couchbase.isPrimaryNode", "flag to determine if the current couchbase node is the primary node for the cluster"); - AttributeSensor<Boolean> IS_IN_CLUSTER = Sensors.newBooleanSensor("couchbase.isInCluster", "flag to determine if the current couchbase node has been added to a cluster"); + AttributeSensor<Boolean> IS_IN_CLUSTER = Sensors.newBooleanSensor("couchbase.isInCluster", "flag to determine if the current couchbase node has been added to a cluster, " + + "including being the first / primary node"); AttributeSensor<URI> COUCHBASE_WEB_ADMIN_URL = Attributes.MAIN_URI; // Interesting stats http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d26acd87/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseSyncGatewaySshDriver.java ---------------------------------------------------------------------- diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseSyncGatewaySshDriver.java b/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseSyncGatewaySshDriver.java index 164f60a..d21f9b5 100644 --- a/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseSyncGatewaySshDriver.java +++ b/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseSyncGatewaySshDriver.java @@ -26,12 +26,11 @@ import static java.lang.String.format; import java.util.List; -import javax.annotation.Nullable; - import brooklyn.entity.Entity; import brooklyn.entity.basic.AbstractSoftwareProcessSshDriver; import brooklyn.entity.basic.Entities; import brooklyn.entity.basic.EntityLocal; +import brooklyn.entity.basic.EntityPredicates; import brooklyn.entity.drivers.downloads.DownloadResolver; import brooklyn.event.basic.DependentConfiguration; import brooklyn.location.OsDetails; @@ -42,7 +41,6 @@ import brooklyn.util.time.Duration; import brooklyn.util.time.Time; import com.google.common.base.Optional; -import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -88,22 +86,15 @@ public class CouchbaseSyncGatewaySshDriver extends AbstractSoftwareProcessSshDri // Even once the bucket has published its API URL, it can still take a couple of seconds for it to become available Time.sleep(10 * 1000); if (cbNode instanceof CouchbaseCluster) { - Optional<Entity> cbClusterNode = Iterables.tryFind(cbNode.getAttribute(CouchbaseCluster.GROUP_MEMBERS), new Predicate<Entity>() { - - @Override - public boolean apply(@Nullable Entity entity) { - // Must either be recognised by a cluster as added, or be the primary node in a cluster of ONE. - return entity instanceof CouchbaseNode - && (Boolean.TRUE.equals(entity.getAttribute(CouchbaseNode.IS_IN_CLUSTER)) - || Boolean.TRUE.equals(entity.getAttribute(CouchbaseNode.IS_PRIMARY_NODE))); - } - }); - if (cbClusterNode.isPresent()) { - cbNode = cbClusterNode.get(); - } else { + // in_cluster now applies even to a node in a cluster of size 1 + Optional<Entity> cbClusterNode = Iterables.tryFind(cbNode.getAttribute(CouchbaseCluster.GROUP_MEMBERS), + Predicates.and(Predicates.instanceOf(CouchbaseNode.class), EntityPredicates.attributeEqualTo(CouchbaseNode.IS_IN_CLUSTER, Boolean.TRUE))); + + if (!cbClusterNode.isPresent()) { throw new IllegalArgumentException(format("The cluster %s does not contain any suitable Couchbase nodes to connect to..", cbNode.getId())); } - + + cbNode = cbClusterNode.get(); } String hostname = cbNode.getAttribute(CouchbaseNode.HOSTNAME); String webPort = cbNode.getAttribute(CouchbaseNode.COUCHBASE_WEB_ADMIN_PORT).toString();
