Search in sources :

Example 1 with ContainerAutoScalerFactory

use of io.fabric8.api.ContainerAutoScalerFactory in project fabric8 by jboss-fuse.

the class FabricServiceImpl method createContainerAutoScaler.

@Override
public ContainerAutoScaler createContainerAutoScaler(FabricRequirements requirements, ProfileRequirements profileRequirements) {
    Collection<ContainerProvider> providerCollection = getProviders().values();
    for (ContainerProvider containerProvider : providerCollection) {
        // lets pick the highest weighted autoscaler (e.g. to prefer openshift to docker to child
        SortedMap<Integer, ContainerAutoScaler> sortedAutoScalers = new TreeMap<Integer, ContainerAutoScaler>();
        if (containerProvider instanceof ContainerAutoScalerFactory) {
            ContainerAutoScalerFactory provider = (ContainerAutoScalerFactory) containerProvider;
            ContainerAutoScaler autoScaler = provider.createAutoScaler(requirements, profileRequirements);
            if (autoScaler != null) {
                int weight = autoScaler.getWeight();
                sortedAutoScalers.put(weight, autoScaler);
            }
        }
        if (!sortedAutoScalers.isEmpty()) {
            Integer key = sortedAutoScalers.lastKey();
            if (key != null) {
                return sortedAutoScalers.get(key);
            }
        }
    }
    return null;
}
Also used : ContainerProvider(io.fabric8.api.ContainerProvider) ContainerAutoScalerFactory(io.fabric8.api.ContainerAutoScalerFactory) ContainerAutoScaler(io.fabric8.api.ContainerAutoScaler) TreeMap(java.util.TreeMap)

Aggregations

ContainerAutoScaler (io.fabric8.api.ContainerAutoScaler)1 ContainerAutoScalerFactory (io.fabric8.api.ContainerAutoScalerFactory)1 ContainerProvider (io.fabric8.api.ContainerProvider)1 TreeMap (java.util.TreeMap)1