use of com.emc.fapiclient.ws.ConsistencyGroupState 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);
}
Aggregations