Search in sources :

Example 1 with ImageAccessMode

use of com.emc.fapiclient.ws.ImageAccessMode in project coprhd-controller by CoprHD.

the class RecoverPointImageManagementUtils method waitForCGCopyState.

/**
 * Wait for a CG copy to change state
 *
 * @param port - RP handle to use for RP operations
 * @param groupCopy - RP group copy we are looking at
 * @param expectRollComplete - true or false we are expecting the state to be LOGGED_ACCESS_WITH_ROLL, and the roll is complete
 * @param accessMode - Access modes we are waiting for. Optional
 *
 * @return void
 *
 * @throws RecoverPointException, FunctionalAPIActionFailedException_Exception, FunctionalAPIInternalError_Exception,
 *             InterruptedException
 */
public void waitForCGCopyState(FunctionalAPIImpl port, ConsistencyGroupCopyUID groupCopy, boolean expectRollComplete, ImageAccessMode... accessMode) throws FunctionalAPIActionFailedException_Exception, FunctionalAPIInternalError_Exception, InterruptedException, RecoverPointException {
    ConsistencyGroupUID groupUID = groupCopy.getGroupUID();
    List<ConsistencyGroupCopyState> groupCopyStateList;
    // groupCopyStateList = groupState.getGroupCopiesState();
    String cgName = port.getGroupName(groupCopy.getGroupUID());
    String cgCopyName = port.getGroupCopyName(groupCopy);
    final int maxMinutes = 30;
    // seconds
    final int sleepTimeSeconds = 15;
    final int secondsPerMin = 60;
    final int numItersPerMin = secondsPerMin / sleepTimeSeconds;
    List<ImageAccessMode> accessModes = new ArrayList<ImageAccessMode>();
    if (accessMode != null) {
        accessModes = Arrays.asList(accessMode);
    }
    logger.info("waitForCGCopyState called for copy " + cgCopyName + " of group " + cgName);
    if (!accessModes.isEmpty()) {
        logger.info("Waiting up to " + maxMinutes + " minutes for state to change to: " + accessModes.toString());
    } else {
        logger.info("Waiting up to " + maxMinutes + " minutes for state to change to: DIRECT_ACCESS or NO_ACCESS");
    }
    for (int minIter = 0; minIter < maxMinutes; minIter++) {
        for (int perMinIter = 0; perMinIter < numItersPerMin; perMinIter++) {
            groupCopyStateList = port.getGroupState(groupUID).getGroupCopiesStates();
            for (ConsistencyGroupCopyState groupCopyState : groupCopyStateList) {
                if (RecoverPointUtils.copiesEqual(groupCopyState.getCopyUID(), groupCopy)) {
                    StorageAccessState copyAccessState = groupCopyState.getStorageAccessState();
                    logger.info("Current Copy Access State: " + copyAccessState);
                    if (accessModes.contains(ImageAccessMode.LOGGED_ACCESS)) {
                        // HACK HACK HACK WJE had to add check for no access journal preserved, otherwise my restore wouldn't continue
                        if (copyAccessState == StorageAccessState.LOGGED_ACCESS || copyAccessState == StorageAccessState.NO_ACCESS_JOURNAL_PRESERVED) {
                            logger.info("Copy " + cgCopyName + " of group " + cgName + " is in logged access.  Enable has completed");
                            return;
                        }
                    } else if (accessModes.contains(ImageAccessMode.VIRTUAL_ACCESS)) {
                        if (copyAccessState == StorageAccessState.VIRTUAL_ACCESS) {
                            logger.info("Copy " + cgCopyName + " of group " + cgName + " is in virtual access.  Enable has completed");
                            return;
                        }
                    } else if (accessModes.contains(ImageAccessMode.VIRTUAL_ACCESS_WITH_ROLL)) {
                        if (expectRollComplete) {
                            if (copyAccessState == StorageAccessState.LOGGED_ACCESS_ROLL_COMPLETE) {
                                logger.info("Copy " + cgCopyName + " of group " + cgName + " is in virtual access with roll complete.  Enable has completed");
                                return;
                            }
                        } else {
                            if ((copyAccessState == StorageAccessState.VIRTUAL_ACCESS_ROLLING_IMAGE) || (copyAccessState == StorageAccessState.LOGGED_ACCESS_ROLL_COMPLETE)) {
                                logger.info("Copy " + cgCopyName + " of group " + cgName + " is in virtual access with roll or roll complete.  Enable has completed");
                                return;
                            }
                        }
                    } else {
                        // Wait for NO_ACCESS or DIRECT_ACCESS
                        if (copyAccessState == StorageAccessState.DIRECT_ACCESS) {
                            logger.info("Copy " + cgCopyName + " of group " + cgName + " is DIRECT_ACCESS mode");
                            return;
                        }
                        if (copyAccessState == StorageAccessState.NO_ACCESS) {
                            logger.info("Copy " + cgCopyName + " of group " + cgName + " is NO_ACCESS mode");
                            return;
                        }
                    }
                }
            }
            logger.info("Copy image " + cgCopyName + " of group " + cgName + " not in correct state.  Sleeping " + sleepTimeSeconds + " seconds");
            Thread.sleep(Long.valueOf(sleepTimeSeconds * numMillisInSecond));
        }
    }
    throw RecoverPointException.exceptions.stateChangeNeverCompleted();
}
Also used : ImageAccessMode(com.emc.fapiclient.ws.ImageAccessMode) ConsistencyGroupCopyState(com.emc.fapiclient.ws.ConsistencyGroupCopyState) ConsistencyGroupUID(com.emc.fapiclient.ws.ConsistencyGroupUID) ArrayList(java.util.ArrayList) StorageAccessState(com.emc.fapiclient.ws.StorageAccessState)

Aggregations

ConsistencyGroupCopyState (com.emc.fapiclient.ws.ConsistencyGroupCopyState)1 ConsistencyGroupUID (com.emc.fapiclient.ws.ConsistencyGroupUID)1 ImageAccessMode (com.emc.fapiclient.ws.ImageAccessMode)1 StorageAccessState (com.emc.fapiclient.ws.StorageAccessState)1 ArrayList (java.util.ArrayList)1