Search in sources :

Example 76 with Initiator

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

the class VolumeIngestionUtil method findUnManagedVolumesForCluster.

/**
 * Returns a List of UnManagedVolumes for the given Cluster URI.
 *
 * @param clusterUri the Cluster URI to check
 * @param dbClient a reference to the database client
 * @return a List of UnManagedVolumes for the given Cluster URI
 */
public static List<UnManagedVolume> findUnManagedVolumesForCluster(URI clusterUri, DbClient dbClient) {
    _logger.info("finding unmanaged volumes for cluster " + clusterUri);
    Set<URI> consistentVolumeUris = new HashSet<URI>();
    List<URI> hostUris = ComputeSystemHelper.getChildrenUris(dbClient, clusterUri, Host.class, "cluster");
    int hostIndex = 0;
    for (URI hostUri : hostUris) {
        _logger.info("   looking at host " + hostUri);
        List<Initiator> initiators = ComputeSystemHelper.queryInitiators(dbClient, hostUri);
        URIQueryResultList results = new URIQueryResultList();
        Set<URI> unManagedVolumeUris = new HashSet<URI>();
        for (Initiator initiator : initiators) {
            _logger.info("      looking at initiator " + initiator.getInitiatorPort());
            dbClient.queryByConstraint(AlternateIdConstraint.Factory.getUnManagedVolumeInitiatorNetworkIdConstraint(initiator.getInitiatorPort()), results);
            if (results.iterator() != null) {
                for (URI uri : results) {
                    _logger.info("      found UnManagedVolume " + uri);
                    unManagedVolumeUris.add(uri);
                }
            }
        }
        Set<URI> thisHostsUris = new HashSet<URI>();
        for (URI unmanagedVolumeUri : unManagedVolumeUris) {
            if (hostIndex == 0) {
                // on the first host, just add all UnManagedVolumes that were found
                consistentVolumeUris.add(unmanagedVolumeUri);
            } else {
                // on subsequent hosts, create a collection to use in diffing the sets
                thisHostsUris.add(unmanagedVolumeUri);
            }
        }
        if (hostIndex > 0) {
            // retain only UnManagedVolumes that are found exposed to all hosts in the cluster
            consistentVolumeUris.retainAll(thisHostsUris);
        }
        hostIndex++;
    }
    _logger.info("   found {} UnManagedVolumes to be consistent across all hosts", consistentVolumeUris.size());
    List<UnManagedVolume> unmanagedVolumes = new ArrayList<UnManagedVolume>();
    for (URI unmanagedVolumeUri : consistentVolumeUris) {
        UnManagedVolume unmanagedVolume = dbClient.queryObject(UnManagedVolume.class, unmanagedVolumeUri);
        if (unmanagedVolume == null || unmanagedVolume.getInactive() == true) {
            continue;
        }
        unmanagedVolumes.add(unmanagedVolume);
        _logger.info("      volume: " + unmanagedVolume.getLabel() + " nativeGuid: " + unmanagedVolume.getNativeGuid());
    }
    return unmanagedVolumes;
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) HashSet(java.util.HashSet)

Example 77 with Initiator

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

the class VolumeIngestionUtil method verifyNumPath.

/**
 * Given a ZoneInfoMap, check that the hosts in a cluster have a number of
 * paths that is compliant with the vpool specifications.
 *
 * @param initiatorUris
 *            a list of initiators sets, each set belongs to one host in the
 *            cluster
 * @param umask
 *            the UnManagedExportMask being checked
 * @param block
 *            the volume or snapshot for which the zoning are verified
 * @param vPoolURI
 *            - URI of the VPool to ingest blockObject.
 * @param varrayURI
 *            - URI of the Varray to ingest blockObject.
 * @param dbClient
 *            an instance of dbclient
 * @return true if the number of paths is valid.
 */
private static boolean verifyNumPath(List<Set<String>> initiatorUris, UnManagedExportMask umask, BlockObject block, URI vPoolURI, URI varrayUri, DbClient dbClient) {
    DbModelClientImpl dbModelClient = new DbModelClientImpl(dbClient);
    ExportPathParams pathParams = BlockStorageScheduler.getExportPathParam(block, vPoolURI, dbClient);
    for (Set<String> hostInitiatorUris : initiatorUris) {
        List<Initiator> initiators = CustomQueryUtility.iteratorToList(dbModelClient.find(Initiator.class, StringSetUtil.stringSetToUriList(hostInitiatorUris)));
        // If this an RP initiator, do not validate num path against the vpool; it's a back-end mask with different
        // pathing rules.
        boolean avoidNumPathCheck = false;
        for (Initiator initiator : initiators) {
            if (initiator.checkInternalFlags(Flag.RECOVERPOINT)) {
                avoidNumPathCheck = true;
            }
        }
        // if vplex distributed, only verify initiators connected to same vplex cluster as unmanaged export mask
        if (isVplexVolume(block, dbClient)) {
            VirtualPool vpool = dbClient.queryObject(VirtualPool.class, vPoolURI);
            if (VirtualPool.vPoolSpecifiesHighAvailabilityDistributed(vpool)) {
                _logger.info("initiators before filtering for vplex distributed: " + initiators);
                // determine the source and ha vplex cluster names for comparing to the unmanaged export mask
                StorageSystem vplex = dbClient.queryObject(StorageSystem.class, umask.getStorageSystemUri());
                String sourceVarrayVplexClusterName = VPlexControllerUtils.getVPlexClusterName(dbClient, varrayUri, vplex.getId());
                List<URI> varrayUris = new ArrayList<URI>();
                varrayUris.add(varrayUri);
                URI haVarrayUri = VPlexUtil.getHAVarray(vpool);
                String haVarrayVplexClusterName = null;
                if (null != haVarrayUri) {
                    varrayUris.add(haVarrayUri);
                    haVarrayVplexClusterName = VPlexControllerUtils.getVPlexClusterName(dbClient, haVarrayUri, vplex.getId());
                }
                // determine the vplex cluster name that the unmanaged export mask resides upon
                String umaskVplexClusterId = ConnectivityUtil.getVplexClusterForStoragePortUris(URIUtil.toURIList(umask.getKnownStoragePortUris()), umask.getStorageSystemUri(), dbClient);
                String umaskVplexClusterName = VPlexControllerUtils.getClusterNameForId(umaskVplexClusterId, vplex.getId(), dbClient);
                // partition the host's initiators by virtual array (source or high availability)
                Map<URI, List<URI>> varraysToInitiators = VPlexUtil.partitionInitiatorsByVarray(dbClient, URIUtil.toURIList(hostInitiatorUris), varrayUris, vplex);
                // determine the varray to check by matching the vplex cluster names
                URI varrayToCheck = null;
                URI otherVarray = null;
                if (null != umaskVplexClusterName) {
                    if (umaskVplexClusterName.equalsIgnoreCase(sourceVarrayVplexClusterName)) {
                        varrayToCheck = varrayUri;
                        otherVarray = haVarrayUri;
                    } else if (umaskVplexClusterName.equalsIgnoreCase(haVarrayVplexClusterName)) {
                        varrayToCheck = haVarrayUri;
                        otherVarray = varrayUri;
                    }
                } else {
                    _logger.error("Could not determine UnManagedExportMask VPLEX cluster name for mask " + umask.getMaskName());
                    return false;
                }
                // if no initiators match, then skip the num path check, it doesn't apply to this host.
                if (null != varrayToCheck) {
                    List<URI> initsToCheck = varraysToInitiators.get(varrayToCheck);
                    if (initsToCheck != null && !initsToCheck.isEmpty()) {
                        initiators = CustomQueryUtility.iteratorToList(dbModelClient.find(Initiator.class, initsToCheck));
                    } else {
                        List<URI> otherVarrayInits = varraysToInitiators.get(otherVarray);
                        if (null != otherVarrayInits && !otherVarrayInits.isEmpty()) {
                            avoidNumPathCheck = true;
                        }
                    }
                } else {
                    _logger.error("inits not filtered for vplex distributed because a varray couldn't be determined for mask " + umask.getMaskName());
                    return false;
                }
                _logger.info("initiators after filtering for vplex distributed: " + initiators);
            }
        }
        if (hasFCInitiators(initiators) && !avoidNumPathCheck) {
            return verifyHostNumPath(pathParams, initiators, umask.getZoningMap(), dbClient);
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) DbModelClientImpl(com.emc.storageos.db.client.impl.DbModelClientImpl) Initiator(com.emc.storageos.db.client.model.Initiator) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) ExportPathParams(com.emc.storageos.db.client.model.ExportPathParams) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 78 with Initiator

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

the class BlockDeviceController method getInitiatorAlias.

@Override
public String getInitiatorAlias(URI systemURI, URI initiatorURI) throws Exception {
    StorageSystem system = _dbClient.queryObject(StorageSystem.class, systemURI);
    Initiator initiator = _dbClient.queryObject(Initiator.class, initiatorURI);
    return getDevice(system.getSystemType()).doInitiatorAliasGet(system, initiator);
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 79 with Initiator

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

the class BlockDeviceController method setInitiatorAlias.

@Override
public void setInitiatorAlias(URI systemURI, URI initiatorURI, String initiatorAlias) throws Exception {
    StorageSystem system = _dbClient.queryObject(StorageSystem.class, systemURI);
    Initiator initiator = _dbClient.queryObject(Initiator.class, initiatorURI);
    getDevice(system.getSystemType()).doInitiatorAliasSet(system, initiator, initiatorAlias);
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 80 with Initiator

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

the class HDSExportOperations method findExportMasks.

@Override
public Map<String, Set<URI>> findExportMasks(StorageSystem storage, List<String> initiatorNames, boolean mustHaveAllPorts) throws DeviceControllerException {
    Map<String, Set<URI>> matchingMasks = new HashMap<String, Set<URI>>();
    log.info("finding export masks for storage {}", storage.getId());
    String systemObjectID = HDSUtils.getSystemObjectID(storage);
    Map<URI, Set<HostStorageDomain>> matchedHostHSDsMap = new HashMap<URI, Set<HostStorageDomain>>();
    Map<URI, Set<URI>> hostToInitiatorMap = new HashMap<URI, Set<URI>>();
    Map<URI, Set<String>> matchedHostInitiators = new HashMap<URI, Set<String>>();
    try {
        HDSApiClient client = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
        HDSApiExportManager exportManager = client.getHDSApiExportManager();
        List<HostStorageDomain> hsdList = exportManager.getHostStorageDomains(systemObjectID);
        for (HostStorageDomain hsd : hsdList) {
            List<String> initiatorsExistsOnHSD = getInitiatorsExistsOnHSD(hsd.getWwnList(), hsd.getIscsiList());
            // Find out if the port is in this masking container
            for (String initiatorName : initiatorNames) {
                String normalizedName = initiatorName.replace(HDSConstants.COLON, HDSConstants.DOT_OPERATOR);
                if (initiatorsExistsOnHSD.contains(normalizedName)) {
                    log.info("Found a matching HSD for {}", initiatorName);
                    Initiator initiator = fetchInitiatorByName(initiatorName);
                    Set<HostStorageDomain> matchedHSDs = matchedHostHSDsMap.get(initiator.getHost());
                    if (matchedHSDs == null) {
                        matchedHSDs = new HashSet<HostStorageDomain>();
                        matchedHostHSDsMap.put(initiator.getHost(), matchedHSDs);
                    }
                    matchedHSDs.add(hsd);
                    Set<String> matchedInitiators = matchedHostInitiators.get(initiator.getHost());
                    if (null == matchedInitiators) {
                        matchedInitiators = new HashSet<String>();
                        matchedHostInitiators.put(initiator.getHost(), matchedInitiators);
                    }
                    matchedInitiators.add(initiatorName);
                }
            }
        }
        hsdList.clear();
        log.info("matchedHSDs: {}", matchedHostHSDsMap);
        log.info("initiatorURIToNameMap: {}", matchedHostInitiators);
        processInitiators(initiatorNames, hostToInitiatorMap);
        List<URI> activeMaskIdsInDb = dbClient.queryByType(ExportMask.class, true);
        List<ExportMask> activeMasks = dbClient.queryObject(ExportMask.class, activeMaskIdsInDb);
        if (null != matchedHostHSDsMap && !matchedHostHSDsMap.isEmpty()) {
            // Iterate through each host
            for (URI hostURI : hostToInitiatorMap.keySet()) {
                Set<URI> hostInitiators = hostToInitiatorMap.get(hostURI);
                boolean isNewExportMask = false;
                // Create single ExportMask for each host-varray combination
                List<ExportMask> exportMaskWithHostInitiators = fetchExportMasksFromDB(activeMasks, hostInitiators, storage);
                Set<HostStorageDomain> hsds = matchedHostHSDsMap.get(hostURI);
                if (!CollectionUtils.isEmpty(hsds)) {
                    for (HostStorageDomain hsd : hsds) {
                        String storagePortOFHDSURI = getStoragePortURIs(Arrays.asList(hsd.getPortID()), storage).get(0);
                        ExportMask maskForHSD = null;
                        for (ExportMask exportMaskhavingInitiators : exportMaskWithHostInitiators) {
                            if (exportMaskhavingInitiators.getStoragePorts().contains(storagePortOFHDSURI)) {
                                maskForHSD = exportMaskhavingInitiators;
                                break;
                            }
                        }
                        if (null == maskForHSD) {
                            // first get the varrays associated with the storage port of the HSD and then check if
                            // any of the export masks have storage ports, which have virtual arrays overlapping with the virtual
                            // arrays of the HSD storage port
                            // NOTE: If the storageport is assigned to multiple varrays, then maintaining one
                            // export mask per varray is not possible. Proper seggregation has to be done.
                            StringSet varraysAssociatedWithHSDStoragePort = getTaggedVarrays(storagePortOFHDSURI);
                            if (!varraysAssociatedWithHSDStoragePort.isEmpty()) {
                                boolean bMaskFound = false;
                                for (ExportMask exportMaskhavingInitiators : exportMaskWithHostInitiators) {
                                    for (String storagePortUriIter : exportMaskhavingInitiators.getStoragePorts()) {
                                        // get the storage port entity
                                        StringSet varraysOfStoragePort = getTaggedVarrays(storagePortUriIter);
                                        if (StringSetUtil.hasIntersection(varraysOfStoragePort, varraysAssociatedWithHSDStoragePort)) {
                                            maskForHSD = exportMaskhavingInitiators;
                                            // Ingest the foreign HSD into a matching export mask with same host and varray combination
                                            bMaskFound = true;
                                            break;
                                        }
                                    }
                                    if (bMaskFound) {
                                        break;
                                    }
                                }
                            } else {
                                // Since this HSD port is not tagged to any varray, we will not ingest it
                                continue;
                            }
                            if (null == maskForHSD) {
                                // No matching export mask found for the same host and varray combination. Creating a new export mask.
                                isNewExportMask = true;
                                maskForHSD = new ExportMask();
                                maskForHSD.setId(URIUtil.createId(ExportMask.class));
                                maskForHSD.setStorageDevice(storage.getId());
                                maskForHSD.setCreatedBySystem(false);
                            }
                        }
                        Set<HostStorageDomain> hsdSet = new HashSet<>();
                        hsdSet.add(hsd);
                        updateHSDInfoInExportMask(maskForHSD, hostInitiators, hsdSet, storage, matchingMasks);
                        if (isNewExportMask) {
                            dbClient.createObject(maskForHSD);
                            exportMaskWithHostInitiators.add(maskForHSD);
                        } else {
                            ExportMaskUtils.sanitizeExportMaskContainers(dbClient, maskForHSD);
                            dbClient.updateObject(maskForHSD);
                        }
                        updateMatchingMasksForHost(matchedHostInitiators.get(hostURI), maskForHSD, matchingMasks);
                    }
                }
            }
        }
    } catch (Exception e) {
        log.error("Error when attempting to query LUN masking information", e);
        throw HDSException.exceptions.queryExistingMasksFailure(e.getMessage());
    }
    log.info("Found matching masks: {}", matchingMasks);
    return matchingMasks;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) HashMap(java.util.HashMap) URI(java.net.URI) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) Initiator(com.emc.storageos.db.client.model.Initiator) StringSet(com.emc.storageos.db.client.model.StringSet) HashSet(java.util.HashSet) HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) ExportMask(com.emc.storageos.db.client.model.ExportMask) HDSApiExportManager(com.emc.storageos.hds.api.HDSApiExportManager) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HDSException(com.emc.storageos.hds.HDSException)

Aggregations

Initiator (com.emc.storageos.db.client.model.Initiator)487 URI (java.net.URI)345 ArrayList (java.util.ArrayList)266 HashMap (java.util.HashMap)170 HashSet (java.util.HashSet)161 ExportMask (com.emc.storageos.db.client.model.ExportMask)156 List (java.util.List)119 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)102 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)98 Map (java.util.Map)85 StringSet (com.emc.storageos.db.client.model.StringSet)83 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)82 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)81 StoragePort (com.emc.storageos.db.client.model.StoragePort)78 NamedURI (com.emc.storageos.db.client.model.NamedURI)73 Set (java.util.Set)72 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)58 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)57 StringMap (com.emc.storageos.db.client.model.StringMap)55 Host (com.emc.storageos.db.client.model.Host)54