private String getProperty(long snapshotId, String property) { SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(snapshotId, property); if (snapshotDetails != null) { return snapshotDetails.getValue(); } return null; }
private String getSnapshotProperty(long snapshotId, String property) { SnapshotDetailsVO snapshotDetails = _snapshotDetailsDao.findDetail(snapshotId, property); if (snapshotDetails != null) { return snapshotDetails.getValue(); } return null; }
private boolean shouldTakeSnapshot(long snapshotId) { SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(snapshotId, "takeSnapshot"); return snapshotDetails != null && snapshotDetails.getValue() != null && Boolean.parseBoolean(snapshotDetails.getValue()); }
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); }
private void deleteSolidFireVolume(SolidFireUtil.SolidFireConnection sfConnection, long csVolumeId, long sfVolumeId) { List<SnapshotVO> lstSnapshots = getNonDestroyedSnapshots(csVolumeId); boolean deleteVolume = true; for (SnapshotVO snapshot : lstSnapshots) { SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(snapshot.getId(), SolidFireUtil.SNAPSHOT_ID); if (snapshotDetails != null && snapshotDetails.getValue() != null) { deleteVolume = false; break; } } if (deleteVolume) { SolidFireUtil.deleteVolume(sfConnection, sfVolumeId); } }
private void addTempVolumeId(long csSnapshotId, String tempVolumeId) { SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, SolidFireUtil.VOLUME_ID); if (snapshotDetails == null || snapshotDetails.getValue() == null) { throw new CloudRuntimeException("'addTempVolumeId' should not be invoked unless " + SolidFireUtil.VOLUME_ID + " exists."); } String originalVolumeId = snapshotDetails.getValue(); handleSnapshotDetails(csSnapshotId, SolidFireUtil.TEMP_VOLUME_ID, originalVolumeId); handleSnapshotDetails(csSnapshotId, SolidFireUtil.VOLUME_ID, tempVolumeId); }
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; } }
SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, SolidFireUtil.ORIG_CS_VOLUME_ID); snapshotDetails = snapshotDetailsDao.findDetail(snapshotVo.getId(), SolidFireUtil.SNAPSHOT_ID);
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 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 SolidFireUtil.SolidFireVolume createClone(SolidFireUtil.SolidFireConnection sfConnection, long dataObjectId, VolumeInfo volumeInfo, long sfAccountId, long storagePoolId, DataObjectType dataObjectType) { String sfNewVolumeName = volumeInfo.getName(); long sfVolumeId = Long.MIN_VALUE; long sfSnapshotId = Long.MIN_VALUE; if (dataObjectType == DataObjectType.SNAPSHOT) { SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(dataObjectId, SolidFireUtil.SNAPSHOT_ID); if (snapshotDetails != null && snapshotDetails.getValue() != null) { sfSnapshotId = Long.parseLong(snapshotDetails.getValue()); } snapshotDetails = snapshotDetailsDao.findDetail(dataObjectId, SolidFireUtil.VOLUME_ID); sfVolumeId = Long.parseLong(snapshotDetails.getValue()); } else if (dataObjectType == DataObjectType.TEMPLATE) { // get the cached template on this storage VMTemplateStoragePoolVO templatePoolRef = tmpltPoolDao.findByPoolTemplate(storagePoolId, dataObjectId); if (templatePoolRef != null) { sfVolumeId = Long.parseLong(templatePoolRef.getLocalDownloadPath()); } } if (sfVolumeId <= 0) { throw new CloudRuntimeException("Unable to find SolidFire volume for the following data-object ID: " + dataObjectId + " and data-object type: " + dataObjectType); } final long newSfVolumeId = SolidFireUtil.createClone(sfConnection, sfVolumeId, sfSnapshotId, sfAccountId, SolidFireUtil.getSolidFireVolumeName(sfNewVolumeName), getVolumeAttributes(volumeInfo)); final Iops iops = getIops(volumeInfo.getMinIops(), volumeInfo.getMaxIops(), storagePoolId); SolidFireUtil.modifyVolume(sfConnection, newSfVolumeId, null, null, iops.getMinIops(), iops.getMaxIops(), iops.getBurstIops()); return SolidFireUtil.getVolume(sfConnection, newSfVolumeId); }
SnapshotDetailsVO snapshotDetails = _snapshotDetailsDao.findDetail(snapshot.getId(), SolidFireUtil.STORAGE_POOL_ID);
SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(snapshot.getId(), SolidFireUtil.STORAGE_POOL_ID); snapshotDetails = snapshotDetailsDao.findDetail(snapshot.getId(), SolidFireUtil.VOLUME_SIZE);
private long getSolidFireVolumeId(DataObject dataObject, boolean grantAccess) { if (dataObject.getType() == DataObjectType.VOLUME) { final VolumeInfo volumeInfo = (VolumeInfo)dataObject; final long volumeId = volumeInfo.getId(); if (grantAccess && isBasicGrantAccess(volumeId)) { volumeDetailsDao.removeDetail(volumeInfo.getId(), BASIC_GRANT_ACCESS); final Long sfVolumeId = getBasicSfVolumeId(volumeId); Preconditions.checkNotNull(sfVolumeId, "'sfVolumeId' should not be 'null' (basic grant access)."); return sfVolumeId; } else if (!grantAccess && isBasicRevokeAccess(volumeId)) { volumeDetailsDao.removeDetail(volumeInfo.getId(), BASIC_REVOKE_ACCESS); final Long sfVolumeId = getBasicSfVolumeId(volumeId); Preconditions.checkNotNull(sfVolumeId, "'sfVolumeId' should not be 'null' (basic revoke access)."); return sfVolumeId; } return Long.parseLong(volumeInfo.getFolder()); } if (dataObject.getType() == DataObjectType.SNAPSHOT) { SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(dataObject.getId(), SolidFireUtil.VOLUME_ID); if (snapshotDetails == null || snapshotDetails.getValue() == null) { throw new CloudRuntimeException("Unable to locate the volume ID associated with the following snapshot ID: " + dataObject.getId()); } return Long.parseLong(snapshotDetails.getValue()); } if (dataObject.getType() == DataObjectType.TEMPLATE) { return getVolumeIdFrom_iScsiPath(((TemplateInfo)dataObject).getInstallPath()); } throw new CloudRuntimeException("Invalid DataObjectType (" + dataObject.getType() + ") passed to getSolidFireVolumeId(DataObject, boolean)"); }
@Override public void revertSnapshot(SnapshotInfo snapshot, SnapshotInfo snapshot2, AsyncCompletionCallback<CommandResult> callback) { VolumeInfo volumeInfo = snapshot.getBaseVolume(); VolumeVO volumeVO = volumeDao.findById(volumeInfo.getId()); if (volumeVO == null || volumeVO.getRemoved() != null) { String errMsg = "The volume that the snapshot belongs to no longer exists."; CommandResult commandResult = new CommandResult(); commandResult.setResult(errMsg); callback.complete(commandResult); return; } SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(volumeVO.getPoolId(), storagePoolDetailsDao); long sfVolumeId = Long.parseLong(volumeInfo.getFolder()); SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(snapshot.getId(), SolidFireUtil.SNAPSHOT_ID); long sfSnapshotId = Long.parseLong(snapshotDetails.getValue()); SolidFireUtil.rollBackVolumeToSnapshot(sfConnection, sfVolumeId, sfSnapshotId); SolidFireUtil.SolidFireVolume sfVolume = SolidFireUtil.getVolume(sfConnection, sfVolumeId); updateVolumeDetails(volumeVO.getId(), sfVolume.getTotalSize(), sfVolume.getScsiNaaDeviceId()); CommandResult commandResult = new CommandResult(); callback.complete(commandResult); }