Search in sources :

Example 31 with RecoverPointClient

use of com.emc.storageos.recoverpoint.impl.RecoverPointClient 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

RecoverPointClient (com.emc.storageos.recoverpoint.impl.RecoverPointClient)31 ArrayList (java.util.ArrayList)18 URI (java.net.URI)17 ProtectionSystem (com.emc.storageos.db.client.model.ProtectionSystem)15 Volume (com.emc.storageos.db.client.model.Volume)15 RecoverPointException (com.emc.storageos.recoverpoint.exceptions.RecoverPointException)15 URISyntaxException (java.net.URISyntaxException)15 FunctionalAPIActionFailedException_Exception (com.emc.fapiclient.ws.FunctionalAPIActionFailedException_Exception)13 FunctionalAPIInternalError_Exception (com.emc.fapiclient.ws.FunctionalAPIInternalError_Exception)13 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)13 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)13 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)13 LockRetryException (com.emc.storageos.locking.LockRetryException)13 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)13 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)13 ControllerException (com.emc.storageos.volumecontroller.ControllerException)13 WorkflowException (com.emc.storageos.workflow.WorkflowException)13 NamedURI (com.emc.storageos.db.client.model.NamedURI)12 ProtectionSet (com.emc.storageos.db.client.model.ProtectionSet)10 StringSet (com.emc.storageos.db.client.model.StringSet)7