Search in sources :

Example 16 with URIQueryResultList

use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.

the class ConnectivityUtil method getVplexClusterForVarray.

/**
 * This method returns the VPLEX cluster information for the virtual array. The assumption here is that the passed
 * varrayURI will not have ports from both VPLEX clusters. This is true when its called for the varray
 * which has VPLEX volume created on it. Until VPLEX volume create is attempted on the varray we cannot use this
 * method as user can just assign the network and varray could get ports from both the VPLEX clusters
 *
 * @param varrayURI The URI of the virtaul array
 * @param vplexStorageSystemURI The URI of the VPLEX storage system
 * @param dbClient dbclient
 * @return "1" or "2". Returns "unknown-cluster" if error.
 *
 *         TODO: Move this method to VPlexUtil
 */
public static String getVplexClusterForVarray(URI varrayURI, URI vplexStorageSystemURI, DbClient dbClient) {
    String vplexCluster = CLUSTER_UNKNOWN;
    URIQueryResultList storagePortURIs = new URIQueryResultList();
    dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVirtualArrayStoragePortsConstraint(varrayURI.toString()), storagePortURIs);
    for (URI uri : storagePortURIs) {
        StoragePort storagePort = dbClient.queryObject(StoragePort.class, uri);
        if ((storagePort != null) && DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name().equals(storagePort.getCompatibilityStatus()) && (RegistrationStatus.REGISTERED.toString().equals(storagePort.getRegistrationStatus())) && DiscoveryStatus.VISIBLE.toString().equals(storagePort.getDiscoveryStatus())) {
            if (storagePort.getStorageDevice().equals(vplexStorageSystemURI)) {
                // Assumption is this varray cannot have mix of CLuster 1
                // and Cluster 2 ports from VPLEX so getting
                // cluster information from one of the VPLEX port should
                // work.
                vplexCluster = getVplexClusterOfPort(storagePort);
                break;
            }
        }
    }
    return vplexCluster;
}
Also used : StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 17 with URIQueryResultList

use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.

the class ExportUtils method getInitiatorExportGroups.

/**
 * Returns all the ExportGroups the initiator is a member of.
 *
 * @param initiator Initiator
 * @param dbClient
 * @return List<ExportGroup> that contain a key to the Initiator URI
 */
public static List<ExportGroup> getInitiatorExportGroups(Initiator initiator, DbClient dbClient) {
    List<ExportGroup> exportGroups = new ArrayList<ExportGroup>();
    URIQueryResultList egUris = new URIQueryResultList();
    dbClient.queryByConstraint(AlternateIdConstraint.Factory.getExportGroupInitiatorConstraint(initiator.getId().toString()), egUris);
    ExportGroup exportGroup = null;
    for (URI egUri : egUris) {
        exportGroup = dbClient.queryObject(ExportGroup.class, egUri);
        if (exportGroup == null || exportGroup.getInactive() || exportGroup.getExportMasks() == null) {
            continue;
        }
        exportGroups.add(exportGroup);
    }
    return exportGroups;
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 18 with URIQueryResultList

use of com.emc.storageos.db.client.constraint.URIQueryResultList 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;
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ExportMask(com.emc.storageos.db.client.model.ExportMask) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Initiator(com.emc.storageos.db.client.model.Initiator) BlockObject(com.emc.storageos.db.client.model.BlockObject) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 19 with URIQueryResultList

use of com.emc.storageos.db.client.constraint.URIQueryResultList 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");
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Initiator(com.emc.storageos.db.client.model.Initiator) ExportMask(com.emc.storageos.db.client.model.ExportMask) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 20 with URIQueryResultList

use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.

the class ExportUtils method storagePortNamesToURIs.

/**
 * Take in a list of storage port names (hex digits separated by colons),
 * then returns a list of URIs representing the StoragePort URIs they represent.
 *
 * This method ignores the storage ports from cinder storage systems.
 *
 * @param storagePorts [in] - Storage port name, hex digits separated by colons
 * @return List of StoragePort URIs
 */
public static List<String> storagePortNamesToURIs(DbClient dbClient, List<String> storagePorts) {
    List<String> storagePortURIStrings = new ArrayList<String>();
    Map<URI, String> systemURIToType = new HashMap<URI, String>();
    for (String port : storagePorts) {
        URIQueryResultList portUriList = new URIQueryResultList();
        dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStoragePortEndpointConstraint(port), portUriList);
        Iterator<URI> storagePortIter = portUriList.iterator();
        while (storagePortIter.hasNext()) {
            URI portURI = storagePortIter.next();
            StoragePort sPort = dbClient.queryObject(StoragePort.class, portURI);
            if (sPort != null && !sPort.getInactive()) {
                String systemType = getStoragePortSystemType(dbClient, sPort, systemURIToType);
                // ignore cinder managed storage system's port
                if (!DiscoveredDataObject.Type.openstack.name().equals(systemType)) {
                    storagePortURIStrings.add(portURI.toString());
                }
            }
        }
    }
    return storagePortURIStrings;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StoragePort(com.emc.storageos.db.client.model.StoragePort) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Aggregations

URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)664 URI (java.net.URI)497 ArrayList (java.util.ArrayList)258 HashMap (java.util.HashMap)107 Volume (com.emc.storageos.db.client.model.Volume)97 NamedURI (com.emc.storageos.db.client.model.NamedURI)96 HashSet (java.util.HashSet)92 StoragePort (com.emc.storageos.db.client.model.StoragePort)91 StringSet (com.emc.storageos.db.client.model.StringSet)83 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)64 Produces (javax.ws.rs.Produces)55 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)54 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)54 Path (javax.ws.rs.Path)54 List (java.util.List)53 StoragePool (com.emc.storageos.db.client.model.StoragePool)49 Initiator (com.emc.storageos.db.client.model.Initiator)47 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)45 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)39 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)38