use of com.emc.fapiclient.ws.StorageAccessState 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();
}
use of com.emc.fapiclient.ws.StorageAccessState in project coprhd-controller by CoprHD.
the class RecoverPointImageManagementUtils method isGroupCopyImageEnabledForAPIT.
/**
* Verify that a group copy image is enabled for an APIT time. Not a "wait for", just a check
*
* @param port - RP handle to use for RP operations
* @param groupCopy - CG copy we are checking
* @param expectLoggedAccess - We are explicitly checking for LOGGED_ACCESS
* @param apitTime - An APIT time we are expecting to be enabled)
*
* @return boolean - true (enabled) or false (not enabled)
*
* @throws RecoverPointException, FunctionalAPIActionFailedException_Exception, FunctionalAPIInternalError_Exception,
* InterruptedException
*/
private boolean isGroupCopyImageEnabledForAPIT(FunctionalAPIImpl port, ConsistencyGroupCopyUID groupCopy, boolean expectLoggedAccess, RecoverPointTimeStamp apitTime) throws FunctionalAPIActionFailedException_Exception, FunctionalAPIInternalError_Exception, RecoverPointException {
ConsistencyGroupUID groupUID = groupCopy.getGroupUID();
ConsistencyGroupState groupState;
List<ConsistencyGroupCopyState> groupCopyStateList;
groupState = port.getGroupState(groupUID);
groupCopyStateList = groupState.getGroupCopiesStates();
String cgName = port.getGroupName(groupCopy.getGroupUID());
String cgCopyName = port.getGroupCopyName(groupCopy);
Timestamp enabledApitTime = null;
// logger.debug ("isGroupCopyImageEnabledForAPIT called for copy " + cgCopyName + " of group " + cgName);
for (ConsistencyGroupCopyState groupCopyState : groupCopyStateList) {
if (RecoverPointUtils.copiesEqual(groupCopyState.getCopyUID(), groupCopy)) {
StorageAccessState accessState = groupCopyState.getStorageAccessState();
if (accessState == StorageAccessState.DIRECT_ACCESS) {
// Not enabled
logger.info("Copy image copy " + cgCopyName + " of group " + cgName + " is in direct access mode.");
return false;
}
if (accessState == StorageAccessState.NO_ACCESS) {
// Not enabled
logger.info("Copy image copy " + cgCopyName + " of group " + cgName + " is in NO access mode.");
return false;
}
// Enabled. Check out the details
logger.info("Copy image copy " + cgCopyName + " of group " + cgName + " IS enabled. State is: " + accessState.toString());
if (groupCopyState.getAccessedImage().getDescription().isEmpty()) {
RecoverPointTimeStamp enabledTimeDisplay = groupCopyState.getAccessedImage().getClosingTimeStamp();
enabledApitTime = new Timestamp(enabledTimeDisplay.getTimeInMicroSeconds() / numMicroSecondsInMilli);
logger.debug("No name. Mounted snapshot timestamp: " + enabledApitTime.toString());
} else {
// Unexpected, this is
throw RecoverPointException.exceptions.expectingAPITMountFoundBookmark(groupCopyState.getAccessedImage().getDescription());
}
// Let's throw if its the wrong image
if (apitTime != null) {
//
// See if the time enabled is exactly the time we requested (regardless of whether it is
// system generated, or AppSync generated.
//
RecoverPointTimeStamp enabledTime = groupCopyState.getAccessedImage().getClosingTimeStamp();
// Give it a 60 second variation
if (Math.abs(enabledTime.getTimeInMicroSeconds() - apitTime.getTimeInMicroSeconds()) < (numMicroSecondsInSecond * 60)) {
//
if (expectLoggedAccess) {
logger.debug("Seeing if copy is enabled for LOGGED_ACCESS");
if (accessState == StorageAccessState.LOGGED_ACCESS) {
logger.info("Copy image copy " + cgCopyName + " of group " + cgName + " IS enabled in LOGGED_ACCESS");
return true;
}
logger.info("Copy image copy " + cgCopyName + " of group " + cgName + " is NOT enabled in LOGGED_ACCESS. Image state is: " + accessState.toString());
return false;
} else {
logger.debug("APIT enabled for same time requested");
return true;
}
}
//
// It IS possible that an APIT image is not quite exactly the same time requested, but it is "close enough"
// How do we tell? Well, we get the list of system snaps + or - 5 minutes from requested time, see if the one before the
// requested APIT time is the one we are looking for. Limit the snaps we look at to 1 hour before/after requested APIT
// time
//
final Long timeDeviationInMicroSeconds = Long.valueOf(5 * 60 * numMicroSecondsInMilli * numMillisInSecond);
TimeFrame window = new TimeFrame();
RecoverPointTimeStamp endTime = new RecoverPointTimeStamp();
RecoverPointTimeStamp startTime = new RecoverPointTimeStamp();
RecoverPointTimeStamp prevSnapTime = null;
// RecoverPointTimeStamp now = new RecoverPointTimeStamp();
// now.setTimeInMicroSeconds (System.currentTimeMillis() * numMicroSecondsInMilli );
// endTime.setTimeInMicroSeconds(now.getTimeInMicroSeconds() + timeDeviationInMicroSeconds);
// startTime.setTimeInMicroSeconds(now.getTimeInMicroSeconds() - timeDeviationInMicroSeconds);
endTime.setTimeInMicroSeconds(apitTime.getTimeInMicroSeconds() + timeDeviationInMicroSeconds);
startTime.setTimeInMicroSeconds(apitTime.getTimeInMicroSeconds() - timeDeviationInMicroSeconds);
window.setStartTime(startTime);
window.setEndTime(endTime);
// + " snapshots in the timeframe");
for (Snapshot snapItem : port.getGroupCopySnapshotsForTimeFrameAndName(groupCopy, window, null).getSnapshots()) {
// logger.info("Checking snap with time: " + apitTimeStr.toString());
if (prevSnapTime == null) {
prevSnapTime = snapItem.getClosingTimeStamp();
} else {
if (prevSnapTime.getTimeInMicroSeconds() < snapItem.getClosingTimeStamp().getTimeInMicroSeconds()) {
prevSnapTime = snapItem.getClosingTimeStamp();
}
}
}
if (prevSnapTime != null) {
RecoverPointTimeStamp enabledTimeDisplay = groupCopyState.getAccessedImage().getClosingTimeStamp();
enabledApitTime = new Timestamp(enabledTimeDisplay.getTimeInMicroSeconds() / numMicroSecondsInMilli);
logger.debug("Previous snap time is : " + enabledApitTime.toString());
if (Math.abs(enabledTime.getTimeInMicroSeconds() - prevSnapTime.getTimeInMicroSeconds()) < numMicroSecondsInSecond) {
logger.debug("Currently enabled image is requested snap!");
if (expectLoggedAccess) {
logger.debug("Seeing if copy is enabled for LOGGED_ACCESS");
if (accessState == StorageAccessState.LOGGED_ACCESS) {
logger.info("Copy image copy " + cgCopyName + " of group " + cgName + " IS enabled in LOGGED_ACCESS");
return true;
}
logger.info("Copy image copy " + cgCopyName + " of group " + cgName + " is NOT enabled in LOGGED_ACCESS. Image state is: " + accessState.toString());
return false;
} else {
return true;
}
} else {
throw RecoverPointException.exceptions.wrongTimestampEnabled(enabledApitTime);
}
}
} else {
return false;
}
}
}
logger.error("Could not locate CG copy state");
return false;
}
use of com.emc.fapiclient.ws.StorageAccessState in project coprhd-controller by CoprHD.
the class RecoverPointClient method getCopyAccessStates.
/**
* Checks to see if the given copy is in direct access state.
*
* @param copyToExamine the copy to check for direct access state
* @return true if the given copy is in direct access state, false otherwise
*/
public Map<String, String> getCopyAccessStates(Set<String> rpWWNs) {
Map<String, String> copyAccessStates = new HashMap<String, String>();
if (rpWWNs != null) {
for (String wwn : rpWWNs) {
RecoverPointVolumeProtectionInfo protectionInfo = getProtectionInfoForVolume(wwn);
ConsistencyGroupCopyUID cgCopyUID = RecoverPointUtils.mapRPVolumeProtectionInfoToCGCopyUID(protectionInfo);
if (cgCopyUID != null) {
RecoverPointImageManagementUtils imageManager = new RecoverPointImageManagementUtils();
ConsistencyGroupCopyState copyState = imageManager.getCopyState(functionalAPI, cgCopyUID);
if (copyState != null) {
StorageAccessState copyAccessState = copyState.getStorageAccessState();
copyAccessStates.put(wwn, copyAccessState.name());
}
}
}
}
logger.info(String.format("Access states for requested copies: %s", copyAccessStates));
return copyAccessStates;
}
use of com.emc.fapiclient.ws.StorageAccessState in project coprhd-controller by CoprHD.
the class RecoverPointImageManagementUtils method verifyGroupCopyImageIsEnabled.
/**
* Verify that a group copy image is enabled. Not a "wait for", just a check
*
* @param port - RP handle to use for RP operations
* @param groupCopy - CG copy we are checking
* @param expectLoggedAccess - We are explicitly checking for LOGGED_ACCESS
* @param bookmarkName - A bookmark we are expecting to be enabled (null means don't care)
*
* @return boolean - true (enabled) or false (not enabled)
*
* @throws RecoverPointException, FunctionalAPIActionFailedException_Exception, FunctionalAPIInternalError_Exception,
* InterruptedException
*/
private boolean verifyGroupCopyImageIsEnabled(FunctionalAPIImpl port, ConsistencyGroupCopyUID groupCopy, boolean expectLoggedAccess, String bookmarkName) throws FunctionalAPIActionFailedException_Exception, FunctionalAPIInternalError_Exception, RecoverPointException {
ConsistencyGroupUID groupUID = groupCopy.getGroupUID();
ConsistencyGroupState groupState;
List<ConsistencyGroupCopyState> groupCopyStateList;
groupState = port.getGroupState(groupUID);
groupCopyStateList = groupState.getGroupCopiesStates();
String cgName = port.getGroupName(groupCopy.getGroupUID());
String cgCopyName = port.getGroupCopyName(groupCopy);
boolean isAPITCheck = false;
RecoverPointTimeStamp apitTimeStamp = null;
if (bookmarkName == null) {
// Most "recent"
isAPITCheck = true;
} else {
apitTimeStamp = new RecoverPointTimeStamp();
isAPITCheck = true;
apitTimeStamp.setTimeInMicroSeconds(Long.parseLong(bookmarkName) * numMicroSecondsInMilli);
}
logger.info("verifyGroupCopyImageIsEnabled called for copy " + cgCopyName + " of group " + cgName + " and bookmarkName/APIT: " + bookmarkName);
for (ConsistencyGroupCopyState groupCopyState : groupCopyStateList) {
if (RecoverPointUtils.copiesEqual(groupCopyState.getCopyUID(), groupCopy)) {
StorageAccessState accessState = groupCopyState.getStorageAccessState();
if (expectLoggedAccess) {
// Explicitly looking for LOGGED_ACCESS
logger.debug("Seeing if copy is enabled for LOGGED_ACCESS");
if (accessState == StorageAccessState.LOGGED_ACCESS) {
if (!bookmarkName.equals(groupCopyState.getAccessedImage().getDescription())) {
// Enabled, but for a different snapshot image
if (groupCopyState.getAccessedImage().getDescription().length() > 0) {
throw RecoverPointException.exceptions.wrongSnapshotImageEnabled(bookmarkName, groupCopyState.getAccessedImage().getDescription());
} else {
Timestamp enabledAPITTime = null;
RecoverPointTimeStamp enabledTimeDisplay = groupCopyState.getAccessedImage().getClosingTimeStamp();
enabledAPITTime = new Timestamp(enabledTimeDisplay.getTimeInMicroSeconds() / numMicroSecondsInMilli);
throw RecoverPointException.exceptions.wrongSnapshotImageEnabled(bookmarkName, enabledAPITTime.toString());
}
}
logger.info("Copy image copy " + cgCopyName + " of group " + cgName + " IS enabled in LOGGED_ACCESS");
return true;
} else {
logger.info("Copy image copy " + cgCopyName + " of group " + cgName + " is NOT enabled in LOGGED_ACCESS. Image state is: " + accessState.toString());
return false;
}
}
logger.debug("Seeing if copy is enabled for any access mode other than DIRECT_ACCESS or NO_ACCESS");
if (accessState == StorageAccessState.DIRECT_ACCESS) {
logger.info("Copy image copy " + cgCopyName + " of group " + cgName + " is in direct access mode");
return false;
}
if (accessState == StorageAccessState.NO_ACCESS) {
logger.info("Copy image copy " + cgCopyName + " of group " + cgName + " is in NO access mode");
return false;
}
if (groupCopyState.getAccessedImage() != null) {
logger.info("Copy image IS enabled. State is: " + accessState.toString() + ". Mounted snapshot name: " + groupCopyState.getAccessedImage().getDescription());
} else {
logger.info("Copy image IS enabled. State is: " + accessState.toString() + ". Enabled image: restore state");
}
// Let's throw if its the wrong image, otherwise return true
if (!isAPITCheck) {
if ((bookmarkName == null) && (groupCopyState.getAccessedImage() == null)) {
return true;
}
if ((bookmarkName != null) && !bookmarkName.equals(groupCopyState.getAccessedImage().getDescription())) {
// Enabled, but for a different snapshot image
if (groupCopyState.getAccessedImage().getDescription().length() > 0) {
throw RecoverPointException.exceptions.wrongSnapshotImageEnabled(bookmarkName, groupCopyState.getAccessedImage().getDescription());
} else {
Timestamp enabledAPITTime = null;
RecoverPointTimeStamp enabledTimeDisplay = groupCopyState.getAccessedImage().getClosingTimeStamp();
enabledAPITTime = new Timestamp(enabledTimeDisplay.getTimeInMicroSeconds() / numMicroSecondsInMilli);
throw RecoverPointException.exceptions.wrongSnapshotImageEnabled(bookmarkName, enabledAPITTime.toString());
}
}
return true;
} else {
if (bookmarkName == null) {
return true;
} else {
return isGroupCopyImageEnabledForAPIT(port, groupCopy, expectLoggedAccess, apitTimeStamp);
}
}
}
}
logger.error("Could not locate CG copy state");
return false;
}
use of com.emc.fapiclient.ws.StorageAccessState in project coprhd-controller by CoprHD.
the class RecoverPointImageManagementUtils method verifyCopyCapableOfEnableImageAccess.
/**
* Verify that a copy is capable of being enabled.
*
* @param impl - RP handle
* @param cgCopy - CG Copy, contains CG
* @param failover - for a failover operation?
* @return true if the copy is capable of enable image access, false if it's in some other state
* @throws RecoverPointException
*/
public boolean verifyCopyCapableOfEnableImageAccess(FunctionalAPIImpl impl, ConsistencyGroupCopyUID cgCopy, String copyToEnable, boolean failover) throws RecoverPointException {
String cgCopyName = NAME_UNKNOWN;
String cgName = NAME_UNKNOWN;
try {
cgCopyName = impl.getGroupCopyName(cgCopy);
cgName = impl.getGroupName(cgCopy.getGroupUID());
ConsistencyGroupCopyState cgCopyState = getCopyState(impl, cgCopy);
if (cgCopyState != null) {
StorageAccessState copyAccessState = cgCopyState.getStorageAccessState();
logger.info("Current Copy Access State: " + copyAccessState);
// Check for NO_ACCESS state (or LOGGED ACCESS for failover)
if (copyAccessState == StorageAccessState.NO_ACCESS) {
return true;
}
// Failover-test state
if ((copyAccessState == StorageAccessState.LOGGED_ACCESS) && failover) {
ConsistencyGroupLinkState cgLinkState = getCopyLinkState(impl, cgCopy);
if ((cgLinkState != null) && (cgLinkState.getPipeState() == PipeState.PAUSED)) {
return true;
}
}
// return true if CG is already in LOGGED_ACCESS state
if (copyAccessState == StorageAccessState.LOGGED_ACCESS && cgCopyState.getAccessedImage().getDescription().equals(copyToEnable)) {
return true;
}
}
return false;
} catch (FunctionalAPIActionFailedException_Exception e) {
throw RecoverPointException.exceptions.failedToEnableCopy(cgCopyName, cgName, e);
} catch (FunctionalAPIInternalError_Exception e) {
throw RecoverPointException.exceptions.failedToEnableCopy(cgCopyName, cgName, e);
}
}
Aggregations