Search in sources :

Example 1 with GetBookmarksResponse

use of com.emc.storageos.recoverpoint.responses.GetBookmarksResponse 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.");
        }
    }
}
Also used : GetBookmarksResponse(com.emc.storageos.recoverpoint.responses.GetBookmarksResponse) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) UnManagedProtectionSet(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedProtectionSet) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) RPBookmark(com.emc.storageos.recoverpoint.objectmodel.RPBookmark) HashSet(java.util.HashSet)

Example 2 with GetBookmarksResponse

use of com.emc.storageos.recoverpoint.responses.GetBookmarksResponse in project coprhd-controller by CoprHD.

the class RPHelper method getRPBookmarks.

/**
 * For an RP configuration, get all RP bookmarks for the CGs provided
 *
 * @param system RP system
 * @param cgIDs IDs of the consistency groups to get the bookmarks
 * @return command result object, object list [0] has GetBookmarksResponse
 * @throws RecoverPointException
 */
private static BiosCommandResult getRPBookmarks(ProtectionSystem system, Set<Integer> cgIDs) throws RecoverPointException {
    _log.info("getRPBookmarks {} - start", system.getId());
    RecoverPointClient rp = RPHelper.getRecoverPointClient(system);
    GetBookmarksResponse bookmarkResponse = rp.getRPBookmarks(cgIDs);
    _log.info("getRPBookmarks {} - complete", system.getId());
    BiosCommandResult result = BiosCommandResult.createSuccessfulResult();
    List<Object> returnList = new ArrayList<Object>();
    returnList.add(bookmarkResponse);
    result.setObjectList(returnList);
    return result;
}
Also used : GetBookmarksResponse(com.emc.storageos.recoverpoint.responses.GetBookmarksResponse) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) RecoverPointClient(com.emc.storageos.recoverpoint.impl.RecoverPointClient) ArrayList(java.util.ArrayList)

Example 3 with GetBookmarksResponse

use of com.emc.storageos.recoverpoint.responses.GetBookmarksResponse in project coprhd-controller by CoprHD.

the class RecoverPointClient method getRPBookmarks.

/**
 * Get all RP bookmarks for all CGs specified
 *
 * @param request - set of CG integer IDs
 * @return GetBookmarkResponse - a map of CGs to bookmarks for that CG
 * @throws RecoverPointException
 */
public GetBookmarksResponse getRPBookmarks(Set<Integer> request) throws RecoverPointException {
    String mgmtIPAddress = _endpoint.toASCIIString();
    if (null == mgmtIPAddress) {
        throw RecoverPointException.exceptions.noRecoverPointEndpoint();
    }
    RecoverPointBookmarkManagementUtils bookmarkManager = new RecoverPointBookmarkManagementUtils();
    GetBookmarksResponse response = new GetBookmarksResponse();
    response.setCgBookmarkMap(new HashMap<Integer, List<RPBookmark>>());
    for (Integer cgID : request) {
        ConsistencyGroupUID cgUID = new ConsistencyGroupUID();
        cgUID.setId(cgID);
        response.getCgBookmarkMap().put(cgID, bookmarkManager.getRPBookmarksForCG(functionalAPI, cgUID));
    }
    response.setReturnCode(RecoverPointReturnCode.SUCCESS);
    return response;
}
Also used : GetBookmarksResponse(com.emc.storageos.recoverpoint.responses.GetBookmarksResponse) RecoverPointBookmarkManagementUtils(com.emc.storageos.recoverpoint.utils.RecoverPointBookmarkManagementUtils) ConsistencyGroupUID(com.emc.fapiclient.ws.ConsistencyGroupUID) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 4 with GetBookmarksResponse

use of com.emc.storageos.recoverpoint.responses.GetBookmarksResponse 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

GetBookmarksResponse (com.emc.storageos.recoverpoint.responses.GetBookmarksResponse)4 ArrayList (java.util.ArrayList)3 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)2 NamedURI (com.emc.storageos.db.client.model.NamedURI)2 ProtectionSet (com.emc.storageos.db.client.model.ProtectionSet)2 RecoverPointClient (com.emc.storageos.recoverpoint.impl.RecoverPointClient)2 RPBookmark (com.emc.storageos.recoverpoint.objectmodel.RPBookmark)2 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)2 URI (java.net.URI)2 List (java.util.List)2 ConsistencyGroupUID (com.emc.fapiclient.ws.ConsistencyGroupUID)1 Constraint (com.emc.storageos.db.client.constraint.Constraint)1 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)1 ProtectionSystem (com.emc.storageos.db.client.model.ProtectionSystem)1 UnManagedProtectionSet (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedProtectionSet)1 Volume (com.emc.storageos.db.client.model.Volume)1 RecoverPointBookmarkManagementUtils (com.emc.storageos.recoverpoint.utils.RecoverPointBookmarkManagementUtils)1 ApplicationAddVolumeList (com.emc.storageos.volumecontroller.ApplicationAddVolumeList)1 HashMap (java.util.HashMap)1