AttributeSensor<String> mappedHostAndPortAttribute = DockerUtils.mappedPortSensor(Attributes.HTTP_PORT);
MySqlNode mysql = addChild(EntitySpec.create(MySqlNode.class)
.configure("creationScriptUrl", Entities.getRequiredUrlConfig(this, DB_SETUP_SQL_URL)));
ControlledDynamicWebAppCluster web = addChild(EntitySpec.create(ControlledDynamicWebAppCluster.class)
.configure(Cluster.INITIAL_SIZE, getConfig(INITIAL_SIZE))
.configure(ControlledDynamicWebAppCluster.MEMBER_SPEC, EntitySpec.create(TomcatServer.class)
.configure(DockerAttributes.DOCKERFILE_URL, "https://s3-eu-west-1.amazonaws.com/brooklyn-clocker/UsesJavaDockerfile")
.configure(WebAppService.HTTP_PORT, PortRanges.fromString("8080+"))
.configure(SoftwareProcess.SUGGESTED_VERSION, "7.0.53")
.configure(UsesJmx.USE_JMX, Boolean.TRUE)
.configure(UsesJmx.JMX_AGENT_MODE, JmxAgentModes.JMXMP)
.configure(UsesJmx.JMX_PORT, PortRanges.fromString("30000+"))
.configure(JavaWebAppService.ROOT_WAR, Entities.getRequiredUrlConfig(this, WAR_PATH))
.configure(javaSysProp("brooklyn.example.db.url"),
formatString("jdbc:%s%s?user=%s&password=%s",
attributeWhenReady(mysql, mappedDatastoreUrl),
DB_TABLE, DB_USERNAME, DB_PASSWORD)))
.configure(ControlledDynamicWebAppCluster.CONTROLLER_SPEC, EntitySpec.create(NginxController.class)
.configure(NginxController.HOST_AND_PORT_SENSOR, mappedHostAndPortAttribute)));
web.addEnricher(Enrichers.builder()
.propagating(mappedWebUrl)
.from(web.getController())
.build());
web.addEnricher(HttpLatencyDetector.builder().
url(mappedWebUrl).
rollup(10, TimeUnit.SECONDS).
build());
// simple scaling policy
web.getCluster().addPolicy(AutoScalerPolicy.builder()
.metric(DynamicWebAppCluster.REQUESTS_PER_SECOND_IN_WINDOW_PER_NODE)
.metricRange(0.1, 10.0)
.sizeRange(getConfig(INITIAL_SIZE), 10)
.resizeDownStabilizationDelay(Duration.ONE_MINUTE.toMilliseconds())
.resizeUpStabilizationDelay(Duration.THIRTY_SECONDS.toMilliseconds())