use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.
the class ExportUtils method cleanStaleZoningMapEntries.
/**
* Cleanup any stale entries in the zoning maps for the export masks with the passed URIs.
*
* @param maskURIs The URIs of the export masks to examine.
* @param dbClient A reference to a database client.
*/
private static void cleanStaleZoningMapEntries(List<URI> maskURIs, DbClient dbClient) {
Iterator<ExportMask> maskIter = dbClient.queryIterativeObjects(ExportMask.class, maskURIs);
while (maskIter.hasNext()) {
ExportMask maskObj = maskIter.next();
StringSetMap zoningMap = maskObj.getZoningMap();
StringSet maskInitIds = maskObj.getInitiators();
Set<String> zoningMapInitIds = new HashSet<>(zoningMap.keySet());
for (String zoningMapInitId : zoningMapInitIds) {
if (maskInitIds == null || maskInitIds.isEmpty() || !maskInitIds.contains(zoningMapInitId)) {
zoningMap.remove(zoningMapInitId);
}
}
maskObj.setZoningMap(zoningMap);
dbClient.updateObject(maskObj);
}
}
use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.
the class ExportUtils method cleanStaleClusterReferences.
/**
* Cleans stale cluster references from export group instance
*
* @param exportGroup {@link ExportGroup}
* @param dbClient {@link DbClient}
*/
private static void cleanStaleClusterReferences(ExportGroup exportGroup, DbClient dbClient) {
if (null == exportGroup || exportGroup.getInactive()) {
return;
}
StringSet exportGroupInitiators = exportGroup.getInitiators();
if (!CollectionUtils.isEmpty(exportGroup.getClusters()) && !CollectionUtils.isEmpty(exportGroupInitiators)) {
Set<String> egClusterURIs = new HashSet<>();
Collection<Host> hosts = Collections2.transform(exportGroup.getHosts(), CommonTransformerFunctions.fctnStringToHost(dbClient));
for (Host host : hosts) {
if (host.getCluster() != null) {
egClusterURIs.add(host.getCluster().toString());
}
}
Set<String> staleClusters = new HashSet<>(Sets.difference(exportGroup.getClusters(), egClusterURIs));
if (!CollectionUtils.isEmpty(staleClusters)) {
Collection<URI> staleClusterURIs = Collections2.transform(staleClusters, CommonTransformerFunctions.FCTN_STRING_TO_URI);
_log.info(String.format("Stale cluster references [%s] will be removed from Export Group %s", Joiner.on(',').join(staleClusterURIs), exportGroup.getId()));
exportGroup.removeClusters(new ArrayList<>(staleClusterURIs));
}
}
if (ExportGroupType.Cluster.toString().equalsIgnoreCase(exportGroup.getType()) && CollectionUtils.isEmpty(exportGroup.getClusters()) && !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 clusters in the export Group {}-->{} , after cleaning slate clusters.", exportGroup.getId(), exportGroup.getLabel());
resetExportGroup(exportGroup, dbClient);
}
}
use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.
the class ExportUtils method cleanStaleHostReferences.
/**
* Cleans stale host references from export group instance
*
* @param exportGroup {@link ExportGroup}
* @param dbClient {@link DbClient}
*/
private static void cleanStaleHostReferences(ExportGroup exportGroup, DbClient dbClient) {
if (null == exportGroup || exportGroup.getInactive()) {
return;
}
StringSet exportGroupInitiators = exportGroup.getInitiators();
// not be empty
if (!CollectionUtils.isEmpty(exportGroup.getHosts()) && !CollectionUtils.isEmpty(exportGroupInitiators)) {
Set<String> egHosts = new HashSet<>();
Collection<Initiator> initiators = Collections2.transform(exportGroupInitiators, CommonTransformerFunctions.fctnStringToInitiator(dbClient));
for (Initiator initiator : initiators) {
// upgrade.
if (null != initiator && initiator.getHost() != null) {
egHosts.add(initiator.getHost().toString());
}
}
Set<String> staleHosts = new HashSet<>(Sets.difference(exportGroup.getHosts(), egHosts));
if (!CollectionUtils.isEmpty(staleHosts)) {
Collection<URI> staleHostURIs = Collections2.transform(staleHosts, CommonTransformerFunctions.FCTN_STRING_TO_URI);
_log.info(String.format("Stale host references [%s] will be removed from Export Group %s", Joiner.on(',').join(staleHostURIs), exportGroup.getId()));
exportGroup.removeHosts(new ArrayList<>(staleHostURIs));
}
}
if (!ExportGroupType.Initiator.toString().equalsIgnoreCase(exportGroup.getType()) && CollectionUtils.isEmpty(exportGroup.getHosts()) && !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 hosts in the export Group {}-->{} after cleaning up stale hosts.", exportGroup.getId(), exportGroup.getLabel());
resetExportGroup(exportGroup, dbClient);
}
}
use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.
the class ExportUtils method cleanStaleMaskReferences.
/**
* Cleans stale mask references from export group instance
*
* @param exportGroup {@link ExportGroup}
* @param dbClient {@link DbClient}
*/
private static void cleanStaleMaskReferences(ExportGroup exportGroup, DbClient dbClient) {
if (null == exportGroup || exportGroup.getInactive()) {
return;
}
// Clean stale export mask references from ExportGroup.
StringSet exportMasks = exportGroup.getExportMasks();
if (!CollectionUtils.isEmpty(exportMasks)) {
List<URI> staleMasks = new ArrayList<>();
List<URI> unstaleMasks = new ArrayList<>();
StringSet exportGroupInitiators = exportGroup.getInitiators();
for (String mask : exportMasks) {
boolean isStaleMask = false;
URI maskURI = null;
try {
maskURI = URI.create(mask);
} catch (Exception e) {
_log.error(e.getMessage(), e);
isStaleMask = true;
}
if (maskURI != null) {
ExportMask maskObj = dbClient.queryObject(ExportMask.class, maskURI);
if (maskObj != null && !CollectionUtils.isEmpty(maskObj.getInitiators())) {
isStaleMask = Sets.intersection(exportGroupInitiators, maskObj.getInitiators()).isEmpty();
} else {
isStaleMask = true;
}
}
if (isStaleMask) {
staleMasks.add(maskURI);
_log.info("Stale mask {} will be removed from Export Group {}", maskURI, exportGroup.getId());
} else {
unstaleMasks.add(maskURI);
}
}
if (!CollectionUtils.isEmpty(staleMasks)) {
exportGroup.removeExportMasks(staleMasks);
for (URI maskURI : staleMasks) {
List<ExportGroup> exportGroups = getExportGroupsForMask(maskURI, dbClient);
if (exportGroups.isEmpty() || (exportGroups.size() == 1 && exportGroups.get(0).getId().equals(exportGroup.getId()))) {
ExportMask maskObj = dbClient.queryObject(ExportMask.class, maskURI);
if (maskObj != null) {
_log.info("Deleting export mask {} because it is no longer in use by an export group", maskObj);
dbClient.removeObject(maskObj);
}
}
}
}
// masks that are not stale.
if (!CollectionUtils.isEmpty(unstaleMasks)) {
cleanStaleZoningMapEntries(unstaleMasks, dbClient);
}
}
if (CollectionUtils.isEmpty(exportGroup.getExportMasks()) && !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 masks in the export Group {}-->{} after cleaning up stale masks.", exportGroup.getId(), exportGroup.getLabel());
resetExportGroup(exportGroup, dbClient);
}
}
use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.
the class ExportUtils method updateZoningMap.
/**
* This method updates zoning map to add new assignments.
*
* @param dbClient an instance of {@link DbClient}
* @param exportMask The reference to exportMask
* @param assignments New assignments Map of initiator to storagePorts that will be updated in the zoning map
* @param exportMasksToUpdateOnDeviceWithStoragePorts OUT param -- Map of ExportMask to new Storage ports
* @return returns an updated exportMask
*/
public static ExportMask updateZoningMap(DbClient dbClient, ExportMask exportMask, Map<URI, List<URI>> assignments, Map<URI, List<URI>> exportMasksToUpdateOnDeviceWithStoragePorts) {
StringSetMap existingZoningMap = exportMask.getZoningMap();
for (URI initiatorURI : assignments.keySet()) {
boolean initiatorMatchFound = false;
if (existingZoningMap != null && !existingZoningMap.isEmpty()) {
for (String initiatorId : existingZoningMap.keySet()) {
if (initiatorURI.toString().equals(initiatorId)) {
StringSet ports = existingZoningMap.get(initiatorId);
if (ports != null && !ports.isEmpty()) {
initiatorMatchFound = true;
StringSet newTargets = StringSetUtil.uriListToStringSet(assignments.get(initiatorURI));
if (!ports.containsAll(newTargets)) {
ports.addAll(newTargets);
// Adds zoning map entry with new and existing ports. Its kind of updating storage ports for the initiator.
exportMask.addZoningMapEntry(initiatorId, ports);
updateExportMaskStoragePortsMap(exportMask, exportMasksToUpdateOnDeviceWithStoragePorts, assignments, initiatorURI);
}
}
}
}
}
if (!initiatorMatchFound) {
// Adds new zoning map entry for the initiator with new assignments as there isn't one already.
exportMask.addZoningMapEntry(initiatorURI.toString(), StringSetUtil.uriListToStringSet(assignments.get(initiatorURI)));
updateExportMaskStoragePortsMap(exportMask, exportMasksToUpdateOnDeviceWithStoragePorts, assignments, initiatorURI);
}
}
dbClient.persistObject(exportMask);
return exportMask;
}
Aggregations