Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/25#discussion_r14664973
--- Diff:
software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseNodeSshDriver.java
---
@@ -175,8 +201,83 @@ public void rebalance() {
.failOnNonZeroResultCode()
.execute();
entity.setAttribute(CouchbaseNode.REBALANCE_STATUS, "Rebalance
Started");
+ // wait until the re-balance is complete
+ Repeater.create()
+ .every(Duration.millis(500))
+ .limitTimeTo(Duration.THIRTY_SECONDS)
+ .until(new Callable<Boolean>() {
+ @Override
+ public Boolean call() throws Exception {
+ for (String nodeHostName :
CouchbaseNodeSshDriver.this.getNodeHostNames()) {
+ if (isNodeRebalancing(nodeHostName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ })
+ .run();
+ Repeater.create()
+ .every(Duration.FIVE_SECONDS)
+ .limitTimeTo(Duration.FIVE_MINUTES)
+ .until(new Callable<Boolean>() {
+ @Override
+ public Boolean call() throws Exception {
+ for (String nodeHostName :
CouchbaseNodeSshDriver.this.getNodeHostNames()) {
+ if (isNodeRebalancing(nodeHostName)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ })
+ .run();
+ log.info("rebalanced cluster via primary node {}", getEntity());
}
+ private Iterable<String> getNodeHostNames() throws URISyntaxException {
+ Function<JsonElement, Iterable<String>> getNodesAsList = new
Function<JsonElement, Iterable<String>>() {
+ @Override public Iterable<String> apply(JsonElement input) {
+ if (input == null) {
+ return Collections.emptyList();
+ }
+ Collection<String> names = Lists.newArrayList();
+ JsonArray nodes = input.getAsJsonArray();
+ for (JsonElement element : nodes) {
+ // NOTE: the 'hostname' element also includes the port
+
names.add(element.getAsJsonObject().get("hostname").toString().replace("\"",
""));
+ }
+ return names;
+ }
+ };
+ HttpToolResponse nodesResponse =
getAPIResponse(String.format("http://%s:%s/pools/nodes", getHostname(),
getWebPort()));
+ return Functionals.chain(
+ HttpValueFunctions.jsonContents(),
+ JsonFunctions.walkN("nodes"),
+ getNodesAsList
+ ).apply(nodesResponse);
+ }
+
+ private boolean isNodeRebalancing(String nodeHostName) throws
URISyntaxException {
+ HttpToolResponse response = getAPIResponse("http://" +
nodeHostName + "/pools/nodes/rebalanceProgress");
+ if (response.getResponseCode() != 200) {
+ throw new IllegalStateException("failed to rebalance cluster:
" + response);
+ }
+ return !HttpValueFunctions.jsonContents("status",
String.class).apply(response).equals("none");
+ }
+
+ private HttpToolResponse getAPIResponse(String path) throws
URISyntaxException {
--- End diff --
Instead of `path`, perhaps call it `uri` or some such. Path mean a
particular part of the uri:
http://docs.oracle.com/javase/7/docs/api/java/net/URI.html#getPath()
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---