JsonFunctions.walkM("resources", "mem"), JsonFunctions.castM(Long.class))) .onFailureOrException(Functions.constant(-1L))) .poll(HttpPollConfig.forSensor(CPU_AVAILABLE) .suburl("/master/state.json") JsonFunctions.walkM("resources", "cpus"), JsonFunctions.castM(Double.class))) .onFailureOrException(Functions.constant(-1d))) .poll(HttpPollConfig.forSensor(DISK_AVAILABLE) .suburl("/master/state.json") JsonFunctions.walkM("resources", "disk"), JsonFunctions.castM(Long.class))) .onFailureOrException(Functions.constant(-1L))) .poll(HttpPollConfig.forSensor(MEMORY_USED) .suburl("/master/state.json") JsonFunctions.walkM("used_resources", "mem"), JsonFunctions.castM(Long.class))) .onFailureOrException(Functions.constant(-1L))) .poll(HttpPollConfig.forSensor(CPU_USED) .suburl("/master/state.json") JsonFunctions.walkM("used_resources", "cpus"), JsonFunctions.castM(Double.class))) .onFailureOrException(Functions.constant(-1d))) .poll(HttpPollConfig.forSensor(DISK_USED) .suburl("/master/state.json")
.onFailureOrException(Functions.constant(managed ? Boolean.FALSE : true))) .poll(new HttpPollConfig<Long>(TASK_STARTED_AT) .suppressDuplicates(true) .onFailureOrException(Functions.<Long>constant(-1L))) .poll(new HttpPollConfig<Long>(TASK_STAGED_AT) .suppressDuplicates(true) .onFailureOrException(Functions.<Long>constant(-1L))) .poll(new HttpPollConfig<String>(Attributes.HOSTNAME) .suppressDuplicates(true) .onFailureOrException(Functions.<String>constant(null))) .poll(new HttpPollConfig<String>(TASK_ID) .suppressDuplicates(true) .onFailureOrException((Function) Functions.<Object>constant(managed ? null : FeedConfig.UNCHANGED))) .poll(new HttpPollConfig<String>(Attributes.ADDRESS) .suppressDuplicates(true) .onFailureOrException(Functions.<String>constant(null))); httpFeed = httpFeedBuilder.build();
@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(); }
private void connectAuthenticatedSensors() { hostsHttpFeed = HttpFeed.builder() .entity(this) .period(1000, TimeUnit.MILLISECONDS) .baseUri(String.format("%s/api/v1/hosts", ambariUri)) .credentials(usernamePasswordCredentials.getUserName(), usernamePasswordCredentials.getPassword()) .header(HttpHeaders.AUTHORIZATION, HttpTool.toBasicAuthorizationValue(usernamePasswordCredentials)) .poll(new HttpPollConfig<List<String>>(REGISTERED_HOSTS) .onSuccess(Functionals.chain(HttpValueFunctions.jsonContents(), getHosts())) .onFailureOrException(Functions.<List<String>>constant(ImmutableList.<String>of()))) .build(); clusterHttpFeed = HttpFeed.builder() .entity(this) .period(1000, TimeUnit.MILLISECONDS) .baseUri(String.format("%s/api/v1/clusters/%s/requests/%d", ambariUri, getConfig(AmbariCluster.CLUSTER_NAME), 1)) .credentials(usernamePasswordCredentials.getUserName(), usernamePasswordCredentials.getPassword()) .header(HttpHeaders.AUTHORIZATION, HttpTool.toBasicAuthorizationValue(usernamePasswordCredentials)) .poll(new HttpPollConfig<String>(CLUSTER_STATE) .onSuccess(Functionals.chain(HttpValueFunctions.jsonContents(), getRequestState())) .onFailureOrException(Functions.<String>constant(null))) .build(); }
@Override public void connectSensors() { super.connectSensors(); HttpFeed.Builder httpFeedBuilder = HttpFeed.builder() .entity(this) .period(2000, TimeUnit.MILLISECONDS) .baseUri(sensors().get(FRAMEWORK_URL)) .credentialsIfNotNull(config().get(MesosCluster.MESOS_USERNAME), config().get(MesosCluster.MESOS_PASSWORD)) .poll(HttpPollConfig.forSensor(MARATHON_APPLICATIONS) .suppressDuplicates(true) .suburl("/v2/apps/") .onSuccess(Functionals.chain(HttpValueFunctions.jsonContents(), JsonFunctions.walk("apps"), JsonFunctions.forEach(JsonFunctions.<String>getPath("id")))) .onFailureOrException(Functions.constant(Arrays.asList(new String[0])))) .poll(HttpPollConfig.forSensor(MARATHON_VERSION) .suppressDuplicates(true) .suburl("/v2/info/") .onSuccess(HttpValueFunctions.jsonContents("version", String.class)) .onFailureOrException(Functions.constant(""))) .poll(HttpPollConfig.forSensor(SERVICE_UP) .suppressDuplicates(true) .suburl("/ping") .onSuccess(HttpValueFunctions.responseCodeEquals(200)) .onFailureOrException(Functions.constant(Boolean.FALSE))); httpFeed = httpFeedBuilder.build(); }
.onFailureOrException(Functions.constant((T) null)) .onSuccess(successFunction) .suppressDuplicates(Boolean.TRUE.equals(suppressDuplicates))
.suburl("/sensors/current-state") .onSuccess(mirrorSensors) .onFailureOrException(new Function<Object, Void>() { @Override public Void apply(Object input) {
.suburl("/master/health") .onSuccess(HttpValueFunctions.responseCodeEquals(200)) .onFailureOrException(Functions.constant(Boolean.FALSE))) .poll(HttpPollConfig.forSensor(CLUSTER_NAME) .suburl("/master/state.json") .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();
private void newMultiFeed(URL baseUrl) { feed = HttpFeed.builder() .entity(entity) .baseUrl(baseUrl) .poll(HttpPollConfig.forMultiple() .onSuccess(new Function<HttpToolResponse,Void>() { @Override public Void apply(HttpToolResponse response) { entity.sensors().set(SENSOR_INT, response.getResponseCode()); if (response.getResponseCode()==200) entity.sensors().set(SENSOR_STRING, response.getContentAsString()); return null; } }) .onFailureOrException(Functionals.function(EntityFunctions.settingSensorsConstant(entity, MutableMap.<AttributeSensor<?>,Object>of( SENSOR_INT, -1, SENSOR_STRING, PollConfig.REMOVE)))) .period(100)) .build(); }
@Override public void connectSensors() { Duration scanInterval = config().get(MesosCluster.SCAN_INTERVAL); HttpFeed.Builder taskScanBuilder = HttpFeed.builder() .entity(this) .period(scanInterval) .baseUri(config().get(MesosCluster.MESOS_URL)) .credentialsIfNotNull(config().get(MesosCluster.MESOS_USERNAME), config().get(MesosCluster.MESOS_PASSWORD)) .poll(HttpPollConfig.forSensor(MESOS_TASK_LIST) .description("Scan Tasks") .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 scanTasks(frameworks.getAsJsonArray()); } })) .onFailureOrException(Functions.<List<String>>constant(null))); taskScan = taskScanBuilder.build(); }
.poll(new HttpPollConfig<Boolean>(URL_REACHABLE) .onSuccess(HttpValueFunctions.responseCodeEquals(200)) .onFailureOrException(Functions.constant(false))) .build();
.poll(new HttpPollConfig<Boolean>(MANAGEMENT_URL_UP) .onSuccess(HttpValueFunctions.responseCodeEquals(200)) .onFailureOrException(Functions.constant(false)) .suppressDuplicates(true)) .poll(new HttpPollConfig<Integer>(REQUEST_COUNT) .vars(includeRuntimeUriVars) .onSuccess(HttpValueFunctions.jsonContents("requestCount", Integer.class)) .onFailureOrException(EntityFunctions.attribute(this, REQUEST_COUNT)) .enabled(retrieveUsageMetrics)) .poll(new HttpPollConfig<Integer>(ERROR_COUNT)