Search in sources :

Example 6 with RPConsistencyGroup

use of com.emc.storageos.recoverpoint.objectmodel.RPConsistencyGroup in project coprhd-controller by CoprHD.

the class RecoverPointClient method restoreImageCopies.

/**
 * Restore copy images for one or more consistency group copies
 *
 * @param MultiCopyRestoreImageRequestParams request - contains the information about which CG copies to restore
 *
 * @return MultiCopyRestoreImageResponse - response as to success or fail of restoring the image copies
 *
 * @throws RecoverPointException
 */
public MultiCopyRestoreImageResponse restoreImageCopies(MultiCopyRestoreImageRequestParams request) throws RecoverPointException {
    MultiCopyRestoreImageResponse response = new MultiCopyRestoreImageResponse();
    RecoverPointImageManagementUtils imageManager = new RecoverPointImageManagementUtils();
    RecoverPointBookmarkManagementUtils bookmarkManager = new RecoverPointBookmarkManagementUtils();
    String mgmtIPAddress = _endpoint.toASCIIString();
    if (null == mgmtIPAddress) {
        throw RecoverPointException.exceptions.noRecoverPointEndpoint();
    }
    Set<String> wwnSet = request.getVolumeWWNSet();
    if (wwnSet == null) {
        throw RecoverPointException.exceptions.noWWNsFoundInRequest();
    }
    Set<String> unmappedWWNs = new HashSet<String>();
    CreateBookmarkRequestParams mapRequest = new CreateBookmarkRequestParams();
    mapRequest.setBookmark(request.getBookmark());
    mapRequest.setVolumeWWNSet(wwnSet);
    Map<String, RPConsistencyGroup> rpCGMap = bookmarkManager.mapCGsForWWNs(functionalAPI, mapRequest, unmappedWWNs);
    if (!unmappedWWNs.isEmpty()) {
        throw RecoverPointException.exceptions.couldNotMapWWNsToAGroup(unmappedWWNs);
    }
    if (rpCGMap == null) {
        throw RecoverPointException.exceptions.couldNotMapWWNsToAGroup(wwnSet);
    }
    Set<RPConsistencyGroup> cgSetToEnable = new HashSet<RPConsistencyGroup>();
    for (String volume : rpCGMap.keySet()) {
        // logger.info("Get RPCG for volume: " + volume);
        cgSetToEnable.add(rpCGMap.get(volume));
    }
    ClusterUID siteToRestore = null;
    // Verify that we are not restoring from different sites
    for (RPConsistencyGroup rpcg : cgSetToEnable) {
        Set<RPCopy> copies = rpcg.getCopies();
        for (RPCopy copy : copies) {
            if (siteToRestore == null) {
                siteToRestore = copy.getCGGroupCopyUID().getGlobalCopyUID().getClusterUID();
            } else if (siteToRestore.getId() != copy.getCGGroupCopyUID().getGlobalCopyUID().getClusterUID().getId()) {
                throw RecoverPointException.exceptions.cannotRestoreVolumesFromDifferentSites(wwnSet);
            }
            try {
                List<ConsistencyGroupCopyUID> productionCopiesUIDs = functionalAPI.getGroupSettings(copy.getCGGroupCopyUID().getGroupUID()).getProductionCopiesUIDs();
                for (ConsistencyGroupCopyUID productionCopyUID : productionCopiesUIDs) {
                    if (RecoverPointUtils.copiesEqual(productionCopyUID, copy.getCGGroupCopyUID())) {
                        throw RecoverPointException.exceptions.cannotRestoreVolumesInConsistencyGroup(wwnSet);
                    }
                }
            } catch (FunctionalAPIActionFailedException_Exception e) {
                logger.error(e.getMessage());
                logger.error("Received FunctionalAPIActionFailedException_Exception. Get production copy");
                throw RecoverPointException.exceptions.failureRestoringVolumes();
            } catch (FunctionalAPIInternalError_Exception e) {
                logger.error(e.getMessage());
                logger.error("Received FunctionalAPIActionFailedException_Exception. Get production copy");
                throw RecoverPointException.exceptions.failureRestoringVolumes();
            }
        }
    }
    try {
        for (RPConsistencyGroup rpcg : cgSetToEnable) {
            Set<RPCopy> copies = rpcg.getCopies();
            for (RPCopy copy : copies) {
                boolean waitForLinkState = false;
                imageManager.enableCGCopy(functionalAPI, copy.getCGGroupCopyUID(), waitForLinkState, ImageAccessMode.LOGGED_ACCESS, request.getBookmark(), request.getAPITTime());
            }
        }
    } catch (RecoverPointException e) {
        logger.error("Caught exception while enabling CG copies for restore.  Return copies to previous state");
        for (RPConsistencyGroup rpcg : cgSetToEnable) {
            Set<RPCopy> copies = rpcg.getCopies();
            for (RPCopy copy : copies) {
                imageManager.disableCGCopy(functionalAPI, copy.getCGGroupCopyUID());
            }
        }
        throw e;
    }
    for (RPConsistencyGroup rpcg : cgSetToEnable) {
        Set<RPCopy> copies = rpcg.getCopies();
        for (RPCopy copy : copies) {
            imageManager.restoreEnabledCGCopy(functionalAPI, copy.getCGGroupCopyUID());
        }
    }
    response.setReturnCode(RecoverPointReturnCode.SUCCESS);
    return response;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) SortedSet(java.util.SortedSet) HashSet(java.util.HashSet) FunctionalAPIActionFailedException_Exception(com.emc.fapiclient.ws.FunctionalAPIActionFailedException_Exception) RecoverPointBookmarkManagementUtils(com.emc.storageos.recoverpoint.utils.RecoverPointBookmarkManagementUtils) RPCopy(com.emc.storageos.recoverpoint.objectmodel.RPCopy) RecoverPointImageManagementUtils(com.emc.storageos.recoverpoint.utils.RecoverPointImageManagementUtils) RPConsistencyGroup(com.emc.storageos.recoverpoint.objectmodel.RPConsistencyGroup) ConsistencyGroupCopyUID(com.emc.fapiclient.ws.ConsistencyGroupCopyUID) CreateBookmarkRequestParams(com.emc.storageos.recoverpoint.requests.CreateBookmarkRequestParams) ClusterUID(com.emc.fapiclient.ws.ClusterUID) MultiCopyRestoreImageResponse(com.emc.storageos.recoverpoint.responses.MultiCopyRestoreImageResponse) FunctionalAPIInternalError_Exception(com.emc.fapiclient.ws.FunctionalAPIInternalError_Exception) RecoverPointException(com.emc.storageos.recoverpoint.exceptions.RecoverPointException) HashSet(java.util.HashSet)

Example 7 with RPConsistencyGroup

use of com.emc.storageos.recoverpoint.objectmodel.RPConsistencyGroup in project coprhd-controller by CoprHD.

the class RecoverPointBookmarkManagementUtils method findRPBookmarks.

/**
 * Find the bookmarks that were created for a CG
 *
 * @param impl - RP handle to use for RP operations
 * @param rpCGset - List of CGs that had this bookmark created
 * @param request - Information about the bookmark that was created on the CGs
 *
 * @return Map of CGs with the bookmark information (CDP and/or CRR)
 *
 * @throws RecoverPointException
 */
public Map<RPConsistencyGroup, Set<RPBookmark>> findRPBookmarks(FunctionalAPIImpl impl, Set<RPConsistencyGroup> rpCGSet, CreateBookmarkRequestParams request) throws RecoverPointException {
    Map<RPConsistencyGroup, Set<RPBookmark>> returnMap = new HashMap<RPConsistencyGroup, Set<RPBookmark>>();
    final int numRetries = 6;
    final int secondsToWaitForRetry = 5;
    RecoverPointCopyType rpCopyType = RecoverPointCopyType.UNKNOWN_PROTECTION;
    boolean wantCDP = false;
    boolean wantCRR = false;
    // If rpCopyType not specified
    boolean acceptAnyCopy = false;
    // later.
    if (rpCopyType == null || rpCopyType == RecoverPointCopyType.UNKNOWN_PROTECTION) {
        acceptAnyCopy = true;
    } else {
        if (rpCopyType == RecoverPointCopyType.CDP_PROTECTION) {
            wantCDP = true;
        } else if (rpCopyType == RecoverPointCopyType.CRR_PROTECTION) {
            wantCRR = true;
        } else if (rpCopyType == RecoverPointCopyType.CRR_PROTECTION) {
            wantCRR = true;
            wantCDP = true;
        }
    }
    boolean tooManyRetries = false;
    for (RPConsistencyGroup rpCG : rpCGSet) {
        if (tooManyRetries) {
            // Stop trying
            break;
        }
        for (int i = 0; i < numRetries; i++) {
            logger.info(String.format("Getting event markers for CG: %s.  Attempt number %d.  Copy type: %s", rpCG.getName() != null ? rpCG.getName() : rpCG.getCGUID().getId(), i, rpCopyType.toString()));
            Set<RPBookmark> rpEventMarkersForCG = getBookmarksForMostRecentBookmarkName(impl, request, rpCG.getCGUID());
            if (rpEventMarkersForCG != null) {
                if (acceptAnyCopy && (!rpEventMarkersForCG.isEmpty())) {
                    // We will take anything, and we found at least one event marker
                    returnMap.put(rpCG, rpEventMarkersForCG);
                    // Go to the next CG
                    break;
                } else if ((wantCDP && wantCRR) && rpEventMarkersForCG.size() > 1) {
                    // Need 2 event markers for CLR
                    returnMap.put(rpCG, rpEventMarkersForCG);
                    // Go to the next CG
                    break;
                } else if ((wantCDP && wantCRR) && rpEventMarkersForCG.size() < 2) {
                    logger.error("Didn't find enough bookmarks for CG: " + rpCG.getName() + ". Going to sleep and retry.");
                } else if (!rpEventMarkersForCG.isEmpty()) {
                    // Either want CDP or CRR and we found at least 1
                    returnMap.put(rpCG, rpEventMarkersForCG);
                    // Go to the next CG
                    break;
                } else {
                    logger.error("Didn't find enough bookmarks for CG: " + rpCG.getName() + ". Going to sleep and retry.");
                }
            } else {
                // Didn't get what we wanted
                logger.error("Didn't find any bookmarks for CG: " + rpCG.getName() + ". Going to sleep and retry.");
            }
            try {
                Thread.sleep(Long.valueOf((secondsToWaitForRetry * numMillisInSecond)));
            } catch (InterruptedException e) {
            // NOSONAR
            // It's ok to ignore this
            }
        }
    }
    if (returnMap.size() != rpCGSet.size()) {
        throw RecoverPointException.exceptions.failedToFindExpectedBookmarks();
    }
    return returnMap;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) RPConsistencyGroup(com.emc.storageos.recoverpoint.objectmodel.RPConsistencyGroup) RPBookmark(com.emc.storageos.recoverpoint.objectmodel.RPBookmark)

Example 8 with RPConsistencyGroup

use of com.emc.storageos.recoverpoint.objectmodel.RPConsistencyGroup in project coprhd-controller by CoprHD.

the class RecoverPointBookmarkManagementUtils method createCGBookmarks.

/**
 * Create bookmarks for a CG
 *
 * @param impl - RP handle to use for RP operations
 * @param rpCGMap - The mapping of RP CGs to WWNs. Used to create a list of CGs to bookmark
 * @param request - Information about the bookmark to request
 *
 * @return CreateBookmarkResponse - Results of the create bookmark.
 *         TODO: Return bookmark information (date/time)
 *
 * @throws RecoverPointException
 */
public CreateBookmarkResponse createCGBookmarks(FunctionalAPIImpl impl, Map<String, RPConsistencyGroup> rpCGMap, CreateBookmarkRequestParams request) throws RecoverPointException {
    Set<ConsistencyGroupUID> uniqueCGUIDSet = new HashSet<ConsistencyGroupUID>();
    List<ConsistencyGroupUID> uniqueCGUIDlist = new LinkedList<ConsistencyGroupUID>();
    Set<RPConsistencyGroup> rpCGSet = new HashSet<RPConsistencyGroup>();
    CreateBookmarkResponse response = new CreateBookmarkResponse();
    for (String volume : rpCGMap.keySet()) {
        RPConsistencyGroup rpCG = rpCGMap.get(volume);
        if (rpCG.getCGUID() != null) {
            boolean foundCGUID = false;
            ConsistencyGroupUID cguid = rpCG.getCGUID();
            for (ConsistencyGroupUID cguidunique : uniqueCGUIDSet) {
                if (cguidunique.getId() == cguid.getId()) {
                    foundCGUID = true;
                    break;
                }
            }
            if (!foundCGUID) {
                logger.info("Adding CG: " + rpCG.getName() + " with ID " + rpCG.getCGUID().getId() + " to unique CGUID list");
                uniqueCGUIDSet.add(cguid);
                uniqueCGUIDlist.add(cguid);
                rpCGSet.add(rpCG);
            }
        }
    }
    // Make sure the CG is in a good state before we make bookmarks
    RecoverPointImageManagementUtils imageManager = new RecoverPointImageManagementUtils();
    for (ConsistencyGroupUID cgID : uniqueCGUIDlist) {
        // Make sure the CG is ready for enable
        imageManager.waitForCGLinkState(impl, cgID, RecoverPointImageManagementUtils.getPipeActiveState(impl, cgID), PipeState.PAUSED);
    }
    try {
        impl.createBookmark(uniqueCGUIDlist, request.getBookmark(), BookmarkConsolidationPolicy.NEVER_CONSOLIDATE, SnapshotConsistencyType.APPLICATION_CONSISTENT);
        logger.info(String.format("Created RP Bookmark successfully: %s", request.getBookmark()));
        response.setCgBookmarkMap(findRPBookmarks(impl, rpCGSet, request));
        response.setReturnCode(RecoverPointReturnCode.SUCCESS);
    } catch (FunctionalAPIActionFailedException_Exception | FunctionalAPIInternalError_Exception e) {
        throw RecoverPointException.exceptions.failedToCreateBookmarkOnRecoverPoint(e);
    }
    return response;
}
Also used : FunctionalAPIActionFailedException_Exception(com.emc.fapiclient.ws.FunctionalAPIActionFailedException_Exception) LinkedList(java.util.LinkedList) RPConsistencyGroup(com.emc.storageos.recoverpoint.objectmodel.RPConsistencyGroup) CreateBookmarkResponse(com.emc.storageos.recoverpoint.responses.CreateBookmarkResponse) FunctionalAPIInternalError_Exception(com.emc.fapiclient.ws.FunctionalAPIInternalError_Exception) ConsistencyGroupUID(com.emc.fapiclient.ws.ConsistencyGroupUID) HashSet(java.util.HashSet)

Aggregations

RPConsistencyGroup (com.emc.storageos.recoverpoint.objectmodel.RPConsistencyGroup)8 HashSet (java.util.HashSet)7 FunctionalAPIActionFailedException_Exception (com.emc.fapiclient.ws.FunctionalAPIActionFailedException_Exception)4 FunctionalAPIInternalError_Exception (com.emc.fapiclient.ws.FunctionalAPIInternalError_Exception)4 RPCopy (com.emc.storageos.recoverpoint.objectmodel.RPCopy)4 RecoverPointBookmarkManagementUtils (com.emc.storageos.recoverpoint.utils.RecoverPointBookmarkManagementUtils)4 CreateBookmarkRequestParams (com.emc.storageos.recoverpoint.requests.CreateBookmarkRequestParams)3 RecoverPointImageManagementUtils (com.emc.storageos.recoverpoint.utils.RecoverPointImageManagementUtils)3 ConsistencyGroupCopyUID (com.emc.fapiclient.ws.ConsistencyGroupCopyUID)2 ConsistencyGroupUID (com.emc.fapiclient.ws.ConsistencyGroupUID)2 RPBookmark (com.emc.storageos.recoverpoint.objectmodel.RPBookmark)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 ClusterUID (com.emc.fapiclient.ws.ClusterUID)1 ConsistencyGroupCopyState (com.emc.fapiclient.ws.ConsistencyGroupCopyState)1 ConsistencyGroupSettings (com.emc.fapiclient.ws.ConsistencyGroupSettings)1 ReplicationSetSettings (com.emc.fapiclient.ws.ReplicationSetSettings)1 UserVolumeSettings (com.emc.fapiclient.ws.UserVolumeSettings)1 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1