Search in sources :

Example 16 with UnManagedProtectionSet

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;
}
Also used : ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) UnManagedProtectionSet(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedProtectionSet) VolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.VolumeIngestionContext)

Example 17 with UnManagedProtectionSet

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;
}
Also used : ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) Set(java.util.Set) HashSet(java.util.HashSet) UnManagedProtectionSet(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedProtectionSet) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet) StringSet(com.emc.storageos.db.client.model.StringSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) UnManagedProtectionSet(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedProtectionSet) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) UnManagedProtectionSet(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedProtectionSet) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Volume(com.emc.storageos.db.client.model.Volume) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) StringSet(com.emc.storageos.db.client.model.StringSet) Map(java.util.Map) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) StringMap(com.emc.storageos.db.client.model.StringMap) HashSet(java.util.HashSet)

Aggregations

UnManagedProtectionSet (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedProtectionSet)17 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)10 BlockObject (com.emc.storageos.db.client.model.BlockObject)8 DataObject (com.emc.storageos.db.client.model.DataObject)6 ProtectionSet (com.emc.storageos.db.client.model.ProtectionSet)6 Volume (com.emc.storageos.db.client.model.Volume)6 StringSet (com.emc.storageos.db.client.model.StringSet)5 URI (java.net.URI)5 ArrayList (java.util.ArrayList)5 RecoverPointVolumeIngestionContext (com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.impl.RecoverPointVolumeIngestionContext)3 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)3 HashMap (java.util.HashMap)3 VolumeIngestionContext (com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.VolumeIngestionContext)2 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)2 ProtectionSystem (com.emc.storageos.db.client.model.ProtectionSystem)2 IngestionRequestContext (com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.IngestionRequestContext)1 BlockVolumeIngestionContext (com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.impl.BlockVolumeIngestionContext)1 AbstractChangeTrackingSet (com.emc.storageos.db.client.model.AbstractChangeTrackingSet)1 BlockMirror (com.emc.storageos.db.client.model.BlockMirror)1 DiscoveredDataObject (com.emc.storageos.db.client.model.DiscoveredDataObject)1