Search in sources :

Example 66 with Version

use of org.ovirt.engine.core.compat.Version in project ovirt-engine by oVirt.

the class CpuLevelFilterPolicyUnit method filter.

@Override
public List<VDS> filter(Cluster cluster, List<VDS> hosts, VM vm, Map<String, String> parameters, PerHostMessages messages) {
    List<VDS> hostsToRunOn = new ArrayList<>();
    // full name of the vm cpu
    String customCpu;
    Version latestVer = cpuFlagsManagerHandler.getLatestDictionaryVersion();
    /* get required cpu name */
    if (StringUtils.isNotEmpty(vm.getCpuName())) {
        // dynamic check - used for 1.migrating vms 2.run-once 3.after dynamic field is updated with current static-field\cluster
        customCpu = vm.getCpuName();
    } else if (StringUtils.isNotEmpty(vm.getCustomCpuName())) {
        // static check - used only for cases where the dynamic value hasn't been updated yet(validate)
        customCpu = vm.getCustomCpuName();
    } else {
        // use cluster default - all hosts are valid
        return hosts;
    }
    // translate vdsVerb to full cpu name
    customCpu = cpuFlagsManagerHandler.getCpuNameByCpuId(customCpu, latestVer);
    if (StringUtils.isNotEmpty(customCpu)) {
        /* find compatible hosts */
        for (VDS host : hosts) {
            ServerCpu cpu = cpuFlagsManagerHandler.findMaxServerCpuByFlags(host.getCpuFlags(), latestVer);
            String hostCpuName = cpu == null ? null : cpu.getCpuName();
            if (StringUtils.isNotEmpty(hostCpuName)) {
                if (cpuFlagsManagerHandler.checkIfCpusSameManufacture(customCpu, hostCpuName, latestVer)) {
                    // verify comparison uses only one cpu-level scale
                    int compareResult = cpuFlagsManagerHandler.compareCpuLevels(customCpu, hostCpuName, latestVer);
                    if (compareResult <= 0) {
                        hostsToRunOn.add(host);
                        log.debug("Host '{}' wasn't filtered out as it has a CPU level ({}) which is higher or equal than the CPU level the VM was run with ({})", host.getName(), hostCpuName, customCpu);
                    } else {
                        log.debug("Host '{}' was filtered out as it has a CPU level ({}) which is lower than the CPU level the VM was run with ({})", host.getName(), hostCpuName, customCpu);
                        messages.addMessage(host.getId(), String.format("$hostCPULevel %1$s", hostCpuName));
                        messages.addMessage(host.getId(), String.format("$vmCPULevel %1$s", customCpu));
                        messages.addMessage(host.getId(), EngineMessage.VAR__DETAIL__LOW_CPU_LEVEL.toString());
                    }
                }
            }
        }
    }
    return hostsToRunOn;
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) Version(org.ovirt.engine.core.compat.Version) ArrayList(java.util.ArrayList) ServerCpu(org.ovirt.engine.core.common.businessentities.ServerCpu)

Example 67 with Version

use of org.ovirt.engine.core.compat.Version in project ovirt-engine by oVirt.

the class CommonVmPoolCommandTestAbstract method mockCluster.

/**
 * Mock VDS Group.
 */
private Cluster mockCluster() {
    Cluster group = new Cluster();
    group.setClusterId(clusterId);
    group.setCompatibilityVersion(new Version());
    group.setStoragePoolId(storagePoolId);
    group.setCpuName("Intel Conroe Family");
    group.setArchitecture(ArchitectureType.x86_64);
    return group;
}
Also used : Version(org.ovirt.engine.core.compat.Version) MacPoolPerCluster(org.ovirt.engine.core.bll.network.macpool.MacPoolPerCluster) Cluster(org.ovirt.engine.core.common.businessentities.Cluster)

Example 68 with Version

use of org.ovirt.engine.core.compat.Version in project ovirt-engine by oVirt.

the class CompatibilityVersionUtils method getEffective.

public static Version getEffective(VmBase vmBase, Cluster cluster) {
    Version vmCustomCompatibilityVersion = vmBase != null ? vmBase.getCustomCompatibilityVersion() : null;
    Version clusterCompatibilityVersion = cluster != null ? cluster.getCompatibilityVersion() : null;
    return CompatibilityVersionUtils.getEffective(vmCustomCompatibilityVersion, clusterCompatibilityVersion, Version.getLast());
}
Also used : Version(org.ovirt.engine.core.compat.Version)

Example 69 with Version

use of org.ovirt.engine.core.compat.Version in project ovirt-engine by oVirt.

the class ConvergenceConfigProviderTest method jsonProperlyFilled.

@Test
public void jsonProperlyFilled() throws IOException {
    Guid id = Guid.newGuid();
    List<MigrationPolicy> policies = new ArrayList<>();
    ConvergenceConfig config = new ConvergenceConfig();
    config.setInitialItems(Collections.singletonList(new ConvergenceItem("setDowntime2", 1)));
    config.setLastItems(Collections.singletonList(new ConvergenceItem("setDowntime3", 15)));
    config.setConvergenceItems(Collections.singletonList(new ConvergenceItemWithStallingLimit(1, "someAction", 12)));
    MigrationPolicy policy = new MigrationPolicy(id, "some name", "some long description", config);
    policies.add(policy);
    String json = JsonHelper.objectToJson(policies, false);
    provider.initMigrationPolicies(json, VERSION);
    // just basic sanity check
    assertEquals(policy.getName(), provider.getMigrationPolicy(id, VERSION).getName());
    assertEquals(policy.getDescription(), provider.getMigrationPolicy(id, VERSION).getDescription());
    assertTrue(provider.getMigrationPolicy(id, new Version()) instanceof NoMigrationPolicy);
}
Also used : NoMigrationPolicy(org.ovirt.engine.core.common.migration.NoMigrationPolicy) ConvergenceConfig(org.ovirt.engine.core.common.migration.ConvergenceConfig) Version(org.ovirt.engine.core.compat.Version) ConvergenceItem(org.ovirt.engine.core.common.migration.ConvergenceItem) ArrayList(java.util.ArrayList) ConvergenceItemWithStallingLimit(org.ovirt.engine.core.common.migration.ConvergenceItemWithStallingLimit) Guid(org.ovirt.engine.core.compat.Guid) NoMigrationPolicy(org.ovirt.engine.core.common.migration.NoMigrationPolicy) MigrationPolicy(org.ovirt.engine.core.common.migration.MigrationPolicy) Test(org.junit.Test)

Example 70 with Version

use of org.ovirt.engine.core.compat.Version in project ovirt-engine by oVirt.

the class VmBaseMapper method mapCommonModelToEntity.

/**
 * Common for VM, template and instance type
 */
protected static void mapCommonModelToEntity(org.ovirt.engine.core.common.businessentities.VmBase entity, VmBase model) {
    if (model.isSetName()) {
        entity.setName(model.getName());
    }
    if (model.isSetMemory()) {
        entity.setMemSizeMb((int) (model.getMemory() / BYTES_PER_MB));
    }
    if (model.isSetIo() && model.getIo().isSetThreads()) {
        entity.setNumOfIoThreads(model.getIo().getThreads());
    }
    if (model.isSetDescription()) {
        entity.setDescription(model.getDescription());
    }
    if (model.isSetCpu() && model.getCpu().isSetTopology()) {
        if (model.getCpu().getTopology().getCores() != null) {
            entity.setCpuPerSocket(model.getCpu().getTopology().getCores());
        }
        if (model.getCpu().getTopology().getSockets() != null) {
            entity.setNumOfSockets(model.getCpu().getTopology().getSockets());
        }
        if (model.getCpu().getTopology().getThreads() != null) {
            entity.setThreadsPerCpu(model.getCpu().getTopology().getThreads());
        }
    }
    if (model.isSetHighAvailability()) {
        if (model.getHighAvailability().isSetEnabled()) {
            entity.setAutoStartup(model.getHighAvailability().isEnabled());
        }
        if (model.getHighAvailability().isSetPriority()) {
            entity.setPriority(model.getHighAvailability().getPriority());
        }
    }
    if (model.isSetDisplay()) {
        if (model.getDisplay().isSetType()) {
            // let backend decide which video device to use
            entity.setDefaultDisplayType(null);
        }
        if (model.getDisplay().isSetMonitors()) {
            entity.setNumOfMonitors(model.getDisplay().getMonitors());
        }
        if (model.getDisplay().isSetSingleQxlPci()) {
            entity.setSingleQxlPci(model.getDisplay().isSingleQxlPci());
        }
        if (model.getDisplay().isSetSmartcardEnabled()) {
            entity.setSmartcardEnabled(model.getDisplay().isSmartcardEnabled());
        }
    }
    if (model.isSetMigrationDowntime()) {
        entity.setMigrationDowntime(mapMinusOneToNull(model.getMigrationDowntime()));
    }
    if (model.isSetMigration()) {
        MigrationOptionsMapper.copyMigrationOptions(model.getMigration(), entity);
    }
    if (model.isSetCustomCpuModel()) {
        entity.setCustomCpuName(model.getCustomCpuModel());
    }
    if (model.isSetCustomEmulatedMachine()) {
        entity.setCustomEmulatedMachine(model.getCustomEmulatedMachine());
    }
    if (model.isSetMemoryPolicy() && model.getMemoryPolicy().isSetGuaranteed()) {
        Long memGuaranteed = model.getMemoryPolicy().getGuaranteed() / BYTES_PER_MB;
        entity.setMinAllocatedMem(memGuaranteed.intValue());
    }
    if (model.isSetMemoryPolicy() && model.getMemoryPolicy().isSetMax()) {
        Long maxMemory = model.getMemoryPolicy().getMax() / BYTES_PER_MB;
        entity.setMaxMemorySizeMb(maxMemory.intValue());
    }
    if (model.isSetOs()) {
        Boot boot = model.getOs().getBoot();
        if (boot != null && boot.isSetDevices() && boot.getDevices().isSetDevices()) {
            entity.setDefaultBootSequence(VmMapper.map(model.getOs().getBoot(), null));
        }
    }
    if (model.isSetCustomCompatibilityVersion()) {
        Version entityMappedVersion = VersionMapper.map(model.getCustomCompatibilityVersion());
        entity.setCustomCompatibilityVersion(entityMappedVersion.isNotValid() ? null : entityMappedVersion);
    }
    if (model.isSetLease()) {
        entity.setLeaseStorageDomainId(StorageDomainLeaseMapper.map(model.getLease()));
    }
    if (model.isSetPlacementPolicy()) {
        if (model.getPlacementPolicy().isSetAffinity()) {
            // read migration policy
            entity.setMigrationSupport(map(model.getPlacementPolicy().getAffinity(), null));
        }
        // reset previous dedicated host or hosts
        Set<Guid> hostGuidsSet = new HashSet<>();
        // read multiple hosts if there are few
        if (model.getPlacementPolicy().isSetHosts() && model.getPlacementPolicy().getHosts().getHosts().size() > 0) {
            for (Host currHost : model.getPlacementPolicy().getHosts().getHosts()) {
                Guid hostGuid;
                if (currHost.isSetId()) {
                    hostGuid = Guid.createGuidFromString(currHost.getId());
                } else {
                    continue;
                }
                hostGuidsSet.add(hostGuid);
            }
        }
        entity.setDedicatedVmForVdsList(new LinkedList<>(hostGuidsSet));
    }
}
Also used : Version(org.ovirt.engine.core.compat.Version) Host(org.ovirt.engine.api.model.Host) Guid(org.ovirt.engine.core.compat.Guid) Boot(org.ovirt.engine.api.model.Boot) HashSet(java.util.HashSet)

Aggregations

Version (org.ovirt.engine.core.compat.Version)102 ArrayList (java.util.ArrayList)24 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)20 Guid (org.ovirt.engine.core.compat.Guid)20 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)17 Map (java.util.Map)16 List (java.util.List)15 HashSet (java.util.HashSet)14 VDS (org.ovirt.engine.core.common.businessentities.VDS)14 HashMap (java.util.HashMap)13 ServerCpu (org.ovirt.engine.core.common.businessentities.ServerCpu)12 VM (org.ovirt.engine.core.common.businessentities.VM)11 ConfigValues (org.ovirt.engine.core.common.config.ConfigValues)11 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)11 Arrays (java.util.Arrays)10 MigrationPolicy (org.ovirt.engine.core.common.migration.MigrationPolicy)10 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)10 Collection (java.util.Collection)9 Collections (java.util.Collections)9 ArchitectureType (org.ovirt.engine.core.common.businessentities.ArchitectureType)9