Search in sources :

Example 91 with Disk

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

the class BackendStorageDomainDiskSnapshotsResource method mapCollection.

protected DiskSnapshots mapCollection(List<Disk> entities) {
    DiskSnapshots collection = new DiskSnapshots();
    for (Disk disk : entities) {
        DiskSnapshot diskSnapshot = getMapper(Disk.class, DiskSnapshot.class).map(disk, null);
        // this code generates back-link to the corresponding SD
        diskSnapshot.setStorageDomain(new StorageDomain());
        diskSnapshot.getStorageDomain().setId(this.storageDomainId.toString());
        collection.getDiskSnapshots().add(addLinks(populate(diskSnapshot, disk)));
    }
    return collection;
}
Also used : StorageDomain(org.ovirt.engine.api.model.StorageDomain) DiskSnapshots(org.ovirt.engine.api.model.DiskSnapshots) DiskSnapshot(org.ovirt.engine.api.model.DiskSnapshot) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk)

Example 92 with Disk

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

the class DiskSnapshotMapperTest method testRoundtrip.

@Test
@Override
public void testRoundtrip() throws Exception {
    setUpConfigExpectations();
    DiskSnapshot model = DiskSnapshot.class.cast(populate(DiskSnapshot.class));
    model = postPopulate(model);
    Mapper<DiskSnapshot, Disk> out = getMappingLocator().getMapper(DiskSnapshot.class, Disk.class);
    Mapper<Disk, DiskSnapshot> back = getMappingLocator().getMapper(Disk.class, DiskSnapshot.class);
    DiskImage to = (DiskImage) out.map(model, null);
    DiskImage inverse = getInverse(to);
    DiskSnapshot transform = back.map(inverse, null);
    verify(model, transform);
}
Also used : DiskSnapshot(org.ovirt.engine.api.model.DiskSnapshot) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test)

Example 93 with Disk

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

the class DisksViewColumns method getStatusColumn.

public static final AbstractColumn<Disk, Disk> getStatusColumn(String sortBy) {
    DiskTransferProgressColumn uploadImageProgressColumn = new DiskTransferProgressColumn();
    DiskProgressColumn diskProgressColumn = new DiskProgressColumn();
    List<HasCell<Disk, ?>> list = new ArrayList<>();
    list.add(getStatusOnlyColumn(null));
    list.add(uploadImageProgressColumn);
    list.add(diskProgressColumn);
    Cell<Disk> compositeCell = new StatusCompositeCell<>(list);
    AbstractColumn<Disk, Disk> column = new AbstractColumn<Disk, Disk>(compositeCell) {

        @Override
        public Disk getValue(Disk object) {
            return object;
        }
    };
    if (sortBy != null) {
        column.makeSortable(sortBy);
    }
    return column;
}
Also used : DiskProgressColumn(org.ovirt.engine.ui.common.widget.table.column.DiskProgressColumn) HasCell(com.google.gwt.cell.client.HasCell) ArrayList(java.util.ArrayList) StatusCompositeCell(org.ovirt.engine.ui.common.widget.table.cell.StatusCompositeCell) AbstractColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractColumn) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskTransferProgressColumn(org.ovirt.engine.ui.common.widget.table.column.DiskTransferProgressColumn)

Example 94 with Disk

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

the class StorageHandlingCommandBase method getAllOVFDisks.

protected List<DiskImage> getAllOVFDisks(Guid storageDomainId, Guid storagePoolId) {
    // fetched yet.
    if (ovfDisks == null) {
        ovfDisks = new ArrayList<>();
        // Get all unregistered disks.
        List<DiskImage> disksFromStorage = backend.runInternalQuery(QueryType.GetUnregisteredDisks, new GetUnregisteredDisksQueryParameters(storageDomainId, storagePoolId)).getReturnValue();
        if (disksFromStorage == null) {
            log.error("An error occurred while fetching unregistered disks from Storage Domain id '{}'", storageDomainId);
            return ovfDisks;
        } else {
            castDiskImagesToUnregisteredDisks(disksFromStorage, storageDomainId);
        }
        for (Disk disk : disksFromStorage) {
            DiskImage ovfStoreDisk = (DiskImage) disk;
            String diskDescription = ovfStoreDisk.getDescription();
            if (ovfStoreDisk.isOvfStore() || diskDescription.contains(OvfInfoFileConstants.OvfStoreDescriptionLabel)) {
                Map<String, Object> diskDescriptionMap;
                try {
                    diskDescriptionMap = JsonHelper.jsonToMap(diskDescription);
                } catch (IOException e) {
                    log.warn("Exception while generating json containing ovf store info: {}", e.getMessage());
                    log.debug("Exception", e);
                    continue;
                }
                // Domain.
                if (!isDomainExistsInDiskDescription(diskDescriptionMap, storageDomainId)) {
                    log.warn("The disk description does not contain the storage domain id '{}'", storageDomainId);
                    continue;
                }
                ovfDisks.add(ovfStoreDisk);
            }
        }
    }
    return ovfDisks;
}
Also used : GetUnregisteredDisksQueryParameters(org.ovirt.engine.core.common.queries.GetUnregisteredDisksQueryParameters) IOException(java.io.IOException) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) UnregisteredDisk(org.ovirt.engine.core.common.businessentities.storage.UnregisteredDisk)

Example 95 with Disk

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

the class StorageHandlingCommandBase method getLatestOVFDisk.

/**
 * Returns the best match for OVF disk from all the disks. If no OVF disk was found, it returns null for disk and
 * size 0. If there are OVF disks, we first match the updated ones, and from them we retrieve the one which was last
 * updated.
 *
 * @param ovfStoreDiskImages
 *            - A list of OVF_STORE disks
 * @return A Pair which contains the best OVF disk to retrieve data from and its size.
 */
private Pair<DiskImage, Long> getLatestOVFDisk(List<DiskImage> ovfStoreDiskImages) {
    Date foundOvfDiskUpdateDate = new Date();
    boolean isFoundOvfDiskUpdated = false;
    Long size = 0L;
    Disk ovfDisk = null;
    for (DiskImage ovfStoreDisk : ovfStoreDiskImages) {
        boolean isBetterOvfDiskFound = false;
        Map<String, Object> diskDescriptionMap;
        try {
            diskDescriptionMap = JsonHelper.jsonToMap(ovfStoreDisk.getDescription());
        } catch (IOException e) {
            log.warn("Exception while generating json containing ovf store info: {}", e.getMessage());
            log.debug("Exception", e);
            continue;
        }
        boolean isUpdated = Boolean.valueOf(diskDescriptionMap.get(OvfInfoFileConstants.IsUpdated).toString());
        Date date = getDateFromDiskDescription(diskDescriptionMap);
        if (date == null) {
            continue;
        }
        if (isFoundOvfDiskUpdated && !isUpdated) {
            continue;
        }
        if ((isUpdated && !isFoundOvfDiskUpdated) || date.after(foundOvfDiskUpdateDate)) {
            isBetterOvfDiskFound = true;
        }
        if (isBetterOvfDiskFound) {
            isFoundOvfDiskUpdated = isUpdated;
            foundOvfDiskUpdateDate = date;
            ovfDisk = ovfStoreDisk;
            size = Long.valueOf(diskDescriptionMap.get(OvfInfoFileConstants.Size).toString());
        }
    }
    return new Pair<>((DiskImage) ovfDisk, size);
}
Also used : IOException(java.io.IOException) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) UnregisteredDisk(org.ovirt.engine.core.common.businessentities.storage.UnregisteredDisk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Date(java.util.Date) Pair(org.ovirt.engine.core.common.utils.Pair)

Aggregations

Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)152 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)82 ArrayList (java.util.ArrayList)56 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)47 Guid (org.ovirt.engine.core.compat.Guid)45 VM (org.ovirt.engine.core.common.businessentities.VM)36 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)35 Test (org.junit.Test)29 HashMap (java.util.HashMap)26 List (java.util.List)26 DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)25 Map (java.util.Map)24 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)18 Collectors (java.util.stream.Collectors)16 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)15 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)15 Collection (java.util.Collection)14 Collections (java.util.Collections)14 Set (java.util.Set)14 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)14