Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ Pair<VirtualMachine, Host> getBestMigration(Cluster cluster, ClusterDrsAlgorithm
Map<Host, Boolean> requiresStorageMotion = hostsForMigrationOfVM.third();

for (Host destHost : compatibleDestinationHosts) {
if (!suitableDestinationHosts.contains(destHost)) {
if (!suitableDestinationHosts.contains(destHost) || cluster.getId() != destHost.getClusterId()) {
continue;
}
Ternary<Double, Double, Double> metrics = algorithm.getMetrics(cluster.getId(), vm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;

@RunWith(MockitoJUnitRunner.class)
public class ClusterDrsServiceImplTest {
Expand Down Expand Up @@ -353,6 +354,7 @@ public void testGetBestMigration() throws ConfigurationException {
Mockito.when(cluster.getId()).thenReturn(1L);

HostVO destHost = Mockito.mock(HostVO.class);
Mockito.when(destHost.getClusterId()).thenReturn(1L);

HostVO host = Mockito.mock(HostVO.class);
Mockito.when(host.getId()).thenReturn(2L);
Expand Down Expand Up @@ -386,13 +388,9 @@ public void testGetBestMigration() throws ConfigurationException {
}

Mockito.when(managementServer.listHostsForMigrationOfVM(vm1, 0L, 500L, null, vmList)).thenReturn(
new Ternary<Pair<List<? extends Host>, Integer>, List<? extends Host>, Map<Host, Boolean>>(
new Pair<>(List.of(destHost), 1), List.of(destHost), Map.of(destHost,
false)));
new Ternary<>(new Pair<>(List.of(destHost), 1), List.of(destHost), Map.of(destHost, false)));
Mockito.when(managementServer.listHostsForMigrationOfVM(vm2, 0L, 500L, null, vmList)).thenReturn(
new Ternary<Pair<List<? extends Host>, Integer>, List<? extends Host>, Map<Host, Boolean>>(
new Pair<>(List.of(destHost), 1), List.of(destHost), Map.of(destHost,
false)));
new Ternary<>(new Pair<>(List.of(destHost), 1), List.of(destHost), Map.of(destHost, false)));
Mockito.when(balancedAlgorithm.getMetrics(cluster.getId(), vm1, serviceOffering, destHost, new HashMap<>(),
new HashMap<>(), false)).thenReturn(new Ternary<>(1.0, 0.5, 1.5));

Expand All @@ -406,6 +404,56 @@ public void testGetBestMigration() throws ConfigurationException {
assertEquals(vm1, bestMigration.first());
}

@Test
public void testGetBestMigrationDifferentCluster() throws ConfigurationException {
ClusterVO cluster = Mockito.mock(ClusterVO.class);
Mockito.when(cluster.getId()).thenReturn(1L);

HostVO destHost = Mockito.mock(HostVO.class);
Mockito.when(destHost.getClusterId()).thenReturn(2L);

HostVO host = Mockito.mock(HostVO.class);
Mockito.when(host.getId()).thenReturn(2L);

VMInstanceVO vm1 = Mockito.mock(VMInstanceVO.class);
Mockito.when(vm1.getId()).thenReturn(1L);
Mockito.when(vm1.getType()).thenReturn(VirtualMachine.Type.User);
Mockito.when(vm1.getState()).thenReturn(VirtualMachine.State.Running);
Mockito.when(vm1.getDetails()).thenReturn(Collections.emptyMap());

VMInstanceVO vm2 = Mockito.mock(VMInstanceVO.class);
Mockito.when(vm2.getId()).thenReturn(2L);
Mockito.when(vm2.getType()).thenReturn(VirtualMachine.Type.User);
Mockito.when(vm2.getState()).thenReturn(VirtualMachine.State.Running);
Mockito.when(vm2.getDetails()).thenReturn(Collections.emptyMap());

List<VirtualMachine> vmList = new ArrayList<>();
vmList.add(vm1);
vmList.add(vm2);

Map<Long, List<VirtualMachine>> hostVmMap = new HashMap<>();
hostVmMap.put(host.getId(), new ArrayList<>());
hostVmMap.get(host.getId()).add(vm1);
hostVmMap.get(host.getId()).add(vm2);

Map<Long, ServiceOffering> vmIdServiceOfferingMap = new HashMap<>();

ServiceOffering serviceOffering = Mockito.mock(ServiceOffering.class);
for (VirtualMachine vm : vmList) {
vmIdServiceOfferingMap.put(vm.getId(), serviceOffering);
}

Mockito.when(managementServer.listHostsForMigrationOfVM(vm1, 0L, 500L, null, vmList)).thenReturn(
new Ternary<>(new Pair<>(List.of(destHost), 1), List.of(destHost), Map.of(destHost, false)));
Mockito.when(managementServer.listHostsForMigrationOfVM(vm2, 0L, 500L, null, vmList)).thenReturn(
new Ternary<>(new Pair<>(List.of(destHost), 1), List.of(destHost), Map.of(destHost, false)));
Pair<VirtualMachine, Host> bestMigration = clusterDrsService.getBestMigration(cluster, balancedAlgorithm,
vmList, vmIdServiceOfferingMap, new HashMap<>(), new HashMap<>());

assertNull(bestMigration.second());
assertNull(bestMigration.first());
}

@Test
public void testSavePlan() {
Mockito.when(drsPlanDao.persist(Mockito.any(ClusterDrsPlanVO.class))).thenReturn(
Expand Down