use of com.emc.storageos.db.client.model.ExportMask in project coprhd-controller by CoprHD.
the class ExportUtils method getExportMasksSharingInitiatorAndHasUnManagedVolumes.
/**
* Check if the initiator is being shared across masks and check if the mask has unmanaged volumes.
* This will return an error message to append to the caller's error message string.
*
* @param dbClient
* @param initiatorUri
* @param curExportMask
* @param exportMaskURIs
* @return error message to append
*/
public static String getExportMasksSharingInitiatorAndHasUnManagedVolumes(DbClient dbClient, Initiator initiator, ExportMask curExportMask, Collection<URI> exportMaskURIs) {
List<ExportMask> results = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, ExportMask.class, ContainmentConstraint.Factory.getConstraint(ExportMask.class, "initiators", initiator.getId()));
List<String> sharedExportMaskNameList = new ArrayList<>();
Set<String> unmanagedVolumeWWNs = new HashSet<>();
for (ExportMask exportMask : results) {
if (exportMask != null && !exportMask.getId().equals(curExportMask.getId()) && exportMask.getStorageDevice().equals(curExportMask.getStorageDevice()) && !exportMaskURIs.contains(exportMask.getId()) && StringSetUtil.areEqual(exportMask.getInitiators(), curExportMask.getInitiators()) && exportMask.hasAnyExistingVolumes()) {
_log.info("Initiator {} is shared with mask {} and has unmanaged volumes", initiator.getId(), exportMask.getMaskName());
sharedExportMaskNameList.add(exportMask.getMaskName());
unmanagedVolumeWWNs.addAll(exportMask.getExistingVolumes().keySet());
}
}
if (!sharedExportMaskNameList.isEmpty()) {
return String.format(" Initiator %s is shared between mask %s and other masks [%s] and has unmanaged volumes [%s]. Removing initiator will affect the other masking view", // initiator wwn
Initiator.normalizePort(initiator.getInitiatorPort()), // mask name being validated
curExportMask.getMaskName(), // names of masks
Joiner.on(", ").join(sharedExportMaskNameList), // unmanaged volumes (up to 9)
(unmanagedVolumeWWNs.size() < 10) ? Joiner.on(", ").join(unmanagedVolumeWWNs) : "10 or more volumes");
}
return null;
}
use of com.emc.storageos.db.client.model.ExportMask in project coprhd-controller by CoprHD.
the class ExportUtils method getAllLUNsForHost.
/**
* Get all LUNs on the array that mapped to a host identified by initiators in the mask
*
* @param dbClient
* @param exportMask
* @return LUNs mapped to the host
*/
public static Set<String> getAllLUNsForHost(DbClient dbClient, ExportMask exportMask) {
Set<String> lunIds = new HashSet<>();
URI storageUri = exportMask.getStorageDevice();
if (NullColumnValueGetter.isNullURI(storageUri)) {
return lunIds;
}
URI hostUri = null;
for (String init : exportMask.getInitiators()) {
Initiator initiator = dbClient.queryObject(Initiator.class, URI.create(init));
if (initiator != null && !initiator.getInactive()) {
hostUri = initiator.getHost();
if (!NullColumnValueGetter.isNullURI(hostUri)) {
break;
}
}
}
// get initiators from host
Map<URI, ExportMask> exportMasks = new HashMap<>();
if (!NullColumnValueGetter.isNullURI(hostUri)) {
URIQueryResultList list = new URIQueryResultList();
dbClient.queryByConstraint(ContainmentConstraint.Factory.getContainedObjectsConstraint(hostUri, Initiator.class, "host"), list);
Iterator<URI> uriIter = list.iterator();
while (uriIter.hasNext()) {
URI initiatorId = uriIter.next();
URIQueryResultList egUris = new URIQueryResultList();
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getExportGroupInitiatorConstraint(initiatorId.toString()), egUris);
ExportGroup exportGroup = null;
for (URI egUri : egUris) {
exportGroup = dbClient.queryObject(ExportGroup.class, egUri);
if (exportGroup == null || exportGroup.getInactive() || exportGroup.getExportMasks() == null) {
continue;
}
List<ExportMask> masks = ExportMaskUtils.getExportMasks(dbClient, exportGroup);
for (ExportMask mask : masks) {
if (mask != null && !mask.getInactive() && mask.hasInitiator(initiatorId.toString()) && mask.getVolumes() != null && storageUri.equals(mask.getStorageDevice())) {
exportMasks.put(mask.getId(), mask);
}
}
}
}
}
for (ExportMask mask : exportMasks.values()) {
StringMap volumeMap = mask.getVolumes();
if (volumeMap != null && !volumeMap.isEmpty()) {
for (String strUri : mask.getVolumes().keySet()) {
BlockObject bo = BlockObject.fetch(dbClient, URI.create(strUri));
if (bo != null && !bo.getInactive()) {
lunIds.add(bo.getNativeId());
}
}
}
}
return lunIds;
}
use of com.emc.storageos.db.client.model.ExportMask in project coprhd-controller by CoprHD.
the class ExportUtils method cleanStaleExportMasks.
/**
* Method to clean ExportMask stale instances from ViPR db if any stale EM available.
*
* @param storage the storage
* @param maskNamesFromArray Mask Names collected from Array for the set of initiator names
* @param initiatorNames initiator names
* @param dbClient
*/
public static void cleanStaleExportMasks(StorageSystem storage, Set<String> maskNamesFromArray, List<String> initiatorNames, DbClient dbClient) {
Set<Initiator> initiators = ExportUtils.getInitiators(initiatorNames, dbClient);
Set<ExportMask> staleExportMasks = new HashSet<>();
_log.info("Mask Names found in array:{} for the initiators: {}", maskNamesFromArray, initiatorNames);
for (Initiator initiator : initiators) {
URIQueryResultList emUris = new URIQueryResultList();
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getExportMaskInitiatorConstraint(initiator.getId().toString()), emUris);
ExportMask exportMask = null;
for (URI emUri : emUris) {
_log.debug("Export Mask URI :{}", emUri);
exportMask = dbClient.queryObject(ExportMask.class, emUri);
if (exportMask != null && !exportMask.getInactive() && storage.getId().equals(exportMask.getStorageDevice())) {
if (!maskNamesFromArray.contains(exportMask.getMaskName())) {
_log.info("Export Mask {} is not found in array", exportMask.getMaskName());
List<ExportGroup> egList = ExportUtils.getExportGroupsForMask(exportMask.getId(), dbClient);
if (CollectionUtils.isEmpty(egList)) {
_log.info("Found a stale export mask {} - {} and it can be removed from DB", exportMask.getId(), exportMask.getMaskName());
staleExportMasks.add(exportMask);
} else {
_log.info("Export mask is having association with ExportGroup {}", egList);
}
}
}
}
}
if (!CollectionUtils.isEmpty(staleExportMasks)) {
dbClient.markForDeletion(staleExportMasks);
_log.info("Deleted {} stale export masks from DB", staleExportMasks.size());
}
_log.info("Export Mask cleanup activity done");
}
use of com.emc.storageos.db.client.model.ExportMask in project coprhd-controller by CoprHD.
the class ExportUtils method reconcileExportGroupsHLUs.
/**
* Examine ExportGroup's volumes to find any that do not have their HLU filled in. In case it is not filled, the ExportMasks
* will be searched to find an HLU to assign for the volume.
*
* NOTE: ExportGroup is not persisted here.
*
* @param dbClient [IN] - DbClient for DB access
* @param exportGroup [IN] - ExportGroup to examine volumes
*/
public static void reconcileExportGroupsHLUs(DbClient dbClient, ExportGroup exportGroup) {
// Find the volumes that don't have their HLU filled in ...
List<String> egVolumesWithoutHLUs = findVolumesWithoutHLUs(exportGroup);
if (!egVolumesWithoutHLUs.isEmpty()) {
// Search through each ExportMask associated with the ExportGroup ...
for (ExportMask thisMask : ExportMaskUtils.getExportMasks(dbClient, exportGroup)) {
Iterator<String> volumeIter = egVolumesWithoutHLUs.iterator();
while (volumeIter.hasNext()) {
URI volumeURI = URI.create(volumeIter.next());
if (thisMask.hasVolume(volumeURI)) {
// This ExportMask has the volume we're interested in.
String hlu = thisMask.returnVolumeHLU(volumeURI);
// Let's apply its HLU if it's not the 'Unassigned' value ...
if (!hlu.equals(ExportGroup.LUN_UNASSIGNED_DECIMAL_STR)) {
_log.info(String.format("ExportGroup %s (%s) update volume HLU: %s -> %s", exportGroup.getLabel(), exportGroup.getId(), volumeURI, hlu));
exportGroup.addVolume(volumeURI, Integer.valueOf(hlu));
// Now that we've found an HLU for this volume, there's no need to search for it in other ExportMasks.
// Let's remove it from the array list.
volumeIter.remove();
}
}
}
}
}
}
use of com.emc.storageos.db.client.model.ExportMask in project coprhd-controller by CoprHD.
the class ExportUtils method cleanStaleVolumeReferences.
/**
* Get all the user Added volumes from all the masks in the export group.
* Compare the same with volumes with export group and remove stale volumes.
* After removal, if the volumes are empty in export Group, delete the export Group.
*
* @param exportGroup
* @param dbClient
*/
private static void cleanStaleVolumeReferences(ExportGroup exportGroup, DbClient dbClient) {
if (null == exportGroup || exportGroup.getInactive()) {
return;
}
// empty
if ((!CollectionUtils.isEmpty(exportGroup.getVolumes()) || !CollectionUtils.isEmpty(exportGroup.getSnapshots())) && !CollectionUtils.isEmpty(exportGroup.getExportMasks())) {
Set<String> exportGroupVolumes = new HashSet<>();
if (!CollectionUtils.isEmpty(exportGroup.getVolumes())) {
exportGroupVolumes.addAll(exportGroup.getVolumes().keySet());
}
if (!CollectionUtils.isEmpty(exportGroup.getSnapshots())) {
exportGroupVolumes.addAll(exportGroup.getSnapshots());
}
Set<String> volumesInAllMasks = new HashSet<String>();
// Export masks inside export Group will be limited in number
for (String mask : exportGroup.getExportMasks()) {
ExportMask maskObj = dbClient.queryObject(ExportMask.class, URI.create(mask));
if (null != maskObj && !CollectionUtils.isEmpty(maskObj.getUserAddedVolumes())) {
volumesInAllMasks.addAll(maskObj.getUserAddedVolumes().values());
}
}
// To Avoid concurrent modification exception created new set instance
Set<String> volumeDiff = new HashSet<>(Sets.difference(exportGroupVolumes, volumesInAllMasks));
if (!CollectionUtils.isEmpty(volumeDiff)) {
exportGroup.removeVolumes(new HashSet<String>(volumeDiff));
_log.info("Stale volumes/snapshots {} removed from Export Group {}", volumeDiff, exportGroup.getId());
}
}
if (CollectionUtils.isEmpty(exportGroup.getVolumes()) && CollectionUtils.isEmpty(exportGroup.getSnapshots()) && !exportGroup.checkInternalFlags(DataObject.Flag.INTERNAL_OBJECT)) {
// COP-27689 - Even if all the export masks got cleared, the export
// Group still remains with initiators and volumes.
// Clean up all the initiators, volumes and ports as there are no
// available export masks.
_log.info("There are no volume/snapshot in the export Group {}-->{} after cleaning up stale volumes.", exportGroup.getId(), exportGroup.getLabel());
resetExportGroup(exportGroup, dbClient);
}
}
Aggregations