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;
}
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);
}
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;
}
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;
}
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);
}
Aggregations