AdministrationAgent implements InitializingBean { protected void mapAndExecuteVMsMigrations(ClusterVO cluster, ClusterAdministrationHeuristicAlgorithm administrationAlgorithm) { List<HostResources> hosts = getClusterUpHosts(cluster); long clusterId = cluster.getId(); if (CollectionUtils.isEmpty(hosts) || hosts.size() == 1) { logger.debug(String.format("No hosts or single host on cluster[id=%d], no need to migrate virtual machines.", clusterId)); return; } logger.info(String.format("Starting ranking hosts for cluster[id=%d] administration.", clusterId)); List<HostResources> rankedHosts = administrationAlgorithm.rankHosts(hosts); logger.info(String.format("Starting mapping VMs for cluster[id=%d] administration.", clusterId)); Map<Long, HostResources> migrations = administrationAlgorithm.mapVMsToHost(rankedHosts); logger.info(String.format("Starting migrating VMs for cluster[id=%d] administration.", clusterId)); for (Entry<Long, HostResources> mappedMig : migrations.entrySet()) { Long vmId = mappedMig.getKey(); HostVO targetHost = hostService.findHostById(mappedMig.getValue().getHostId()); migrateVM(virtualMachineService.searchVmInstanceById(vmId), targetHost); } logger.info(String.format("Migration of VMs for cluster[id=%d] administration was finished.", clusterId)); }  void receiveClusterToBeManaged(Long clusterId); Long searchClusterToBeManaged(); List<ClusterResourcesUp> createAllClustersResourcesUp(); @Override void afterPropertiesSet();  }
@Test public void mapAndExecuteVMsMigrationsTestEmptyHostList() { ClusterVO cluster = createCluster(null); List<HostResources> hosts = new ArrayList<>(); setupMapAndExecuteVMsMigrationsTest(hosts, true); administrationAgent.mapAndExecuteVMsMigrations(cluster, clusterAdministrationHeuristicAlgorithm); verifyMapAndExecuteVMsMigrationsCalledMethods(0, 0); }
@Test public void mapAndExecuteVMsMigrationsTestOneHost() { ClusterVO cluster = createCluster(null); List<HostResources> hosts = createHosts(1); setupMapAndExecuteVMsMigrationsTest(hosts, true); administrationAgent.mapAndExecuteVMsMigrations(cluster, clusterAdministrationHeuristicAlgorithm); verifyMapAndExecuteVMsMigrationsCalledMethods(0, 0); }
@Test public void mapAndExecuteVMsMigrationsTestFullExecution() { ClusterVO cluster = createCluster(null); List<HostResources> hosts = createHosts(2); setupMapAndExecuteVMsMigrationsTest(hosts, true); administrationAgent.mapAndExecuteVMsMigrations(cluster, clusterAdministrationHeuristicAlgorithm); verifyMapAndExecuteVMsMigrationsCalledMethods(1, 1); }
@Test public void mapAndExecuteVMsMigrationsTestEmptyMigrationsMap() { ClusterVO cluster = createCluster(null); List<HostResources> hosts = createHosts(2); setupMapAndExecuteVMsMigrationsTest(hosts, false); administrationAgent.mapAndExecuteVMsMigrations(cluster, clusterAdministrationHeuristicAlgorithm); verifyMapAndExecuteVMsMigrationsCalledMethods(1, 0); }