Java Code Examples for org.apache.brooklyn.core.location.Locations#findUniqueSshMachineLocation()

The following examples show how to use org.apache.brooklyn.core.location.Locations#findUniqueSshMachineLocation() . 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: PostgreSqlNodeChefImplFromScratch.java    From brooklyn-library with Apache License 2.0 6 votes vote down vote up
protected void connectSensors() {
    sensors().set(DATASTORE_URL, String.format("postgresql://%s:%s/", getAttribute(HOSTNAME), getAttribute(POSTGRESQL_PORT)));

    Maybe<SshMachineLocation> machine = Locations.findUniqueSshMachineLocation(getLocations());

    if (machine.isPresent()) {
        feed = SshFeed.builder()
                .entity(this)
                .machine(machine.get())
                .poll(new SshPollConfig<Boolean>(SERVICE_UP)
                        .command("ps -ef | grep [p]ostgres")
                        .setOnSuccess(true)
                        .setOnFailureOrException(false))
                .build();
    } else {
        LOG.warn("Location(s) {} not an ssh-machine location, so not polling for status; setting serviceUp immediately", getLocations());
    }
}
 
Example 2
Source File: AnsibleEntityImpl.java    From brooklyn-library with Apache License 2.0 6 votes vote down vote up
@Override
protected void connectSensors() {
    super.connectSensors();

    Maybe<SshMachineLocation> machine = Locations.findUniqueSshMachineLocation(getLocations());

    if (machine.isPresent()) {
        String cmd = getDriver().getStatusCmd();
        feed = SshFeed.builder()
                .entity(this)
                .period(config().get(SERVICE_PROCESS_IS_RUNNING_POLL_PERIOD))
                .machine(machine.get())
                .poll(new SshPollConfig<Boolean>(SERVICE_UP)
                        .command(cmd)
                        .setOnSuccess(true)
                        .setOnFailureOrException(false))
                .build();
    } else {
        LOG.warn("Location(s) {} not an ssh-machine location, so not polling for status; setting serviceUp immediately", getLocations());
        sensors().set(SERVICE_UP, true);
    }
}
 
Example 3
Source File: SshCommandEffector.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
public String callMany(Collection<Entity> targets, ConfigBag params) {
    TaskBuilder<Object> ptb = Tasks.builder().parallel(true).displayName("effector "+effector.getName()+" ssh to targets");
    for (Entity target: targets) {
        if (Entities.isNoLongerManaged(target)) continue;
        
        Lifecycle state = target.getAttribute(Attributes.SERVICE_STATE_ACTUAL);
        if (state==Lifecycle.STOPPING || state==Lifecycle.STOPPED) continue;

        Maybe<SshMachineLocation> machine = Locations.findUniqueSshMachineLocation(target.getLocations());
        if (machine.isAbsent()) continue;
        
        SshEffectorTaskFactory<String> t = makePartialTaskFactory(params, target);
        t.summary("effector "+effector.getName()+" at "+target); 
        t.machine( machine.get() );
        
        ptb.add(t.newTask());
    }
    queue(ptb.build()).getUnchecked();
    return null;
}
 
Example 4
Source File: MariaDbNodeImpl.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
@Override
protected void connectSensors() {
    super.connectSensors();
    sensors().set(DATASTORE_URL, String.format("mysql://%s:%s/", getAttribute(HOSTNAME), getAttribute(MARIADB_PORT)));

    /*        
     * TODO status gives us things like:
     *   Uptime: 2427  Threads: 1  Questions: 581  Slow queries: 0  Opens: 53  Flush tables: 1  Open tables: 35  Queries per second avg: 0.239
     * So can extract lots of sensors from that.
     */
    Maybe<SshMachineLocation> machine = Locations.findUniqueSshMachineLocation(getLocations());

    if (machine.isPresent()) {
        String cmd = getDriver().getStatusCmd();
        feed = SshFeed.builder()
                .entity(this)
                .period(config().get(SERVICE_PROCESS_IS_RUNNING_POLL_PERIOD))
                .machine(machine.get())
                .poll(new SshPollConfig<Boolean>(SERVICE_UP)
                        .command(cmd)
                        .setOnSuccess(true)
                        .setOnFailureOrException(false))
                .poll(new SshPollConfig<Double>(QUERIES_PER_SECOND_FROM_MARIADB)
                        .command(cmd)
                        .onSuccess(new Function<SshPollValue, Double>() {
                            @Override
                            public Double apply(SshPollValue input) {
                                String q = Strings.getFirstWordAfter(input.getStdout(), "Queries per second avg:");
                                return (q == null) ? null : Double.parseDouble(q);
                            }})
                        .setOnFailureOrException(null) )
                .build();
    } else {
        LOG.warn("Location(s) {} not an ssh-machine location, so not polling for status; setting serviceUp immediately", getLocations());
        sensors().set(SERVICE_UP, true);
    }
}
 
Example 5
Source File: MySqlNodeImpl.java    From brooklyn-library with Apache License 2.0 4 votes vote down vote up
@Override
protected void connectSensors() {
    super.connectSensors();
    sensors().set(DATASTORE_URL, String.format("mysql://%s:%s/", getAttribute(HOSTNAME), getAttribute(MYSQL_PORT)));
    sensors().set(USER, getUser());
    /*
     * TODO status gives us things like:
     *   Uptime: 2427  Threads: 1  Questions: 581  Slow queries: 0  Opens: 53  Flush tables: 1  Open tables: 35  Queries per second avg: 0.239
     * So can extract lots of sensors from that.
     */
    Maybe<SshMachineLocation> machine = Locations.findUniqueSshMachineLocation(getLocations());
    boolean retrieveUsageMetrics = getConfig(RETRIEVE_USAGE_METRICS);

    if (machine.isPresent()) {
        String cmd = getDriver().getStatusCmd();
        feed = SshFeed.builder()
                .entity(this)
                .period(config().get(SERVICE_PROCESS_IS_RUNNING_POLL_PERIOD))
                .machine(machine.get())
                .poll(new SshPollConfig<Double>(QUERIES_PER_SECOND_FROM_MYSQL)
                        .command(cmd)
                        .onSuccess(new Function<SshPollValue, Double>() {
                            @Override
                            public Double apply(SshPollValue input) {
                                String q = Strings.getFirstWordAfter(input.getStdout(), "Queries per second avg:");
                                if (q==null) return null;
                                return Double.parseDouble(q);
                            }})
                        .setOnFailureOrException(null)
                        .enabled(retrieveUsageMetrics))
                .poll(new SshPollConfig<Boolean>(SERVICE_PROCESS_IS_RUNNING)
                        .command(cmd)
                        .setOnSuccess(true)
                        .setOnFailureOrException(false)
                        .suppressDuplicates(true))
                .build();
    } else {
        LOG.warn("Location(s) {} not an ssh-machine location, so not polling for status; setting serviceUp immediately", getLocations());
        sensors().set(SERVICE_UP, true);
    }
}
 
Example 6
Source File: JmxSupport.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public Maybe<SshMachineLocation> getMachine() {
    return Locations.findUniqueSshMachineLocation(entity.getLocations());
}