in qa/src/main/java/org/apache/brooklyn/qa/load/SimulatedJBoss7ServerImpl.java [95:153]
protected void connectSensors() {
boolean simulateEntity = getConfig(SIMULATE_ENTITY);
boolean simulateExternalMonitoring = getConfig(SIMULATE_EXTERNAL_MONITORING);
if (!simulateEntity && !simulateExternalMonitoring) {
super.connectSensors();
return;
}
HostAndPort hp = BrooklynAccessUtils.getBrooklynAccessibleAddress(this,
getAttribute(MANAGEMENT_HTTP_PORT) + getConfig(PORT_INCREMENT));
String managementUri = String.format("http://%s:%s/management/subsystem/web/connector/http/read-resource",
hp.getHost(), hp.getPort());
sensors().set(MANAGEMENT_URL, managementUri);
if (simulateExternalMonitoring) {
// TODO What would set this normally, if not doing connectServiceUpIsRunning?
sensors().set(SERVICE_PROCESS_IS_RUNNING, true);
} else {
// if simulating entity, then simulate work of periodic HTTP request; TODO but not parsing JSON response
String uriToPoll = (simulateEntity) ? "http://localhost:8081" : managementUri;
httpFeed = HttpFeed.builder()
.entity(this)
.period(200)
.baseUri(uriToPoll)
.credentials(getConfig(MANAGEMENT_USER), getConfig(MANAGEMENT_PASSWORD))
.poll(new HttpPollConfig<Integer>(MANAGEMENT_STATUS)
.onSuccess(HttpValueFunctions.responseCode()))
.build();
// Polls over ssh for whether process is running
connectServiceUpIsRunning();
}
functionFeed = FunctionFeed.builder()
.entity(this)
.period(5000)
.poll(new FunctionPollConfig<Boolean,Boolean>(MANAGEMENT_URL_UP)
.callable(new Callable<Boolean>() {
private int counter = 0;
@Override
public Boolean call() {
sensors().set(REQUEST_COUNT, (counter++ % 100));
sensors().set(ERROR_COUNT, (counter++ % 100));
sensors().set(TOTAL_PROCESSING_TIME, (counter++ % 100));
sensors().set(MAX_PROCESSING_TIME, (counter++ % 100));
sensors().set(BYTES_RECEIVED, (long) (counter++ % 100));
sensors().set(BYTES_SENT, (long) (counter++ % 100));
return true;
}}))
.build(false); // called on rebind so does not need to be persisted
enrichers().add(Enrichers.builder().updatingMap(Attributes.SERVICE_NOT_UP_INDICATORS)
.from(MANAGEMENT_URL_UP)
.computing(Functionals.ifNotEquals(true).value("Management URL not reachable") )
.build());
}