@Override public void init() { super.init(); ConfigToAttributes.apply(this, MESOS_SLAVE_ID); EnricherSpec<?> serviceUp = Enrichers.builder() .propagating(ImmutableMap.of(SLAVE_ACTIVE, SERVICE_UP)) .from(this) .build(); enrichers().add(serviceUp); }
@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(); }