Search in sources :

Example 26 with VmPool

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

the class VmPoolDaoTest method testUpdateVmPool.

/**
 * Ensures that updating a VM pool works as expected.
 */
@Test
public void testUpdateVmPool() {
    existingVmPool.setVmPoolDescription("This is an updated VM pool.");
    dao.update(existingVmPool);
    VmPool result = dao.get(existingVmPool.getVmPoolId());
    assertEquals(existingVmPool, result);
}
Also used : VmPool(org.ovirt.engine.core.common.businessentities.VmPool) Test(org.junit.Test)

Example 27 with VmPool

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

the class VmPoolDaoTest method testGetVmPoolWithInvalidId.

/**
 * Ensures that null is returned when the id is invalid.
 */
@Test
public void testGetVmPoolWithInvalidId() {
    VmPool result = dao.get(Guid.newGuid());
    assertNull(result);
}
Also used : VmPool(org.ovirt.engine.core.common.businessentities.VmPool) Test(org.junit.Test)

Example 28 with VmPool

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

the class GetVmPoolByIdQueryTest method testExecuteQuery.

@Test
public void testExecuteQuery() {
    Guid vmPoolID = Guid.newGuid();
    VmPool expectedResult = new VmPool();
    expectedResult.setVmPoolId(vmPoolID);
    IdQueryParameters paramsMock = getQueryParameters();
    when(paramsMock.getId()).thenReturn(vmPoolID);
    when(vmPoolDaoMock.get(vmPoolID, getUser().getId(), paramsMock.isFiltered())).thenReturn(expectedResult);
    getQuery().executeQueryCommand();
    VmPool result = getQuery().getQueryReturnValue().getReturnValue();
    assertEquals("Wrong VM pool returned", expectedResult, result);
}
Also used : IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) VmPool(org.ovirt.engine.core.common.businessentities.VmPool) Guid(org.ovirt.engine.core.compat.Guid) Test(org.junit.Test)

Example 29 with VmPool

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

the class UpdateVmVersionCommand method buildDiskInfoDestinationMap.

private HashMap<Guid, DiskImage> buildDiskInfoDestinationMap() {
    HashMap<Guid, DiskImage> destinationMap = new HashMap<>();
    if (getParameters().getVmPoolId() == null) {
        return destinationMap;
    }
    VmPool vmPool = vmPoolDao.get(getParameters().getVmPoolId());
    if (vmPool == null || !vmPool.isAutoStorageSelect()) {
        return destinationMap;
    }
    List<Disk> templateDisks = diskDao.getAllForVm(getParameters().getVmStaticData().getVmtGuid());
    Map<Guid, List<Guid>> diskToProfileMap = templateDisks.stream().collect(Collectors.toMap(Disk::getId, disk -> ((DiskImage) disk).getDiskProfileIds()));
    Map<Guid, List<Guid>> diskToStorageIds = templateDisks.stream().collect(Collectors.toMap(Disk::getId, disk -> ((DiskImage) disk).getStorageIds()));
    Map<Guid, Long> targetDomainsSize = diskToStorageIds.values().stream().flatMap(List::stream).distinct().map(storageDomainDao::get).collect(Collectors.toMap(StorageDomain::getId, StorageDomain::getAvailableDiskSizeInBytes));
    for (Disk disk : templateDisks) {
        DiskImage diskImage = (DiskImage) disk;
        Guid storageId = findAvailableStorageDomain(targetDomainsSize, disk.getSize(), diskToStorageIds.get(disk.getId()));
        diskToProfileMap.get(disk.getId()).stream().map(profileId -> diskProfileDao.get(profileId)).filter(profile -> profile.getStorageDomainId().equals(storageId)).findFirst().ifPresent(profile -> diskImage.setDiskProfileId(profile.getId()));
        // Set target domain
        ArrayList<Guid> storageIds = new ArrayList<>();
        storageIds.add(storageId);
        diskImage.setStorageIds(storageIds);
        // validation
        if (diskImage.getDiskStorageType() == DiskStorageType.CINDER) {
            diskImage.setVolumeFormat(VolumeFormat.RAW);
        } else {
            diskImage.setVolumeFormat(VolumeFormat.COW);
        }
        destinationMap.put(disk.getId(), diskImage);
    }
    return destinationMap;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) LoggerFactory(org.slf4j.LoggerFactory) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) VmTemplateDao(org.ovirt.engine.core.dao.VmTemplateDao) AddVmParameters(org.ovirt.engine.core.common.action.AddVmParameters) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) ActionType(org.ovirt.engine.core.common.action.ActionType) RemoveVmParameters(org.ovirt.engine.core.common.action.RemoveVmParameters) Map(java.util.Map) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmDeviceDao(org.ovirt.engine.core.dao.VmDeviceDao) VmPoolDao(org.ovirt.engine.core.dao.VmPoolDao) DiskStorageType(org.ovirt.engine.core.common.businessentities.storage.DiskStorageType) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) Collectors(java.util.stream.Collectors) List(java.util.List) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType) VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) QueryType(org.ovirt.engine.core.common.queries.QueryType) EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo) LockProperties(org.ovirt.engine.core.common.action.LockProperties) Guid(org.ovirt.engine.core.compat.Guid) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) HashMap(java.util.HashMap) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) UpdateVmVersionParameters(org.ovirt.engine.core.common.action.UpdateVmVersionParameters) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) DiskProfileDao(org.ovirt.engine.core.dao.profiles.DiskProfileDao) Inject(javax.inject.Inject) ExecutionHandler(org.ovirt.engine.core.bll.job.ExecutionHandler) RemoveVmFromPoolParameters(org.ovirt.engine.core.common.action.RemoveVmFromPoolParameters) Permission(org.ovirt.engine.core.common.businessentities.Permission) VolumeFormat(org.ovirt.engine.core.common.businessentities.storage.VolumeFormat) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) Pair(org.ovirt.engine.core.common.utils.Pair) VmPool(org.ovirt.engine.core.common.businessentities.VmPool) LockingGroup(org.ovirt.engine.core.common.locks.LockingGroup) Logger(org.slf4j.Logger) Scope(org.ovirt.engine.core.common.action.LockProperties.Scope) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) PermissionDao(org.ovirt.engine.core.dao.PermissionDao) TransactionScopeOption(org.ovirt.engine.core.compat.TransactionScopeOption) DiskDao(org.ovirt.engine.core.dao.DiskDao) Comparator(java.util.Comparator) StorageDomainDao(org.ovirt.engine.core.dao.StorageDomainDao) Collections(java.util.Collections) VMStatus(org.ovirt.engine.core.common.businessentities.VMStatus) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) VmPool(org.ovirt.engine.core.common.businessentities.VmPool) List(java.util.List) ArrayList(java.util.ArrayList) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk)

Example 30 with VmPool

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

the class RemoveClusterCommand method validate.

@Override
protected boolean validate() {
    List<VmPool> list = null;
    boolean returnValue = true;
    if (getCluster() == null) {
        addValidationMessage(EngineMessage.VMT_CLUSTER_IS_NOT_VALID);
        returnValue = false;
    } else {
        if (getCluster().getId().equals(Config.getValue(ConfigValues.AutoRegistrationDefaultClusterID))) {
            addValidationMessage(EngineMessage.VDS_CANNOT_REMOVE_DEFAULT_CLUSTER);
            returnValue = false;
        }
        if (!vdsStaticDao.getAllForCluster(getCluster().getId()).isEmpty()) {
            addValidationMessage(EngineMessage.VDS_CANNOT_REMOVE_CLUSTER_VDS_DETECTED);
            returnValue = false;
        }
        if (!vmStaticDao.getAllByCluster(getCluster().getId()).isEmpty()) {
            addValidationMessage(EngineMessage.VM_CANNOT_REMOVE_CLUSTER_VMS_DETECTED);
            returnValue = false;
        }
        if (!vmTemplateDao.getAllForCluster(getCluster().getId()).isEmpty()) {
            addValidationMessage(EngineMessage.VMT_CANNOT_REMOVE_CLUSTER_VMTS_DETECTED);
            returnValue = false;
        }
        if (!(list = vmPoolDao.getAll()).isEmpty()) {
            for (VmPool pool : list) {
                if (pool.getClusterId().equals(getCluster().getId())) {
                    addValidationMessage(EngineMessage.CLUSTER_CANNOT_REMOVE_HAS_VM_POOLS);
                    returnValue = false;
                    break;
                }
            }
        }
    }
    return returnValue;
}
Also used : VmPool(org.ovirt.engine.core.common.businessentities.VmPool)

Aggregations

VmPool (org.ovirt.engine.core.common.businessentities.VmPool)32 Test (org.junit.Test)12 VM (org.ovirt.engine.core.common.businessentities.VM)9 ArrayList (java.util.ArrayList)8 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)8 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)7 Guid (org.ovirt.engine.core.compat.Guid)7 QueryType (org.ovirt.engine.core.common.queries.QueryType)6 List (java.util.List)5 Frontend (org.ovirt.engine.ui.frontend.Frontend)5 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)5 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)5 ActionType (org.ovirt.engine.core.common.action.ActionType)4 VmPoolParametersBase (org.ovirt.engine.core.common.action.VmPoolParametersBase)4 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)3 AddVmPoolParameters (org.ovirt.engine.core.common.action.AddVmPoolParameters)3 VmPoolType (org.ovirt.engine.core.common.businessentities.VmPoolType)3 SearchType (org.ovirt.engine.core.common.interfaces.SearchType)3 SearchParameters (org.ovirt.engine.core.common.queries.SearchParameters)3 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)3