Search in sources :

Example 11 with Initiator

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

the class ExportUtils method getExportMaskAllInitiatorPorts.

/**
 * Get all initiator ports in mask.
 *
 * @param exportMask
 * @param dbClient
 * @return
 */
public static Set<String> getExportMaskAllInitiatorPorts(ExportMask exportMask, DbClient dbClient) {
    Set<String> ports = new HashSet<String>();
    if (exportMask.getInitiators() != null && !exportMask.getInitiators().isEmpty()) {
        List<URI> iniUris = StringSetUtil.stringSetToUriList(exportMask.getInitiators());
        List<Initiator> initiators = dbClient.queryObject(Initiator.class, iniUris);
        for (Initiator ini : initiators) {
            if (ini == null || ini.getInitiatorPort() == null) {
                continue;
            }
            ports.add(Initiator.normalizePort(ini.getInitiatorPort()));
        }
    }
    if (exportMask.getExistingInitiators() != null && !exportMask.getExistingInitiators().isEmpty()) {
        for (String initStr : exportMask.getExistingInitiators()) {
            ports.add(initStr);
        }
    }
    return ports;
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 12 with Initiator

use of com.emc.storageos.db.client.model.Initiator 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 13 with Initiator

use of com.emc.storageos.db.client.model.Initiator 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 14 with Initiator

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

the class ExportUtils method getExportMaskAllInitiators.

/**
 * Fetches and returns the initiators for an export mask. If the ExportMask's
 * existing initiators are set, they will also be returned if an instance can
 * be found in ViPR for the given initiator port id.
 *
 * @param exportMask the export mask
 * @param dbClient an instance of {@link DbClient}
 * @return a list of active initiators in the export mask
 */
public static List<URI> getExportMaskAllInitiators(ExportMask exportMask, DbClient dbClient) {
    List<URI> initiators = new ArrayList<URI>();
    if (exportMask.getInitiators() != null && !exportMask.getInitiators().isEmpty()) {
        initiators.addAll(StringSetUtil.stringSetToUriList(exportMask.getInitiators()));
    }
    if (exportMask.getExistingInitiators() != null && !exportMask.getExistingInitiators().isEmpty()) {
        for (String initStr : exportMask.getExistingInitiators()) {
            initStr = Initiator.toPortNetworkId(initStr);
            Initiator init = getInitiator(initStr, dbClient);
            if (init != null && !initiators.contains(init.getId())) {
                initiators.add(init.getId());
            }
        }
    }
    return initiators;
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 15 with Initiator

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

the class ExportUtils method getExportMaskExistingInitiators.

/**
 * A utility function method to get the user-created initiators from an export mask.
 * If an initiator is not found for a given user-created WWN, it is simply
 * ignored and no error is raised.
 *
 * @param exportMask the export mask
 * @param dbClient an instance of DbClient
 * @return a list of Initiators
 */
public static List<Initiator> getExportMaskExistingInitiators(ExportMask exportMask, DbClient dbClient) {
    List<Initiator> initiators = new ArrayList<Initiator>();
    Initiator initiator = null;
    if (exportMask.getExistingInitiators() != null && !exportMask.getExistingInitiators().isEmpty()) {
        for (String initStr : exportMask.getExistingInitiators()) {
            initStr = Initiator.toPortNetworkId(initStr);
            initiator = getInitiator(initStr, dbClient);
            if (initiator != null) {
                initiators.add(initiator);
            }
        }
    }
    return initiators;
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) ArrayList(java.util.ArrayList)

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