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;
}
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;
}
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;
}
Aggregations