Search in sources :

Example 1 with DiskImageDynamic

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

the class ImportVmCommand method saveDiskImageDynamic.

/**
 * Generates and saves a {@link DiskImageDynamic} for the given <code>disk</code>
 *
 * @param disk
 *            The imported disk
 */
protected void saveDiskImageDynamic(DiskImage disk) {
    DiskImageDynamic diskDynamic = new DiskImageDynamic();
    diskDynamic.setId(disk.getImageId());
    diskDynamic.setActualSize(disk.getActualSizeInBytes());
    diskImageDynamicDao.save(diskDynamic);
}
Also used : DiskImageDynamic(org.ovirt.engine.core.common.businessentities.storage.DiskImageDynamic)

Example 2 with DiskImageDynamic

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

the class LiveMigrateDiskCommand method updateImagesInfo.

private void updateImagesInfo() {
    for (DiskImage image : diskImageDao.getAllSnapshotsForImageGroup(getParameters().getImageGroupID())) {
        VDSReturnValue ret = runVdsCommand(VDSCommandType.GetImageInfo, new GetImageInfoVDSCommandParameters(getParameters().getStoragePoolId(), getParameters().getTargetStorageDomainId(), getParameters().getImageGroupID(), image.getImageId()));
        DiskImage imageFromIRS = (DiskImage) ret.getReturnValue();
        setQcowCompatForSnapshot(image, imageFromIRS);
        DiskImageDynamic diskImageDynamic = diskImageDynamicDao.get(image.getImageId());
        // Update image's actual size in DB
        if (imageFromIRS != null && diskImageDynamic != null) {
            diskImageDynamic.setActualSize(imageFromIRS.getActualSizeInBytes());
            diskImageDynamicDao.update(diskImageDynamic);
        }
    }
}
Also used : GetImageInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.GetImageInfoVDSCommandParameters) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) DiskImageDynamic(org.ovirt.engine.core.common.businessentities.storage.DiskImageDynamic) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 3 with DiskImageDynamic

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

the class VdsBrokerObjectsBuilder method buildVmDiskStatistics.

public static List<DiskImageDynamic> buildVmDiskStatistics(Map<String, Object> vmStruct) {
    Map<String, Object> disks = (Map<String, Object>) vmStruct.get(VdsProperties.vm_disks);
    if (disks == null) {
        return Collections.emptyList();
    }
    List<DiskImageDynamic> disksData = new ArrayList<>();
    for (Object diskAsObj : disks.values()) {
        Map<String, Object> disk = (Map<String, Object>) diskAsObj;
        DiskImageDynamic diskData = new DiskImageDynamic();
        String imageGroupIdString = assignStringValue(disk, VdsProperties.image_group_id);
        if (!StringUtils.isEmpty(imageGroupIdString)) {
            Guid imageGroupIdGuid = new Guid(imageGroupIdString);
            diskData.setId(imageGroupIdGuid);
            diskData.setReadRate(assignIntValue(disk, VdsProperties.vm_disk_read_rate));
            diskData.setWriteRate(assignIntValue(disk, VdsProperties.vm_disk_write_rate));
            if (disk.containsKey(VdsProperties.disk_true_size)) {
                Long size = assignLongValue(disk, VdsProperties.disk_true_size);
                diskData.setActualSize(size != null ? size : 0);
            }
            if (disk.containsKey(VdsProperties.vm_disk_read_latency)) {
                diskData.setReadLatency(assignDoubleValueWithNullProtection(disk, VdsProperties.vm_disk_read_latency) / NANO_SECONDS);
            }
            if (disk.containsKey(VdsProperties.vm_disk_write_latency)) {
                diskData.setWriteLatency(assignDoubleValueWithNullProtection(disk, VdsProperties.vm_disk_write_latency) / NANO_SECONDS);
            }
            if (disk.containsKey(VdsProperties.vm_disk_flush_latency)) {
                diskData.setFlushLatency(assignDoubleValueWithNullProtection(disk, VdsProperties.vm_disk_flush_latency) / NANO_SECONDS);
            }
            disksData.add(diskData);
        }
    }
    return disksData;
}
Also used : ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) Map(java.util.Map) HashMap(java.util.HashMap) DiskImageDynamic(org.ovirt.engine.core.common.businessentities.storage.DiskImageDynamic)

Example 4 with DiskImageDynamic

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

the class BaseImagesCommand method addDiskImageToDb.

protected void addDiskImageToDb(DiskImage image, CompensationContext compensationContext, boolean active) {
    image.setActive(active);
    imageDao.save(image.getImage());
    DiskImageDynamic diskDynamic = updateDiskImageDynamicIntoDB(image);
    ImageStorageDomainMap imageStorageDomainMap = new ImageStorageDomainMap(image.getImageId(), image.getStorageIds().get(0), image.getQuotaId(), image.getDiskProfileId());
    imageStorageDomainMapDao.save(imageStorageDomainMap);
    boolean isDiskAdded = saveDiskIfNotExists(image);
    if (compensationContext != null) {
        compensationContext.snapshotNewEntity(image.getImage());
        compensationContext.snapshotNewEntity(diskDynamic);
        compensationContext.snapshotNewEntity(imageStorageDomainMap);
        if (isDiskAdded) {
            compensationContext.snapshotNewEntity(image);
        }
        compensationContext.stateChanged();
    }
}
Also used : ImageStorageDomainMap(org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap) DiskImageDynamic(org.ovirt.engine.core.common.businessentities.storage.DiskImageDynamic)

Example 5 with DiskImageDynamic

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

the class CreateImageTemplateCommand method executeCommand.

@Override
protected void executeCommand() {
    Guid storagePoolId = getDiskImage().getStoragePoolId() != null ? getDiskImage().getStoragePoolId() : Guid.Empty;
    Guid imageGroupId = getDiskImage().getId() != null ? getDiskImage().getId() : Guid.Empty;
    Guid snapshotId = getDiskImage().getImageId();
    // Create new image group id and image id:
    Guid destinationImageGroupID = Guid.newGuid();
    setDestinationImageId(Guid.newGuid());
    DiskImage newImage = cloneDiskImage(getDestinationImageId());
    if (getParameters().getVolumeFormat() == null || getParameters().getVolumeType() == null) {
        // At least one of the volume arguments should be copied from the ancestral image.
        fillVolumeInformation(newImage);
    }
    if (getParameters().getVolumeFormat() != null) {
        newImage.setVolumeFormat(getParameters().getVolumeFormat());
    }
    if (getParameters().getVolumeType() != null) {
        newImage.setVolumeType(getParameters().getVolumeType());
    }
    Guid taskId = persistAsyncTaskPlaceHolder(getParameters().getParentCommand());
    VolumeFormat targetFormat = getTargetVolumeFormat(newImage.getVolumeFormat(), newImage.getVolumeType(), getParameters().getDestinationStorageDomainId());
    newImage.setDiskAlias(getParameters().getDiskAlias() != null ? getParameters().getDiskAlias() : getDiskImage().getDiskAlias());
    VDSReturnValue vdsReturnValue = runVdsCommand(VDSCommandType.CopyImage, postDeleteActionHandler.fixParameters(new CopyImageVDSCommandParameters(storagePoolId, getParameters().getStorageDomainId(), getParameters().getVmId(), imageGroupId, snapshotId, destinationImageGroupID, getDestinationImageId(), getJsonDiskDescription(newImage), getParameters().getDestinationStorageDomainId(), getParameters().getCopyVolumeType(), targetFormat, newImage.getVolumeType(), getDiskImage().isWipeAfterDelete(), storageDomainDao.get(getParameters().getDestinationStorageDomainId()).getDiscardAfterDelete(), false)));
    getReturnValue().getInternalVdsmTaskIdList().add(createTask(taskId, vdsReturnValue.getCreationInfo(), getParameters().getParentCommand(), VdcObjectType.Storage, getParameters().getStorageDomainId(), getParameters().getDestinationStorageDomainId()));
    newImage.setId(destinationImageGroupID);
    newImage.setDiskDescription(getParameters().getDescription() != null ? getParameters().getDescription() : getDiskImage().getDiskDescription());
    newImage.setVmSnapshotId(getParameters().getVmSnapshotId());
    newImage.setQuotaId(getParameters().getQuotaId());
    newImage.setDiskProfileId(getParameters().getDiskProfileId());
    newImage.setParentId(Guid.Empty);
    newImage.setImageTemplateId(Guid.Empty);
    newImage.setStorageIds(new ArrayList<>(Arrays.asList(getParameters().getDestinationStorageDomainId())));
    newImage.setActive(true);
    imagesHandler.saveImage(newImage);
    baseDiskDao.save(newImage);
    DiskImageDynamic diskDynamic = new DiskImageDynamic();
    diskDynamic.setId(newImage.getImageId());
    diskDynamic.setActualSize(getDiskImage().getActualSizeInBytes());
    diskImageDynamicDao.save(diskDynamic);
    setActionReturnValue(newImage);
    // set source image as locked:
    lockImage();
    setSucceeded(true);
}
Also used : VolumeFormat(org.ovirt.engine.core.common.businessentities.storage.VolumeFormat) CopyImageVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.CopyImageVDSCommandParameters) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) DiskImageDynamic(org.ovirt.engine.core.common.businessentities.storage.DiskImageDynamic) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Aggregations

DiskImageDynamic (org.ovirt.engine.core.common.businessentities.storage.DiskImageDynamic)15 ImageStorageDomainMap (org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap)4 Guid (org.ovirt.engine.core.compat.Guid)4 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)3 Test (org.junit.Test)2 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)1 VolumeFormat (org.ovirt.engine.core.common.businessentities.storage.VolumeFormat)1 Pair (org.ovirt.engine.core.common.utils.Pair)1 CopyImageVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.CopyImageVDSCommandParameters)1 GetImageInfoVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.GetImageInfoVDSCommandParameters)1