Search in sources :

Example 21 with ExportGroup

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

the class NetworkScheduler method getZoningTargetsForPaths.

/**
 * Returns a list of zoning targets for adding paths to the export mask.
 *
 * @param exportGroup ExportGroup
 * @param exportMaskURIs export mask URIs
 * @param path Map of initiator URI to List of storage port URIs
 * @param zonesMap a list of existing zones mapped by the initiator port WWN
 * @param dbClient
 * @return List of Zones (NetworkFCZoneInfo)
 * @throws DeviceControllerException
 */
public List<NetworkFCZoneInfo> getZoningTargetsForPaths(URI storageSystemURI, ExportGroup exportGroup, Collection<URI> exportMaskURIs, Map<URI, List<URI>> paths, Map<String, List<Zone>> zonesMap, DbClient dbClient) throws DeviceControllerException {
    List<NetworkFCZoneInfo> zones = new ArrayList<NetworkFCZoneInfo>();
    if (!isZoningRequired(dbClient, exportGroup.getVirtualArray())) {
        _log.info("Zoning not required, returning empty zones list");
        return zones;
    }
    for (URI maskURI : exportMaskURIs) {
        ExportMask mask = _dbClient.queryObject(ExportMask.class, maskURI);
        StringMap volumeMap = mask.getVolumes();
        if (volumeMap == null || volumeMap.isEmpty()) {
            _log.info(String.format("There are no volumes in the export mask %s, skipping", mask.getMaskName()));
            continue;
        }
        List<URI> maskVolumes = StringSetUtil.stringSetToUriList(volumeMap.keySet());
        List<ExportGroup> maskExportGroups = ExportMaskUtils.getExportGroups(dbClient, mask);
        // Filter the paths based on the initiators in zoningMap of this ExportMask
        Map<URI, List<URI>> pathsForMask = new HashMap<URI, List<URI>>();
        for (String initiatorString : mask.getInitiators()) {
            URI initiatorKey = URI.create(initiatorString);
            if (paths.containsKey(initiatorKey)) {
                pathsForMask.put(initiatorKey, paths.get(initiatorKey));
            }
        }
        // Use the intersection of the volumes in the ExportMask and ExportGroup.
        for (ExportGroup group : maskExportGroups) {
            if (group.getVolumes() != null) {
                List<URI> volumes = new ArrayList<URI>(maskVolumes);
                volumes.retainAll(StringSetUtil.stringSetToUriList(group.getVolumes().keySet()));
                zones.addAll(getZoningTargetsForPaths(group, volumes, exportGroup.getVirtualArray(), pathsForMask, zonesMap));
            }
        }
        // Check for zones needed in alternate varray for VPLEX cross-connected
        if (exportGroup.hasAltVirtualArray(storageSystemURI.toString())) {
            URI altVirtualArray = URI.create(exportGroup.getAltVirtualArrays().get(storageSystemURI.toString()));
            if (isZoningRequired(dbClient, altVirtualArray)) {
                for (ExportGroup group : maskExportGroups) {
                    if (group.getVolumes() != null) {
                        List<URI> volumes = new ArrayList<URI>(maskVolumes);
                        volumes.retainAll(StringSetUtil.stringSetToUriList(group.getVolumes().keySet()));
                        zones.addAll(getZoningTargetsForPaths(group, volumes, altVirtualArray, pathsForMask, zonesMap));
                    }
                }
            }
        }
    }
    return zones;
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) HashMap(java.util.HashMap) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) URI(java.net.URI) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) NetworkFCZoneInfo(com.emc.storageos.networkcontroller.NetworkFCZoneInfo) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 22 with ExportGroup

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

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

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

the class ExportUtils method getInitiatorExportMasks.

/**
 * Gets all the export masks of the given system that this initiator is member of.
 *
 * @param initiator the initiator.
 * @param storageURI system uri.
 * @param dbClient an instance of {@link DbClient}
 * @return all the export masks that this initiator is member of
 */
public static List<ExportMask> getInitiatorExportMasks(Initiator initiator, URI storageURI, DbClient dbClient) {
    List<ExportMask> exportMasks = new ArrayList<ExportMask>();
    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) {
            _log.debug("Skipping exportgroup {} as it is not active or no masks found.", egUri);
            continue;
        }
        List<ExportMask> masks = ExportMaskUtils.getExportMasks(dbClient, exportGroup);
        for (ExportMask mask : masks) {
            if (mask != null && !mask.getInactive() && (null == storageURI || URIUtil.identical(mask.getStorageDevice(), storageURI)) && mask.hasInitiator(initiator.getId().toString()) && /*
						 * adding check for the case if the ExportMask contains existing volumes instead
						 * of only volumes. This is for VPlex coexistence case, in particular when ViPR
						 * is trying to use information in StorageView on VPlex to create corresponding ExportMask
						 * Check COP-31815
						 */
            (!CollectionUtils.isEmpty(mask.getVolumes()) || !CollectionUtils.isEmpty(mask.getExistingVolumes())) && mask.getStoragePorts() != null) {
                exportMasks.add(mask);
            }
        }
    }
    _log.info("Found {} export masks for initiator {}", exportMasks.size(), initiator.getInitiatorPort());
    return exportMasks;
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) ExportMask(com.emc.storageos.db.client.model.ExportMask) 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 25 with ExportGroup

use of com.emc.storageos.db.client.model.ExportGroup 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)

Aggregations

ExportGroup (com.emc.storageos.db.client.model.ExportGroup)278 URI (java.net.URI)206 ArrayList (java.util.ArrayList)139 ExportMask (com.emc.storageos.db.client.model.ExportMask)138 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)111 HashMap (java.util.HashMap)94 Initiator (com.emc.storageos.db.client.model.Initiator)86 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)84 NamedURI (com.emc.storageos.db.client.model.NamedURI)80 HashSet (java.util.HashSet)70 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)63 Workflow (com.emc.storageos.workflow.Workflow)61 List (java.util.List)59 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)55 BlockObject (com.emc.storageos.db.client.model.BlockObject)49 Map (java.util.Map)47 ExportOrchestrationTask (com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportOrchestrationTask)44 ControllerException (com.emc.storageos.volumecontroller.ControllerException)41 StringSet (com.emc.storageos.db.client.model.StringSet)38 StringMap (com.emc.storageos.db.client.model.StringMap)33