Search in sources :

Example 1 with PipeState

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

the class RecoverPointImageManagementUtils method waitForCGLinkState.

/**
 * Wait for CG copy links to become ACTIVE
 *
 * @param cgUID - Consistency group we are looking at
 * @param desiredPipeState - Desired state of the pipe
 * @param port - RP handle to use for RP operations
 *
 * @return void
 *
 * @throws RecoverPointException, FunctionalAPIActionFailedException_Exception, FunctionalAPIInternalError_Exception,
 *             InterruptedException
 */
public void waitForCGLinkState(FunctionalAPIImpl impl, ConsistencyGroupUID cgUID, PipeState... desiredPipeState) throws RecoverPointException {
    int numRetries = 0;
    String cgName = null;
    try {
        cgName = impl.getGroupName(cgUID);
    } catch (FunctionalAPIActionFailedException_Exception e) {
        throw RecoverPointException.exceptions.cantCheckLinkState(cgName, e);
    } catch (FunctionalAPIInternalError_Exception e) {
        throw RecoverPointException.exceptions.cantCheckLinkState(cgName, e);
    }
    boolean isInitializing = false;
    boolean allLinksInDesiredState = false;
    int maxRetries = getLinkStateWaitTime() * 4;
    logger.debug("CG link state wait time is {} min and Max retry is {}", getLinkStateWaitTime(), maxRetries);
    while ((!allLinksInDesiredState && numRetries++ < maxRetries) || isInitializing) {
        ConsistencyGroupState cgState = null;
        isInitializing = false;
        try {
            cgState = impl.getGroupState(cgUID);
            List<String> desiredPipeStates = new ArrayList<String>();
            if (desiredPipeState != null) {
                // build the list of desired pipe states
                for (PipeState pipeState : desiredPipeState) {
                    desiredPipeStates.add(pipeState.name());
                }
            }
            // allLinksInDesiredState = true;
            for (ConsistencyGroupLinkState linkstate : cgState.getLinksStates()) {
                PipeState pipeState = linkstate.getPipeState();
                logger.info("CG link state is " + pipeState.toString() + "; desired states are: " + desiredPipeStates.toString());
                // Special consideration if we want the link to be in the active state.
                if (desiredPipeStates.contains(PipeState.ACTIVE.name())) {
                    if (PipeState.ACTIVE.equals(pipeState)) {
                        allLinksInDesiredState = true;
                    } else if (PipeState.STAND_BY.equals(pipeState)) {
                        // STAND_BY is a valid state for a MetroPoint link but we need
                        // an ACTIVE link state as well.
                        logger.info("CG link state is STAND_BY, valid state for MetroPoint.");
                    } else if (PipeState.PAUSED.equals(pipeState)) {
                        if (desiredPipeStates.contains(PipeState.PAUSED.name())) {
                            // When DIRECT_ACCESS mode is set on a target copy, the link will be paused. If one of
                            // the desired states is PAUSED, we must respect that and not attempt to start group
                            // transfer.
                            logger.info("CG link state is PAUSED.");
                            allLinksInDesiredState = true;
                        } else {
                            // We only want to start group transfer if the only desired state is the active state. When
                            // target copies are in DIRECT_ACCESS mode, the link will be paused and we do not want
                            // to resume group transfer.
                            logger.info("CG link state is PAUSED.  Resume link.");
                            impl.startGroupTransfer(cgUID);
                            allLinksInDesiredState = false;
                            break;
                        }
                    } else if (PipeState.INITIALIZING.equals(pipeState)) {
                        logger.info("CG link state is INITIALIZING.");
                        isInitializing = true;
                        allLinksInDesiredState = false;
                        break;
                    } else {
                        logger.info("CG link state is not active. It is: " + pipeState.toString());
                        allLinksInDesiredState = false;
                        break;
                    }
                } else if (desiredPipeStates.contains(PipeState.SNAP_IDLE.name())) {
                    if (PipeState.SNAP_IDLE.equals(pipeState) || PipeState.SNAP_SHIPPING.equals(pipeState)) {
                        allLinksInDesiredState = true;
                        break;
                    }
                } else {
                    // Other desired states (like UNKNOWN [inactive])
                    if (desiredPipeStates.contains(pipeState.name())) {
                        logger.info("CG link state matches the desired state.");
                        allLinksInDesiredState = true;
                    } else {
                        // This makes sure that if you wanted to act on the entire CG, but there's still a copy
                        // in the undesired state, we still need to wait for it.
                        logger.info("CG link state is not in desired state. It is: " + pipeState.toString());
                        allLinksInDesiredState = false;
                        break;
                    }
                }
            }
            if (allLinksInDesiredState) {
                return;
            } else {
                logger.info("All links not in desired state.  Sleep 15 seconds and retry");
                Thread.sleep(WAIT_FOR_LINKS_SLEEP_INTERVAL);
            }
        } catch (FunctionalAPIActionFailedException_Exception e) {
            throw RecoverPointException.exceptions.cantCheckLinkState(cgName, e);
        } catch (FunctionalAPIInternalError_Exception e) {
            throw RecoverPointException.exceptions.cantCheckLinkState(cgName, e);
        } catch (InterruptedException e) {
            throw RecoverPointException.exceptions.cantCheckLinkState(cgName, e);
        }
    }
    throw RecoverPointException.exceptions.cgLinksFailedToBecomeActive(cgName);
}
Also used : ConsistencyGroupLinkState(com.emc.fapiclient.ws.ConsistencyGroupLinkState) FunctionalAPIInternalError_Exception(com.emc.fapiclient.ws.FunctionalAPIInternalError_Exception) FunctionalAPIActionFailedException_Exception(com.emc.fapiclient.ws.FunctionalAPIActionFailedException_Exception) ArrayList(java.util.ArrayList) PipeState(com.emc.fapiclient.ws.PipeState) ConsistencyGroupState(com.emc.fapiclient.ws.ConsistencyGroupState)

Example 2 with PipeState

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

the class RecoverPointImageManagementUtils method waitForCGCopyLinkState.

/**
 * Wait for CG copy links to become ACTIVE
 *
 * @param impl access to RP
 * @param copyUID copy ID
 * @param desiredPipeState - Desired state of the pipe
 *
 * @return void
 *
 * @throws RecoverPointException, FunctionalAPIActionFailedException_Exception, FunctionalAPIInternalError_Exception,
 *             InterruptedException
 */
public void waitForCGCopyLinkState(FunctionalAPIImpl impl, ConsistencyGroupCopyUID copyUID, PipeState... desiredPipeState) throws RecoverPointException {
    int numRetries = 0;
    String cgName = null;
    try {
        cgName = impl.getGroupName(copyUID.getGroupUID());
    } catch (FunctionalAPIActionFailedException_Exception e) {
        throw RecoverPointException.exceptions.cantCheckLinkState(cgName, e);
    } catch (FunctionalAPIInternalError_Exception e) {
        throw RecoverPointException.exceptions.cantCheckLinkState(cgName, e);
    }
    List<String> desiredPipeStates = new ArrayList<String>();
    if (desiredPipeState != null) {
        // build the list of desired pipe states
        for (PipeState pipeState : desiredPipeState) {
            desiredPipeStates.add(pipeState.name());
        }
    }
    while (numRetries++ < MAX_RETRIES) {
        ConsistencyGroupState cgState = null;
        try {
            cgState = impl.getGroupState(copyUID.getGroupUID());
            for (ConsistencyGroupLinkState linkstate : cgState.getLinksStates()) {
                // The copy we're interested in may be in the FirstCopy or SecondCopy, so we need to find the link
                // state where our copy is the first or second copy and the other copy is a production. There may be
                // multiple production copies, so account for that, too. (you can assume there aren't multiple productions
                // going to the same target. We used to assume that the targets are "second copy", but that is not true.
                boolean found = false;
                // Loop through production copies
                if (!cgState.getSourceCopiesUIDs().isEmpty()) {
                    for (ConsistencyGroupCopyUID groupCopyUID : cgState.getSourceCopiesUIDs()) {
                        if (RecoverPointUtils.copiesEqual(linkstate.getGroupLinkUID().getFirstCopy(), groupCopyUID.getGlobalCopyUID()) && RecoverPointUtils.copiesEqual(linkstate.getGroupLinkUID().getSecondCopy(), copyUID.getGlobalCopyUID())) {
                            found = true;
                        }
                        if (RecoverPointUtils.copiesEqual(linkstate.getGroupLinkUID().getSecondCopy(), groupCopyUID.getGlobalCopyUID()) && RecoverPointUtils.copiesEqual(linkstate.getGroupLinkUID().getFirstCopy(), copyUID.getGlobalCopyUID())) {
                            found = true;
                        }
                    }
                } else {
                    // the link source and copy. Just find our copy in the link and go with it.
                    if (RecoverPointUtils.copiesEqual(linkstate.getGroupLinkUID().getFirstCopy(), copyUID.getGlobalCopyUID()) || RecoverPointUtils.copiesEqual(linkstate.getGroupLinkUID().getSecondCopy(), copyUID.getGlobalCopyUID())) {
                        found = true;
                    }
                }
                if (!found) {
                    continue;
                }
                if (desiredPipeStates.contains(PipeState.ACTIVE.name())) {
                    // Treat SNAP_IDLE as ACTIVE
                    if (linkstate.getPipeState().equals(PipeState.SNAP_IDLE)) {
                        linkstate.setPipeState(PipeState.ACTIVE);
                    }
                }
                PipeState pipeState = linkstate.getPipeState();
                logger.info("Copy link state is " + pipeState.toString() + "; desired states are: " + desiredPipeStates.toString());
                if (desiredPipeStates.contains(pipeState.name())) {
                    logger.info("Copy link state matches the desired state.");
                    return;
                } else {
                    // This makes sure that if you wanted to act on the entire CG, but there's still a copy
                    // in the undesired state, we still need to wait for it.
                    logger.info("Copy link state is not in desired state. It is: " + pipeState.toString());
                    break;
                }
            }
            logger.info("Copy link not in desired state.  Sleep 15 seconds and retry");
            Thread.sleep(WAIT_FOR_LINKS_SLEEP_INTERVAL);
        } catch (FunctionalAPIActionFailedException_Exception e) {
            throw RecoverPointException.exceptions.cantCheckLinkState(cgName, e);
        } catch (FunctionalAPIInternalError_Exception e) {
            throw RecoverPointException.exceptions.cantCheckLinkState(cgName, e);
        } catch (InterruptedException e) {
            throw RecoverPointException.exceptions.cantCheckLinkState(cgName, e);
        }
    }
    throw RecoverPointException.exceptions.cgLinksFailedToBecomeActive(cgName);
}
Also used : ConsistencyGroupLinkState(com.emc.fapiclient.ws.ConsistencyGroupLinkState) FunctionalAPIInternalError_Exception(com.emc.fapiclient.ws.FunctionalAPIInternalError_Exception) FunctionalAPIActionFailedException_Exception(com.emc.fapiclient.ws.FunctionalAPIActionFailedException_Exception) ArrayList(java.util.ArrayList) PipeState(com.emc.fapiclient.ws.PipeState) ConsistencyGroupState(com.emc.fapiclient.ws.ConsistencyGroupState) ConsistencyGroupCopyUID(com.emc.fapiclient.ws.ConsistencyGroupCopyUID)

Aggregations

ConsistencyGroupLinkState (com.emc.fapiclient.ws.ConsistencyGroupLinkState)2 ConsistencyGroupState (com.emc.fapiclient.ws.ConsistencyGroupState)2 FunctionalAPIActionFailedException_Exception (com.emc.fapiclient.ws.FunctionalAPIActionFailedException_Exception)2 FunctionalAPIInternalError_Exception (com.emc.fapiclient.ws.FunctionalAPIInternalError_Exception)2 PipeState (com.emc.fapiclient.ws.PipeState)2 ArrayList (java.util.ArrayList)2 ConsistencyGroupCopyUID (com.emc.fapiclient.ws.ConsistencyGroupCopyUID)1