Search in sources :

Example 91 with Guid

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();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Guid(org.ovirt.engine.core.compat.Guid) EngineException(org.ovirt.engine.core.common.errors.EngineException) IOException(java.io.IOException) InMemoryTar(org.ovirt.engine.core.utils.archivers.tar.InMemoryTar) HashSet(java.util.HashSet) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 92 with Guid

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);
}
Also used : VmDynamic(org.ovirt.engine.core.common.businessentities.VmDynamic) HashMap(java.util.HashMap) Guid(org.ovirt.engine.core.compat.Guid)

Example 93 with Guid

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);
        }
    }
}
Also used : KeyValuePairCompat(org.ovirt.engine.core.compat.KeyValuePairCompat) Guid(org.ovirt.engine.core.compat.Guid)

Example 94 with Guid

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;
}
Also used : KeyValuePairCompat(org.ovirt.engine.core.compat.KeyValuePairCompat) HashMap(java.util.HashMap) Label(org.ovirt.engine.core.common.businessentities.Label) Guid(org.ovirt.engine.core.compat.Guid) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup) VM(org.ovirt.engine.core.common.businessentities.VM) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) HashSet(java.util.HashSet)

Example 95 with Guid

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);
        }
    }
}
Also used : KeyValuePairCompat(org.ovirt.engine.core.compat.KeyValuePairCompat) Guid(org.ovirt.engine.core.compat.Guid)

Aggregations

Guid (org.ovirt.engine.core.compat.Guid)1431 ArrayList (java.util.ArrayList)330 Test (org.junit.Test)322 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)219 HashMap (java.util.HashMap)211 List (java.util.List)167 VM (org.ovirt.engine.core.common.businessentities.VM)144 Map (java.util.Map)118 VDS (org.ovirt.engine.core.common.businessentities.VDS)117 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)106 HashSet (java.util.HashSet)102 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)89 Pair (org.ovirt.engine.core.common.utils.Pair)79 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)77 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)72 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)70 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)69 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)57 ActionType (org.ovirt.engine.core.common.action.ActionType)56 Set (java.util.Set)52