use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.
the class DateraPrimaryDataStoreDriver method createTempVolume.
/**
* This function gets invoked when you want to do operations on a snapshot. The
* snapshot could be a native snapshot and you want to create a template out of
* it. Since snapshots don't have an IQN, we create a temp volume for this
* snapshot which will be used to carry out further operations. This function
* also handles deletion of temp volumes. A flag in the snapshot details table
* decides which action is performed.
*
* @param snapshotInfo snapshot on Datera
* @param storagePoolId primary store ID
*/
private void createTempVolume(SnapshotInfo snapshotInfo, long storagePoolId) {
s_logger.debug("createTempVolume() from snapshot called");
String ipPool = getIpPool(storagePoolId);
long csSnapshotId = snapshotInfo.getId();
SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, DateraUtil.SNAPSHOT_ID);
if (snapshotDetails == null || snapshotDetails.getValue() == null) {
throw new CloudRuntimeException("'createTempVolume(SnapshotInfo, long)' should not be invoked unless " + DateraUtil.SNAPSHOT_ID + " exists.");
}
DateraObject.DateraConnection conn = DateraUtil.getDateraConnection(storagePoolId, _storagePoolDetailsDao);
snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, "tempVolume");
if (snapshotDetails != null && snapshotDetails.getValue() != null && snapshotDetails.getValue().equalsIgnoreCase("create")) {
snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, DateraUtil.SNAPSHOT_ID);
String snapshotName = snapshotDetails.getValue();
String clonedAppInstanceName = getAppInstanceName(snapshotInfo);
DateraObject.AppInstance clonedAppInstance;
try {
clonedAppInstance = DateraUtil.cloneAppInstanceFromSnapshot(conn, clonedAppInstanceName, snapshotName, ipPool);
DateraUtil.pollAppInstanceAvailable(conn, clonedAppInstanceName);
} catch (DateraObject.DateraError | UnsupportedEncodingException e) {
String errMesg = "Unable to create temp volume " + csSnapshotId + "Error:" + e.getMessage();
s_logger.error(errMesg, e);
throw new CloudRuntimeException(errMesg, e);
}
if (clonedAppInstance == null) {
throw new CloudRuntimeException("Unable to clone volume for snapshot " + snapshotName);
}
s_logger.debug("Temp app_instance " + clonedAppInstanceName + " created");
addTempVolumeToDb(csSnapshotId, clonedAppInstanceName);
handleSnapshotDetails(csSnapshotId, DiskTO.IQN, DateraUtil.generateIqnPath(clonedAppInstance.getIqn()));
} else if (snapshotDetails != null && snapshotDetails.getValue() != null && snapshotDetails.getValue().equalsIgnoreCase("delete")) {
snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, DateraUtil.VOLUME_ID);
try {
s_logger.debug("Deleting temp app_instance " + snapshotDetails.getValue());
DateraUtil.deleteAppInstance(conn, snapshotDetails.getValue());
} catch (UnsupportedEncodingException | DateraObject.DateraError dateraError) {
String errMesg = "Error deleting temp volume " + dateraError.getMessage();
throw new CloudRuntimeException(errMesg, dateraError);
}
removeTempVolumeFromDb(csSnapshotId);
snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, DiskTO.IQN);
snapshotDetailsDao.remove(snapshotDetails.getId());
} else {
throw new CloudRuntimeException("Invalid state in 'createTempVolume(SnapshotInfo, long)'");
}
}
use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.
the class DateraPrimaryDataStoreDriver method createDateraClone.
/**
* This function creates a new AppInstance on datera by cloning. We can clone
* either from a volume snapshot (in case of native snapshots) or clone from
* another app Instance in case of templates or snapshots as volumes
*
* @param conn Datera Connection
* @param dataObjectId The ID of the clone, used to fetch details on how to
* clone
* @param volumeInfo Information about the clone
* @param storagePoolId Primary store to create the clone on
* @param dataType Type of the source (snapshot or template)
* @return The cloned AppInstance
*/
private DateraObject.AppInstance createDateraClone(DateraObject.DateraConnection conn, long dataObjectId, VolumeInfo volumeInfo, long storagePoolId, DataObjectType dataType) throws UnsupportedEncodingException, DateraObject.DateraError {
s_logger.debug("createDateraClone() called");
String clonedAppInstanceName = getAppInstanceName(volumeInfo);
String baseAppInstanceName = null;
DateraObject.AppInstance appInstance = null;
String ipPool = getIpPool(storagePoolId);
if (dataType == DataObjectType.SNAPSHOT) {
SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(dataObjectId, DateraUtil.SNAPSHOT_ID);
// Clone volume from a snapshot
if (snapshotDetails != null && snapshotDetails.getValue() != null) {
s_logger.debug("Clone volume from a snapshot");
appInstance = DateraUtil.cloneAppInstanceFromSnapshot(conn, clonedAppInstanceName, snapshotDetails.getValue(), ipPool);
if (volumeInfo.getMaxIops() != null) {
int totalIops = Math.min(DateraUtil.MAX_IOPS, Ints.checkedCast(volumeInfo.getMaxIops()));
DateraUtil.updateAppInstanceIops(conn, clonedAppInstanceName, totalIops);
appInstance = DateraUtil.getAppInstance(conn, clonedAppInstanceName);
}
if (appInstance == null) {
throw new CloudRuntimeException("Unable to create an app instance from snapshot " + volumeInfo.getId() + " type " + dataType);
}
return appInstance;
} else {
// Clone volume from an appInstance
s_logger.debug("Clone volume from an appInstance");
snapshotDetails = snapshotDetailsDao.findDetail(dataObjectId, DateraUtil.VOLUME_ID);
baseAppInstanceName = snapshotDetails.getValue();
}
} else if (dataType == DataObjectType.TEMPLATE) {
s_logger.debug("Clone volume from a template");
VMTemplateStoragePoolVO templatePoolRef = tmpltPoolDao.findByPoolTemplate(storagePoolId, dataObjectId, null);
if (templatePoolRef != null) {
baseAppInstanceName = templatePoolRef.getLocalDownloadPath();
}
}
if (baseAppInstanceName == null) {
throw new CloudRuntimeException("Unable to find a base volume to clone " + volumeInfo.getId() + " type " + dataType);
}
// Clone the app Instance
appInstance = DateraUtil.cloneAppInstanceFromVolume(conn, clonedAppInstanceName, baseAppInstanceName, ipPool);
if (dataType == DataObjectType.TEMPLATE) {
// Update maxIops
if (volumeInfo.getMaxIops() != null) {
int totalIops = Math.min(DateraUtil.MAX_IOPS, Ints.checkedCast(volumeInfo.getMaxIops()));
DateraUtil.updateAppInstanceIops(conn, clonedAppInstanceName, totalIops);
appInstance = DateraUtil.getAppInstance(conn, clonedAppInstanceName);
}
// Update placementMode
String newPlacementMode = getVolPlacement(storagePoolId);
if (newPlacementMode != null) {
DateraUtil.updateAppInstancePlacement(conn, clonedAppInstanceName, newPlacementMode);
}
appInstance = DateraUtil.getAppInstance(conn, clonedAppInstanceName);
}
if (appInstance == null) {
throw new CloudRuntimeException("Unable to create an app instance from snapshot or template " + volumeInfo.getId() + " type " + dataType);
}
s_logger.debug("Datera - Cloned " + baseAppInstanceName + " to " + clonedAppInstanceName);
return appInstance;
}
use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.
the class StorageSystemDataMotionStrategy method handleSnapshotDetails.
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);
}
use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.
the class SolidFirePrimaryDataStoreDriver method updateSnapshotDetails.
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);
}
use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.
the class SolidFirePrimaryDataStoreLifeCycle method deleteDataStore.
// invoked to delete primary storage that is based on the SolidFire plug-in
@Override
public boolean deleteDataStore(DataStore dataStore) {
long storagePoolId = dataStore.getId();
List<SnapshotVO> lstSnapshots = _snapshotDao.listAll();
if (lstSnapshots != null) {
for (SnapshotVO snapshot : lstSnapshots) {
SnapshotDetailsVO snapshotDetails = _snapshotDetailsDao.findDetail(snapshot.getId(), SolidFireUtil.STORAGE_POOL_ID);
// if this snapshot belongs to the storagePool that was passed in
if (snapshotDetails != null && snapshotDetails.getValue() != null && Long.parseLong(snapshotDetails.getValue()) == storagePoolId) {
throw new CloudRuntimeException("This primary storage cannot be deleted because it currently contains one or more snapshots.");
}
}
}
List<VMTemplateStoragePoolVO> lstTemplatePoolRefs = _tmpltPoolDao.listByPoolId(storagePoolId);
if (lstTemplatePoolRefs != null) {
for (VMTemplateStoragePoolVO templatePoolRef : lstTemplatePoolRefs) {
try {
SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, _storagePoolDetailsDao);
long sfTemplateVolumeId = Long.parseLong(templatePoolRef.getLocalDownloadPath());
SolidFireUtil.deleteVolume(sfConnection, sfTemplateVolumeId);
} catch (Exception ex) {
s_logger.error(ex.getMessage() != null ? ex.getMessage() : "Error deleting SolidFire template volume");
}
_tmpltPoolDao.remove(templatePoolRef.getId());
}
}
StoragePoolVO storagePool = _storagePoolDao.findById(storagePoolId);
storagePool.setUsedBytes(0);
_storagePoolDao.update(storagePoolId, storagePool);
_storagePoolDetailsDao.removeDetails(storagePoolId);
return _dataStoreHelper.deletePrimaryDataStore(dataStore);
}
Aggregations