use of com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedProtectionSet in project coprhd-controller by CoprHD.
the class RecoverPointVolumeIngestionContext method findExistingProtectionSet.
/**
* Finds an existing ProtectionSet in any RecoverPoint volume ingestion context within the scope of this ingestion request.
*
* @param psetLabel the label for the ProtectionSet
* @param rpProtectionId the RecoverPoint protection set id
* @param protectionSystemUri the RecoverPoint device URI
* @param umpsetNativeGuid the nativeGuid for the discovered UnManagedProtectionSet
* @return an existing ProtectionSet matching the arguments
*/
public ProtectionSet findExistingProtectionSet(String psetLabel, String rpProtectionId, URI protectionSystemUri, String umpsetNativeGuid) {
for (VolumeIngestionContext volumeContext : getRootIngestionRequestContext().getProcessedUnManagedVolumeMap().values()) {
if (volumeContext != null && volumeContext instanceof RecoverPointVolumeIngestionContext) {
RecoverPointVolumeIngestionContext rpContext = (RecoverPointVolumeIngestionContext) volumeContext;
ProtectionSet pset = rpContext.getManagedProtectionSet();
if (pset != null) {
if ((pset.getLabel().equals(psetLabel)) && (pset.getProtectionId().equals(rpProtectionId)) && (pset.getProtectionSystem().equals(protectionSystemUri)) && (pset.getNativeGuid().equals(umpsetNativeGuid))) {
_logger.info("found already-instantiated ProtectionSet {} (hash {})", pset.getLabel(), pset.hashCode());
return pset;
}
}
}
}
_logger.info("did not find an already-instantiated ProtectionSet for ", psetLabel);
return null;
}
use of com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedProtectionSet in project coprhd-controller by CoprHD.
the class RPHelper method getVolumesToDelete.
/**
* This method will return all volumes that should be deleted based on the entire list of volumes to be deleted.
* If this is the last source volume in the CG, this method will return all journal volumes as well.
*
* @param reqDeleteVolumes all volumes in the delete request
* @param dbClient DbClient
* @return list of volumes to unexport and delete
* @throws InternalException
* @throws URISyntaxException
*/
public static Set<URI> getVolumesToDelete(Collection<URI> reqDeleteVolumes, DbClient dbClient) throws InternalException {
_log.info(String.format("Getting all RP volumes to delete for requested list: %s", reqDeleteVolumes));
Set<URI> volumeIDs = new HashSet<URI>();
Set<URI> protectionSetIds = new HashSet<URI>();
Iterator<Volume> volumes = dbClient.queryIterativeObjects(Volume.class, reqDeleteVolumes, true);
// Divide the RP volumes by BlockConsistencyGroup so we can determine if all volumes in the
// RP consistency group are being removed.
Map<URI, Set<URI>> cgsToVolumesForDelete = new HashMap<URI, Set<URI>>();
// to that volume to the list of volumes to be deleted
while (volumes.hasNext()) {
Volume volume = volumes.next();
// get the list of all source and target volumes in the same replication set as the
// volume passed in
List<Volume> allVolsInRSet = getVolumesInRSet(volume, dbClient);
List<URI> allVolsInRSetURI = new ArrayList<URI>();
URI cgURI = null;
// 3. If partially ingested volume, clean up corresponding unmanaged protection set
for (Volume vol : allVolsInRSet) {
allVolsInRSetURI.add(vol.getId());
if (!NullColumnValueGetter.isNullURI(vol.getConsistencyGroup())) {
cgURI = vol.getConsistencyGroup();
}
if (!NullColumnValueGetter.isNullNamedURI(vol.getProtectionSet())) {
// Keep track of the protection sets for a cleanup operation later in case we
// find any stale volume references
protectionSetIds.add(vol.getProtectionSet().getURI());
}
// If this is a partially ingested RP volume, clean up the corresponding unmanaged protection set
List<UnManagedProtectionSet> umpsets = CustomQueryUtility.getUnManagedProtectionSetByManagedVolumeId(dbClient, vol.getId().toString());
for (UnManagedProtectionSet umpset : umpsets) {
umpset.getManagedVolumeIds().remove(vol.getId().toString());
// Clean up the volume's reference, if any, in the unmanaged volumes associated with the unmanaged protection set
for (String umv : umpset.getUnManagedVolumeIds()) {
UnManagedVolume umVolume = dbClient.queryObject(UnManagedVolume.class, URI.create(umv));
StringSet rpManagedSourceVolumeInfo = umVolume.getVolumeInformation().get(SupportedVolumeInformation.RP_MANAGED_SOURCE_VOLUME.toString());
StringSet rpManagedTargetVolumeInfo = umVolume.getVolumeInformation().get(SupportedVolumeInformation.RP_MANAGED_TARGET_VOLUMES.toString());
if (rpManagedSourceVolumeInfo != null && !rpManagedSourceVolumeInfo.isEmpty()) {
rpManagedSourceVolumeInfo.remove(vol.getId().toString());
}
if (rpManagedTargetVolumeInfo != null && !rpManagedTargetVolumeInfo.isEmpty()) {
rpManagedTargetVolumeInfo.remove(vol.getId().toString());
}
dbClient.updateObject(umVolume);
}
dbClient.updateObject(umpset);
}
}
// Add the replication set volume IDs to the list of volumes to be deleted
_log.info(String.format("Adding volume %s to the list of volumes to be deleted", allVolsInRSetURI.toString()));
volumeIDs.addAll(allVolsInRSetURI);
// the entire CG which would indicate journals are also being deleted.
if (cgURI != null) {
if (cgsToVolumesForDelete.get(cgURI) == null) {
cgsToVolumesForDelete.put(cgURI, new HashSet<URI>());
}
cgsToVolumesForDelete.get(cgURI).addAll(allVolsInRSetURI);
} else {
_log.warn(String.format("Unable to find a valid CG for replication set volumes %s. Unable to determine if the entire CG is being deleted as part of this request.", allVolsInRSetURI.toString()));
}
}
// Determine if we're deleting all of the volumes in this consistency group
for (Map.Entry<URI, Set<URI>> cgToVolumesForDelete : cgsToVolumesForDelete.entrySet()) {
BlockConsistencyGroup cg = null;
URI cgURI = cgToVolumesForDelete.getKey();
cg = dbClient.queryObject(BlockConsistencyGroup.class, cgURI);
List<Volume> cgVolumes = getAllCgVolumes(cgURI, dbClient);
// determine if all of the source and target volumes in the consistency group are on the list
// of volumes to delete; if so, we will add the journal volumes to the list.
// also create a list of stale volumes to be removed from the protection set
boolean wholeCG = true;
if (cgVolumes != null) {
for (Volume cgVol : cgVolumes) {
Set<URI> cgVolsToDelete = cgToVolumesForDelete.getValue();
// determine if it's a journal or another source/target not being deleted.
if (!cgVolsToDelete.contains(cgVol.getId())) {
// Do not consider VPlex backing volumes or inactive volumes
if (!cgVol.getInactive() && NullColumnValueGetter.isNotNullValue(cgVol.getPersonality())) {
if (!Volume.PersonalityTypes.METADATA.toString().equals(cgVol.getPersonality())) {
// the volume is either a source or target; this means there are other volumes in the rset
wholeCG = false;
break;
}
}
}
}
}
if (wholeCG) {
// add them to the list of volumes to be removed
if (cg != null) {
List<Volume> allJournals = getCgVolumes(dbClient, cg.getId(), Volume.PersonalityTypes.METADATA.toString());
if (allJournals != null && !allJournals.isEmpty()) {
Set<URI> allJournalURIs = new HashSet<URI>();
for (Volume journalVolume : allJournals) {
allJournalURIs.add(journalVolume.getId());
}
_log.info(String.format("Determined that this is a request to delete consistency group %s. Adding journal volumes to the list of volumes to delete: %s", cgURI, allJournalURIs.toString()));
volumeIDs.addAll(allJournalURIs);
}
} else {
_log.info(String.format("Could not determine journal volumes for consistency group %s .", cgToVolumesForDelete.getKey()));
}
} else {
_log.info(String.format("Consistency group %s will not be removed. Only a subset of the replication sets are being removed.", cgToVolumesForDelete.getKey()));
}
}
// "bad things" from happening.
for (URI protSetId : protectionSetIds) {
List<String> staleVolumes = new ArrayList<String>();
ProtectionSet protectionSet = dbClient.queryObject(ProtectionSet.class, protSetId);
if (protectionSet.getVolumes() != null) {
for (String protSetVol : protectionSet.getVolumes()) {
URI protSetVolUri = URI.create(protSetVol);
if (!volumeIDs.contains(protSetVolUri)) {
Volume vol = dbClient.queryObject(Volume.class, protSetVolUri);
if (vol == null || vol.getInactive()) {
// The ProtectionSet references a stale volume that no longer exists in the DB.
_log.info("ProtectionSet " + protectionSet.getLabel() + " references volume " + protSetVol + " that no longer exists in the DB. Removing this volume reference.");
staleVolumes.add(protSetVol);
}
}
}
}
// remove stale entries from protection set
if (!staleVolumes.isEmpty()) {
for (String vol : staleVolumes) {
protectionSet.getVolumes().remove(vol);
}
dbClient.updateObject(protectionSet);
}
}
return volumeIDs;
}
Aggregations