@@ -0,0 +1,2975 @@
+package brooklyn.entity.container.policy;%0A%0Aimport java.util.Map;%0A%0Aimport com.google.common.base.Function;%0Aimport com.google.common.collect.ImmutableMap;%0Aimport com.google.common.collect.Maps;%0Aimport com.google.common.reflect.TypeToken;%0A%0Aimport brooklyn.config.ConfigKey;%0Aimport brooklyn.enricher.basic.AbstractEnricher;%0Aimport brooklyn.entity.Entity;%0Aimport brooklyn.entity.basic.ConfigKeys;%0Aimport brooklyn.entity.basic.EntityLocal;%0Aimport brooklyn.entity.container.docker.DockerInfrastructure;%0Aimport brooklyn.event.AttributeSensor;%0Aimport brooklyn.event.SensorEvent;%0Aimport brooklyn.event.SensorEventListener;%0Aimport brooklyn.policy.autoscaling.AutoScalerPolicy;%0A%0Apublic class AvailableContainersScalingEnricher extends AbstractEnricher %7B%0A%0A    ConfigKey%3CConfigKey%3CInteger%3E%3E MAX_CONTAINERS = ConfigKeys.newConfigKey(new TypeToken%3CConfigKey%3CInteger%3E%3E() %7B%7D,%0A            %22enricher.availability.containers%22, %22Sensor producing the number of containers in the cluster%22,%0A            DockerInfrastructure.DOCKER_CONTAINER_CLUSTER_MAX_SIZE);%0A%0A    ConfigKey%3CAttributeSensor%3CInteger%3E%3E CONTAINERS = ConfigKeys.newConfigKey(new TypeToken%3CAttributeSensor%3CInteger%3E%3E() %7B%7D,%0A            %22enricher.availability.containers%22, %22Sensor producing the number of containers in the cluster%22,%0A            DockerInfrastructure.DOCKER_CONTAINER_COUNT);%0A%0A    ConfigKey%3CAttributeSensor%3CInteger%3E%3E HOSTS = ConfigKeys.newConfigKey(new TypeToken%3CAttributeSensor%3CInteger%3E%3E() %7B%7D,%0A            %22enricher.availability.hosts%22, %22Sensor producing the number of hosts in the cluster%22,%0A            DockerInfrastructure.DOCKER_HOST_COUNT);%0A%0A    ConfigKey%3CAttributeSensor%3C?%3E%3E NOTIFIER = ConfigKeys.newConfigKey(new TypeToken%3CAttributeSensor%3C?%3E%3E() %7B%7D,%0A            %22enricher.availability.notifier%22, %22The sensor on which to emit an event%22);%0A%0A    public void setEntity(EntityLocal entity) %7B%0A        super.setEntity(entity);%0A        subscribe(entity, getConfig(CONTAINERS), new Listener());%0A        subscribe(entity, getConfig(HOSTS), new Listener());%0A    %7D%0A%0A    private class Listener implements SensorEventListener%3CObject%3E %7B%0A        @Override%0A        public void onEvent(SensorEvent%3CObject%3E event) %7B%0A            recalculate();%0A        %7D%0A    %7D%0A%0A    private void recalculate() %7B%0A        int maxContainers = entity.getConfig(getConfig(MAX_CONTAINERS));%0A        int containers = entity.getAttribute(getConfig(CONTAINERS));%0A        int hosts = entity.getAttribute(getConfig(HOSTS));%0A        if ((maxContainers * hosts) - containers %3C maxContainers) %7B%0A            // Emit event with Map with properties from AutoScalerPolicy:%0A            Map%3CString, Object%3E properties = ImmutableMap.of(%0A                    AutoScalerPolicy.POOL_CURRENT_SIZE_KEY, null,%0A                    AutoScalerPolicy.POOL_HIGH_THRESHOLD_KEY, null,%0A                    AutoScalerPolicy.POOL_LOW_THRESHOLD_KEY, null,%0A                    AutoScalerPolicy.POOL_CURRENT_WORKRATE_KEY, null);%0A            emit(getConfig(NOTIFIER), properties);%0A%0A        %7D%0A    %7D%0A%7D%0A

Add new AvailableContainersScalingEnricher