Search in sources :

Example 41 with VmStatic

use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.

the class VmStaticDaoTest method initVmStaticsOrderedByMigrationSupport.

/**
 * {@code initVmStaticsOrderedByAutoStartup(List)} is the first method in VMs order selection tests. The other init
 * methods: <br>
 * {@code initVmStaticsOrderedByPriority} and {@code initVmStaticsOrderedByAutoStartup} are relying on each other
 * for creating an array of VM Static objects.<br>
 * Each of the methods modifies the VM static array according to the column which is being tested, started from the
 * least important column to the most.<br>
 * That way prioritizing a preceded column should be reflected in the selection and therefore to validate the order
 * is maintained.
 *
 * @return an array of VmStatics, in descending order according to: auto_startup, priority, MigrationSupport.<br>
 *         The MigrationSupport is the one being checked.<br>
 */
private VmStatic[] initVmStaticsOrderedByMigrationSupport(List<VmStatic> vmStatics) {
    VmStatic[] vmStaticArray = new VmStatic[getEntitiesTotalCount()];
    vmStaticArray = vmStatics.toArray(vmStaticArray);
    // initialize the VMs with equal settings: non HA, priority 1 and MIGRATABLE
    for (VmStatic element : vmStaticArray) {
        element.setAutoStartup(false);
        element.setPriority(1);
        element.setMigrationSupport(MigrationSupport.MIGRATABLE);
    }
    // set higher migration support value for the first VM
    vmStaticArray[0].setMigrationSupport(MigrationSupport.PINNED_TO_HOST);
    vmStaticArray[1].setMigrationSupport(MigrationSupport.IMPLICITLY_NON_MIGRATABLE);
    updateArrayOfVmStaticsInDb(vmStaticArray);
    return vmStaticArray;
}
Also used : VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic)

Example 42 with VmStatic

use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.

the class VmDaoTest method createHostedEngineVm.

private void createHostedEngineVm(Guid id) {
    VmStatic vmStatic = new VmStatic();
    vmStatic.setId(id);
    vmStatic.setClusterId(FixturesTool.CLUSTER_RHEL6_ISCSI);
    vmStatic.setName("HostedEngine");
    vmStatic.setOrigin(OriginType.HOSTED_ENGINE);
    vmStatic.setCpuProfileId(FixturesTool.CPU_PROFILE_1);
    getDbFacade().getVmStaticDao().save(vmStatic);
    VmDynamic vmDynamic = new VmDynamic();
    vmDynamic.setId(id);
    getDbFacade().getVmDynamicDao().save(vmDynamic);
    VmStatistics vmStatistics = new VmStatistics();
    vmStatistics.setId(id);
    getDbFacade().getVmStatisticsDao().save(vmStatistics);
}
Also used : VmDynamic(org.ovirt.engine.core.common.businessentities.VmDynamic) VmStatistics(org.ovirt.engine.core.common.businessentities.VmStatistics) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic)

Example 43 with VmStatic

use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.

the class VdsDaoTest method setupHostedEngineTests.

private void setupHostedEngineTests(boolean isHostedEngineVm, int vmCount) {
    // create the VmStatic instance
    VmStatic vmStatic = new VmStatic();
    vmStatic.setId(newVmId);
    vmStatic.setOrigin(isHostedEngineVm ? OriginType.MANAGED_HOSTED_ENGINE : OriginType.RHEV);
    dbFacade.getVmStaticDao().save(vmStatic);
    // create the VmDynamic instance
    VmDynamic vmDynamic = new VmDynamic();
    vmDynamic.setId(newVmId);
    vmDynamic.setStatus(VMStatus.Up);
    vmDynamic.setRunOnVds(existingVds.getId());
    dbFacade.getVmDynamicDao().save(vmDynamic);
    // update the VDS instance
    existingVds.setVmCount(vmCount);
    dbFacade.getVdsDynamicDao().update(existingVds.getDynamicData());
}
Also used : VmDynamic(org.ovirt.engine.core.common.businessentities.VmDynamic) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic)

Example 44 with VmStatic

use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.

the class DeactivateStorageDomainCommandTest method deactivateStorageDomainWithRunningVmWithLeaseFails.

@Test
public void deactivateStorageDomainWithRunningVmWithLeaseFails() {
    VmStatic vm = new VmStatic();
    vm.setName("myRunningVmWithLease");
    mockDomain();
    when(vmStaticDao.getAllRunningWithLeaseOnStorageDomain(domain.getId())).thenReturn(Collections.singletonList(vm));
    ValidateTestUtils.runAndAssertValidateFailure(cmd, EngineMessage.ERROR_CANNOT_DEACTIVATE_DOMAIN_WITH_RUNNING_VMS_WITH_LEASES);
    assertTrue(cmd.getReturnValue().getValidationMessages().contains(String.format("$vmNames %s", vm.getName())));
}
Also used : VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Test(org.junit.Test) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest)

Example 45 with VmStatic

use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.

the class VmMapper method map.

@Mapping(from = Vm.class, to = VmStatic.class)
public static VmStatic map(Vm vm, VmStatic template) {
    VmStatic staticVm = template != null ? template : new VmStatic();
    mapVmBaseModelToEntity(staticVm, vm);
    if (!vm.isSetMemory() && staticVm.getMemSizeMb() == 0) {
        // TODO: Get rid of this logic code when Backend supports default memory.
        staticVm.setMemSizeMb(DEFAULT_MEMORY_SIZE);
    }
    if (vm.isSetTemplate()) {
        if (vm.getTemplate().getId() != null) {
            staticVm.setVmtGuid(GuidUtils.asGuid(vm.getTemplate().getId()));
        }
        // it will be handled by the backend.
        if (vm.isSetUseLatestTemplateVersion()) {
            staticVm.setUseLatestVersion(vm.isUseLatestTemplateVersion());
        }
    }
    if (vm.isSetCpu()) {
        if (vm.getCpu().isSetMode()) {
            staticVm.setUseHostCpuFlags(vm.getCpu().getMode() == CpuMode.HOST_PASSTHROUGH);
        }
        if (vm.getCpu().isSetCpuTune()) {
            staticVm.setCpuPinning(cpuTuneToString(vm.getCpu().getCpuTune()));
        }
    }
    if (vm.isSetInitialization()) {
        staticVm.setVmInit(InitializationMapper.map(vm.getInitialization(), staticVm.getVmInit()));
    }
    // if the Domain set via VmInit we ignore it
    if (vm.isSetDomain() && vm.getDomain().isSetName()) {
        if (staticVm.getVmInit() == null) {
            staticVm.setVmInit(new VmInit());
        }
        // We don't want to override the domain if it set via the Initialization object
        if (!vm.isSetInitialization() || !vm.getInitialization().isSetDomain()) {
            staticVm.getVmInit().setDomain(vm.getDomain().getName());
        }
    }
    if (vm.isSetNumaTuneMode()) {
        staticVm.setNumaTuneMode(map(vm.getNumaTuneMode(), null));
    }
    if (vm.isSetExternalHostProvider()) {
        String providerId = vm.getExternalHostProvider().getId();
        staticVm.setProviderId(providerId == null ? null : GuidUtils.asGuid(providerId));
    }
    return staticVm;
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic)

Aggregations

VmStatic (org.ovirt.engine.core.common.businessentities.VmStatic)87 Test (org.junit.Test)26 Guid (org.ovirt.engine.core.compat.Guid)15 VM (org.ovirt.engine.core.common.businessentities.VM)11 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)9 VmDynamic (org.ovirt.engine.core.common.businessentities.VmDynamic)8 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)8 Label (org.ovirt.engine.core.common.businessentities.Label)7 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)5 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Response (javax.ws.rs.core.Response)4 AddVmTemplateParameters (org.ovirt.engine.core.common.action.AddVmTemplateParameters)4 LabelBuilder (org.ovirt.engine.core.common.businessentities.LabelBuilder)4 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)4 VmStatistics (org.ovirt.engine.core.common.businessentities.VmStatistics)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 PostConstruct (javax.annotation.PostConstruct)3 Before (org.junit.Before)3