use of com.emc.storageos.db.client.model.ProtectionSet in project coprhd-controller by CoprHD.
the class RPDeviceController method cgCreateStep.
/**
* Workflow step method for creating/updating a consistency group.
*
* @param rpSystemId
* RP system Id
* @param recommendation
* parameters needed to create the CG
* @param token
* the task
* @return
* @throws InternalException
*/
public boolean cgCreateStep(URI rpSystemId, List<VolumeDescriptor> volumeDescriptors, String token) throws InternalException {
RecoverPointClient rp;
CGRequestParams cgParams = null;
boolean metropoint = false;
boolean lockException = false;
try {
// Get only the RP volumes from the descriptors.
List<VolumeDescriptor> sourceVolumeDescriptors = VolumeDescriptor.filterByType(volumeDescriptors, new VolumeDescriptor.Type[] { VolumeDescriptor.Type.RP_SOURCE, VolumeDescriptor.Type.RP_EXISTING_SOURCE, VolumeDescriptor.Type.RP_VPLEX_VIRT_SOURCE }, new VolumeDescriptor.Type[] {});
WorkflowStepCompleter.stepExecuting(token);
ProtectionSystem rpSystem = _dbClient.queryObject(ProtectionSystem.class, rpSystemId);
URI cgId = volumeDescriptors.iterator().next().getCapabilitiesValues().getBlockConsistencyGroup();
boolean attachAsClean = true;
for (VolumeDescriptor sourceVolumedescriptor : sourceVolumeDescriptors) {
Volume sourceVolume = _dbClient.queryObject(Volume.class, sourceVolumedescriptor.getVolumeURI());
metropoint = RPHelper.isMetroPointVolume(_dbClient, sourceVolume);
// if this is a change vpool, attachAsClean should be false so that source and target are synchronized
if (VolumeDescriptor.Type.RP_EXISTING_SOURCE.equals(sourceVolumedescriptor.getType())) {
attachAsClean = false;
}
}
// Build the CG Request params
cgParams = getCGRequestParams(volumeDescriptors, rpSystem);
updateCGParams(cgParams);
// Validate the source/target volumes before creating a CG.
validateCGVolumes(volumeDescriptors);
rp = RPHelper.getRecoverPointClient(rpSystem);
// Scan the rp sites for volume visibility
rp.waitForVolumesToBeVisible(cgParams);
// Before acquiring a lock on the CG we need to ensure that the
// CG is created. If it hasn't, then the first CGRequestParams
// to be allowed to pass through needs to have the journals
// defined.
//
// NOTE: The CG may not yet be created on the RP protection system and
// that's OK since this might be the first request going in.
waitForCGToBeCreated(cgId, cgParams);
// lock around create and delete operations on the same CG
List<String> lockKeys = new ArrayList<String>();
lockKeys.add(ControllerLockingUtil.getConsistencyGroupStorageKey(_dbClient, cgId, rpSystem.getId()));
boolean lockAcquired = _workflowService.acquireWorkflowStepLocks(token, lockKeys, LockTimeoutValue.get(LockType.RP_CG));
if (!lockAcquired) {
lockException = true;
throw DeviceControllerException.exceptions.failedToAcquireLock(lockKeys.toString(), String.format("Create or add volumes to RP consistency group id: %s", cgId.toString()));
}
RecoverPointCGResponse response = null;
// The CG already exists if it contains volumes and is of type RP
_log.info("Submitting RP Request: " + cgParams);
BlockConsistencyGroup cg = _dbClient.queryObject(BlockConsistencyGroup.class, cgId);
// Check to see if the CG has been created in ViPR and on the RP protection system
boolean cgAlreadyExists = rpCGExists(cg, rp, cgParams.getCgName(), rpSystem.getId());
if (cgAlreadyExists) {
// cg exists in both the ViPR db and on the RP system
_log.info(String.format("RP CG [%s] already exists, adding replication set(s) to it...", cgParams.getCgName()));
response = rp.addReplicationSetsToCG(cgParams, metropoint, attachAsClean);
} else {
_log.info(String.format("RP CG [%s] does not already exist, creating it now and adding replication set(s) to it...", cgParams.getCgName()));
response = rp.createCG(cgParams, metropoint, attachAsClean);
// "Turn-on" the consistency group
cg = _dbClient.queryObject(BlockConsistencyGroup.class, cgParams.getCgUri());
cg.addSystemConsistencyGroup(rpSystemId.toString(), cgParams.getCgName());
cg.addConsistencyGroupTypes(Types.RP.name());
}
// At this point, always clear the journal provisioning lock on the
// CG for any concurrent orders that may come in.
cg.setJournalProvisioningLock(0L);
_dbClient.updateObject(cg);
setVolumeConsistencyGroup(volumeDescriptors, cgParams.getCgUri());
// If this was a vpool Update, now is a good time to update the vpool and Volume information
if (VolumeDescriptor.getVirtualPoolChangeVolume(volumeDescriptors) != null) {
Volume volume = _dbClient.queryObject(Volume.class, VolumeDescriptor.getVirtualPoolChangeVolume(volumeDescriptors));
URI newVpoolURI = getVirtualPoolChangeNewVirtualPool(volumeDescriptors);
volume.setVirtualPool(newVpoolURI);
volume.setPersonality(Volume.PersonalityTypes.SOURCE.toString());
volume.setAccessState(Volume.VolumeAccessState.READWRITE.name());
volume.setLinkStatus(Volume.LinkStatus.IN_SYNC.name());
volume.setProtectionController(rpSystemId);
_dbClient.updateObject(volume);
// We might need to update the vpools of the backing volumes if this is an RP+VPLEX
// or MetroPoint change vpool.
VPlexUtil.updateVPlexBackingVolumeVpools(volume, newVpoolURI, _dbClient);
// Record Audit operation. (virtualpool change only)
AuditBlockUtil.auditBlock(_dbClient, OperationTypeEnum.CHANGE_VOLUME_VPOOL, true, AuditLogManager.AUDITOP_END, token);
}
// Create the ProtectionSet to contain the CG UID (which is truly unique to the protection system)
if (response.getCgId() != null) {
List<ProtectionSet> protectionSets = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, ProtectionSet.class, AlternateIdConstraint.Factory.getConstraint(ProtectionSet.class, "protectionId", response.getCgId().toString()));
ProtectionSet protectionSet = null;
if (protectionSets.isEmpty()) {
// A protection set corresponding to the CG does not exist so we need to create one
protectionSet = createProtectionSet(rpSystem, cgParams, response.getCgId());
} else {
// Update the existing protection set. We will only have 1 protection set
// get the first one.
protectionSet = protectionSets.get(0);
protectionSet = updateProtectionSet(protectionSet, cgParams);
}
_dbClient.updateObject(protectionSet);
}
// Set the CG last created time to now.
rpSystem.setCgLastCreatedTime(Calendar.getInstance());
_dbClient.updateObject(rpSystem);
// Update the workflow state.
WorkflowStepCompleter.stepSucceded(token);
// collect and update the protection system statistics to account for
// the newly created CG.
_log.info("Collecting RP statistics post CG create.");
collectRPStatistics(rpSystem);
} catch (Exception e) {
if (lockException) {
List<URI> volUris = VolumeDescriptor.getVolumeURIs(volumeDescriptors);
ServiceError serviceError = DeviceControllerException.errors.createVolumesAborted(volUris.toString(), e);
doFailCgCreateStep(volumeDescriptors, cgParams, rpSystemId, token);
stepFailed(token, serviceError, "cgCreateStep");
} else {
doFailCgCreateStep(volumeDescriptors, cgParams, rpSystemId, token);
stepFailed(token, e, "cgCreateStep");
}
return false;
}
return true;
}
use of com.emc.storageos.db.client.model.ProtectionSet in project coprhd-controller by CoprHD.
the class RPHelper method getMetropointStandbyCopies.
/**
* Returns the list of copies residing on the standby varray given the active production volume in a
* Metropoint environment
*
* @param volume the active production volume
* @param dbClient DbClient ref
* @return returns the list of copies on the standby varray
*/
public static List<Volume> getMetropointStandbyCopies(Volume volume, DbClient dbClient) {
List<Volume> standbyCopies = new ArrayList<Volume>();
if (volume.getProtectionSet() == null) {
return standbyCopies;
}
ProtectionSet protectionSet = dbClient.queryObject(ProtectionSet.class, volume.getProtectionSet());
if (protectionSet.getVolumes() == null) {
return standbyCopies;
}
// look for the standby varray in the volume's vpool
VirtualPool vpool = dbClient.queryObject(VirtualPool.class, volume.getVirtualPool());
if (vpool == null) {
return standbyCopies;
}
StringMap varrayVpoolMap = vpool.getHaVarrayVpoolMap();
if (varrayVpoolMap != null && !varrayVpoolMap.isEmpty()) {
URI standbyVarrayId = URI.create(varrayVpoolMap.keySet().iterator().next());
// now loop through the replication set volumes and look for any copies from the standby varray
for (String rsetVolId : protectionSet.getVolumes()) {
Volume rsetVol = dbClient.queryObject(Volume.class, URI.create(rsetVolId));
if (rsetVol != null && !rsetVol.getInactive() && rsetVol.getRpTargets() != null) {
for (String targetVolId : rsetVol.getRpTargets()) {
Volume targetVol = dbClient.queryObject(Volume.class, URI.create(targetVolId));
if (targetVol.getVirtualArray().equals(standbyVarrayId)) {
standbyCopies.add(targetVol);
}
}
}
}
}
return standbyCopies;
}
use of com.emc.storageos.db.client.model.ProtectionSet in project coprhd-controller by CoprHD.
the class RPHelper method cleanupSnapshots.
/**
* Validate Block snapshots that correspond to RP bookmarks. Some may no longer exist in the RP system, and we
* need to mark them as invalid.
*
* The strategy is as follows:
* 1. Get all of the protection sets associated with the protection system
* 2. Are there any Block Snapshots of type RP? (if not, don't bother cleaning up)
* 3. Query the RP Appliance for all bookmarks for that CG (protection set)
* 4. Find each block snapshot of type RP for each site
* 5. If you can't find the bookmark in the RP list, move the block snapshot to inactive
*
* @param protectionSystem Protection System
*/
public static void cleanupSnapshots(DbClient dbClient, ProtectionSystem protectionSystem) throws RecoverPointException {
// 1. Get all of the protection sets associated with the protection system
Set<URI> protectionSetIDs = new HashSet<URI>();
Set<Integer> cgIDs = new HashSet<Integer>();
URIQueryResultList list = new URIQueryResultList();
Constraint constraint = ContainmentConstraint.Factory.getProtectionSystemProtectionSetConstraint(protectionSystem.getId());
dbClient.queryByConstraint(constraint, list);
Iterator<URI> it = list.iterator();
while (it.hasNext()) {
URI protectionSetId = it.next();
// Get all snapshots that are part of this protection set.
URIQueryResultList plist = new URIQueryResultList();
Constraint pconstraint = ContainmentConstraint.Factory.getProtectionSetBlockSnapshotConstraint(protectionSetId);
dbClient.queryByConstraint(pconstraint, plist);
if (plist.iterator().hasNext()) {
// OK, we know there are snapshots for this protection set/CG.
// Retrieve all of the bookmarks associated with this protection set/CG later on by adding to the list now
ProtectionSet protectionSet = dbClient.queryObject(ProtectionSet.class, protectionSetId);
if (protectionSet != null && !protectionSet.getInactive()) {
protectionSetIDs.add(protectionSet.getId());
cgIDs.add(Integer.valueOf(protectionSet.getProtectionId()));
}
}
}
// 2. No reason to bother the RPAs if there are no protection sets for this protection system.
if (protectionSetIDs.isEmpty()) {
_log.info("Block Snapshot of RP Bookmarks cleanup not run for this protection system. No Protections or RP Block Snapshots found on protection system: " + protectionSystem.getLabel());
return;
}
// 3. Query the RP appliance for all of the bookmarks for these CGs in one call
BiosCommandResult result = getRPBookmarks(protectionSystem, cgIDs);
GetBookmarksResponse bookmarkMap = (GetBookmarksResponse) result.getObjectList().get(0);
// 4. Go through each protection set's snapshots and see if they're there.
it = protectionSetIDs.iterator();
while (it.hasNext()) {
URI protectionSetId = it.next();
ProtectionSet protectionSet = dbClient.queryObject(ProtectionSet.class, protectionSetId);
// The map should have an entry for that CG with an empty list if it looked and couldn't find any. (a successful empty set)
if (protectionSet.getProtectionId() != null && bookmarkMap.getCgBookmarkMap() != null && bookmarkMap.getCgBookmarkMap().containsKey(new Integer(protectionSet.getProtectionId()))) {
// list to avoid issues further down.
if (bookmarkMap.getCgBookmarkMap().get(new Integer(protectionSet.getProtectionId())) == null) {
bookmarkMap.getCgBookmarkMap().put(new Integer(protectionSet.getProtectionId()), new ArrayList<RPBookmark>());
}
// Get all snapshots that are part of this protection set.
URIQueryResultList plist = new URIQueryResultList();
Constraint pconstraint = ContainmentConstraint.Factory.getProtectionSetBlockSnapshotConstraint(protectionSetId);
dbClient.queryByConstraint(pconstraint, plist);
Iterator<URI> snapshotIter = plist.iterator();
while (snapshotIter.hasNext()) {
URI snapshotId = snapshotIter.next();
BlockSnapshot snapshot = dbClient.queryObject(BlockSnapshot.class, snapshotId);
boolean deleteSnapshot = true;
if (snapshot.getInactive()) {
// Don't bother deleting or processing if the snapshot is already on its way out.
deleteSnapshot = false;
} else if (snapshot.getEmCGGroupCopyId() == null) {
// If something bad happened and we weren't able to get the site information off of the snapshot
_log.info("Found that ViPR Snapshot corresponding to RP Bookmark is missing Site information, thus not analyzing for automated deletion. " + snapshot.getId() + " - " + protectionSet.getLabel() + ":" + snapshot.getEmInternalSiteName() + ":" + snapshot.getEmName());
deleteSnapshot = false;
} else if (!bookmarkMap.getCgBookmarkMap().get(Integer.valueOf(protectionSet.getProtectionId())).isEmpty()) {
for (RPBookmark bookmark : bookmarkMap.getCgBookmarkMap().get(Integer.valueOf(protectionSet.getProtectionId()))) {
// bookmark (from RP) vs. snapshot (from ViPR)
if (snapshot.getEmName().equalsIgnoreCase(bookmark.getBookmarkName()) && snapshot.getEmCGGroupCopyId().equals(bookmark.getCGGroupCopyUID().getGlobalCopyUID().getCopyUID())) {
deleteSnapshot = false;
_log.info("Found that ViPR Snapshot corresponding to RP Bookmark still exists, thus saving in ViPR: " + snapshot.getId() + " - " + protectionSet.getLabel() + ":" + snapshot.getEmInternalSiteName() + ":" + snapshot.getEmCGGroupCopyId() + ":" + snapshot.getEmName());
}
}
} else {
// Just for debugging, otherwise useless
_log.debug("Found that ViPR Snapshot corresponding to RP Bookmark doesn't exist, thus going to delete from ViPR: " + snapshot.getId() + " - " + protectionSet.getLabel() + ":" + snapshot.getEmInternalSiteName() + ":" + snapshot.getEmCGGroupCopyId() + ":" + snapshot.getEmName());
}
if (deleteSnapshot) {
// 5. We couldn't find the bookmark, and the query for it was successful, so it's time to mark it as gone
_log.info("Found that ViPR Snapshot corresponding to RP Bookmark no longer exists, thus deleting in ViPR: " + snapshot.getId() + " - " + protectionSet.getLabel() + ":" + snapshot.getEmInternalSiteName() + ":" + snapshot.getEmCGGroupCopyId() + ":" + snapshot.getEmName());
dbClient.markForDeletion(snapshot);
}
}
} else if (protectionSet.getProtectionId() == null) {
_log.error("Can not determine the consistency group ID of protection set: " + protectionSet.getLabel() + ", can not perform any cleanup of snapshots.");
} else {
_log.info("No consistency groups were found associated with protection system: " + protectionSystem.getLabel() + ", can not perform cleanup of snapshots.");
}
}
}
use of com.emc.storageos.db.client.model.ProtectionSet in project coprhd-controller by CoprHD.
the class ProtectionSystemService method checkForVolumes.
/**
* checks for the existence of any volumes associated with a protection sysem
* also compiles a list of empty protection sets associated with the protection system that can be deleted
*
* @param system protection system
* @param protectionSetsToDelete (return) empty list to be populated by this method
* @return true if volumes exist; else false
*/
private boolean checkForVolumes(URI id, List<ProtectionSet> protectionSetsToDelete) {
boolean volumesExist = false;
URIQueryResultList list = new URIQueryResultList();
Constraint constraint = ContainmentConstraint.Factory.getProtectionSystemProtectionSetConstraint(id);
_dbClient.queryByConstraint(constraint, list);
Iterator<URI> it = list.iterator();
while (it.hasNext()) {
URI protectionSetId = it.next();
ProtectionSet protectionSet = _dbClient.queryObject(ProtectionSet.class, protectionSetId);
if (protectionSet != null && !protectionSet.getInactive()) {
if (protectionSet.getVolumes() != null && !protectionSet.getVolumes().isEmpty()) {
for (String volId : protectionSet.getVolumes()) {
Volume vol = _dbClient.queryObject(Volume.class, URI.create(volId));
if (vol != null && !vol.getInactive()) {
volumesExist = true;
break;
}
}
}
if (!volumesExist) {
// there are no volumes in this protection set, we can delete it
protectionSetsToDelete.add(protectionSet);
}
}
}
return volumesExist;
}
use of com.emc.storageos.db.client.model.ProtectionSet in project coprhd-controller by CoprHD.
the class ProtectionSystemService method deleteProtectionSystem.
/**
* Deactivate protection system, this will move it to a "marked-for-delete" state.
* It will be deleted in the next iteration of garbage collector
*
* @param id the URN of a ViPR protection system
* @brief Delete protection system
* @return No data returned in response body
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deactivate")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public Response deleteProtectionSystem(@PathParam("id") URI id) {
ArgValidator.checkFieldUriType(id, ProtectionSystem.class, "id");
ProtectionSystem system = _dbClient.queryObject(ProtectionSystem.class, id);
ArgValidator.checkEntityNotNull(system, id, isIdEmbeddedInURL(id));
// Check to make sure there are no volumes associated with this protection system
List<ProtectionSet> protectionSetsToDelete = new ArrayList<ProtectionSet>();
if (checkForVolumes(id, protectionSetsToDelete)) {
// don't allow the delete protection system if there are volumes
throw APIException.badRequests.unableToDeactivateDueToDependencies(id);
}
// delete any empty protection sets
_dbClient.markForDeletion(protectionSetsToDelete);
// Side-effect: RPSiteArray entries need to be cleaned up so placement and connectivity feeds are correct
// Mark all of the RPSiteArray entries associated with this protection system for deletion
URIQueryResultList sitelist = new URIQueryResultList();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getRPSiteArrayProtectionSystemConstraint(id.toString()), sitelist);
Iterator<URI> it = sitelist.iterator();
while (it.hasNext()) {
URI rpSiteArrayId = it.next();
RPSiteArray siteArray = _dbClient.queryObject(RPSiteArray.class, rpSiteArrayId);
if (siteArray != null) {
_dbClient.markForDeletion(siteArray);
}
}
_dbClient.markForDeletion(system);
auditOp(OperationTypeEnum.DELETE_PROTECTION_SYSTEM, true, null, system.getId().toString());
return Response.ok().build();
}
Aggregations