@Override public void connectSensors() { super.connectSensors(); connectServiceUpIsRunning(); HostAndPort hostAndPort = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, sensors().get(DOCKER_REGISTRY_PORT)); sensors().set(Attributes.MAIN_URI, URI.create("https://" + hostAndPort + "/v2")); httpFeed = HttpFeed.builder() .entity(this) .period(Duration.seconds(3)) .baseUri(getAttribute(Attributes.MAIN_URI)) .poll( new HttpPollConfig<Boolean>(Attributes.SERVICE_UP) .onSuccess(Functions.constant(true)) .onFailureOrException(Functions.constant(false))) .poll( new HttpPollConfig<List<String>>(DOCKER_REGISTRY_CATALOG) .suburl("/_catalog") .onSuccess( Functionals.chain( HttpValueFunctions.jsonContents(), JsonFunctions.walk("repositories"), JsonFunctions.forEach(JsonFunctions.cast(String.class)))) .onFailureOrException(Functions.constant(Collections.<String>emptyList()))) .build(); }
@Override public void disconnectSensors() { if (httpFeed != null) { httpFeed.stop(); } disconnectServiceUpIsRunning(); super.disconnectSensors(); }
public void disconnectSensors() { if (httpFeed != null && httpFeed.isActivated()) httpFeed.destroy(); if (scanner != null && scanner.isActivated()) scanner.destroy(); }
public void connectSensors() { sensors().set(Attributes.MAIN_URI, URI.create(config().get(MESOS_URL))); HttpFeed.Builder httpFeedBuilder = HttpFeed.builder() .entity(this) .period(1, TimeUnit.MINUTES) .baseUri(sensors().get(Attributes.MAIN_URI)) .credentialsIfNotNull(config().get(MESOS_USERNAME), config().get(MESOS_PASSWORD)) .poll( HttpPollConfig.forSensor(SERVICE_UP) .suburl("/master/health") .onSuccess(HttpValueFunctions.responseCodeEquals(200)) .onFailureOrException(Functions.constant(Boolean.FALSE))) .poll( HttpPollConfig.forSensor(CLUSTER_NAME) .suburl("/master/state.json") .onSuccess(HttpValueFunctions.jsonContents("cluster", String.class)) .onFailureOrException(Functions.constant(""))) .poll( HttpPollConfig.forSensor(CLUSTER_ID) .suburl("/master/state.json") .onSuccess(HttpValueFunctions.jsonContents("id", String.class)) .onFailureOrException(Functions.constant(""))) .poll( HttpPollConfig.forSensor(MESOS_VERSION) .suburl("/master/state.json") .onSuccess(HttpValueFunctions.jsonContents("version", String.class)) .onFailureOrException(Functions.constant(""))) .poll( HttpPollConfig.forSensor(CPUS_TOTAL) .suburl("/system/stats.json") .onSuccess(HttpValueFunctions.jsonContents("cpus_total", Integer.class)) .onFailureOrException(Functions.constant(-1))) .poll( HttpPollConfig.forSensor(LOAD_1MIN) .suburl("/system/stats.json") .onSuccess(HttpValueFunctions.jsonContents("avg_load_1min", Double.class)) .onFailureOrException(Functions.constant(-1.0d))) .poll( HttpPollConfig.forSensor(LOAD_5MIN) .suburl("/system/stats.json") .onSuccess(HttpValueFunctions.jsonContents("avg_load_5min", Double.class)) .onFailureOrException(Functions.constant(-1.0d))) .poll( HttpPollConfig.forSensor(LOAD_15MIN) .suburl("/system/stats.json") .onSuccess(HttpValueFunctions.jsonContents("avg_load_15min", Double.class)) .onFailureOrException(Functions.constant(-1.0d))) .poll( HttpPollConfig.forSensor(MEMORY_FREE_BYTES) .suburl("/system/stats.json") .onSuccess(HttpValueFunctions.jsonContents("mem_free_bytes", Long.class)) .onFailureOrException(Functions.constant(-1L))) .poll( HttpPollConfig.forSensor(MEMORY_TOTAL_BYTES) .suburl("/system/stats.json") .onSuccess(HttpValueFunctions.jsonContents("mem_total_bytes", Long.class)) .onFailureOrException(Functions.constant(-1L))); httpFeed = httpFeedBuilder.build(); Duration scanInterval = config().get(SCAN_INTERVAL); HttpFeed.Builder scanBuilder = HttpFeed.builder() .entity(this) .period(scanInterval) .baseUri(sensors().get(Attributes.MAIN_URI)) .credentialsIfNotNull(config().get(MESOS_USERNAME), config().get(MESOS_PASSWORD)) .poll( HttpPollConfig.forSensor(MESOS_SLAVE_LIST) .description("Scan Cluster Slaves") .suburl("/master/state.json") .onSuccess( Functionals.chain( HttpValueFunctions.jsonContents(), JsonFunctions.walk("slaves"), new Function<JsonElement, List<String>>() { @Override public List<String> apply(JsonElement slaves) { try { return scanSlaves(slaves.getAsJsonArray()); } catch (UnknownHostException e) { throw Exceptions.propagate(e); } } })) .onFailureOrException(Functions.<List<String>>constant(null))) .poll( HttpPollConfig.forSensor(MESOS_FRAMEWORK_LIST) .description("Scan Cluster Frameworks") .suburl("/master/state.json") .onSuccess( Functionals.chain( HttpValueFunctions.jsonContents(), JsonFunctions.walk("frameworks"), new Function<JsonElement, List<String>>() { @Override public List<String> apply(JsonElement frameworks) { return scanFrameworks(frameworks.getAsJsonArray()); } })) .onFailureOrException(Functions.<List<String>>constant(null))); scanner = scanBuilder.build(); }
@Override public void connectSensors() { super.connectSensors(); final String id = sensors().get(MESOS_SLAVE_ID); HttpFeed.Builder httpFeedBuilder = HttpFeed.builder() .entity(this) .period(30, TimeUnit.SECONDS) .baseUri(getMesosCluster().sensors().get(Attributes.MAIN_URI)) .credentialsIfNotNull( config().get(MesosCluster.MESOS_USERNAME), config().get(MesosCluster.MESOS_PASSWORD)) .poll( new HttpPollConfig<Long>(MEMORY_AVAILABLE) .suburl("/master/state.json") .onSuccess( Functionals.chain( HttpValueFunctions.jsonContents(), Functions.compose( MesosUtils.selectM( new Predicate<JsonElement>() { @Override public boolean apply(JsonElement input) { return input .getAsJsonObject() .get("id") .getAsString() .equals(id); } }), JsonFunctions.walk("slaves")), JsonFunctions.walkM("resources", "mem"), JsonFunctions.castM(Long.class))) .onFailureOrException(Functions.constant(-1L))) .poll( new HttpPollConfig<Double>(CPU_AVAILABLE) .suburl("/master/state.json") .onSuccess( Functionals.chain( HttpValueFunctions.jsonContents(), Functions.compose( MesosUtils.selectM( new Predicate<JsonElement>() { @Override public boolean apply(JsonElement input) { return input .getAsJsonObject() .get("id") .getAsString() .equals(id); } }), JsonFunctions.walk("slaves")), JsonFunctions.walkM("resources", "cpus"), JsonFunctions.castM(Double.class))) .onFailureOrException(Functions.constant(-1d))) .poll( new HttpPollConfig<Long>(DISK_AVAILABLE) .suburl("/master/state.json") .onSuccess( Functionals.chain( HttpValueFunctions.jsonContents(), Functions.compose( MesosUtils.selectM( new Predicate<JsonElement>() { @Override public boolean apply(JsonElement input) { return input .getAsJsonObject() .get("id") .getAsString() .equals(id); } }), JsonFunctions.walk("slaves")), JsonFunctions.walkM("resources", "disk"), JsonFunctions.castM(Long.class))) .onFailureOrException(Functions.constant(-1L))) .poll( new HttpPollConfig<Long>(MEMORY_USED) .suburl("/master/state.json") .onSuccess( Functionals.chain( HttpValueFunctions.jsonContents(), Functions.compose( MesosUtils.selectM( new Predicate<JsonElement>() { @Override public boolean apply(JsonElement input) { return input .getAsJsonObject() .get("id") .getAsString() .equals(id); } }), JsonFunctions.walk("slaves")), JsonFunctions.walkM("used_resources", "mem"), JsonFunctions.castM(Long.class))) .onFailureOrException(Functions.constant(-1L))) .poll( new HttpPollConfig<Double>(CPU_USED) .suburl("/master/state.json") .onSuccess( Functionals.chain( HttpValueFunctions.jsonContents(), Functions.compose( MesosUtils.selectM( new Predicate<JsonElement>() { @Override public boolean apply(JsonElement input) { return input .getAsJsonObject() .get("id") .getAsString() .equals(id); } }), JsonFunctions.walk("slaves")), JsonFunctions.walkM("used_resources", "cpus"), JsonFunctions.castM(Double.class))) .onFailureOrException(Functions.constant(-1d))) .poll( new HttpPollConfig<Long>(DISK_USED) .suburl("/master/state.json") .onSuccess( Functionals.chain( HttpValueFunctions.jsonContents(), Functions.compose( MesosUtils.selectM( new Predicate<JsonElement>() { @Override public boolean apply(JsonElement input) { return input .getAsJsonObject() .get("id") .getAsString() .equals(id); } }), JsonFunctions.walk("slaves")), JsonFunctions.walkM("used_resources", "disk"), JsonFunctions.castM(Long.class))) .onFailureOrException(Functions.constant(-1L))); httpFeed = httpFeedBuilder.build(); }
@Override public void disconnectSensors() { if (httpFeed != null && httpFeed.isActivated()) httpFeed.destroy(); super.disconnectSensors(); }