use of org.ovirt.engine.core.common.businessentities.StorageDomainOvfInfo in project ovirt-engine by oVirt.
the class ProcessOvfUpdateForStorageDomainCommandComparatorTest method sorting.
@Test
public void sorting() {
Guid sdId = Guid.newGuid();
Guid diskId1 = Guid.createGuidFromString("00000000-0000-0000-0000-000000000001");
Guid diskId2 = Guid.createGuidFromString("00000000-0000-0000-0000-000000000002");
List<StorageDomainOvfInfo> expected = new LinkedList<>(Arrays.asList(new StorageDomainOvfInfo(sdId, null, diskId1, StorageDomainOvfInfoStatus.UPDATED, null), new StorageDomainOvfInfo(sdId, null, diskId2, StorageDomainOvfInfoStatus.UPDATED, null), new StorageDomainOvfInfo(sdId, null, diskId1, StorageDomainOvfInfoStatus.UPDATED, new Date(0L)), new StorageDomainOvfInfo(sdId, null, diskId2, StorageDomainOvfInfoStatus.UPDATED, new Date(0L)), new StorageDomainOvfInfo(sdId, null, diskId1, StorageDomainOvfInfoStatus.UPDATED, new Date(1L)), new StorageDomainOvfInfo(sdId, null, diskId2, StorageDomainOvfInfoStatus.UPDATED, new Date(1L))));
List<StorageDomainOvfInfo> actual = new LinkedList<>(expected);
Collections.shuffle(actual);
actual.sort(ProcessOvfUpdateForStorageDomainCommand.OVF_INFO_COMPARATOR);
assertEquals(expected, actual);
}
use of org.ovirt.engine.core.common.businessentities.StorageDomainOvfInfo in project ovirt-engine by oVirt.
the class ProcessOvfUpdateForStoragePoolCommandTest method mockAnswers.
private void mockAnswers() {
doAnswer(invocation -> {
VM vm = (VM) invocation.getArguments()[0];
return vm.getId().toString();
}).when(ovfUpdateProcessHelper).generateVmMetadata(any(), any());
doAnswer(invocation -> {
VmTemplate template = (VmTemplate) ((FullEntityOvfData) invocation.getArguments()[0]).getVmBase();
return template.getId().toString();
}).when(ovfUpdateProcessHelper).generateVmTemplateMetadata(any());
doAnswer(invocation -> {
List<Guid> neededIds = (List<Guid>) invocation.getArguments()[0];
return neededIds.stream().map(id -> vms.get(id)).collect(Collectors.toList());
}).when(vmDao).getVmsByIds(any());
doAnswer(invocation -> {
List<Guid> neededIds = (List<Guid>) invocation.getArguments()[0];
return neededIds.stream().map(id -> templates.get(id)).collect(Collectors.toList());
}).when(vmTemplateDao).getVmTemplatesByIds(any());
doAnswer(invocation -> {
Map<Guid, KeyValuePairCompat<String, List<Guid>>> updateMap = (Map<Guid, KeyValuePairCompat<String, List<Guid>>>) invocation.getArguments()[1];
assertTrue("too many ovfs were sent in one vdsm call", updateMap.size() <= ITEMS_COUNT_PER_UPDATE);
return true;
}).when(ovfUpdateProcessHelper).executeUpdateVmInSpmCommand(any(), any(), any());
doReturn(true).when(ovfUpdateProcessHelper).executeRemoveVmInSpm(any(), any(), any());
doAnswer(invocation -> {
List<Guid> ids = (List<Guid>) invocation.getArguments()[0];
List<Long> values = (List<Long>) invocation.getArguments()[1];
assertFalse("update of ovf version in db shouldn't be called with an empty value list", values.isEmpty());
assertTrue("update of ovf version in db shouldn't be called with more items then MAX_ITEMS_PER_SQL_STATEMENT", values.size() <= StorageConstants.OVF_MAX_ITEMS_PER_SQL_STATEMENT);
assertEquals("the size of the list of ids for update is not the same as the size of the " + "list with the new ovf values", values.size(), ids.size());
Guid[] ids_array = ids.toArray(new Guid[ids.size()]);
Long[] values_array = values.toArray(new Long[values.size()]);
for (int i = 0; i < ids_array.length; i++) {
executedUpdatedOvfGenerationIdsInDb.put(ids_array[i], values_array[i]);
}
return null;
}).when(vmAndTemplatesGenerationsDao).updateOvfGenerations(any(), any(), any());
doAnswer(invocation -> {
StoragePoolStatus desiredStatus = (StoragePoolStatus) invocation.getArguments()[0];
return buildStoragePoolsList().stream().filter(p -> desiredStatus.equals(p.getStatus())).collect(Collectors.toList());
}).when(storagePoolDao).getAllByStatus(any());
doReturn(poolDomainsOvfInfo.values().stream().map(Pair::getSecond).collect(Collectors.toList())).when(storageDomainDao).getAllForStoragePool(any());
doAnswer(invocation -> {
Guid domainId = (Guid) invocation.getArguments()[0];
Pair<List<StorageDomainOvfInfo>, StorageDomain> pair = poolDomainsOvfInfo.get(domainId);
if (pair != null) {
return pair.getFirst();
}
return null;
}).when(storageDomainOvfInfoDao).getAllForDomain(any());
}
use of org.ovirt.engine.core.common.businessentities.StorageDomainOvfInfo in project ovirt-engine by oVirt.
the class ProcessOvfUpdateForStoragePoolCommandTest method testUpdateCalledForUnupdatedDomain.
@Test
public void testUpdateCalledForUnupdatedDomain() {
Guid poolId = pool1.getId();
StorageDomainOvfInfo ovfInfo = poolDomainsOvfInfo.entrySet().iterator().next().getValue().getFirst().get(0);
ovfInfo.setStatus(StorageDomainOvfInfoStatus.OUTDATED);
initTestForPool(pool1, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
executeCommand();
verify(command, never()).performOvfUpdate(any());
Map<Guid, List<Guid>> domainsRequiredUpdateForPool = Collections.singletonMap(poolId, Collections.singletonList(ovfInfo.getStorageDomainId()));
verifyOvfUpdatedForSupportedPools(Collections.singletonList(poolId), domainsRequiredUpdateForPool);
}
use of org.ovirt.engine.core.common.businessentities.StorageDomainOvfInfo in project ovirt-engine by oVirt.
the class StorageHandlingCommandBase method addOvfStoreDiskToDomain.
/**
* Register all the OVF_STORE disks as floating disks in the engine.
*/
private void addOvfStoreDiskToDomain(DiskImage ovfDisk, Guid storageDomainId) {
// Setting OVF_STORE disk to be outdated so it will be updated.
StorageDomainOvfInfo storageDomainOvfInfo = new StorageDomainOvfInfo(storageDomainId, null, ovfDisk.getId(), StorageDomainOvfInfoStatus.OUTDATED, null);
storageDomainOvfInfoDao.save(storageDomainOvfInfo);
}
use of org.ovirt.engine.core.common.businessentities.StorageDomainOvfInfo in project ovirt-engine by oVirt.
the class CreateOvfVolumeForStorageDomainCommand method endSuccessfully.
@Override
protected void endSuccessfully() {
Guid createdDiskId = getActionReturnValue();
endChildCommand(true);
StorageDomainOvfInfo storageDomainOvfInfoDb = storageDomainOvfInfoDao.get(createdDiskId);
if (storageDomainOvfInfoDb == null || storageDomainOvfInfoDb.getStatus() != StorageDomainOvfInfoStatus.DISABLED) {
return;
}
storageDomainOvfInfoDb.setStatus(StorageDomainOvfInfoStatus.OUTDATED);
storageDomainOvfInfoDao.update(storageDomainOvfInfoDb);
setSucceeded(true);
}
Aggregations