private void handleSnapshotDetails(long csSnapshotId, String name, String value) { snapshotDetailsDao.removeDetail(csSnapshotId, name); SnapshotDetailsVO snapshotDetails = new SnapshotDetailsVO(csSnapshotId, name, value, false); snapshotDetailsDao.persist(snapshotDetails); }
private String getProperty(long snapshotId, String property) { SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(snapshotId, property); if (snapshotDetails != null) { return snapshotDetails.getValue(); } return null; }
private void removeTempVolumeId(long csSnapshotId) { SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, SolidFireUtil.TEMP_VOLUME_ID); if (snapshotDetails == null || snapshotDetails.getValue() == null) { throw new CloudRuntimeException("'removeTempVolumeId' should not be invoked unless " + SolidFireUtil.TEMP_VOLUME_ID + " exists."); } String originalVolumeId = snapshotDetails.getValue(); handleSnapshotDetails(csSnapshotId, SolidFireUtil.VOLUME_ID, originalVolumeId); snapshotDetailsDao.remove(snapshotDetails.getId()); }
private void updateSnapshotDetails(long csSnapshotId, long sfNewVolumeId, long storagePoolId, long sfNewVolumeSize, String sfNewVolumeIqn) { SnapshotDetailsVO snapshotDetail = new SnapshotDetailsVO(csSnapshotId, SolidFireUtil.VOLUME_ID, String.valueOf(sfNewVolumeId), false); snapshotDetailsDao.persist(snapshotDetail); snapshotDetail = new SnapshotDetailsVO(csSnapshotId, SolidFireUtil.STORAGE_POOL_ID, String.valueOf(storagePoolId), false); snapshotDetailsDao.persist(snapshotDetail); snapshotDetail = new SnapshotDetailsVO(csSnapshotId, SolidFireUtil.VOLUME_SIZE, String.valueOf(sfNewVolumeSize), false); snapshotDetailsDao.persist(snapshotDetail); snapshotDetail = new SnapshotDetailsVO(csSnapshotId, DiskTO.IQN, sfNewVolumeIqn, false); snapshotDetailsDao.persist(snapshotDetail); }
final List<SnapshotDetailsVO> snapshotList = _snapshotDetailsDao.findDetails(AsyncJob.Constants.MS_ID, Long.toString(msid), false); for (final SnapshotDetailsVO snapshotDetailsVO : snapshotList) { SnapshotInfo snapshot = snapshotFactory.getSnapshot(snapshotDetailsVO.getResourceId(), DataStoreRole.Primary); snapshotSrv.processEventOnSnapshotObject(snapshot, Snapshot.Event.OperationFailed); _snapshotDetailsDao.removeDetail(snapshotDetailsVO.getResourceId(), AsyncJob.Constants.MS_ID);
@Override public void doInTransactionWithoutResult(TransactionStatus status) { try { SnapshotObject srcSnapshot = (SnapshotObject)snapshot; srcSnapshot.processEvent(Event.DestroyRequested); srcSnapshot.processEvent(Event.OperationSuccessed); srcSnapshot.processEvent(Snapshot.Event.OperationFailed); _snapshotDetailsDao.removeDetail(srcSnapshot.getId(), AsyncJob.Constants.MS_ID); _snapshotDao.remove(srcSnapshot.getId()); } catch (NoTransitionException ex) { s_logger.debug("Failed to create backup " + ex.toString()); throw new CloudRuntimeException("Failed to backup snapshot" + snapshot.getId()); } } });
private void deleteSnapshot(SnapshotInfo snapshotInfo, long storagePoolId) { long csSnapshotId = snapshotInfo.getId(); try { SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, storagePoolDetailsDao); SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, SolidFireUtil.SNAPSHOT_ID); if (snapshotDetails != null && snapshotDetails.getValue() != null) { // A SolidFire snapshot is being used to support the CloudStack volume snapshot. long sfSnapshotId = Long.parseLong(snapshotDetails.getValue()); deleteSolidFireSnapshot(sfConnection, csSnapshotId, sfSnapshotId); } else { // A SolidFire volume is being used to support the CloudStack volume snapshot. snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, SolidFireUtil.VOLUME_ID); long sfVolumeId = Long.parseLong(snapshotDetails.getValue()); SolidFireUtil.deleteVolume(sfConnection, sfVolumeId); } snapshotDetailsDao.removeDetails(csSnapshotId); StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId); // getUsedBytes(StoragePool) will not include the snapshot to delete because it has already been deleted by this point long usedBytes = getUsedBytes(storagePool); storagePool.setUsedBytes(usedBytes < 0 ? 0 : usedBytes); storagePoolDao.update(storagePoolId, storagePool); } catch (Exception ex) { LOGGER.debug(SolidFireUtil.LOG_PREFIX + "Issue in 'deleteSnapshot(SnapshotInfo, long)'. CloudStack snapshot ID: " + csSnapshotId, ex); throw ex; } }
/** * If the underlying storage system needed to create a volume from a snapshot for createVolumeFromSnapshot(SnapshotInfo), then * this is its opportunity to delete that temporary volume and restore properties in snapshot_details to the way they were before the * invocation of createVolumeFromSnapshot(SnapshotInfo). */ private void deleteVolumeFromSnapshot(SnapshotInfo snapshotInfo) { SnapshotDetailsVO snapshotDetails = handleSnapshotDetails(snapshotInfo.getId(), "delete"); try { snapshotInfo.getDataStore().getDriver().createAsync(snapshotInfo.getDataStore(), snapshotInfo, null); } finally { _snapshotDetailsDao.remove(snapshotDetails.getId()); } }
public List<ApiVolumeSnapshotDetailsResponse> getSnapshotDetails(String snapshotUuid) { SnapshotVO snapshot = snapshotDao.findByUuid(snapshotUuid); if (snapshot == null) { throw new CloudRuntimeException("Unable to find Volume for ID: " + snapshotUuid); } List<SnapshotDetailsVO> snapshotDetails = snapshotDetailsDao.listDetails(snapshot.getId()); List<ApiVolumeSnapshotDetailsResponse> responses = new ArrayList<>(); if (snapshotDetails != null) { for (SnapshotDetailsVO snapshotDetail : snapshotDetails) { ApiVolumeSnapshotDetailsResponse response = new ApiVolumeSnapshotDetailsResponse( snapshotDetail.getResourceId(), snapshotDetail.getName(), snapshotDetail.getValue() ); responses.add(response); } } return responses; } }
_snapshotDetailsDao.addDetail(((SnapshotObject)snapshotOnPrimary).getId(), AsyncJob.Constants.MS_ID, Long.toString(ManagementServerNode.getManagementServerId()), false); return snapshotOnPrimary; } finally {
private void updateSnapshotDetails(long csSnapshotId, long csVolumeId, long sfVolumeId, long sfNewSnapshotId, long storagePoolId, long sfNewVolumeSize) { SnapshotDetailsVO snapshotDetail = new SnapshotDetailsVO(csSnapshotId, SolidFireUtil.ORIG_CS_VOLUME_ID, String.valueOf(csVolumeId), false); snapshotDetailsDao.persist(snapshotDetail); snapshotDetail = new SnapshotDetailsVO(csSnapshotId, SolidFireUtil.VOLUME_ID, String.valueOf(sfVolumeId), false); snapshotDetailsDao.persist(snapshotDetail); snapshotDetail = new SnapshotDetailsVO(csSnapshotId, SolidFireUtil.SNAPSHOT_ID, String.valueOf(sfNewSnapshotId), false); snapshotDetailsDao.persist(snapshotDetail); snapshotDetail = new SnapshotDetailsVO(csSnapshotId, SolidFireUtil.STORAGE_POOL_ID, String.valueOf(storagePoolId), false); snapshotDetailsDao.persist(snapshotDetail); snapshotDetail = new SnapshotDetailsVO(csSnapshotId, SolidFireUtil.VOLUME_SIZE, String.valueOf(sfNewVolumeSize), false); snapshotDetailsDao.persist(snapshotDetail); }
@Override public void doInTransactionWithoutResult(TransactionStatus status) { _snapshotDetailsDao.removeDetail(((SnapshotObject)snapshotOnPrimary).getId(), AsyncJob.Constants.MS_ID); DataStore primaryStore = snapshotOnPrimary.getDataStore(); try {
/** * If the underlying storage system is making use of read-only snapshots, this gives the storage system the opportunity to * create a volume from the snapshot so that we can copy the VHD file that should be inside of the snapshot to secondary storage. * * The resultant volume must be writable because we need to resign the SR and the VDI that should be inside of it before we copy * the VHD file to secondary storage. * * If the storage system is using writable snapshots, then nothing need be done by that storage system here because we can just * resign the SR and the VDI that should be inside of the snapshot before copying the VHD file to secondary storage. */ private void createVolumeFromSnapshot(SnapshotInfo snapshotInfo) { SnapshotDetailsVO snapshotDetails = handleSnapshotDetails(snapshotInfo.getId(), "create"); try { snapshotInfo.getDataStore().getDriver().createAsync(snapshotInfo.getDataStore(), snapshotInfo, null); } finally { _snapshotDetailsDao.remove(snapshotDetails.getId()); } }
private String getSnapshotProperty(long snapshotId, String property) { SnapshotDetailsVO snapshotDetails = _snapshotDetailsDao.findDetail(snapshotId, property); if (snapshotDetails != null) { return snapshotDetails.getValue(); } return null; }
private SnapshotDetailsVO handleSnapshotDetails(long csSnapshotId, String value) { String name = "tempVolume"; _snapshotDetailsDao.removeDetail(csSnapshotId, name); SnapshotDetailsVO snapshotDetails = new SnapshotDetailsVO(csSnapshotId, name, value, false); return _snapshotDetailsDao.persist(snapshotDetails); }
private void createTempVolume(SnapshotInfo snapshotInfo, long storagePoolId) { long csSnapshotId = snapshotInfo.getId(); SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, SolidFireUtil.SNAPSHOT_ID); if (snapshotDetails == null || snapshotDetails.getValue() == null) { throw new CloudRuntimeException("'createTempVolume(SnapshotInfo, long)' should not be invoked unless " + SolidFireUtil.SNAPSHOT_ID + " exists."); } SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, storagePoolDetailsDao); snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, "tempVolume"); if (snapshotDetails != null && snapshotDetails.getValue() != null && snapshotDetails.getValue().equalsIgnoreCase("create")) { long sfAccountId = getCreateSolidFireAccountId(sfConnection, snapshotInfo.getAccountId(), storagePoolId); SolidFireUtil.SolidFireVolume sfVolume = createCloneFromSnapshot(sfConnection, csSnapshotId, sfAccountId); addTempVolumeId(csSnapshotId, String.valueOf(sfVolume.getId())); handleSnapshotDetails(csSnapshotId, DiskTO.IQN, sfVolume.getIqn()); handleSnapshotDetails(csSnapshotId, DiskTO.SCSI_NAA_DEVICE_ID, sfVolume.getScsiNaaDeviceId()); } else if (snapshotDetails != null && snapshotDetails.getValue() != null && snapshotDetails.getValue().equalsIgnoreCase("delete")) { snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, SolidFireUtil.VOLUME_ID); SolidFireUtil.deleteVolume(sfConnection, Long.parseLong(snapshotDetails.getValue())); removeTempVolumeId(csSnapshotId); snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, DiskTO.IQN); snapshotDetailsDao.remove(snapshotDetails.getId()); snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, DiskTO.SCSI_NAA_DEVICE_ID); snapshotDetailsDao.remove(snapshotDetails.getId()); } else { throw new CloudRuntimeException("Invalid state in 'createTempVolume(SnapshotInfo, long)'"); } }
private void setVmdk(SnapshotInfo snapshotInfo, VolumeInfo volumeInfo) { if (!ImageFormat.OVA.equals(volumeInfo.getFormat())) { return; } String search = "]"; String path = volumeInfo.getPath(); int startIndex = path.indexOf(search); SnapshotDetailsVO snapshotDetail = new SnapshotDetailsVO(snapshotInfo.getId(), DiskTO.VMDK, path.substring(startIndex + search.length()).trim(), false); snapshotDetailsDao.persist(snapshotDetail); }
private boolean shouldTakeSnapshot(long snapshotId) { SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(snapshotId, "takeSnapshot"); return snapshotDetails != null && snapshotDetails.getValue() != null && Boolean.parseBoolean(snapshotDetails.getValue()); }
false); snapshotDetailsDao.persist(snapshotDetail);
private SolidFireUtil.SolidFireVolume createCloneFromSnapshot(SolidFireUtil.SolidFireConnection sfConnection, long csSnapshotId, long sfAccountId) { SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, SolidFireUtil.VOLUME_ID); long sfVolumeId = Long.parseLong(snapshotDetails.getValue()); snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, SolidFireUtil.SNAPSHOT_ID); long sfSnapshotId = Long.parseLong(snapshotDetails.getValue()); SolidFireUtil.SolidFireSnapshot sfSnapshot = SolidFireUtil.getSnapshot(sfConnection, sfVolumeId, sfSnapshotId); long newSfVolumeId = SolidFireUtil.createClone(sfConnection, sfVolumeId, sfSnapshotId, sfAccountId, SolidFireUtil.getSolidFireVolumeName(sfSnapshot.getName()), null); snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, SolidFireUtil.STORAGE_POOL_ID); long storagePoolId = Long.parseLong(snapshotDetails.getValue()); final Iops iops = getIops(MIN_IOPS_FOR_TEMP_VOLUME, MAX_IOPS_FOR_TEMP_VOLUME, storagePoolId); SolidFireUtil.modifyVolume(sfConnection, newSfVolumeId, null, null, iops.getMinIops(), iops.getMaxIops(), iops.getBurstIops()); return SolidFireUtil.getVolume(sfConnection, newSfVolumeId); }