private DiskImage createDiskSnapshot(Guid diskId) { DiskImage di = new DiskImage(); di.setActive(false); di.setId(diskId); di.setImageId(Guid.newGuid()); di.setParentId(Guid.newGuid()); di.setImageStatus(ImageStatus.OK); return di; }
private DiskImage createDiskImage(boolean active) { DiskImage di = new DiskImage(); di.setId(Guid.newGuid()); di.setImageId(Guid.newGuid()); di.setParentId(Guid.newGuid()); di.setImageStatus(ImageStatus.OK); di.setActive(active); return di; }
protected List<DiskImage> createDiskSnapshot(Guid diskId, int numOfImages) { List<DiskImage> disksList = new ArrayList<>(); for (int i = 0; i < numOfImages; ++i) { DiskImage diskImage = new DiskImage(); diskImage.setActive(false); diskImage.setId(diskId); diskImage.setImageId(Guid.newGuid()); diskImage.setParentId(Guid.newGuid()); diskImage.setImageStatus(ImageStatus.OK); disksList.add(diskImage); } return disksList; }
@Override protected void readDiskImageItem(XmlNode node) { final Guid guid = new Guid(node.SelectSingleNode("rasd:InstanceId", _xmlNS).innerText); DiskImage image = LinqUtils.firstOrNull( _images, new Predicate<DiskImage>() { @Override public boolean eval(DiskImage diskImage) { return diskImage.getImageId().equals(guid); } }); image.setId( OvfParser.GetImageGrupIdFromImageFile( node.SelectSingleNode("rasd:HostResource", _xmlNS).innerText)); if (StringUtils.isNotEmpty(node.SelectSingleNode("rasd:Parent", _xmlNS).innerText)) { image.setParentId(new Guid(node.SelectSingleNode("rasd:Parent", _xmlNS).innerText)); } if (StringUtils.isNotEmpty(node.SelectSingleNode("rasd:Template", _xmlNS).innerText)) { image.setImageTemplateId(new Guid(node.SelectSingleNode("rasd:Template", _xmlNS).innerText)); } image.setAppList(node.SelectSingleNode("rasd:ApplicationList", _xmlNS).innerText); if (StringUtils.isNotEmpty(node.SelectSingleNode("rasd:StorageId", _xmlNS).innerText)) { image.setStorageIds( new ArrayList<Guid>( Arrays.asList(new Guid(node.SelectSingleNode("rasd:StorageId", _xmlNS).innerText)))); } if (StringUtils.isNotEmpty(node.SelectSingleNode("rasd:StoragePoolId", _xmlNS).innerText)) { image.setStoragePoolId( new Guid(node.SelectSingleNode("rasd:StoragePoolId", _xmlNS).innerText)); } final Date creationDate = OvfParser.UtcDateStringToLocaDate( node.SelectSingleNode("rasd:CreationDate", _xmlNS).innerText); if (creationDate != null) { image.setCreationDate(creationDate); } final Date lastModified = OvfParser.UtcDateStringToLocaDate( node.SelectSingleNode("rasd:LastModified", _xmlNS).innerText); if (lastModified != null) { image.setLastModified(lastModified); } readManagedVmDevice(node, image.getId()); }
public static DiskImage cloneDiskImage( Guid storageDomainId, Guid newImageGroupId, Guid newImageGuid, DiskImage srcDiskImage, Guid diskProfileId, Guid snapshotId, DiskImage diskImageFromClient) { DiskImage clonedDiskImage = DiskImage.copyOf(srcDiskImage); clonedDiskImage.setImageId(newImageGuid); clonedDiskImage.setParentId(Guid.Empty); clonedDiskImage.setImageTemplateId(Guid.Empty); clonedDiskImage.setVmSnapshotId(snapshotId); clonedDiskImage.setId(newImageGroupId); clonedDiskImage.setLastModifiedDate(new Date()); clonedDiskImage.setvolumeFormat(srcDiskImage.getVolumeFormat()); clonedDiskImage.setVolumeType(srcDiskImage.getVolumeType()); ArrayList<Guid> storageIds = new ArrayList<>(); storageIds.add(storageDomainId); clonedDiskImage.setStorageIds(storageIds); clonedDiskImage.setDiskProfileId(diskProfileId); // If volume information was changed at client , use its volume information. // If volume information was not changed at client - use the volume information of the ancestral // image if (diskImageFromClient != null) { if (volumeInfoChanged(diskImageFromClient, srcDiskImage)) { changeVolumeInfo(clonedDiskImage, diskImageFromClient); } else { DiskImage ancestorDiskImage = getDiskImageDao().getAncestor(srcDiskImage.getImageId()); changeVolumeInfo(clonedDiskImage, ancestorDiskImage); } } else { DiskImage ancestorDiskImage = getDiskImageDao().getAncestor(srcDiskImage.getImageId()); changeVolumeInfo(clonedDiskImage, ancestorDiskImage); } return clonedDiskImage; }
/** * After merging the snapshots, update the image and snapshot records in the database to reflect * the changes. This handles either forward or backwards merge (detected). It will either then * remove the images, or mark them illegal (to handle the case where image deletion failed). * * @param removeImages Remove the images from the database, or if false, only mark them illegal */ private void syncDbRecords(boolean removeImages) { // If deletion failed after a backwards merge, the snapshots' images need to be swapped // as they would upon success. Instead of removing them, mark them illegal. DiskImage baseImage = getDiskImage(); DiskImage topImage = getDestinationDiskImage(); // The vdsm merge verb may decide to perform a forward or backward merge. if (topImage == null) { log.debug("No merge destination image, not updating image/snapshot association"); } else if (getParameters().getMergeStatusReturnValue().getBlockJobType() == VmBlockJobType.PULL) { // For forward merge, the volume format and type may change. topImage.setvolumeFormat(baseImage.getVolumeFormat()); topImage.setVolumeType(baseImage.getVolumeType()); topImage.setParentId(baseImage.getParentId()); topImage.setImageStatus(ImageStatus.OK); getBaseDiskDao().update(topImage); getImageDao().update(topImage.getImage()); updateDiskImageDynamic(topImage); updateVmConfigurationForImageRemoval( baseImage.getImage().getSnapshotId(), baseImage.getImageId()); } else { // For backwards merge, the prior base image now has the data associated with the newer // snapshot we want to keep. Re-associate this older image with the newer snapshot. // The base snapshot is deleted if everything went well. In case it's not deleted, we // hijack it to preserve a link to the broken image. This makes the image discoverable // so that we can retry the deletion later, yet doesn't corrupt the VM image chain. List<DiskImage> children = DbFacade.getInstance().getDiskImageDao().getAllSnapshotsForParent(topImage.getImageId()); if (!children.isEmpty()) { DiskImage childImage = children.get(0); childImage.setParentId(baseImage.getImageId()); getImageDao().update(childImage.getImage()); } Image oldTopImage = topImage.getImage(); topImage.setImage(baseImage.getImage()); baseImage.setImage(oldTopImage); Guid oldTopSnapshotId = topImage.getImage().getSnapshotId(); topImage.getImage().setSnapshotId(baseImage.getImage().getSnapshotId()); baseImage.getImage().setSnapshotId(oldTopSnapshotId); boolean oldTopIsActive = topImage.getImage().isActive(); topImage.getImage().setActive(baseImage.getImage().isActive()); VolumeClassification baseImageVolumeClassification = VolumeClassification.getVolumeClassificationByActiveFlag(baseImage.getImage().isActive()); topImage.getImage().setVolumeClassification(baseImageVolumeClassification); baseImage.getImage().setActive(oldTopIsActive); VolumeClassification oldTopVolumeClassification = VolumeClassification.getVolumeClassificationByActiveFlag(oldTopIsActive); topImage.getImage().setVolumeClassification(oldTopVolumeClassification); topImage.setSize(baseImage.getSize()); topImage.setImageStatus(ImageStatus.OK); getBaseDiskDao().update(topImage); getImageDao().update(topImage.getImage()); updateDiskImageDynamic(topImage); getBaseDiskDao().update(baseImage); getImageDao().update(baseImage.getImage()); updateVmConfigurationForImageChange( topImage.getImage().getSnapshotId(), baseImage.getImageId(), topImage); updateVmConfigurationForImageRemoval( baseImage.getImage().getSnapshotId(), topImage.getImageId()); } Set<Guid> imagesToUpdate = getParameters().getMergeStatusReturnValue().getImagesToRemove(); if (imagesToUpdate == null) { log.error("Failed to update orphaned images in db: image list could not be retrieved"); return; } for (Guid imageId : imagesToUpdate) { if (removeImages) { getImageDao().remove(imageId); } else { // The (illegal && no-parent && no-children) status indicates an orphaned image. Image image = getImageDao().get(imageId); image.setStatus(ImageStatus.ILLEGAL); image.setParentId(Guid.Empty); getImageDao().update(image); } } }