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);
}
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);
}
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);
}
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;
}
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;
}
Aggregations