Search in sources :

Example 1 with AffinityRule

use of org.ovirt.engine.api.model.AffinityRule in project ovirt-engine by oVirt.

the class AffinityGroupMapper method map.

@Mapping(from = org.ovirt.engine.core.common.scheduling.AffinityGroup.class, to = AffinityGroup.class)
public static AffinityGroup map(org.ovirt.engine.core.common.scheduling.AffinityGroup entity, AffinityGroup template) {
    AffinityGroup model = template != null ? template : new AffinityGroup();
    model.setId(entity.getId().toString());
    model.setName(entity.getName());
    model.setDescription(entity.getDescription());
    // These two fields are maintained to keep the backwards compatibility
    // with version 4 of the API and will be removed in future.
    model.setPositive(entity.isVmAffinityEnabled() ? entity.getVmPolarityBooleanObject() : null);
    model.setEnforcing(entity.isVmEnforcing());
    AffinityRule hostsRule = model.getHostsRule();
    if (hostsRule == null) {
        hostsRule = new AffinityRule();
        model.setHostsRule(hostsRule);
    }
    hostsRule.setEnabled(entity.isVdsAffinityEnabled());
    hostsRule.setEnforcing(entity.isVdsEnforcing());
    hostsRule.setPositive(entity.isVdsPositive());
    AffinityRule vmsRule = model.getVmsRule();
    if (vmsRule == null) {
        vmsRule = new AffinityRule();
        model.setVmsRule(vmsRule);
    }
    vmsRule.setEnabled(entity.isVmAffinityEnabled());
    vmsRule.setEnforcing(entity.isVmEnforcing());
    vmsRule.setPositive(entity.isVmPositive());
    Cluster cluster = new Cluster();
    cluster.setId(entity.getClusterId().toString());
    model.setCluster(cluster);
    Hosts hosts = model.getHosts();
    if (hosts == null) {
        hosts = new Hosts();
        model.setHosts(hosts);
    }
    entity.getVdsIds().stream().map(id -> {
        Host host = new Host();
        host.setId(id.toString());
        return host;
    }).forEach(model.getHosts().getHosts()::add);
    Vms vms = model.getVms();
    if (vms == null) {
        vms = new Vms();
        model.setVms(vms);
    }
    entity.getVmIds().stream().map(id -> {
        Vm vm = new Vm();
        vm.setId(id.toString());
        return vm;
    }).forEach(model.getVms().getVms()::add);
    return model;
}
Also used : AffinityGroup(org.ovirt.engine.api.model.AffinityGroup) Hosts(org.ovirt.engine.api.model.Hosts) List(java.util.List) Host(org.ovirt.engine.api.model.Host) Guid(org.ovirt.engine.core.compat.Guid) AffinityRule(org.ovirt.engine.api.model.AffinityRule) EntityAffinityRule(org.ovirt.engine.core.common.scheduling.EntityAffinityRule) Vm(org.ovirt.engine.api.model.Vm) Cluster(org.ovirt.engine.api.model.Cluster) GuidUtils(org.ovirt.engine.api.restapi.utils.GuidUtils) ArrayList(java.util.ArrayList) Vms(org.ovirt.engine.api.model.Vms) Hosts(org.ovirt.engine.api.model.Hosts) AffinityRule(org.ovirt.engine.api.model.AffinityRule) EntityAffinityRule(org.ovirt.engine.core.common.scheduling.EntityAffinityRule) Vm(org.ovirt.engine.api.model.Vm) Cluster(org.ovirt.engine.api.model.Cluster) Host(org.ovirt.engine.api.model.Host) Vms(org.ovirt.engine.api.model.Vms) AffinityGroup(org.ovirt.engine.api.model.AffinityGroup)

Example 2 with AffinityRule

use of org.ovirt.engine.api.model.AffinityRule in project ovirt-engine by oVirt.

the class AffinityGroupMapperTest method testVmsRuleStructure.

@Test
public void testVmsRuleStructure() throws Exception {
    AffinityGroup model = new AffinityGroup();
    AffinityRule rule = new AffinityRule();
    rule.setEnforcing(true);
    rule.setPositive(false);
    rule.setEnabled(true);
    model.setVmsRule(rule);
    org.ovirt.engine.core.common.scheduling.AffinityGroup entity = new org.ovirt.engine.core.common.scheduling.AffinityGroup();
    AffinityGroupMapper.map(model, entity);
    assertEquals(EntityAffinityRule.NEGATIVE, entity.getVmAffinityRule());
    assertEquals(true, entity.isVmEnforcing());
    assertEquals(true, entity.isVmAffinityEnabled());
}
Also used : AffinityRule(org.ovirt.engine.api.model.AffinityRule) EntityAffinityRule(org.ovirt.engine.core.common.scheduling.EntityAffinityRule) AffinityGroup(org.ovirt.engine.api.model.AffinityGroup) Test(org.junit.Test)

Example 3 with AffinityRule

use of org.ovirt.engine.api.model.AffinityRule in project ovirt-engine by oVirt.

the class AffinityGroupMapperTest method testVmsRuleStructureNeg.

@Test
public void testVmsRuleStructureNeg() throws Exception {
    AffinityGroup model = new AffinityGroup();
    AffinityRule rule = new AffinityRule();
    rule.setEnforcing(false);
    rule.setPositive(true);
    rule.setEnabled(true);
    model.setVmsRule(rule);
    org.ovirt.engine.core.common.scheduling.AffinityGroup entity = new org.ovirt.engine.core.common.scheduling.AffinityGroup();
    AffinityGroupMapper.map(model, entity);
    assertEquals(EntityAffinityRule.POSITIVE, entity.getVmAffinityRule());
    assertEquals(false, entity.isVmEnforcing());
    assertEquals(true, entity.isVmAffinityEnabled());
}
Also used : AffinityRule(org.ovirt.engine.api.model.AffinityRule) EntityAffinityRule(org.ovirt.engine.core.common.scheduling.EntityAffinityRule) AffinityGroup(org.ovirt.engine.api.model.AffinityGroup) Test(org.junit.Test)

Example 4 with AffinityRule

use of org.ovirt.engine.api.model.AffinityRule in project ovirt-engine by oVirt.

the class AffinityGroupMapperTest method testHostsRuleStructureNeg.

@Test
public void testHostsRuleStructureNeg() throws Exception {
    AffinityGroup model = new AffinityGroup();
    AffinityRule rule = new AffinityRule();
    rule.setEnabled(true);
    rule.setEnforcing(false);
    rule.setPositive(true);
    model.setHostsRule(rule);
    org.ovirt.engine.core.common.scheduling.AffinityGroup entity = new org.ovirt.engine.core.common.scheduling.AffinityGroup();
    AffinityGroupMapper.map(model, entity);
    assertEquals(EntityAffinityRule.POSITIVE, entity.getVdsAffinityRule());
    assertEquals(false, entity.isVdsEnforcing());
}
Also used : AffinityRule(org.ovirt.engine.api.model.AffinityRule) EntityAffinityRule(org.ovirt.engine.core.common.scheduling.EntityAffinityRule) AffinityGroup(org.ovirt.engine.api.model.AffinityGroup) Test(org.junit.Test)

Example 5 with AffinityRule

use of org.ovirt.engine.api.model.AffinityRule in project ovirt-engine by oVirt.

the class AffinityGroupMapperTest method testVmsRuleStructureWins.

@Test
public void testVmsRuleStructureWins() throws Exception {
    AffinityGroup model = new AffinityGroup();
    model.setEnforcing(false);
    model.setPositive(false);
    AffinityRule rule = new AffinityRule();
    rule.setEnforcing(true);
    rule.setPositive(true);
    rule.setEnabled(true);
    model.setVmsRule(rule);
    org.ovirt.engine.core.common.scheduling.AffinityGroup entity = new org.ovirt.engine.core.common.scheduling.AffinityGroup();
    AffinityGroupMapper.map(model, entity);
    assertEquals(EntityAffinityRule.POSITIVE, entity.getVmAffinityRule());
    assertEquals(true, entity.isVmEnforcing());
    assertEquals(true, entity.isVmAffinityEnabled());
}
Also used : AffinityRule(org.ovirt.engine.api.model.AffinityRule) EntityAffinityRule(org.ovirt.engine.core.common.scheduling.EntityAffinityRule) AffinityGroup(org.ovirt.engine.api.model.AffinityGroup) Test(org.junit.Test)

Aggregations

AffinityGroup (org.ovirt.engine.api.model.AffinityGroup)7 AffinityRule (org.ovirt.engine.api.model.AffinityRule)7 EntityAffinityRule (org.ovirt.engine.core.common.scheduling.EntityAffinityRule)7 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Cluster (org.ovirt.engine.api.model.Cluster)1 Host (org.ovirt.engine.api.model.Host)1 Hosts (org.ovirt.engine.api.model.Hosts)1 Vm (org.ovirt.engine.api.model.Vm)1 Vms (org.ovirt.engine.api.model.Vms)1 GuidUtils (org.ovirt.engine.api.restapi.utils.GuidUtils)1 Guid (org.ovirt.engine.core.compat.Guid)1