use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.
the class ProcessOvfUpdateForStorageDomainCommand method buildOvfInfoFileByteArray.
private byte[] buildOvfInfoFileByteArray(List<Guid> vmAndTemplatesIds) {
ByteArrayOutputStream bufferedOutputStream = new ByteArrayOutputStream();
Set<Guid> processedIds = new HashSet<>();
try (InMemoryTar inMemoryTar = new InMemoryTar(bufferedOutputStream)) {
inMemoryTar.addTarEntry(generateInfoFileData().getBytes(), OvfInfoFileConstants.InfoFileName);
Map<String, Object> metaDataForEntities = generateMetaDataFile(vmAndTemplatesIds);
int i = 0;
while (i < vmAndTemplatesIds.size()) {
int size = Math.min(StorageConstants.OVF_MAX_ITEMS_PER_SQL_STATEMENT, vmAndTemplatesIds.size() - i);
List<Guid> idsToProcess = vmAndTemplatesIds.subList(i, i + size);
i += size;
List<Pair<Guid, String>> ovfs = vmAndTemplatesGenerationsDao.loadOvfDataForIds(idsToProcess);
if (!ovfs.isEmpty()) {
processedIds.addAll(buildFilesForOvfs(ovfs, inMemoryTar));
}
}
List<Pair<Guid, String>> unprocessedOvfData = retrieveUnprocessedUnregisteredOvfData(processedIds, metaDataForEntities);
inMemoryTar.addTarEntry(buildJson(metaDataForEntities, true).getBytes(), OvfInfoFileConstants.MetaDataFileName);
buildFilesForOvfs(unprocessedOvfData, inMemoryTar);
} catch (Exception e) {
throw new RuntimeException(String.format("Exception while building in memory tar of the OVFs of domain %s", getParameters().getStorageDomainId()), e);
}
return bufferedOutputStream.toByteArray();
}
use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.
the class ProcessOvfUpdateForStorageDomainCommand method addVmsStatus.
private void addVmsStatus(List<Guid> vmAndTemplatesIds, Map<String, Object> data) {
Map<String, Object> vmsStatus = new HashMap<>();
for (Guid vmId : vmAndTemplatesIds) {
VmDynamic vmDynamic = vmDynamicDao.get(vmId);
if (vmDynamic != null && vmDynamic.getStatus() != VMStatus.Down) {
vmsStatus.put(vmId.toString(), vmDynamic.getStatus().getValue());
log.debug("OVF_STORE - Add vm id '{}' with status: '{}'", vmId, vmDynamic.getStatus());
} else {
log.debug("OVF_STORE - Skip entity id '{}' with status: '{}'", vmId, vmDynamic != null ? vmDynamic.getStatus() : "N/A");
}
}
data.put(OvfInfoFileConstants.VmStatus, vmsStatus);
}
use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.
the class ProcessOvfUpdateForStoragePoolCommand method updateOvfForVmsOfStoragePool.
/**
* Update ovfs for updated/newly vms since last run for the given storage pool
*/
protected void updateOvfForVmsOfStoragePool(StoragePool pool) {
Guid poolId = pool.getId();
List<Guid> vmsIdsForUpdate = vmAndTemplatesGenerationsDao.getVmsIdsForOvfUpdate(poolId);
int i = 0;
while (i < vmsIdsForUpdate.size()) {
int size = Math.min(itemsCountPerUpdate, vmsIdsForUpdate.size() - i);
List<Guid> idsToProcess = vmsIdsForUpdate.subList(i, i + size);
i += size;
Map<Guid, KeyValuePairCompat<String, List<Guid>>> vmsAndTemplateMetadata = populateVmsMetadataForOvfUpdate(idsToProcess);
if (!vmsAndTemplateMetadata.isEmpty()) {
performOvfUpdate(vmsAndTemplateMetadata);
}
}
}
use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.
the class ProcessOvfUpdateForStoragePoolCommand method populateVmsMetadataForOvfUpdate.
/**
* Create and returns map contains valid vms metadata
*/
protected Map<Guid, KeyValuePairCompat<String, List<Guid>>> populateVmsMetadataForOvfUpdate(List<Guid> idsToProcess) {
Map<Guid, KeyValuePairCompat<String, List<Guid>>> vmsAndTemplateMetadata = new HashMap<>();
List<VM> vms = vmDao.getVmsByIds(idsToProcess);
for (VM vm : vms) {
if (VMStatus.ImageLocked != vm.getStatus()) {
updateVmDisksFromDb(vm);
if (!verifyImagesStatus(vm.getDiskList())) {
continue;
}
ArrayList<DiskImage> vmImages = ovfUpdateProcessHelper.getVmImagesFromDb(vm);
if (!verifyImagesStatus(vmImages)) {
continue;
}
vm.setSnapshots(snapshotDao.getAllWithConfiguration(vm.getId()));
if (!verifySnapshotsStatus(vm.getSnapshots())) {
continue;
}
ovfUpdateProcessHelper.loadVmData(vm);
Long currentDbGeneration = vmStaticDao.getDbGeneration(vm.getId());
if (currentDbGeneration == null) {
log.warn("currentDbGeneration of VM (name: '{}', id: '{}') is null, probably because the VM was deleted during the run of OvfDataUpdater.", vm.getName(), vm.getId());
continue;
}
if (vm.getStaticData().getDbGeneration() == currentDbGeneration) {
List<LunDisk> lunDisks = DisksFilter.filterLunDisks(vm.getDiskMap().values());
for (LunDisk lun : lunDisks) {
lun.getLun().setLunConnections(new ArrayList<>(storageServerConnectionDao.getAllForLun(lun.getLun().getId())));
}
List<AffinityGroup> affinityGroups = affinityGroupDao.getAllAffinityGroupsByVmId(vm.getId());
List<Label> affinityLabels = labelDao.getAllByEntityIds(Collections.singletonList(vm.getId()));
Set<DbUser> dbUsers = new HashSet<>(dbUserDao.getAllForVm(vm.getId()));
FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(vm);
fullEntityOvfData.setDiskImages(vmImages);
fullEntityOvfData.setLunDisks(lunDisks);
fullEntityOvfData.setAffinityGroups(affinityGroups);
fullEntityOvfData.setAffinityLabels(affinityLabels);
fullEntityOvfData.setDbUsers(dbUsers);
ovfHelper.populateUserToRoles(fullEntityOvfData, vm.getId());
proccessedOvfConfigurationsInfo.add(ovfUpdateProcessHelper.buildMetadataDictionaryForVm(vm, vmsAndTemplateMetadata, fullEntityOvfData));
proccessedIdsInfo.add(vm.getId());
proccessedOvfGenerationsInfo.add(vm.getStaticData().getDbGeneration());
proccessDisksDomains(vm.getDiskList());
}
}
}
return vmsAndTemplateMetadata;
}
use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.
the class ProcessOvfUpdateForStoragePoolCommand method updateOvfForTemplatesOfStoragePool.
/**
* Update ovfs for updated/added templates since last for the given storage pool
*/
protected void updateOvfForTemplatesOfStoragePool(StoragePool pool) {
Guid poolId = pool.getId();
List<Guid> templateIdsForUpdate = vmAndTemplatesGenerationsDao.getVmTemplatesIdsForOvfUpdate(poolId);
int i = 0;
while (i < templateIdsForUpdate.size()) {
int size = Math.min(templateIdsForUpdate.size() - i, itemsCountPerUpdate);
List<Guid> idsToProcess = templateIdsForUpdate.subList(i, i + size);
i += size;
Map<Guid, KeyValuePairCompat<String, List<Guid>>> vmsAndTemplateMetadata = populateTemplatesMetadataForOvfUpdate(idsToProcess);
if (!vmsAndTemplateMetadata.isEmpty()) {
performOvfUpdate(vmsAndTemplateMetadata);
}
}
}
Aggregations