class AdministrationAgent implements InitializingBean {

    protected void shutdownIdleHosts(ClusterVO cluster, ClusterAdministrationHeuristicAlgorithm administrationAlgorithm) {
        if (!administrationAlgorithm.canHeuristicShutdownHosts()) {
            return;
        }
        List<HostResources> idleHosts = getClusterIdleHosts(cluster);
        long clusterId = cluster.getId();
        if (CollectionUtils.isEmpty(idleHosts)) {
            logger.info(String.format("There are no idle hosts in cluster[%d].", clusterId));
            return;
        }

        logger.info(String.format("Ranking hosts to shutdown on cluster[%d]", clusterId));
        List<HostResources> orderedHostsToPowerOff = administrationAlgorithm.rankHostToPowerOff(idleHosts);
        for (HostResources host : orderedHostsToPowerOff) {
            CloudResources cloudResources = cloudResourcesService.createCloudResources(createAllClustersResourcesUp());
            if (!administrationAlgorithm.canPowerOffAnotherHostInCloud(cloudResources)) {
                logger.info("The agent cannot shut down more hosts given the result of canPowerOffAnotherHostInCloud[false].");
                break;
            }
            long hostId = host.getHostId();
            if (!administrationAlgorithm.canPowerOffHost(host, cloudResources)) {
                logger.info(String.format("Could not shut down host[id=%d] for cluster[id=%d]. Result of canPowerOffHost[false]", hostId, clusterId));
                continue;
            }
            logger.info(String.format("Shutting down host[id=%d] from cluster[id=%d]. Result of canPowerOffHost[true]", hostId, clusterId));
            shutdownHost(hostId);
        }
    }

}