Java Code Examples for org.apache.brooklyn.core.entity.Entities#waitForServiceUp()

The following examples show how to use org.apache.brooklyn.core.entity.Entities#waitForServiceUp() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StormSshDriver.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
@Override
public void launch() {
    boolean needsSleep = false;
    if (getRoleName().equals("supervisor")) {
        Entity nimbus = entity.getConfig(Storm.NIMBUS_ENTITY);
        if (nimbus == null) {
            log.warn("No nimbus entity available; not blocking before starting supervisors");
        } else {
            Entities.waitForServiceUp(nimbus, entity.getConfig(SoftwareProcess.START_TIMEOUT));
            needsSleep = true;
        }
    }

    String subnetHostname = Machines.findSubnetOrPublicHostname(entity).get();
    log.info("Launching " + entity + " with role " + getRoleName() + " and " + "hostname (public) " 
            + getEntity().getAttribute(Attributes.HOSTNAME) + ", " + "hostname (subnet) " + subnetHostname + ")");

    // ensure only one node at a time tries to start
    // attempting to eliminate the causes of:
    // 2013-12-12 09:21:45 supervisor [ERROR] Error on initialization of server mk-supervisor
    // org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = NoNode for /assignments
    // TODO use SoftwareProcess#START_LATCH instead here?

    Object startMutex = Optional.fromNullable(entity.getConfig(Storm.START_MUTEX)).or(new Object());
    synchronized (startMutex) {
        if (needsSleep) {
            // give 10s extra to make sure nimbus is ready; we see weird zookeeper no /assignments node error otherwise
            // (this could be optimized by recording nimbus service_up time)
            Time.sleep(Duration.TEN_SECONDS);
        }
        newScript(MutableMap.of(USE_PID_FILE, getPidFile()), LAUNCHING)
                .body.append(format("nohup ./bin/storm %s > %s 2>&1 &", getRoleName(), getLogFileLocation()))
                .execute();
    }
}
 
Example 2
Source File: PaasWebAppCloudFoundryDriver.java    From SeaCloudsPlatform with Apache License 2.0 5 votes vote down vote up
private void manageService(Entity rawEntity){

        CloudFoundryService cloudFoundryService;
        if (rawEntity instanceof CloudFoundryService){

            cloudFoundryService = (CloudFoundryService) rawEntity;
        
            String serviceName = cloudFoundryService
                    .getConfig(CloudFoundryService.SERVICE_INSTANCE_NAME);


            if (!Strings.isEmpty(serviceName)){

                Entities.waitForServiceUp(cloudFoundryService,
                        cloudFoundryService.getConfig(BrooklynConfigKeys.START_TIMEOUT));

                bindingServiceToEntity(serviceName);
                setCredentialsOnService(cloudFoundryService);
                cloudFoundryService.operation(getEntity());
            } else {
                log.error("Trying to get service instance name from {}, but getting null",
                        cloudFoundryService);
            }
        } else {
            log.error("The service entity {} is not available from the application {}",
                    new Object[]{rawEntity, getEntity()});

            throw new NoSuchElementException("No entity matching id " + rawEntity.getId() +
                    " in Management Context "+getEntity().getManagementContext()+
                    " during entity service binding "+getEntity().getId());
        }
    }
 
Example 3
Source File: CouchbaseSyncGatewaySshDriver.java    From brooklyn-library with Apache License 2.0 4 votes vote down vote up
@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) {
        // 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();


    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();
    String syncRestApiPort = entity.getConfig(CouchbaseSyncGateway.SYNC_REST_API_PORT).iterator().next().toString();

    String serverWebAdminUrl = format("http://%s:%s@%s:%s", username, password, hostname, webPort);
    String options = format("-url %s -bucket %s -adminInterface 0.0.0.0:%s -interface 0.0.0.0:%s -pool %s %s %s",
            serverWebAdminUrl, bucketName, adminRestApiPort, syncRestApiPort, pool, pretty, verbose);

    newScript(ImmutableMap.of("usePidFile", true), LAUNCHING)
            .body.append(format("/opt/couchbase-sync-gateway/bin/sync_gateway %s ", options) + "> out.log 2> err.log < /dev/null &")
            .failOnNonZeroResultCode()
            .execute();
}
 
Example 4
Source File: SoftwareProcessImpl.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public void waitForServiceUp(Duration duration) {
    Entities.waitForServiceUp(this, duration);
}
 
Example 5
Source File: SoftwareProcessImpl.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public void waitForServiceUp(long duration, TimeUnit units) {
    Entities.waitForServiceUp(this, Duration.of(duration, units));
}
 
Example 6
Source File: DynamicClusterImpl.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
protected void waitForServiceUp(Duration duration) {
    Entities.waitForServiceUp(this, duration);
}
 
Example 7
Source File: CloudFoundryEntityImpl.java    From SeaCloudsPlatform with Apache License 2.0 4 votes vote down vote up
public void waitForServiceUp(Duration duration) {
    Entities.waitForServiceUp(this, duration);
}
 
Example 8
Source File: OpenShiftEntityImpl.java    From SeaCloudsPlatform with Apache License 2.0 4 votes vote down vote up
public void waitForServiceUp(Duration duration) {
    Entities.waitForServiceUp(this, duration);
}