fixup me - temp commit
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/4885a798 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/4885a798 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/4885a798 Branch: refs/heads/master Commit: 4885a798700aa22f39e030d97a2d65213ecb9a31 Parents: 48c2217 Author: Martin Harris <[email protected]> Authored: Fri Jul 11 17:12:48 2014 +0100 Committer: Martin Harris <[email protected]> Committed: Mon Aug 18 15:45:44 2014 +0100 ---------------------------------------------------------------------- .../nosql/couchbase/CouchbaseClusterImpl.java | 25 ++++++++++--------- .../nosql/couchbase/CouchbaseNodeSshDriver.java | 8 +++--- .../nosql/couchbase/CouchbaseSyncGateway.java | 22 ++++++++++++++--- .../couchbase/CouchbaseSyncGatewayDriver.java | 18 ++++++++++++++ .../couchbase/CouchbaseSyncGatewayImpl.java | 26 ++++++++++++++++---- .../CouchbaseSyncGatewaySshDriver.java | 18 ++++++++++++++ 6 files changed, 92 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4885a798/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 f424eaf..4affcd1 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 @@ -26,6 +26,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -73,7 +74,9 @@ import com.google.gson.JsonElement; public class CouchbaseClusterImpl extends DynamicClusterImpl implements CouchbaseCluster { private static final Logger log = LoggerFactory.getLogger(CouchbaseClusterImpl.class); private final Object mutex = new Object[0]; - private final HttpFeed[] resetBucketCreation = new HttpFeed[]{null}; + // Used to serialize bucket creation as only one bucket can be created at a time, + // so a feed is used to determine when a bucket has finished being created + private final AtomicReference<HttpFeed> resetBucketCreation = new AtomicReference<HttpFeed>(); public void init() { log.info("Initializing the Couchbase cluster..."); @@ -195,8 +198,8 @@ public class CouchbaseClusterImpl extends DynamicClusterImpl implements Couchbas @Override public void stop() { - if (resetBucketCreation[0] != null) { - resetBucketCreation[0].stop(); + if (resetBucketCreation.get() != null) { + resetBucketCreation.get().stop(); } super.stop(); } @@ -360,8 +363,7 @@ public class CouchbaseClusterImpl extends DynamicClusterImpl implements Couchbas } public void createBuckets() { - //FIXME: multiple buckets require synchronization/wait time (checks for port conflicts and exceeding ram size) - //TODO: check for multiple bucket conflicts with port + //TODO: check for port conflicts if buckets are being created with a port List<Map<String, Object>> bucketsToCreate = getConfig(CREATE_BUCKETS); Entity primaryNode = getPrimaryNode(); @@ -374,7 +376,6 @@ public class CouchbaseClusterImpl extends DynamicClusterImpl implements Couchbas log.info("adding bucket: {} to primary node: {}", bucketName, primaryNode.getId()); createBucket(primaryNode, bucketName, bucketType, bucketPort, bucketRamSize, bucketReplica); - //TODO: add if bucket has been created. } } @@ -384,12 +385,12 @@ public class CouchbaseClusterImpl extends DynamicClusterImpl implements Couchbas @Override public Void call() throws Exception { DependentConfiguration.waitInTaskForAttributeReady(CouchbaseClusterImpl.this, CouchbaseCluster.BUCKET_CREATION_IN_PROGRESS, Predicates.equalTo(false)); - if (CouchbaseClusterImpl.this.resetBucketCreation[0] != null) { - CouchbaseClusterImpl.this.resetBucketCreation[0].stop(); + if (CouchbaseClusterImpl.this.resetBucketCreation.get() != null) { + CouchbaseClusterImpl.this.resetBucketCreation.get().stop(); } setAttribute(CouchbaseCluster.BUCKET_CREATION_IN_PROGRESS, true); - CouchbaseClusterImpl.this.resetBucketCreation[0] = HttpFeed.builder() + CouchbaseClusterImpl.this.resetBucketCreation.set(HttpFeed.builder() .entity(CouchbaseClusterImpl.this) .period(500, TimeUnit.MILLISECONDS) .baseUri(String.format("%s/pools/default/buckets/%s", primaryNode.getAttribute(CouchbaseNode.COUCHBASE_WEB_ADMIN_URL), bucketName)) @@ -420,13 +421,13 @@ public class CouchbaseClusterImpl extends DynamicClusterImpl implements Couchbas throw new IllegalStateException("Unexpected response when creating bucket:" + input); } })) - .build(); + .build()); // TODO: Bail out if bucket creation fails, to allow next bucket to proceed Entities.invokeEffectorWithArgs(CouchbaseClusterImpl.this, primaryNode, CouchbaseNode.BUCKET_CREATE, bucketName, bucketType, bucketPort, bucketRamSize, bucketReplica); DependentConfiguration.waitInTaskForAttributeReady(CouchbaseClusterImpl.this, CouchbaseCluster.BUCKET_CREATION_IN_PROGRESS, Predicates.equalTo(false)); - if (CouchbaseClusterImpl.this.resetBucketCreation[0] != null) { - CouchbaseClusterImpl.this.resetBucketCreation[0].stop(); + if (CouchbaseClusterImpl.this.resetBucketCreation.get() != null) { + CouchbaseClusterImpl.this.resetBucketCreation.get().stop(); } return null; } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4885a798/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 8eb95e0..67fa30a 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 @@ -284,15 +284,15 @@ public class CouchbaseNodeSshDriver extends AbstractSoftwareProcessSshDriver imp return !HttpValueFunctions.jsonContents("status", String.class).apply(response).equals("none"); } - private HttpToolResponse getAPIResponse(String path) throws URISyntaxException { - URI uri = new URI(path); + private HttpToolResponse getAPIResponse(String uri) throws URISyntaxException { + URI apiUri = new URI(uri); Credentials credentials = new UsernamePasswordCredentials(getUsername(), getPassword()); return HttpTool.httpGet(HttpTool.httpClientBuilder() // the uri is required by the HttpClientBuilder in order to set the AuthScope of the credentials - .uri(uri) + .uri(apiUri) .credentials(credentials) .build(), - uri, + apiUri, ImmutableMap.<String, String>of()); } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4885a798/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseSyncGateway.java ---------------------------------------------------------------------- diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseSyncGateway.java b/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseSyncGateway.java index ddea721..c0740ee 100644 --- a/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseSyncGateway.java +++ b/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseSyncGateway.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package brooklyn.entity.nosql.couchbase; import brooklyn.config.ConfigKey; @@ -34,10 +52,6 @@ public interface CouchbaseSyncGateway extends SoftwareProcess { ConfigKey<String> COUCHBASE_SERVER_BUCKET = ConfigKeys.newStringConfigKey("couchbaseSyncGateway.serverBucket", "Name of the Couchbase bucket to use", "sync_gateway"); - @SetFromFlag("couchbaseServerUrl") - ConfigKey<String> COUCHBASE_SERVER_URL = ConfigKeys.newStringConfigKey("couchbaseSyncGateway.couchbaseServerUrl", - "Couchbase Server Admin Url to connect the gateway to"); - @SetFromFlag("pretty") ConfigKey<Boolean> PRETTY = ConfigKeys.newBooleanConfigKey("couchbaseSyncGateway.pretty", "Pretty-print JSON responses. This is useful for debugging, but reduces performance.", false); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4885a798/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseSyncGatewayDriver.java ---------------------------------------------------------------------- diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseSyncGatewayDriver.java b/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseSyncGatewayDriver.java index b1b4339..148ec0b 100644 --- a/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseSyncGatewayDriver.java +++ b/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseSyncGatewayDriver.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package brooklyn.entity.nosql.couchbase; import brooklyn.entity.basic.SoftwareProcessDriver; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4885a798/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseSyncGatewayImpl.java ---------------------------------------------------------------------- diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseSyncGatewayImpl.java b/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseSyncGatewayImpl.java index 0ead110..4ac3400 100644 --- a/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseSyncGatewayImpl.java +++ b/software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseSyncGatewayImpl.java @@ -1,6 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package brooklyn.entity.nosql.couchbase; - import brooklyn.config.render.RendererHints; import brooklyn.entity.basic.SoftwareProcessImpl; import brooklyn.event.feed.http.HttpFeed; @@ -8,6 +25,7 @@ import brooklyn.event.feed.http.HttpPollConfig; import brooklyn.event.feed.http.HttpValueFunctions; import brooklyn.location.access.BrooklynAccessUtils; +import com.google.common.base.Functions; import com.google.common.net.HostAndPort; public class CouchbaseSyncGatewayImpl extends SoftwareProcessImpl implements CouchbaseSyncGateway { @@ -27,8 +45,6 @@ public class CouchbaseSyncGatewayImpl extends SoftwareProcessImpl implements Cou @Override protected void connectServiceUpIsRunning() { - - HostAndPort hp = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, getAttribute(CouchbaseSyncGateway.ADMIN_REST_API_PORT)); @@ -42,9 +58,9 @@ public class CouchbaseSyncGatewayImpl extends SoftwareProcessImpl implements Cou .period(200) .baseUri(managementUri) .poll(new HttpPollConfig<Boolean>(SERVICE_UP) - .onSuccess(HttpValueFunctions.responseCodeEquals(200))) + .onSuccess(HttpValueFunctions.responseCodeEquals(200)) + .onFailureOrException(Functions.constant(false))) .build(); - } @Override http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4885a798/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 6d9157c..3d6104b 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 @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package brooklyn.entity.nosql.couchbase; import static brooklyn.util.ssh.BashCommands.INSTALL_CURL;
