Search in sources :

Example 6 with GetVolumeResponse

use of com.emc.storageos.recoverpoint.responses.GetVolumeResponse in project coprhd-controller by CoprHD.

the class RPHelper method validateCGForDelete.

/**
 * Validate the CG before performing destructive operations.
 * If additional volumes appear in the RP CG on the hardware, this method returns false
 * Clerical errors (such as missing DB entries) result in an Exception
 *
 * @param dbClient
 *            dbclient
 * @param system
 *            protection system
 * @param cgId
 *            BlockConsistencyGroup ID
 * @param volumes
 *            list of volumes
 * @return true if CG is what we expect on the hardware, false otherwise
 */
public static boolean validateCGForDelete(DbClient dbClient, ProtectionSystem system, URI cgId, Set<URI> volumes) {
    _log.info("validateCGForDelete {} - start", system.getId());
    // Retrieve all of the RP CGs, their RSets, and their volumes
    RecoverPointClient rp = RPHelper.getRecoverPointClient(system);
    Set<GetCGsResponse> cgList = rp.getAllCGs();
    if (cgList == null || cgList.isEmpty()) {
        String errMsg = "Could not retrieve CGs from the RPA to perform validation.";
        throw DeviceControllerExceptions.recoverpoint.unableToPerformValidation(errMsg);
    }
    // Grab all of the source volumes from the CG according to ViPR
    List<Volume> srcVolumes = RPHelper.getCgVolumes(dbClient, cgId, PersonalityTypes.SOURCE.toString());
    if (srcVolumes == null || srcVolumes.isEmpty()) {
        String errMsg = "Could not retrieve volumes from the database for CG to perform validation";
        throw DeviceControllerExceptions.recoverpoint.unableToPerformValidation(errMsg);
    }
    // Get the protection set ID from the first source volume. All volumes will have the same pset ID.
    URI psetId = srcVolumes.get(0).getProtectionSet().getURI();
    if (NullColumnValueGetter.isNullURI(psetId)) {
        String errMsg = "Could not retrieve protection set ID from the database for CG to perform validation";
        throw DeviceControllerExceptions.recoverpoint.unableToPerformValidation(errMsg);
    }
    // Get the protection set, which is required to get the CG ID on the RPA
    ProtectionSet pset = dbClient.queryObject(ProtectionSet.class, psetId);
    if (pset == null) {
        String errMsg = "Could not retrieve protection set from the database for CG to perform validation";
        throw DeviceControllerExceptions.recoverpoint.unableToPerformValidation(errMsg);
    }
    // Pre-populate the wwn fields for comparisons later.
    List<String> srcVolumeWwns = new ArrayList<>();
    for (Volume srcVolume : srcVolumes) {
        srcVolumeWwns.add(srcVolume.getWWN());
    }
    // This loop finds the CG on the hardware from the list of all CGs. Ignores all CGs that don't match our ID.
    for (GetCGsResponse cgResponse : cgList) {
        // Compare the stored CG ID (unique per RP System, doesn't change even if CG name changes)
        if (Long.parseLong(pset.getProtectionId()) != cgResponse.getCgId()) {
            continue;
        }
        // Make sure we have rsets before we continue. If the CG has no RSets on the hardware, throw
        if (cgResponse.getRsets() == null || cgResponse.getRsets().isEmpty()) {
            String errMsg = "Could not retrieve replication sets from the hardware to perform validation";
            throw DeviceControllerExceptions.recoverpoint.unableToPerformValidation(errMsg);
        }
        // Find one of our volumes
        for (GetRSetResponse rsetResponse : cgResponse.getRsets()) {
            // Make sure we have volumes in the RSet before we continue
            if (rsetResponse == null || rsetResponse.getVolumes() == null || rsetResponse.getVolumes().isEmpty()) {
                String errMsg = "Could not retrieve the volumes in the replication set from the hardware to perform validation";
                throw DeviceControllerExceptions.recoverpoint.unableToPerformValidation(errMsg);
            }
            // list of WWNs is the list of source volumes we know about.
            for (GetVolumeResponse volumeResponse : rsetResponse.getVolumes()) {
                // This hardware volume should be represented in the list of srcVolumes
                if (!srcVolumeWwns.contains(volumeResponse.getWwn())) {
                    _log.warn("Found at least one volume that isn't in our list of source volumes {}, therefore we can not delete the entire CG.", volumeResponse.getWwn());
                    return false;
                }
            }
        }
    }
    _log.info("validateCGForDelete {} - end", system.getId());
    return true;
}
Also used : GetCGsResponse(com.emc.storageos.recoverpoint.responses.GetCGsResponse) GetRSetResponse(com.emc.storageos.recoverpoint.responses.GetRSetResponse) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Volume(com.emc.storageos.db.client.model.Volume) GetVolumeResponse(com.emc.storageos.recoverpoint.responses.GetVolumeResponse) RecoverPointClient(com.emc.storageos.recoverpoint.impl.RecoverPointClient) ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) UnManagedProtectionSet(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedProtectionSet) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Aggregations

GetVolumeResponse (com.emc.storageos.recoverpoint.responses.GetVolumeResponse)6 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)4 Volume (com.emc.storageos.db.client.model.Volume)4 GetRSetResponse (com.emc.storageos.recoverpoint.responses.GetRSetResponse)4 GetCGsResponse (com.emc.storageos.recoverpoint.responses.GetCGsResponse)3 GetCopyResponse (com.emc.storageos.recoverpoint.responses.GetCopyResponse)3 StringSet (com.emc.storageos.db.client.model.StringSet)2 RecoverPointException (com.emc.storageos.recoverpoint.exceptions.RecoverPointException)2 HashSet (java.util.HashSet)2 ClusterConfiguration (com.emc.fapiclient.ws.ClusterConfiguration)1 ConsistencyGroupCopySettings (com.emc.fapiclient.ws.ConsistencyGroupCopySettings)1 ConsistencyGroupCopyState (com.emc.fapiclient.ws.ConsistencyGroupCopyState)1 ConsistencyGroupLinkSettings (com.emc.fapiclient.ws.ConsistencyGroupLinkSettings)1 ConsistencyGroupSettings (com.emc.fapiclient.ws.ConsistencyGroupSettings)1 ConsistencyGroupState (com.emc.fapiclient.ws.ConsistencyGroupState)1 ConsistencyGroupUID (com.emc.fapiclient.ws.ConsistencyGroupUID)1 FullRecoverPointSettings (com.emc.fapiclient.ws.FullRecoverPointSettings)1 FunctionalAPIActionFailedException_Exception (com.emc.fapiclient.ws.FunctionalAPIActionFailedException_Exception)1 FunctionalAPIInternalError_Exception (com.emc.fapiclient.ws.FunctionalAPIInternalError_Exception)1 FunctionalAPIValidationException_Exception (com.emc.fapiclient.ws.FunctionalAPIValidationException_Exception)1