use of com.emc.storageos.storagedriver.model.VolumeSnapshot in project coprhd-controller by CoprHD.
the class ExternalBlockStorageDevice method deleteVolumeSnapshot.
private void deleteVolumeSnapshot(StorageSystem storageSystem, URI snapshot, TaskCompleter taskCompleter) {
BlockSnapshot blockSnapshot = dbClient.queryObject(BlockSnapshot.class, snapshot);
if (blockSnapshot != null && !blockSnapshot.getInactive() && // state against the BlockSnapshot object can be set.
!Strings.isNullOrEmpty(blockSnapshot.getNativeId())) {
_log.info("Deleting snapshot of a volume. Snapshot: {}", snapshot);
Volume parent = dbClient.queryObject(Volume.class, blockSnapshot.getParent().getURI());
VolumeSnapshot driverSnapshot = new VolumeSnapshot();
driverSnapshot.setStorageSystemId(storageSystem.getNativeId());
driverSnapshot.setNativeId(blockSnapshot.getNativeId());
driverSnapshot.setParentId(parent.getNativeId());
driverSnapshot.setConsistencyGroup(blockSnapshot.getReplicationGroupInstance());
// call driver
BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
DriverTask task = driver.deleteVolumeSnapshot(driverSnapshot);
// todo: need to implement support for async case.
if (task.getStatus() == DriverTask.TaskStatus.READY) {
// update snapshots
blockSnapshot.setInactive(true);
dbClient.updateObject(blockSnapshot);
String msg = String.format("deleteVolumeSnapshot -- Deleted snapshot: %s .", task.getMessage());
_log.info(msg);
taskCompleter.ready(dbClient);
} else {
String errorMsg = String.format("doDeleteSnapshot -- Failed to delete snapshot: %s .", task.getMessage());
_log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.deleteSnapshotFailed("doDeleteSnapshot", errorMsg);
taskCompleter.error(dbClient, serviceError);
}
} else if (blockSnapshot != null) {
blockSnapshot.setInactive(true);
dbClient.updateObject(blockSnapshot);
String msg = String.format("deleteVolumeSnapshot -- Deleted snapshot: %s .", blockSnapshot.getId());
_log.info(msg);
taskCompleter.ready(dbClient);
}
}
use of com.emc.storageos.storagedriver.model.VolumeSnapshot in project coprhd-controller by CoprHD.
the class ExternalDeviceUnManagedVolumeDiscoverer method getExportInfoForManagedVolumeReplicas.
/**
* Get export info for replicas (snaps and clones) of managed volume.
* We expect that all replicas of managed volume should be managed (known to the system) ---
* enforced by ingest framework, plus we do not support coexistence .
* Warning log message is generated for each replica which is unmanaged.
*
* @param managedVolumeNativeIdToUriMap [OUT], map: key --- managed volume native id, value: volume uri.
* @param hostToManagedVolumeExportInfoMap [OUT], map: key --- host name, value: list of export infos for volumes exported
* to this host.
* @param dbClient reference to db client [IN]
* @param storageSystem storage system [IN]
* @param systemVolume system volume [IN]
* @param driverVolume native volume [IN]
* @param driver reference to driver [IN]
* @throws Exception
*/
private void getExportInfoForManagedVolumeReplicas(Map<String, URI> managedVolumeNativeIdToUriMap, Map<String, List<HostExportInfo>> hostToManagedVolumeExportInfoMap, DbClient dbClient, com.emc.storageos.db.client.model.StorageSystem storageSystem, Volume systemVolume, StorageVolume driverVolume, BlockStorageDriver driver) throws Exception {
// get export info for managed volume snapshots
log.info("Processing snapshots for managed volume {} ", systemVolume.getNativeGuid());
List<VolumeSnapshot> driverSnapshots = driver.getVolumeSnapshots(driverVolume);
if (driverSnapshots == null || driverSnapshots.isEmpty()) {
log.info("There are no snapshots for volume {} ", systemVolume.getNativeGuid());
} else {
log.info("Snapshots for managed volume {}:" + Joiner.on("\t").join(driverSnapshots), systemVolume.getNativeGuid());
for (VolumeSnapshot driverSnapshot : driverSnapshots) {
String managedSnapNativeGuid = NativeGUIDGenerator.generateNativeGuidForVolumeOrBlockSnapShot(storageSystem.getNativeGuid(), driverSnapshot.getNativeId());
BlockSnapshot systemSnap = DiscoveryUtils.checkBlockSnapshotExistsInDB(dbClient, managedSnapNativeGuid);
if (systemSnap == null) {
log.warn("Found unmanaged snapshot of managed volume --- this is unexpected! Skipping this snapshot {}.", driverSnapshot.getNativeId());
continue;
} else {
log.info("Processing managed {} snapshot of managed volume ().", systemSnap.getNativeId(), systemVolume.getNativeGuid());
}
// get export data for the snapshot
managedVolumeNativeIdToUriMap.put(driverSnapshot.getNativeId(), systemSnap.getId());
getSnapshotExportInfo(driver, driverSnapshot, hostToManagedVolumeExportInfoMap);
}
}
// get export info for managed volume clones
log.info("Processing clones for managed volume {} ", systemVolume.getNativeGuid());
List<VolumeClone> driverClones = driver.getVolumeClones(driverVolume);
if (driverClones == null || driverClones.isEmpty()) {
log.info("There are no clones for volume {} ", systemVolume.getNativeGuid());
} else {
log.info("Clones for managed volume {}:" + Joiner.on("\t").join(driverClones), systemVolume.getNativeGuid());
for (VolumeClone driverClone : driverClones) {
String managedCloneNativeGuid = NativeGUIDGenerator.generateNativeGuidForVolumeOrBlockSnapShot(storageSystem.getNativeGuid(), driverClone.getNativeId());
Volume systemClone = DiscoveryUtils.checkStorageVolumeExistsInDB(dbClient, managedCloneNativeGuid);
if (systemClone == null) {
log.warn("Found unmanaged clone of managed volume --- this is unexpected! Skipping this clone {}.", driverClone.getNativeId());
continue;
} else {
log.info("Processing managed {} clone of managed volume ().", systemClone.getNativeId(), systemVolume.getNativeGuid());
}
// get export data for the clone
managedVolumeNativeIdToUriMap.put(driverClone.getNativeId(), systemClone.getId());
getCloneExportInfo(driver, driverClone, hostToManagedVolumeExportInfoMap);
}
}
}
use of com.emc.storageos.storagedriver.model.VolumeSnapshot in project coprhd-controller by CoprHD.
the class ExternalDeviceUnManagedVolumeDiscoverer method processUnManagedSnapshots.
/**
* Process snapshots of unManaged volume.
* Check if unManaged snapshot should be created and create unManaged volume instance for a snapshot in such a case.
* Add unManaged snapshot to parent volume CG if needed and update the snap with parent volume CG information.
* Gets export information for snapshots and stores it in the provided map.
*
* @param driverVolume driver volume for snap parent volume. [IN]
* @param unManagedParentVolume unManaged parent volume [IN/OUT]
* @param storageSystem storage system [IN]
* @param storagePool storage pool [IN]
* @param unManagedVolumesToCreate list of unmanaged volumes to create [OUT]
* @param unManagedVolumesToUpdate list of unmanaged volumes to update [OUT]
* @param allCurrentUnManagedCgURIs set of unManaged CG uris found in the current discovery [OUT]
* @param unManagedCGToUpdateMap map of unManaged CG GUID to unManaged CG instance [IN/OUT]
* @param unManagedVolumeNativeIdToUriMap map of unmanaged volumes nativeId to their uri [OUT]
* @param hostToUnManagedVolumeExportInfoMap map with export data for unmanaged volumes (including snaps and clones)
* @param driver storage driver [IN]
* @param dbClient reference to db client [IN]
* @return set of URIs for unmanaged snapshots
* @throws Exception
*/
private Set<URI> processUnManagedSnapshots(StorageVolume driverVolume, UnManagedVolume unManagedParentVolume, com.emc.storageos.db.client.model.StorageSystem storageSystem, com.emc.storageos.db.client.model.StoragePool storagePool, List<UnManagedVolume> unManagedVolumesToCreate, List<UnManagedVolume> unManagedVolumesToUpdate, Set<URI> allCurrentUnManagedCgURIs, Map<String, UnManagedConsistencyGroup> unManagedCGToUpdateMap, Map<String, URI> unManagedVolumeNativeIdToUriMap, Map<String, List<HostExportInfo>> hostToUnManagedVolumeExportInfoMap, BlockStorageDriver driver, DbClient dbClient) throws Exception {
log.info("Processing snapshots for volume {} ", unManagedParentVolume.getNativeGuid());
Set<URI> snapshotUris = new HashSet<>();
List<VolumeSnapshot> driverSnapshots = driver.getVolumeSnapshots(driverVolume);
if (driverSnapshots == null || driverSnapshots.isEmpty()) {
log.info("There are no snapshots for volume {} ", unManagedParentVolume.getNativeGuid());
} else {
log.info("Snapshots for unManaged volume {}:" + Joiner.on("\t").join(driverSnapshots), unManagedParentVolume.getNativeGuid());
StringSet unManagedSnaps = new StringSet();
for (VolumeSnapshot driverSnapshot : driverSnapshots) {
String managedSnapNativeGuid = NativeGUIDGenerator.generateNativeGuidForVolumeOrBlockSnapShot(storageSystem.getNativeGuid(), driverSnapshot.getNativeId());
BlockSnapshot systemSnap = DiscoveryUtils.checkBlockSnapshotExistsInDB(dbClient, managedSnapNativeGuid);
if (null != systemSnap) {
log.info("Skipping snapshot {} as it is already managed by the system.", managedSnapNativeGuid);
continue;
}
String unManagedSnapNatvieGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingVolume(storageSystem.getNativeGuid(), driverSnapshot.getNativeId());
UnManagedVolume unManagedSnap = createUnManagedSnapshot(driverSnapshot, unManagedParentVolume, storageSystem, storagePool, unManagedVolumesToCreate, unManagedVolumesToUpdate, dbClient);
snapshotUris.add(unManagedSnap.getId());
unManagedSnaps.add(unManagedSnapNatvieGuid);
// Check if this snap is for a volume in consistency group on device.
String isParentVolumeInCG = unManagedParentVolume.getVolumeCharacterstics().get(UnManagedVolume.SupportedVolumeCharacterstics.IS_VOLUME_ADDED_TO_CONSISTENCYGROUP.toString());
if (isParentVolumeInCG.equals(Boolean.TRUE.toString())) {
// add snapshot to parent volume unManaged consistency group, update snapshot with parent volume CG information.
addObjectToUnManagedConsistencyGroup(storageSystem, driverVolume.getConsistencyGroup(), unManagedSnap, allCurrentUnManagedCgURIs, unManagedCGToUpdateMap, driver, dbClient);
}
// get export data for the snapshot
unManagedVolumeNativeIdToUriMap.put(driverSnapshot.getNativeId(), unManagedSnap.getId());
getSnapshotExportInfo(driver, driverSnapshot, hostToUnManagedVolumeExportInfoMap);
}
if (!unManagedSnaps.isEmpty()) {
// set the HAS_REPLICAS property
unManagedParentVolume.getVolumeCharacterstics().put(UnManagedVolume.SupportedVolumeCharacterstics.HAS_REPLICAS.toString(), TRUE);
StringSetMap unManagedVolumeInformation = unManagedParentVolume.getVolumeInformation();
log.info("New unManaged snaps for unManaged volume {}:" + Joiner.on("\t").join(unManagedSnaps), unManagedParentVolume.getNativeGuid());
if (unManagedVolumeInformation.containsKey(UnManagedVolume.SupportedVolumeInformation.SNAPSHOTS.toString())) {
log.info("Old unManaged snaps for unManaged volume {}:" + Joiner.on("\t").join(unManagedVolumeInformation.get(UnManagedVolume.SupportedVolumeInformation.SNAPSHOTS.toString())), unManagedParentVolume.getNativeGuid());
// replace with new StringSet
unManagedParentVolume.putVolumeInfo(UnManagedVolume.SupportedVolumeInformation.SNAPSHOTS.toString(), unManagedSnaps);
log.info("Replaced snaps :" + Joiner.on("\t").join(unManagedVolumeInformation.get(UnManagedVolume.SupportedVolumeInformation.SNAPSHOTS.toString())));
} else {
unManagedParentVolume.putVolumeInfo(UnManagedVolume.SupportedVolumeInformation.SNAPSHOTS.toString(), unManagedSnaps);
}
} else {
log.info("All snapshots for volume {} are already managed.", unManagedParentVolume.getNativeGuid());
}
}
return snapshotUris;
}
use of com.emc.storageos.storagedriver.model.VolumeSnapshot in project coprhd-controller by CoprHD.
the class ExternalBlockStorageDevice method createGroupSnapshots.
private void createGroupSnapshots(StorageSystem storageSystem, List<BlockSnapshot> snapshots, Boolean createInactive, Boolean readOnly, TaskCompleter taskCompleter) {
_log.info("Creating snapshot of consistency group .....");
List<VolumeSnapshot> driverSnapshots = new ArrayList<>();
Map<VolumeSnapshot, BlockSnapshot> driverSnapshotToSnapshotMap = new HashMap<>();
URI cgUri = snapshots.get(0).getConsistencyGroup();
BlockConsistencyGroup consistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, cgUri);
// Prepare driver snapshots
String storageSystemNativeId = storageSystem.getNativeId();
for (BlockSnapshot snapshot : snapshots) {
Volume parent = dbClient.queryObject(Volume.class, snapshot.getParent().getURI());
VolumeSnapshot driverSnapshot = new VolumeSnapshot();
driverSnapshot.setParentId(parent.getNativeId());
driverSnapshot.setStorageSystemId(storageSystemNativeId);
driverSnapshot.setDisplayName(snapshot.getLabel());
if (readOnly) {
driverSnapshot.setAccessStatus(StorageObject.AccessStatus.READ_ONLY);
} else {
driverSnapshot.setAccessStatus(StorageObject.AccessStatus.READ_WRITE);
}
driverSnapshotToSnapshotMap.put(driverSnapshot, snapshot);
driverSnapshots.add(driverSnapshot);
}
// Prepare driver consistency group of the parent volume
VolumeConsistencyGroup driverCG = new VolumeConsistencyGroup();
driverCG.setNativeId(consistencyGroup.getNativeId());
driverCG.setDisplayName(consistencyGroup.getLabel());
driverCG.setStorageSystemId(storageSystem.getNativeId());
// call driver
BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
DriverTask task = driver.createConsistencyGroupSnapshot(driverCG, Collections.unmodifiableList(driverSnapshots), null);
// todo: need to implement support for async case.
if (task.getStatus() == DriverTask.TaskStatus.READY) {
// update snapshots
for (VolumeSnapshot driverSnapshot : driverSnapshotToSnapshotMap.keySet()) {
BlockSnapshot snapshot = driverSnapshotToSnapshotMap.get(driverSnapshot);
snapshot.setNativeId(driverSnapshot.getNativeId());
snapshot.setDeviceLabel(driverSnapshot.getDeviceLabel());
snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storageSystem, snapshot));
snapshot.setIsSyncActive(true);
// we use driver snapshot consistency group id as replication group label for group snapshots
snapshot.setReplicationGroupInstance(driverSnapshot.getConsistencyGroup());
if (driverSnapshot.getProvisionedCapacity() > 0) {
snapshot.setProvisionedCapacity(driverSnapshot.getProvisionedCapacity());
}
if (driverSnapshot.getAllocatedCapacity() > 0) {
snapshot.setAllocatedCapacity(driverSnapshot.getAllocatedCapacity());
}
}
dbClient.updateObject(driverSnapshotToSnapshotMap.values());
String msg = String.format("createGroupSnapshots -- Created snapshots: %s .", task.getMessage());
_log.info(msg);
taskCompleter.ready(dbClient);
} else {
for (BlockSnapshot snapshot : snapshots) {
snapshot.setInactive(true);
}
dbClient.updateObject(snapshots);
String errorMsg = String.format("doCreateSnapshot -- Failed to create snapshots: %s .", task.getMessage());
_log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.createSnapshotsFailed("doCreateSnapshot", errorMsg);
taskCompleter.error(dbClient, serviceError);
}
}
use of com.emc.storageos.storagedriver.model.VolumeSnapshot in project coprhd-controller by CoprHD.
the class ExternalBlockStorageDevice method createVolumeSnapshots.
private void createVolumeSnapshots(StorageSystem storageSystem, List<BlockSnapshot> snapshots, Boolean createInactive, Boolean readOnly, TaskCompleter taskCompleter) {
_log.info("Creating snapshots for volumes.....");
List<VolumeSnapshot> driverSnapshots = new ArrayList<>();
Map<VolumeSnapshot, BlockSnapshot> driverSnapshotToSnapshotMap = new HashMap<>();
// Prepare driver snapshots
String storageSystemNativeId = storageSystem.getNativeId();
for (BlockSnapshot snapshot : snapshots) {
Volume parent = dbClient.queryObject(Volume.class, snapshot.getParent().getURI());
VolumeSnapshot driverSnapshot = new VolumeSnapshot();
driverSnapshot.setParentId(parent.getNativeId());
driverSnapshot.setStorageSystemId(storageSystemNativeId);
driverSnapshot.setDisplayName(snapshot.getLabel());
if (readOnly) {
driverSnapshot.setAccessStatus(StorageObject.AccessStatus.READ_ONLY);
} else {
driverSnapshot.setAccessStatus(StorageObject.AccessStatus.READ_WRITE);
}
driverSnapshotToSnapshotMap.put(driverSnapshot, snapshot);
driverSnapshots.add(driverSnapshot);
}
// call driver
BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
DriverTask task = driver.createVolumeSnapshot(Collections.unmodifiableList(driverSnapshots), null);
// todo: need to implement support for async case.
if (task.getStatus() == DriverTask.TaskStatus.READY) {
// update snapshots
for (VolumeSnapshot driverSnapshot : driverSnapshotToSnapshotMap.keySet()) {
BlockSnapshot snapshot = driverSnapshotToSnapshotMap.get(driverSnapshot);
snapshot.setNativeId(driverSnapshot.getNativeId());
snapshot.setDeviceLabel(driverSnapshot.getDeviceLabel());
snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storageSystem, snapshot));
snapshot.setIsSyncActive(true);
snapshot.setReplicationGroupInstance(driverSnapshot.getConsistencyGroup());
if (driverSnapshot.getProvisionedCapacity() > 0) {
snapshot.setProvisionedCapacity(driverSnapshot.getProvisionedCapacity());
}
if (driverSnapshot.getAllocatedCapacity() > 0) {
snapshot.setAllocatedCapacity(driverSnapshot.getAllocatedCapacity());
}
}
dbClient.updateObject(driverSnapshotToSnapshotMap.values());
String msg = String.format("createVolumeSnapshots -- Created snapshots: %s .", task.getMessage());
_log.info(msg);
taskCompleter.ready(dbClient);
} else {
for (BlockSnapshot snapshot : snapshots) {
snapshot.setInactive(true);
}
dbClient.updateObject(snapshots);
String errorMsg = String.format("doCreateSnapshot -- Failed to create snapshots: %s .", task.getMessage());
_log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.createSnapshotsFailed("doCreateSnapshot", errorMsg);
taskCompleter.error(dbClient, serviceError);
}
}
Aggregations