use of com.emc.storageos.recoverpoint.objectmodel.RPBookmark in project coprhd-controller by CoprHD.
the class RPDeviceController method searchForBookmarks.
/**
* Searches for all specified bookmarks (RP snapshots). If even just one
* bookmark does not exist, an exception will be thrown.
*
* @param protectionDevice
* the protection system URI
* @param snapshots
* the RP snapshots to search for
*/
private void searchForBookmarks(URI protectionDevice, Set<URI> snapshots) {
ProtectionSystem rpSystem = getRPSystem(protectionDevice);
RecoverPointClient rpClient = RPHelper.getRecoverPointClient(rpSystem);
// Check that the bookmarks actually exist
Set<Integer> cgIDs = null;
boolean bookmarkExists;
// Map used to keep track of which BlockSnapshots map to which CGs
Map<Integer, List<BlockSnapshot>> cgSnaps = new HashMap<Integer, List<BlockSnapshot>>();
for (URI snapshotID : snapshots) {
cgIDs = new HashSet<Integer>();
BlockSnapshot snapshot = _dbClient.queryObject(BlockSnapshot.class, snapshotID);
// Get the volume associated with this snapshot
Volume volume = _dbClient.queryObject(Volume.class, snapshot.getParent().getURI());
// Now get the protection set (CG) associated with the volume so we can use
// it to search for the bookmark
ProtectionSet protectionSet = _dbClient.queryObject(ProtectionSet.class, volume.getProtectionSet());
Integer cgID = null;
try {
cgID = Integer.valueOf(protectionSet.getProtectionId());
} catch (NumberFormatException nfe) {
throw DeviceControllerExceptions.recoverpoint.exceptionLookingForBookmarks(nfe);
}
cgIDs.add(cgID);
if (cgSnaps.get(cgID) == null) {
cgSnaps.put(cgID, new ArrayList<BlockSnapshot>());
}
cgSnaps.get(cgID).add(snapshot);
}
GetBookmarksResponse bookmarkResponse = rpClient.getRPBookmarks(cgIDs);
// one exists in RP. Fail if any of the snapshots does not exist.
for (Integer cgID : cgSnaps.keySet()) {
for (BlockSnapshot snapshot : cgSnaps.get(cgID)) {
bookmarkExists = false;
if (bookmarkResponse.getCgBookmarkMap() != null && !bookmarkResponse.getCgBookmarkMap().isEmpty()) {
List<RPBookmark> rpBookmarks = bookmarkResponse.getCgBookmarkMap().get(cgID);
if (rpBookmarks != null && !rpBookmarks.isEmpty()) {
// Find the bookmark
for (RPBookmark rpBookmark : rpBookmarks) {
if (rpBookmark.getBookmarkName().equals(snapshot.getEmName())) {
bookmarkExists = true;
}
}
}
}
if (!bookmarkExists) {
throw DeviceControllerExceptions.recoverpoint.failedToFindExpectedBookmarks();
}
}
}
}
Aggregations