use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class RPDeviceController method addStepsForRestoreVolume.
@Override
public String addStepsForRestoreVolume(Workflow workflow, String waitFor, URI storage, URI pool, URI volume, URI snapshot, Boolean updateOpStatus, String syncDirection, String taskId, BlockSnapshotRestoreCompleter completer) throws InternalException {
BlockSnapshot snap = _dbClient.queryObject(BlockSnapshot.class, snapshot);
if (snap != null && NullColumnValueGetter.isNotNullValue(snap.getTechnologyType())) {
Volume vol = _dbClient.queryObject(Volume.class, volume);
if (vol != null) {
if (snap.getTechnologyType().equals(TechnologyType.RP.toString())) {
// Perform an RP controller restore operation only if restoring from an RP BlockSnapshot.
ProtectionSystem rpSystem = null;
rpSystem = _dbClient.queryObject(ProtectionSystem.class, vol.getProtectionController());
if (rpSystem == null) {
// Verify non-null storage device returned from the database client.
throw DeviceControllerExceptions.recoverpoint.failedConnectingForMonitoring(vol.getProtectionController());
}
String stepId = workflow.createStepId();
Workflow.Method restoreVolumeFromSnapshotMethod = new Workflow.Method(METHOD_RESTORE_VOLUME_STEP, rpSystem.getId(), storage, snapshot, completer);
waitFor = workflow.createStep(null, "Restore volume from RP snapshot: " + volume.toString(), waitFor, rpSystem.getId(), rpSystem.getSystemType(), this.getClass(), restoreVolumeFromSnapshotMethod, rollbackMethodNullMethod(), stepId);
_log.info(String.format("Created workflow step to restore RP volume %s from snapshot %s.", volume, snapshot));
}
}
}
return waitFor;
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class RPHelper method cleanupSnapshots.
/**
* Validate Block snapshots that correspond to RP bookmarks. Some may no longer exist in the RP system, and we
* need to mark them as invalid.
*
* The strategy is as follows:
* 1. Get all of the protection sets associated with the protection system
* 2. Are there any Block Snapshots of type RP? (if not, don't bother cleaning up)
* 3. Query the RP Appliance for all bookmarks for that CG (protection set)
* 4. Find each block snapshot of type RP for each site
* 5. If you can't find the bookmark in the RP list, move the block snapshot to inactive
*
* @param protectionSystem Protection System
*/
public static void cleanupSnapshots(DbClient dbClient, ProtectionSystem protectionSystem) throws RecoverPointException {
// 1. Get all of the protection sets associated with the protection system
Set<URI> protectionSetIDs = new HashSet<URI>();
Set<Integer> cgIDs = new HashSet<Integer>();
URIQueryResultList list = new URIQueryResultList();
Constraint constraint = ContainmentConstraint.Factory.getProtectionSystemProtectionSetConstraint(protectionSystem.getId());
dbClient.queryByConstraint(constraint, list);
Iterator<URI> it = list.iterator();
while (it.hasNext()) {
URI protectionSetId = it.next();
// Get all snapshots that are part of this protection set.
URIQueryResultList plist = new URIQueryResultList();
Constraint pconstraint = ContainmentConstraint.Factory.getProtectionSetBlockSnapshotConstraint(protectionSetId);
dbClient.queryByConstraint(pconstraint, plist);
if (plist.iterator().hasNext()) {
// OK, we know there are snapshots for this protection set/CG.
// Retrieve all of the bookmarks associated with this protection set/CG later on by adding to the list now
ProtectionSet protectionSet = dbClient.queryObject(ProtectionSet.class, protectionSetId);
if (protectionSet != null && !protectionSet.getInactive()) {
protectionSetIDs.add(protectionSet.getId());
cgIDs.add(Integer.valueOf(protectionSet.getProtectionId()));
}
}
}
// 2. No reason to bother the RPAs if there are no protection sets for this protection system.
if (protectionSetIDs.isEmpty()) {
_log.info("Block Snapshot of RP Bookmarks cleanup not run for this protection system. No Protections or RP Block Snapshots found on protection system: " + protectionSystem.getLabel());
return;
}
// 3. Query the RP appliance for all of the bookmarks for these CGs in one call
BiosCommandResult result = getRPBookmarks(protectionSystem, cgIDs);
GetBookmarksResponse bookmarkMap = (GetBookmarksResponse) result.getObjectList().get(0);
// 4. Go through each protection set's snapshots and see if they're there.
it = protectionSetIDs.iterator();
while (it.hasNext()) {
URI protectionSetId = it.next();
ProtectionSet protectionSet = dbClient.queryObject(ProtectionSet.class, protectionSetId);
// The map should have an entry for that CG with an empty list if it looked and couldn't find any. (a successful empty set)
if (protectionSet.getProtectionId() != null && bookmarkMap.getCgBookmarkMap() != null && bookmarkMap.getCgBookmarkMap().containsKey(new Integer(protectionSet.getProtectionId()))) {
// list to avoid issues further down.
if (bookmarkMap.getCgBookmarkMap().get(new Integer(protectionSet.getProtectionId())) == null) {
bookmarkMap.getCgBookmarkMap().put(new Integer(protectionSet.getProtectionId()), new ArrayList<RPBookmark>());
}
// Get all snapshots that are part of this protection set.
URIQueryResultList plist = new URIQueryResultList();
Constraint pconstraint = ContainmentConstraint.Factory.getProtectionSetBlockSnapshotConstraint(protectionSetId);
dbClient.queryByConstraint(pconstraint, plist);
Iterator<URI> snapshotIter = plist.iterator();
while (snapshotIter.hasNext()) {
URI snapshotId = snapshotIter.next();
BlockSnapshot snapshot = dbClient.queryObject(BlockSnapshot.class, snapshotId);
boolean deleteSnapshot = true;
if (snapshot.getInactive()) {
// Don't bother deleting or processing if the snapshot is already on its way out.
deleteSnapshot = false;
} else if (snapshot.getEmCGGroupCopyId() == null) {
// If something bad happened and we weren't able to get the site information off of the snapshot
_log.info("Found that ViPR Snapshot corresponding to RP Bookmark is missing Site information, thus not analyzing for automated deletion. " + snapshot.getId() + " - " + protectionSet.getLabel() + ":" + snapshot.getEmInternalSiteName() + ":" + snapshot.getEmName());
deleteSnapshot = false;
} else if (!bookmarkMap.getCgBookmarkMap().get(Integer.valueOf(protectionSet.getProtectionId())).isEmpty()) {
for (RPBookmark bookmark : bookmarkMap.getCgBookmarkMap().get(Integer.valueOf(protectionSet.getProtectionId()))) {
// bookmark (from RP) vs. snapshot (from ViPR)
if (snapshot.getEmName().equalsIgnoreCase(bookmark.getBookmarkName()) && snapshot.getEmCGGroupCopyId().equals(bookmark.getCGGroupCopyUID().getGlobalCopyUID().getCopyUID())) {
deleteSnapshot = false;
_log.info("Found that ViPR Snapshot corresponding to RP Bookmark still exists, thus saving in ViPR: " + snapshot.getId() + " - " + protectionSet.getLabel() + ":" + snapshot.getEmInternalSiteName() + ":" + snapshot.getEmCGGroupCopyId() + ":" + snapshot.getEmName());
}
}
} else {
// Just for debugging, otherwise useless
_log.debug("Found that ViPR Snapshot corresponding to RP Bookmark doesn't exist, thus going to delete from ViPR: " + snapshot.getId() + " - " + protectionSet.getLabel() + ":" + snapshot.getEmInternalSiteName() + ":" + snapshot.getEmCGGroupCopyId() + ":" + snapshot.getEmName());
}
if (deleteSnapshot) {
// 5. We couldn't find the bookmark, and the query for it was successful, so it's time to mark it as gone
_log.info("Found that ViPR Snapshot corresponding to RP Bookmark no longer exists, thus deleting in ViPR: " + snapshot.getId() + " - " + protectionSet.getLabel() + ":" + snapshot.getEmInternalSiteName() + ":" + snapshot.getEmCGGroupCopyId() + ":" + snapshot.getEmName());
dbClient.markForDeletion(snapshot);
}
}
} else if (protectionSet.getProtectionId() == null) {
_log.error("Can not determine the consistency group ID of protection set: " + protectionSet.getLabel() + ", can not perform any cleanup of snapshots.");
} else {
_log.info("No consistency groups were found associated with protection system: " + protectionSystem.getLabel() + ", can not perform cleanup of snapshots.");
}
}
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class NetworkScheduler method getNeighborhoodURIForVolume.
/**
* Get varray URI for a volume, be it a real volume, or a block snapshot
*
* @param uri - URI of Volume or BlockSnapshot
* @return
*/
private URI getNeighborhoodURIForVolume(URI uri) {
URI nhURI = null;
// Volume is the normal case
Volume volume = _dbClient.queryObject(Volume.class, uri);
if (volume != null) {
nhURI = volume.getVirtualArray();
} else // Check if snapshot
{
BlockSnapshot snap = _dbClient.queryObject(BlockSnapshot.class, uri);
if (snap != null) {
volume = _dbClient.queryObject(Volume.class, snap.getParent().getURI());
if (volume != null) {
nhURI = volume.getVirtualArray();
}
}
}
return nhURI;
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class ExportUtils method getBlockObjectVirtualPool.
/**
* Get the Virtual Pool for a Block Object.
*
* @param blockObject
* @param dbClient
* @return VirtualPool or null if could not locate
*/
public static VirtualPool getBlockObjectVirtualPool(BlockObject blockObject, DbClient dbClient) {
Volume volume = null;
if (blockObject instanceof BlockSnapshot) {
BlockSnapshot snapshot = (BlockSnapshot) blockObject;
volume = dbClient.queryObject(Volume.class, snapshot.getParent());
} else if (blockObject instanceof Volume) {
volume = (Volume) blockObject;
}
if (volume != null) {
VirtualPool vpool = dbClient.queryObject(VirtualPool.class, volume.getVirtualPool());
return vpool;
}
return null;
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class VPlexUtil method getVPlexVolumesBuiltOnSnapshots.
/**
* Gets a list of the VPLEX volumes, if any, that are built on the passed snapshots.
*
* @param snapshots A list of snapshots
* @param dbClient A reference to a database client
*
* @return A list of the VPLEX volumes built on the passed snapshots.
*/
public static List<Volume> getVPlexVolumesBuiltOnSnapshots(List<BlockSnapshot> snapshots, DbClient dbClient) {
List<Volume> vplexVolumes = new ArrayList<Volume>();
for (BlockSnapshot snapshotToResync : snapshots) {
String nativeGuid = snapshotToResync.getNativeGuid();
List<Volume> volumes = CustomQueryUtility.getActiveVolumeByNativeGuid(dbClient, nativeGuid);
if (!volumes.isEmpty()) {
// If we find a volume instance with the same native GUID as the
// snapshot, then this volume represents the snapshot target volume
// and a VPLEX volume must have been built on top of it. Note that
// for a given snapshot, I should only ever find 0 or 1 volumes with
// the nativeGuid of the snapshot. Get the VPLEX volume built on
// this volume.
Volume vplexVolume = Volume.fetchVplexVolume(dbClient, volumes.get(0));
vplexVolumes.add(vplexVolume);
}
}
return vplexVolumes;
}
Aggregations