Search in sources :

Example 1 with ValidatorConfig

use of com.emc.storageos.volumecontroller.impl.validators.ValidatorConfig in project coprhd-controller by CoprHD.

the class ExportGroupService method validateVolumesNotMounted.

/**
 * Verify that none of the volumes in the export group are mounted.
 * Unexporting a mounted volume is dangerous and should be avoided.
 *
 * @param exportGroup
 *            export group
 * @param boURIList
 *            URI list of block objects
 */
private void validateVolumesNotMounted(ExportGroup exportGroup, List<URI> boURIList) {
    if (exportGroup == null) {
        throw APIException.badRequests.exportGroupContainsMountedVolumesInvalidParam();
    }
    Map<URI, String> boToLabelMap = new HashMap<>();
    // It is valid for there to be no storage volumes in the EG, so only perform the check if there are volumes
    if (boURIList != null) {
        for (URI boID : boURIList) {
            BlockObject bo = BlockObject.fetch(_dbClient, boID);
            if (bo != null && bo.getTag() != null) {
                ScopedLabelSet tagSet = bo.getTag();
                Iterator<ScopedLabel> tagIter = tagSet.iterator();
                while (tagIter.hasNext()) {
                    ScopedLabel sl = tagIter.next();
                    if (sl.getLabel() != null && (sl.getLabel().startsWith(MOUNTPOINT) || sl.getLabel().startsWith(VMFS_DATASTORE))) {
                        if (exportGroup.getClusters() != null) {
                            for (String clusterID : exportGroup.getClusters()) {
                                if (sl.getLabel().contains(clusterID)) {
                                    boToLabelMap.put(boID, bo.forDisplay());
                                }
                            }
                        }
                        if (exportGroup.getHosts() != null) {
                            for (String hostID : exportGroup.getHosts()) {
                                if (sl.getLabel().contains(hostID)) {
                                    boToLabelMap.put(boID, bo.forDisplay());
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (!boToLabelMap.isEmpty()) {
        _log.error("Export Group {} has volumes {} that are marked as mounted.  It is recommended to unmount via controller before unexport.  This validation check can be disabled if needed.  Contact EMC Support.", exportGroup.getId(), Joiner.on(",").join(boToLabelMap.values()));
        ValidatorConfig vc = new ValidatorConfig();
        vc.setCoordinator(_coordinator);
        if (vc.isValidationEnabled()) {
            throw APIException.badRequests.exportGroupContainsMountedVolumes(exportGroup.getId(), Joiner.on(",").join(boToLabelMap.values()));
        }
    }
}
Also used : HashMap(java.util.HashMap) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) ValidatorConfig(com.emc.storageos.volumecontroller.impl.validators.ValidatorConfig)

Example 2 with ValidatorConfig

use of com.emc.storageos.volumecontroller.impl.validators.ValidatorConfig in project coprhd-controller by CoprHD.

the class VPlexDeviceController method validateVPlexVolume.

/**
 * Validates that the backend volumes of the passed VPLEX volumes in the
 * ViPR database are the actual backend volumes used by the VPLEX volume
 * on the VPLEX system.
 *
 * @param vplexSystemURI
 *            The URI of the VPLEX storage system.
 * @param vplexVolumeURI
 *            The URI of the VPLEX volume to validate.
 * @param stepId
 *            The workflow step id.
 */
public void validateVPlexVolume(URI vplexSystemURI, URI vplexVolumeURI, String stepId) {
    Volume vplexVolume = null;
    try {
        // Skip this if validation disabled
        ValidatorConfig validatorConfig = new ValidatorConfig();
        validatorConfig.setCoordinator(coordinator);
        if (!validatorConfig.isValidationEnabled()) {
            WorkflowStepCompleter.stepSucceeded(stepId, "Validations not enabled");
            return;
        }
        // Update step state to executing.
        WorkflowStepCompleter.stepExecuting(stepId);
        // Get the VPLEX API client for the VPLEX system.
        VPlexApiClient client = getVPlexAPIClient(_vplexApiFactory, vplexSystemURI, _dbClient);
        // Get the VPLEX volume
        vplexVolume = getDataObject(Volume.class, vplexVolumeURI, _dbClient);
        // Get a VolumeInfo for each backend volume and any mirrors, mapped by VPLEX cluster name.
        Set<String> volumeIds = new HashSet<>();
        Map<String, List<VolumeInfo>> volumeInfoMap = new HashMap<>();
        StringSet associatedVolumeIds = vplexVolume.getAssociatedVolumes();
        if ((associatedVolumeIds == null) || (associatedVolumeIds.isEmpty())) {
            // Ingested volume w/o backend volume ingestion. We can't verify the backend volumes.
            _log.info("VPLEX volume {}:{} has no backend volumes to validate", vplexVolumeURI, vplexVolume.getLabel());
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        } else {
            volumeIds.addAll(associatedVolumeIds);
        }
        // Now mirrors.
        StringSet mirrorIds = vplexVolume.getMirrors();
        if ((mirrorIds != null) && (mirrorIds.isEmpty() == false)) {
            for (String mirrorId : mirrorIds) {
                VplexMirror mirror = getDataObject(VplexMirror.class, URI.create(mirrorId), _dbClient);
                StringSet associatedVolumeIdsForMirror = mirror.getAssociatedVolumes();
                if ((associatedVolumeIdsForMirror == null) || (associatedVolumeIdsForMirror.isEmpty())) {
                    _log.info("VPLEX mirror {}:{} has no associated volumes", mirrorId, mirror.getLabel());
                    throw DeviceControllerExceptions.vplex.vplexMirrorDoesNotHaveAssociatedVolumes(vplexVolume.getLabel(), mirror.getLabel());
                } else {
                    volumeIds.addAll(associatedVolumeIdsForMirror);
                }
            }
        }
        // Get the WWNs for these volumes mapped by VPLEX cluster name.
        for (String volumesId : volumeIds) {
            URI volumeURI = URI.create(volumesId);
            Volume volume = getDataObject(Volume.class, volumeURI, _dbClient);
            String clusterName = VPlexUtil.getVplexClusterName(volume.getVirtualArray(), vplexSystemURI, client, _dbClient);
            StorageSystem storageSystem = getDataObject(StorageSystem.class, volume.getStorageController(), _dbClient);
            List<String> itls = VPlexControllerUtils.getVolumeITLs(volume);
            VolumeInfo volumeInfo = new VolumeInfo(storageSystem.getNativeGuid(), storageSystem.getSystemType(), volume.getWWN().toUpperCase().replaceAll(":", ""), volume.getNativeId(), volume.getThinlyProvisioned().booleanValue(), itls);
            _log.info(String.format("Validating backend volume %s on cluster %s", volumeURI, clusterName));
            if (volumeInfoMap.containsKey(clusterName)) {
                List<VolumeInfo> clusterVolumeInfos = volumeInfoMap.get(clusterName);
                clusterVolumeInfos.add(volumeInfo);
            } else {
                List<VolumeInfo> clusterVolumeInfos = new ArrayList<>();
                clusterVolumeInfos.add(volumeInfo);
                volumeInfoMap.put(clusterName, clusterVolumeInfos);
            }
        }
        // Validate the ViPR backend volume WWNs match those on the VPLEX.
        client.validateBackendVolumesForVPlexVolume(vplexVolume.getDeviceLabel(), vplexVolume.getNativeId(), volumeInfoMap);
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (InternalException ie) {
        _log.info("Exception attempting to validate the backend volumes for VPLEX volume {}", vplexVolumeURI);
        WorkflowStepCompleter.stepFailed(stepId, ie);
    } catch (Exception e) {
        _log.info("Exception attempting to validate the backend volumes for VPLEX volume {}", vplexVolumeURI);
        ServiceCoded sc = DeviceControllerExceptions.vplex.failureValidatingVplexVolume(vplexVolumeURI.toString(), (vplexVolume != null ? vplexVolume.getLabel() : ""), e.getMessage());
        WorkflowStepCompleter.stepFailed(stepId, sc);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VolumeInfo(com.emc.storageos.vplex.api.clientdata.VolumeInfo) VPlexVirtualVolumeInfo(com.emc.storageos.vplex.api.VPlexVirtualVolumeInfo) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ValidatorConfig(com.emc.storageos.volumecontroller.impl.validators.ValidatorConfig) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Volume(com.emc.storageos.db.client.model.Volume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) StringSet(com.emc.storageos.db.client.model.StringSet) ApplicationAddVolumeList(com.emc.storageos.volumecontroller.ApplicationAddVolumeList) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) VplexMirror(com.emc.storageos.db.client.model.VplexMirror) HashSet(java.util.HashSet) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

NamedURI (com.emc.storageos.db.client.model.NamedURI)2 ValidatorConfig (com.emc.storageos.volumecontroller.impl.validators.ValidatorConfig)2 URI (java.net.URI)2 HashMap (java.util.HashMap)2 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 BlockObject (com.emc.storageos.db.client.model.BlockObject)1 ScopedLabel (com.emc.storageos.db.client.model.ScopedLabel)1 ScopedLabelSet (com.emc.storageos.db.client.model.ScopedLabelSet)1 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)1 StringSet (com.emc.storageos.db.client.model.StringSet)1 Volume (com.emc.storageos.db.client.model.Volume)1 VplexMirror (com.emc.storageos.db.client.model.VplexMirror)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)1 ServiceCoded (com.emc.storageos.svcs.errorhandling.model.ServiceCoded)1 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)1 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)1 ApplicationAddVolumeList (com.emc.storageos.volumecontroller.ApplicationAddVolumeList)1 ControllerException (com.emc.storageos.volumecontroller.ControllerException)1 VPlexApiClient (com.emc.storageos.vplex.api.VPlexApiClient)1