in software/webapp/src/main/java/org/apache/brooklyn/entity/proxy/nginx/NginxControllerImpl.java [106:164]
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(null))
.poll(new HttpPollConfig<Boolean>(NGINX_URL_ANSWERS_NICELY)
// Any response from Nginx is good.
.checkSuccess(Predicates.alwaysTrue())
// Accept any nginx response (don't assert specific version), so that sub-classing
// for a custom nginx build is not strict about custom version numbers in headers
.onResult(HttpValueFunctions.containsHeader("Server"))
.setOnException(false)
.suppressDuplicates(true))
.build());
// TODO PERSISTENCE WORKAROUND kept anonymous function in case referenced in persisted state
new Function<HttpToolResponse, Boolean>() {
@Override
public Boolean apply(HttpToolResponse input) {
// Accept any nginx response (don't assert specific version), so that sub-classing
// for a custom nginx build is not strict about custom version numbers in headers
List<String> actual = input.getHeaderLists().get("Server");
return actual != null && actual.size() == 1;
}
};
if (!Lifecycle.RUNNING.equals(getAttribute(SERVICE_STATE_ACTUAL))) {
// TODO when updating the map, if it would change from empty to empty on a successful run
// gate with the above check to prevent flashing on ON_FIRE during rebind (this is invoked on rebind as well as during start)
ServiceNotUpLogic.updateNotUpIndicator(this, NGINX_URL_ANSWERS_NICELY, "No response from nginx yet");
}
enrichers().add(Enrichers.builder().updatingMap(Attributes.SERVICE_NOT_UP_INDICATORS)
.uniqueTag("not-up-unless-url-answers")
.from(NGINX_URL_ANSWERS_NICELY)
.computing(Functionals.ifNotEquals(true).value("URL where nginx listens is not answering correctly (with expected header)") )
.build());
connectServiceUpIsRunning();
// Can guarantee that parent/managementContext has been set
Group urlMappings = getConfig(URL_MAPPINGS);
if (urlMappings!=null && urlMappingsMemberTrackerPolicy==null) {
// Listen to the targets of each url-mapping changing
targetAddressesHandler = subscriptions().subscribeToMembers(urlMappings, UrlMapping.TARGET_ADDRESSES, new SensorEventListener<Collection<String>>() {
@Override public void onEvent(SensorEvent<Collection<String>> event) {
updateNeeded();
}
});
// Listen to url-mappings being added and removed
urlMappingsMemberTrackerPolicy = policies().add(PolicySpec.create(UrlMappingsMemberTrackerPolicy.class)
.configure("group", urlMappings));
}
}