Search in sources :

Example 6 with RPBookmark

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();
            }
        }
    }
}
Also used : GetBookmarksResponse(com.emc.storageos.recoverpoint.responses.GetBookmarksResponse) HashMap(java.util.HashMap) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Volume(com.emc.storageos.db.client.model.Volume) RecoverPointClient(com.emc.storageos.recoverpoint.impl.RecoverPointClient) ApplicationAddVolumeList(com.emc.storageos.volumecontroller.ApplicationAddVolumeList) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) RPBookmark(com.emc.storageos.recoverpoint.objectmodel.RPBookmark)

Aggregations

RPBookmark (com.emc.storageos.recoverpoint.objectmodel.RPBookmark)6 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)3 NamedURI (com.emc.storageos.db.client.model.NamedURI)3 ProtectionSet (com.emc.storageos.db.client.model.ProtectionSet)3 URI (java.net.URI)3 HashSet (java.util.HashSet)3 ConsistencyGroupCopySnapshots (com.emc.fapiclient.ws.ConsistencyGroupCopySnapshots)2 ConsistencyGroupCopyUID (com.emc.fapiclient.ws.ConsistencyGroupCopyUID)2 FunctionalAPIActionFailedException_Exception (com.emc.fapiclient.ws.FunctionalAPIActionFailedException_Exception)2 FunctionalAPIInternalError_Exception (com.emc.fapiclient.ws.FunctionalAPIInternalError_Exception)2 Snapshot (com.emc.fapiclient.ws.Snapshot)2 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 Volume (com.emc.storageos.db.client.model.Volume)2 RecoverPointClient (com.emc.storageos.recoverpoint.impl.RecoverPointClient)2 RPConsistencyGroup (com.emc.storageos.recoverpoint.objectmodel.RPConsistencyGroup)2 GetBookmarksResponse (com.emc.storageos.recoverpoint.responses.GetBookmarksResponse)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ConsistencyGroupCopySettings (com.emc.fapiclient.ws.ConsistencyGroupCopySettings)1 ConsistencyGroupSettings (com.emc.fapiclient.ws.ConsistencyGroupSettings)1