Search in sources :

Example 11 with AffinityGroup

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

the class VmAffinityPolicyUnitTestBase method createAffinityGroup.

protected AffinityGroup createAffinityGroup(Cluster cluster, EntityAffinityRule vmAffinityRule, boolean enforcing, final VM... vmList) {
    AffinityGroup ag = new AffinityGroup();
    ag.setId(Guid.newGuid());
    ag.setVmAffinityRule(vmAffinityRule);
    ag.setClusterId(cluster.getId());
    ag.setVmEnforcing(enforcing);
    ag.setVmIds(Arrays.stream(vmList).map(VM::getId).collect(Collectors.toList()));
    return ag;
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup)

Example 12 with AffinityGroup

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

the class VmToHostAffinityFilterPolicyUnitTest method testWithAffinityIntersection.

@Test
public void testWithAffinityIntersection() throws Exception {
    AffinityGroup positiveCollisionGroup = new AffinityGroup();
    positiveCollisionGroup.setVdsIds(Arrays.asList(host_negative_enforcing.getId()));
    positiveCollisionGroup.setVdsAffinityRule(EntityAffinityRule.POSITIVE);
    positiveCollisionGroup.setVdsEnforcing(true);
    hosts = Arrays.asList(host_positive_enforcing, host_negative_enforcing, host_not_in_affinity_group);
    List<AffinityGroup> affinityGroups = Arrays.asList(positiveCollisionGroup, negative_enforcing_group);
    doReturn(affinityGroups).when(affinityGroupDao).getAllAffinityGroupsByVmId(any());
    assertThat(unit.filter(cluster, hosts, vm, new HashMap<>(), new PerHostMessages())).isEmpty();
}
Also used : PerHostMessages(org.ovirt.engine.core.common.scheduling.PerHostMessages) AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup) Test(org.junit.Test)

Example 13 with AffinityGroup

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

the class VmToHostAffinityPolicyUnitBaseTest method setUp.

@Before
public void setUp() throws Exception {
    cluster = new Cluster();
    cluster.setId(Guid.newGuid());
    vm = new VM();
    vm.setId(Guid.newGuid());
    vm.setClusterId(cluster.getId());
    host_positive_enforcing = new VDS();
    host_positive_enforcing.setId(Guid.newGuid());
    host_positive_enforcing.setClusterId(cluster.getId());
    host_negative_enforcing = new VDS();
    host_negative_enforcing.setId(Guid.newGuid());
    host_negative_enforcing.setClusterId(cluster.getId());
    host_not_in_affinity_group = new VDS();
    host_not_in_affinity_group.setId(Guid.newGuid());
    host_not_in_affinity_group.setClusterId(cluster.getId());
    positive_enforcing_group = new AffinityGroup();
    negative_enforcing_group = new AffinityGroup();
    positive_enforcing_group.setVdsIds(Arrays.asList(host_positive_enforcing.getId()));
    positive_enforcing_group.setVdsAffinityRule(EntityAffinityRule.POSITIVE);
    positive_enforcing_group.setVdsEnforcing(true);
    negative_enforcing_group.setVdsIds(Arrays.asList(host_negative_enforcing.getId()));
    negative_enforcing_group.setVdsAffinityRule(EntityAffinityRule.NEGATIVE);
    negative_enforcing_group.setVdsEnforcing(true);
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) VM(org.ovirt.engine.core.common.businessentities.VM) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup) Before(org.junit.Before)

Example 14 with AffinityGroup

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

the class EditAffinityGroupCommandTest method createAffinityGroup.

private AffinityGroup createAffinityGroup() {
    affinityGroup = new AffinityGroup();
    affinityGroup.setName(AFFINITY_GROUP_NAME);
    affinityGroup.setClusterId(clusterId);
    affinityGroup.setVmIds(new ArrayList<>());
    return affinityGroup;
}
Also used : AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup)

Example 15 with AffinityGroup

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

the class AffinityRulesEnforcerTest method shouldFixEqualSizedAffinityGroupWithHigherIdFirst.

@Test
public void shouldFixEqualSizedAffinityGroupWithHigherIdFirst() {
    vm1.setId(Guid.createGuidFromString("00000000-0000-0000-0000-000000000001"));
    vm4.setId(Guid.createGuidFromString("00000000-0000-0000-0000-000000000007"));
    vm6.setId(Guid.createGuidFromString("00000000-0000-0000-0000-000000000008"));
    vm2.setId(Guid.createGuidFromString("00000000-0000-0000-0000-000000000003"));
    vm5.setId(Guid.createGuidFromString("00000000-0000-0000-0000-000000000004"));
    prepareVmDao(vm1, vm2, vm4, vm5, vm6);
    final AffinityGroup lowIdGroup = createAffinityGroup(cluster, EntityAffinityRule.POSITIVE, vm1, vm4);
    final AffinityGroup highIdGroup = createAffinityGroup(cluster, EntityAffinityRule.POSITIVE, vm2, vm5);
    affinityGroups.add(lowIdGroup);
    affinityGroups.add(highIdGroup);
    assertThat(enforcer.chooseNextVmToMigrate(cluster)).isIn(vm2, vm5);
    affinityGroups.clear();
    affinityGroups.add(highIdGroup);
    affinityGroups.add(lowIdGroup);
    assertThat(enforcer.chooseNextVmToMigrate(cluster)).isIn(vm2, vm5);
    // Bigger groups should always come first
    affinityGroups.clear();
    final AffinityGroup biggestIdGroup = createAffinityGroup(cluster, EntityAffinityRule.POSITIVE, vm1, vm4, vm6);
    affinityGroups.add(highIdGroup);
    affinityGroups.add(biggestIdGroup);
    assertThat(enforcer.chooseNextVmToMigrate(cluster)).isIn(vm1, vm4, vm6);
}
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