Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/25#discussion_r14664590
  
    --- Diff: 
software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseClusterImpl.java
 ---
    @@ -315,6 +341,81 @@ public boolean isMemberInCluster(Entity e) {
             return 
Optional.fromNullable(e.getAttribute(CouchbaseNode.IS_IN_CLUSTER)).or(false);
         }
         
    +    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
    +        List<Map<String, Object>> bucketsToCreate = 
getConfig(CREATE_BUCKETS);
    +        Entity primaryNode = getPrimaryNode();
    +
    +        for (Map<String, Object> bucketMap : bucketsToCreate) {
    +            String bucketName = bucketMap.containsKey("bucket") ? (String) 
bucketMap.get("bucket") : "default";
    +            String bucketType = bucketMap.containsKey("bucket-type") ? 
(String) bucketMap.get("bucket-type") : "couchbase";
    +            Integer bucketPort = bucketMap.containsKey("bucket-port") ? 
(Integer) bucketMap.get("bucket-port") : 11222;
    +            Integer bucketRamSize = 
bucketMap.containsKey("bucket-ramsize") ? (Integer) 
bucketMap.get("bucket-ramsize") : 200;
    +            Integer bucketReplica = 
bucketMap.containsKey("bucket-replica") ? (Integer) 
bucketMap.get("bucket-replica") : 1;
    +
    +            log.info("adding bucket: {} to primary node: {}", bucketName, 
primaryNode.getId());
    +            createBucket(primaryNode, bucketName, bucketType, bucketPort, 
bucketRamSize, bucketReplica);
    +            //TODO: add if bucket has been created.
    +        }
    +    }
    +
    +    public void createBucket(final Entity primaryNode, final String 
bucketName, final String bucketType, final Integer bucketPort, final Integer 
bucketRamSize, final Integer bucketReplica) {
    +        
DynamicTasks.queueIfPossible(TaskBuilder.<Void>builder().name("Creating bucket 
" + bucketName).body(
    +                new Callable<Void>() {
    +                    @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();
    +                        }
    +                        
setAttribute(CouchbaseCluster.BUCKET_CREATION_IN_PROGRESS, true);
    +                        
    +                        CouchbaseClusterImpl.this.resetBucketCreation[0] = 
HttpFeed.builder()
    --- End diff --
    
    An alternative to using the HttpFeed would be to use a 
`brooklyn.util.repeat.Repeater` to poll until success/fail.
    
    It looks like `BUCKET_CREATION_IN_PROGRESS` is just used in this method, 
and unneccessarily by the caller of the createBuckets method (because it 
sequentially calls createBucket, which waits for bucket-creation to complete 
before returning).
    
    Using the attribute to control synchronization feels dangerous - e.g. on 
brooklyn restart would anything reset it to `false`. Also, there is a race if 
two effectors execute concurrently - they both wait for it to be false, and 
then both set it to true. Better would be to use standard Java synchronization 
mechanisms in createBucket.


---
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.
---

Reply via email to