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

    https://github.com/apache/incubator-brooklyn/pull/25#discussion_r14701787
  
    --- Diff: 
software/nosql/src/main/java/brooklyn/entity/nosql/couchbase/CouchbaseSyncGatewaySshDriver.java
 ---
    @@ -0,0 +1,158 @@
    +package brooklyn.entity.nosql.couchbase;
    +
    +import static brooklyn.util.ssh.BashCommands.INSTALL_CURL;
    +import static brooklyn.util.ssh.BashCommands.alternatives;
    +import static brooklyn.util.ssh.BashCommands.chainGroup;
    +import static brooklyn.util.ssh.BashCommands.sudo;
    +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.drivers.downloads.DownloadResolver;
    +import brooklyn.event.basic.DependentConfiguration;
    +import brooklyn.location.OsDetails;
    +import brooklyn.location.basic.SshMachineLocation;
    +import brooklyn.util.collections.MutableMap;
    +import brooklyn.util.ssh.BashCommands;
    +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;
    +import com.google.common.collect.Iterables;
    +
    +public class CouchbaseSyncGatewaySshDriver extends 
AbstractSoftwareProcessSshDriver implements CouchbaseSyncGatewayDriver {
    +    public CouchbaseSyncGatewaySshDriver(EntityLocal entity, 
SshMachineLocation machine) {
    +        super(entity, machine);
    +    }
    +
    +    @Override
    +    public void stop() {
    +
    +    }
    +
    +    @Override
    +    public void install() {
    +        //reference 
http://docs.couchbase.com/sync-gateway/#getting-started-with-sync-gateway
    +        DownloadResolver resolver = Entities.newDownloader(this);
    +        List<String> urls = resolver.getTargets();
    +        String saveAs = resolver.getFilename();
    +
    +        OsDetails osDetails = 
getMachine().getMachineDetails().getOsDetails();
    +
    +        log.info("Installing couchbase-sync-gateway version: {}", 
getVersion());
    +        if (osDetails.isLinux()) {
    +            List<String> commands = installLinux(urls, saveAs);
    +            newScript(INSTALLING)
    +                    .body.append(commands).execute();
    +        }
    +    }
    +
    +    @Override
    +    public void customize() {
    +
    +    }
    +
    +    @Override
    +    public void launch() {
    +        Entity cbNode = 
entity.getConfig(CouchbaseSyncGateway.COUCHBASE_SERVER);
    +        Entities.waitForServiceUp(cbNode, Duration.ONE_HOUR);
    +        DependentConfiguration.waitInTaskForAttributeReady(cbNode, 
CouchbaseCluster.IS_CLUSTER_INITIALIZED, Predicates.equalTo(true));
    +        // 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) {
    +                    if (entity instanceof CouchbaseNode && 
Boolean.TRUE.equals(entity.getAttribute(CouchbaseNode.IS_IN_CLUSTER))) {
    +                        return true;
    +                    }
    +                    return false;
    +                }
    +            });
    +            if (cbClusterNode.isPresent()) {
    +                cbNode = cbClusterNode.get();
    +            } else {
    +                throw new IllegalArgumentException(format("The cluster %s 
does not contain any suitable Couchbase nodes to connect to..", 
cbNode.getId()));
    +            }
    +
    +        }
    +        String hostname = cbNode.getAttribute(CouchbaseNode.HOSTNAME);
    +        String webPort = 
cbNode.getAttribute(CouchbaseNode.COUCHBASE_WEB_ADMIN_PORT).toString();
    +
    +
    +        String username = 
cbNode.getConfig(CouchbaseNode.COUCHBASE_ADMIN_USERNAME);
    +        String password = 
cbNode.getConfig(CouchbaseNode.COUCHBASE_ADMIN_PASSWORD);
    +
    +        String bucketName = 
entity.getConfig(CouchbaseSyncGateway.COUCHBASE_SERVER_BUCKET);
    +        String pool = 
entity.getConfig(CouchbaseSyncGateway.COUCHBASE_SERVER_POOL);
    +        String pretty = entity.getConfig(CouchbaseSyncGateway.PRETTY) ? 
"-pretty" : "";
    +        String verbose = entity.getConfig(CouchbaseSyncGateway.VERBOSE) ? 
"-verbose" : "";
    +
    +        String adminRestApiPort = 
entity.getConfig(CouchbaseSyncGateway.ADMIN_REST_API_PORT).iterator().next().toString();
    --- End diff --
    
    Instead use `entity.getAttribute(CouchbaseSyncGateway.ADMIN_REST_API_PORT)`.
    If `ConfigToAttributes.apply(entity)` has previously been called (which it 
will have because this extends `SoftwareProcess`) then the attribute will have 
been set with the first free port in the range. However, it will be null if 
none of those were available.


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