Search in sources :

Example 16 with AffinityGroup

use of org.ovirt.engine.core.common.scheduling.AffinityGroup in project ovirt-engine by oVirt.

the class AffinityRulesEnforcerTest method testVmToHostsExpectedConflictingAffinityGroupsConflicts.

@Test
public /**
 * Test conflicts for vm to host affinity including combinations
 * with vm to vm affinity.
 *
 * The following scenarios are tested:
 * - Hosts with positive and negative affinity to vm:
 *   {vm1 + host1} , {vm1 - host1}     enforcing
 *   {vm1 [+] host1} , {vm1 - host1}   non enforcing/enforcing
 *
 * - Hosts with positive vm to vm conflict:
 *   {vm1 + host1},{vm1+vm2},{vm2 - host1}
 *
 * - Hosts with negative vm to vm conflict:
 *   {vm1 + host1},{vm1 - vm2},{vm2 + host1}
 *
 * - Non intersecting positive hosts conflict:
 *   {vm1 + host1,host2} , {vm1 + host1,host3}
 *
 * (  + is enforcing positive affinity)
 * ( [+] is non enforcing positive affinity)
 * (  - is enforcing negative affinity)
 * ( [-] is non enforcing negative affinity)
 * ( {} is an affinity group)
 */
void testVmToHostsExpectedConflictingAffinityGroupsConflicts() {
    // {vm1 + host1}
    AffinityGroup groupA = createAffinityGroup(cluster, EntityAffinityRule.POSITIVE, EntityAffinityRule.POSITIVE, true, Arrays.asList(host1), vm1);
    // {vm1 - host1}
    AffinityGroup groupB = createAffinityGroup(cluster, EntityAffinityRule.POSITIVE, EntityAffinityRule.NEGATIVE, true, Arrays.asList(host1), vm1);
    affinityGroups.add(groupA);
    affinityGroups.add(groupB);
    Set<Guid> expectedConflictingVMs = new HashSet<>();
    Set<AffinityGroup> expectedConflictingAffinityGroups = new HashSet<>();
    expectedConflictingAffinityGroups.addAll(Arrays.asList(groupA, groupB));
    AffinityRulesUtils.AffinityGroupConflicts conflicts = AffinityRulesUtils.checkForAffinityGroupHostsConflict(affinityGroups).get(0);
    assertThat(conflicts.getType()).isEqualTo(AffinityRulesConflicts.VM_TO_HOST_CONFLICT_IN_ENFORCING_POSITIVE_AND_NEGATIVE_AFFINITY);
    assertThat(conflicts.getAffinityGroups()).isEqualTo(expectedConflictingAffinityGroups);
    assertThat(conflicts.getHosts()).isEqualTo(new HashSet<>(Arrays.asList(host1.getId())));
    assertThat(conflicts.getVms()).isEqualTo(new HashSet<>(Arrays.asList(vm1.getId())));
    // {vm1 [+] host1}
    groupA = createAffinityGroup(cluster, EntityAffinityRule.POSITIVE, EntityAffinityRule.POSITIVE, false, Arrays.asList(host1), vm1);
    // {vm1 - host1}
    groupB = createAffinityGroup(cluster, EntityAffinityRule.POSITIVE, EntityAffinityRule.NEGATIVE, true, Arrays.asList(host1), vm1);
    affinityGroups.clear();
    affinityGroups.add(groupA);
    affinityGroups.add(groupB);
    expectedConflictingAffinityGroups.clear();
    expectedConflictingAffinityGroups.addAll(Arrays.asList(groupA, groupB));
    conflicts = AffinityRulesUtils.checkForAffinityGroupHostsConflict(affinityGroups).get(0);
    assertThat(conflicts.getType()).isEqualTo(AffinityRulesConflicts.VM_TO_HOST_CONFLICT_IN_POSITIVE_AND_NEGATIVE_AFFINITY);
    assertThat(conflicts.getAffinityGroups()).isEqualTo(expectedConflictingAffinityGroups);
    assertThat(conflicts.getHosts()).isEqualTo(new HashSet<>(Arrays.asList(host1.getId())));
    assertThat(conflicts.getVms()).isEqualTo(new HashSet<>(Arrays.asList(vm1.getId())));
    // {vm1 + host1}
    groupA = createAffinityGroup(cluster, EntityAffinityRule.POSITIVE, EntityAffinityRule.POSITIVE, true, Arrays.asList(host1), vm1);
    // {vm2 - host1}
    groupB = createAffinityGroup(cluster, EntityAffinityRule.POSITIVE, EntityAffinityRule.NEGATIVE, true, Arrays.asList(host1), vm2);
    // {vm1+vm2}
    AffinityGroup groupC = createAffinityGroup(cluster, EntityAffinityRule.POSITIVE, vm1, vm2);
    affinityGroups.clear();
    affinityGroups.add(groupA);
    affinityGroups.add(groupB);
    affinityGroups.add(groupC);
    expectedConflictingAffinityGroups.clear();
    expectedConflictingAffinityGroups.addAll(Arrays.asList(groupA, groupB));
    expectedConflictingVMs.addAll(Arrays.asList(vm1.getId(), vm2.getId()));
    conflicts = AffinityRulesUtils.checkForAffinityGroupHostsConflict(affinityGroups).get(0);
    assertThat(conflicts.getType()).isEqualTo(AffinityRulesConflicts.VM_TO_HOST_CONFLICTS_POSITIVE_VM_TO_VM_AFFINITY);
    assertThat(conflicts.getAffinityGroups()).isEqualTo(expectedConflictingAffinityGroups);
    assertThat(conflicts.getHosts()).isEqualTo(new HashSet<>(Arrays.asList(host1.getId())));
    assertThat(conflicts.getVms()).isEqualTo(new HashSet<>(Arrays.asList(vm1.getId(), vm2.getId())));
    // {vm1 + host1}
    groupA = createAffinityGroup(cluster, EntityAffinityRule.POSITIVE, EntityAffinityRule.POSITIVE, true, Arrays.asList(host1), vm1);
    // {vm2 + host1}
    groupB = createAffinityGroup(cluster, EntityAffinityRule.POSITIVE, EntityAffinityRule.POSITIVE, true, Arrays.asList(host1), vm2);
    // {vm1 - vm2}
    groupC = createAffinityGroup(cluster, EntityAffinityRule.NEGATIVE, vm1, vm2);
    affinityGroups.clear();
    affinityGroups.add(groupA);
    affinityGroups.add(groupB);
    affinityGroups.add(groupC);
    expectedConflictingAffinityGroups.clear();
    expectedConflictingAffinityGroups.addAll(Arrays.asList(groupA, groupB, groupC));
    conflicts = AffinityRulesUtils.checkForAffinityGroupHostsConflict(affinityGroups).get(0);
    assertThat(conflicts.getType()).isEqualTo(AffinityRulesConflicts.VM_TO_HOST_CONFLICTS_NEGATIVE_VM_TO_VM_AFFINITY);
    assertThat(conflicts.getAffinityGroups()).isEqualTo(expectedConflictingAffinityGroups);
    assertThat(conflicts.getHosts()).isEqualTo(new HashSet<>(Arrays.asList(host1.getId())));
    assertThat(conflicts.getVms()).isEqualTo(new HashSet<>(Arrays.asList(vm1.getId(), vm2.getId())));
    // {vm1 + host1,host2}
    groupA = createAffinityGroup(cluster, EntityAffinityRule.POSITIVE, EntityAffinityRule.POSITIVE, true, Arrays.asList(host1, host2), vm1);
    // {vm1 + host1,host3}
    groupB = createAffinityGroup(cluster, EntityAffinityRule.POSITIVE, EntityAffinityRule.POSITIVE, true, Arrays.asList(host1, host3), vm1);
    affinityGroups.clear();
    affinityGroups.add(groupA);
    affinityGroups.add(groupB);
    expectedConflictingAffinityGroups.clear();
    expectedConflictingAffinityGroups.addAll(Arrays.asList(groupA, groupB));
    conflicts = AffinityRulesUtils.checkForAffinityGroupHostsConflict(affinityGroups).get(0);
    assertThat(conflicts.getType()).isEqualTo(AffinityRulesConflicts.NON_INTERSECTING_POSITIVE_HOSTS_AFFINITY_CONFLICTS);
    assertThat(conflicts.getAffinityGroups()).isEqualTo(expectedConflictingAffinityGroups);
    assertThat(conflicts.getHosts()).isEqualTo(new HashSet<>(Arrays.asList(host2.getId(), host3.getId())));
    assertThat(conflicts.getVms()).isEqualTo(new HashSet<>(Arrays.asList(vm1.getId())));
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with AffinityGroup

use of org.ovirt.engine.core.common.scheduling.AffinityGroup in project ovirt-engine by oVirt.

the class AffinityRulesEnforcerTest method shouldMigrateFromHostWithLessHosts.

@Test
public void shouldMigrateFromHostWithLessHosts() {
    AffinityGroup positiveGroup = createAffinityGroup(cluster, EntityAffinityRule.POSITIVE, vm1, vm2, vm4);
    affinityGroups.add(positiveGroup);
    assertThat(enforcer.chooseNextVmToMigrate(cluster)).isEqualTo(vm4);
}
Also used : AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup) Test(org.junit.Test)

Example 18 with AffinityGroup

use of org.ovirt.engine.core.common.scheduling.AffinityGroup in project ovirt-engine by oVirt.

the class AffinityRulesEnforcerTest method shouldFixVmWithMostViolationsFirst.

@Test
public void shouldFixVmWithMostViolationsFirst() {
    AffinityGroup groupA = createAffinityGroup(cluster, EntityAffinityRule.POSITIVE, EntityAffinityRule.POSITIVE, true, Arrays.asList(host2), vm1, vm2);
    AffinityGroup groupB = createAffinityGroup(cluster, EntityAffinityRule.POSITIVE, EntityAffinityRule.POSITIVE, true, Arrays.asList(host3), vm1, vm2);
    AffinityGroup groupC = createAffinityGroup(cluster, EntityAffinityRule.POSITIVE, EntityAffinityRule.POSITIVE, true, Arrays.asList(host1), vm4);
    affinityGroups.clear();
    affinityGroups.add(groupA);
    affinityGroups.add(groupB);
    affinityGroups.add(groupC);
    assertThat(enforcer.chooseNextVmToMigrate(cluster)).isEqualTo(vm4);
    affinityGroups.clear();
    affinityGroups.add(groupB);
    affinityGroups.add(groupC);
    affinityGroups.add(groupA);
    assertThat(enforcer.chooseNextVmToMigrate(cluster)).isEqualTo(vm4);
}
Also used : AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup) Test(org.junit.Test)

Example 19 with AffinityGroup

use of org.ovirt.engine.core.common.scheduling.AffinityGroup in project ovirt-engine by oVirt.

the class AddAffinityGroupCommandTest method validate_vmNameExists_Test.

@Test
public void validate_vmNameExists_Test() {
    doReturn(new AffinityGroup()).when(affinityGroupDao).getByName(any());
    ValidateTestUtils.runAndAssertValidateFailure(command, EngineMessage.ACTION_TYPE_FAILED_AFFINITY_GROUP_NAME_EXISTS);
}
Also used : AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup) Test(org.junit.Test) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest)

Example 20 with AffinityGroup

use of org.ovirt.engine.core.common.scheduling.AffinityGroup in project ovirt-engine by oVirt.

the class AffinityGroupDaoTest method testGetByName.

@Test
public void testGetByName() {
    AffinityGroup affinityGroup = dao.getByName(AFFINITY_GROUP_NAME);
    assertNotNull(affinityGroup);
    affinityGroup = dao.getByName(AFFINITY_GROUP_NAME + "A");
    assertNull(affinityGroup);
}
Also used : AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup) Test(org.junit.Test)

Aggregations

AffinityGroup (org.ovirt.engine.core.common.scheduling.AffinityGroup)49 Test (org.junit.Test)20 Guid (org.ovirt.engine.core.compat.Guid)12 ArrayList (java.util.ArrayList)11 VM (org.ovirt.engine.core.common.businessentities.VM)11 HashSet (java.util.HashSet)9 HashMap (java.util.HashMap)7 List (java.util.List)5 Map (java.util.Map)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 Inject (javax.inject.Inject)5 PerHostMessages (org.ovirt.engine.core.common.scheduling.PerHostMessages)5 AffinityGroupDao (org.ovirt.engine.core.dao.scheduling.AffinityGroupDao)5 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)4 VDS (org.ovirt.engine.core.common.businessentities.VDS)4 AffinityGroupCRUDParameters (org.ovirt.engine.core.common.scheduling.parameters.AffinityGroupCRUDParameters)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Collections (java.util.Collections)3