Search in sources :

Example 21 with StringSet

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);
    }
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) ExportMask(com.emc.storageos.db.client.model.ExportMask) StringSet(com.emc.storageos.db.client.model.StringSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 22 with StringSet

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);
    }
}
Also used : StringSet(com.emc.storageos.db.client.model.StringSet) Host(com.emc.storageos.db.client.model.Host) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 23 with StringSet

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);
    }
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) StringSet(com.emc.storageos.db.client.model.StringSet) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 24 with StringSet

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);
    }
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) ExportMask(com.emc.storageos.db.client.model.ExportMask) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException)

Example 25 with StringSet

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;
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringSet(com.emc.storageos.db.client.model.StringSet) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Aggregations

StringSet (com.emc.storageos.db.client.model.StringSet)753 URI (java.net.URI)366 ArrayList (java.util.ArrayList)274 Volume (com.emc.storageos.db.client.model.Volume)189 NamedURI (com.emc.storageos.db.client.model.NamedURI)173 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)135 HashMap (java.util.HashMap)129 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)119 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)111 HashSet (java.util.HashSet)105 List (java.util.List)105 StoragePort (com.emc.storageos.db.client.model.StoragePort)86 StoragePool (com.emc.storageos.db.client.model.StoragePool)75 StringMap (com.emc.storageos.db.client.model.StringMap)72 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)71 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)70 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)55 Initiator (com.emc.storageos.db.client.model.Initiator)54 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)48 Map (java.util.Map)47