Search in sources :

Example 56 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 57 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 58 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 59 with StringSet

use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.

the class VPlexUtil method getVPLEXBackendVolume.

/**
 * Returns the source or ha backend volume of the passed VPLEX volume.
 *
 * @param vplexVolume A reference to the VPLEX volume.
 * @param sourceVolume A boolean thats used to return either source
 *            or ha backend volume.
 * @param dbClient an instance of {@link DbClient}
 * @param errorIfNotFound A boolean thats used to either return null or throw error
 *
 * @return A reference to the backend volume
 *         If sourceVolume is true returns source backend
 *         volume else returns ha backend volume.
 */
public static Volume getVPLEXBackendVolume(Volume vplexVolume, boolean sourceVolume, DbClient dbClient, boolean errorIfNotFound) {
    StringSet associatedVolumeIds = vplexVolume.getAssociatedVolumes();
    Volume backendVolume = null;
    if (associatedVolumeIds == null) {
        if (errorIfNotFound) {
            throw InternalServerErrorException.internalServerErrors.noAssociatedVolumesForVPLEXVolume(vplexVolume.forDisplay());
        } else {
            return backendVolume;
        }
    }
    // Get the backend volume either source or ha.
    List<URI> volumeUriList = new ArrayList<>();
    for (String associatedVolumeId : associatedVolumeIds) {
        volumeUriList.add(URI.create(associatedVolumeId));
    }
    Iterator<Volume> volumes = dbClient.queryIterativeObjects(Volume.class, volumeUriList, true);
    while (volumes.hasNext()) {
        Volume associatedVolume = volumes.next();
        if (associatedVolume != null) {
            if (sourceVolume && associatedVolume.getVirtualArray().equals(vplexVolume.getVirtualArray())) {
                backendVolume = associatedVolume;
                break;
            }
            if (!sourceVolume && !(associatedVolume.getVirtualArray().equals(vplexVolume.getVirtualArray()))) {
                backendVolume = associatedVolume;
                break;
            }
        }
    }
    return backendVolume;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList) URI(java.net.URI)

Example 60 with StringSet

use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.

the class ConnectivityUtil method updateRpSystemConnectivity.

/**
 * Refreshes the list of connected varrays for an RP system.
 *
 * @param rpSystem
 */
public static void updateRpSystemConnectivity(ProtectionSystem rpSystem, DbClient dbClient) {
    if (rpSystem.getInactive()) {
        return;
    }
    if (rpSystem.getVirtualArrays() == null) {
        rpSystem.setVirtualArrays(new StringSet());
    }
    rpSystem.getVirtualArrays().replace(StringSetUtil.uriListToSet(getRPSystemVirtualArrays(dbClient, rpSystem.getId())));
    dbClient.updateAndReindexObject(rpSystem);
}
Also used : StringSet(com.emc.storageos.db.client.model.StringSet)

Aggregations

StringSet (com.emc.storageos.db.client.model.StringSet)760 URI (java.net.URI)371 ArrayList (java.util.ArrayList)278 Volume (com.emc.storageos.db.client.model.Volume)189 NamedURI (com.emc.storageos.db.client.model.NamedURI)176 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)137 HashMap (java.util.HashMap)132 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)124 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)116 List (java.util.List)108 HashSet (java.util.HashSet)106 StoragePort (com.emc.storageos.db.client.model.StoragePort)90 StoragePool (com.emc.storageos.db.client.model.StoragePool)75 StringMap (com.emc.storageos.db.client.model.StringMap)74 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)71 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)70 Initiator (com.emc.storageos.db.client.model.Initiator)60 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)60 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)50 Map (java.util.Map)48