.header("Accept", "application/json") .poll(new HttpPollConfig<Boolean>(SERVICE_UP) .suppressDuplicates(true) .onSuccess(Functionals.chain(HttpValueFunctions.jsonContents(), JsonFunctions.walk("tasks"), new Function<JsonElement, Boolean>() { .onFailureOrException(Functions.constant(managed ? Boolean.FALSE : true))) .poll(new HttpPollConfig<Long>(TASK_STARTED_AT) .suppressDuplicates(true) .onSuccess(Functionals.chain(HttpValueFunctions.jsonContents(), JsonFunctions.walk("tasks"), new Function<JsonElement, Long>() { .onFailureOrException(Functions.<Long>constant(-1L))) .poll(new HttpPollConfig<Long>(TASK_STAGED_AT) .suppressDuplicates(true) .onSuccess(Functionals.chain(HttpValueFunctions.jsonContents(), JsonFunctions.walk("tasks"), new Function<JsonElement, Long>() { .onFailureOrException(Functions.<Long>constant(-1L))) .poll(new HttpPollConfig<String>(Attributes.HOSTNAME) .suppressDuplicates(true) .onSuccess(Functionals.chain(HttpValueFunctions.jsonContents(), JsonFunctions.walk("tasks"), new Function<JsonElement, String>() { .onFailureOrException(Functions.<String>constant(null))) .poll(new HttpPollConfig<String>(TASK_ID) .suppressDuplicates(true) .onSuccess(Functionals.chain(HttpValueFunctions.jsonContents(), JsonFunctions.walk("tasks"), new Function<JsonElement, String>() {
@Override protected void connectSensors() { super.connectSensors(); ConfigToAttributes.apply(this); HostAndPort accessible = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, getHttpPort()); String nodeJsUrl = String.format("http://%s:%d", accessible.getHostText(), accessible.getPort()); if (isHttpMonitoringEnabled()) { LOG.info("Connecting to {}", nodeJsUrl); httpFeed = HttpFeed.builder() .entity(this) .baseUri(nodeJsUrl) .poll(new HttpPollConfig<Boolean>(SERVICE_UP) .suppressDuplicates(true) .suburl(getConfig(NodeJsWebAppService.SERVICE_UP_PATH)) .checkSuccess(Predicates.alwaysTrue()) .onSuccess(HttpValueFunctions.responseCodeEquals(200)) .setOnException(false)) .build(); } else { connectServiceUpIsRunning(); } WebAppServiceMethods.connectWebAppServerPolicies(this); }
@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)) .period(period);
@Override public void connectSensors() { super.connectSensors(); ConfigToAttributes.apply(this); // "up" is defined as returning a valid HTTP response from nginx (including a 404 etc) httpFeed = addFeed(HttpFeed.builder() .uniqueTag("nginx-poll") .entity(this) .period(getConfig(HTTP_POLL_PERIOD)) .baseUri(new UrlInferencer()) .poll(new HttpPollConfig<String>(SENSOR_STRING) .onResult(HttpValueFunctions.stringContentsFunction()) .setOnException("Failed") .suppressDuplicates(true)) .build()); }
.poll(new HttpPollConfig<Integer>(MANAGEMENT_STATUS) .onSuccess(HttpValueFunctions.responseCode()) .suppressDuplicates(true)) .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)
.suppressDuplicates(true)) .build());