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()));
}
}
}
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);
}
}
Aggregations