Search in sources :

Example 11 with ExportMask

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

the class ExportUtils method buildVolumesToExportMasksMap.

/**
 * Create a TreeMultimap that gives a mapping of a volume URI String to a list of
 * ExportMasks that the volume is associated with. All ExportMasks are associated
 * with the ExportGroup.
 *
 * @param dbClient [in] - DB client object
 * @param exportGroup [in] - ExportGroup object to use build the mapping
 * @return Mapping of volume URI String to list of ExportMask URIs.
 */
private static TreeMultimap<String, URI> buildVolumesToExportMasksMap(DbClient dbClient, ExportGroup exportGroup) {
    TreeMultimap<String, URI> volumesToExportMasks = TreeMultimap.create();
    List<ExportMask> exportMasks = ExportMaskUtils.getExportMasks(dbClient, exportGroup);
    for (ExportMask exportMask : exportMasks) {
        if (exportMask.getUserAddedVolumes() != null) {
            for (String volUriStr : exportMask.getUserAddedVolumes().values()) {
                volumesToExportMasks.put(volUriStr, exportMask.getId());
            }
        }
    }
    return volumesToExportMasks;
}
Also used : ExportMask(com.emc.storageos.db.client.model.ExportMask) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 12 with ExportMask

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

the class ExportUtils method getInitiatorExportMasks.

/**
 * Gets all the export masks that this initiator is member of.
 *
 * @param initiator the initiator
 * @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, 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) {
            continue;
        }
        List<ExportMask> masks = ExportMaskUtils.getExportMasks(dbClient, exportGroup);
        for (ExportMask mask : masks) {
            if (mask != null && !mask.getInactive() && 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 13 with ExportMask

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

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

the class VPlexUtil method getExportMaskForHostInVarray.

/**
 * Given an ExportGroup, a hostURI, a VPlex storage system, and a Varray,
 * finds the ExportMask in the ExportGroup (if any)
 * corresponding to that host and varray on the specified vplex.
 *
 * @param dbClient -- Database client
 * @param exportGroup -- ExportGroup object
 * @param hostURI -- URI of host
 * @param vplexURI -- URI of VPLEX StorageSystem
 * @param varrayURI -- Varray we want the Export Mask in
 * @return ExportMask or null if not found
 * @throws Exception
 */
public static ExportMask getExportMaskForHostInVarray(DbClient dbClient, ExportGroup exportGroup, URI hostURI, URI vplexURI, URI varrayURI) throws Exception {
    if (ExportMaskUtils.getExportMasks(dbClient, exportGroup).isEmpty()) {
        return null;
    }
    ExportMask sharedExportMask = VPlexUtil.getSharedExportMaskInDb(exportGroup, vplexURI, dbClient, varrayURI, null, null);
    List<ExportMask> exportMasks = ExportMaskUtils.getExportMasks(dbClient, exportGroup, vplexURI);
    for (ExportMask exportMask : exportMasks) {
        boolean shared = false;
        if (sharedExportMask != null) {
            if (sharedExportMask.getId().equals(exportMask.getId())) {
                shared = true;
            }
        }
        if (getExportMaskHosts(dbClient, exportMask, shared).contains(hostURI) && ExportMaskUtils.exportMaskInVarray(dbClient, exportMask, varrayURI, true)) {
            return exportMask;
        }
    }
    return null;
}
Also used : ExportMask(com.emc.storageos.db.client.model.ExportMask)

Example 15 with ExportMask

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

the class VPlexUtil method getSharedExportMaskInDb.

/**
 * Returns the shared export mask in the export group i:e single ExportMask in database for multiple hosts
 * corresponding to the single storage view on VPLEX with multiple hosts.
 *
 * At-least there should be two host in the exportMask to be called as sharedExportMask. Also there shouldn't be more than one
 * exportMask for the exportGroup for a VPLEX cluster.
 *
 * Note : This is applicable from Darth release onwards.
 *
 * @param exportGroup ExportGroup object
 * @param vplexURI URI of the VPLEX system
 * @param dbClient database client instance
 * @param varrayUri Varray we want the Export Mask in
 * @param vplexCluster Vplex Cluster we want ExportMask for
 * @param hostInitiatorMap Map of host to initiators that are not yet added to the storage view on VPLEX
 * @return shared ExportMask for a exportGroup
 * @throws Exception
 */
public static ExportMask getSharedExportMaskInDb(ExportGroup exportGroup, URI vplexURI, DbClient dbClient, URI varrayUri, String vplexCluster, Map<URI, List<Initiator>> hostInitiatorMap) throws Exception {
    ExportMask sharedExportMask = null;
    if (exportGroup.getExportMasks() == null) {
        return null;
    }
    StringSet exportGrouphosts = exportGroup.getHosts();
    // Get all the exportMasks for the VPLEX from the export group
    List<ExportMask> exportMasks = ExportMaskUtils.getExportMasks(dbClient, exportGroup, vplexURI);
    // exportMasks list could have mask for both the VPLEX cluster for the same initiators for the cross-connect case
    // for the cross-connect case hence get the ExportMask for the specific VPLEX cluster.
    List<ExportMask> exportMasksForVplexCluster = getExportMasksForVplexCluster(vplexURI, dbClient, varrayUri, vplexCluster, exportMasks);
    // and we found only one exportMask in database for the VPLEX cluster
    if (exportGrouphosts != null && exportGrouphosts.size() > 1 && exportMasksForVplexCluster.size() == 1) {
        ExportMask exportMask = exportMasksForVplexCluster.get(0);
        ArrayList<String> exportMaskInitiators = new ArrayList<>(exportMask.getInitiators());
        Map<URI, List<Initiator>> exportMaskHostInitiatorsMap = makeHostInitiatorsMap(URIUtil.toURIList(exportMaskInitiators), dbClient);
        // Remove the host which is not yet added by CorpHD
        if (hostInitiatorMap != null) {
            for (Entry<URI, List<Initiator>> entry : hostInitiatorMap.entrySet()) {
                exportMaskHostInitiatorsMap.remove(entry.getKey());
            }
        }
        // If we found more than one host in the exportMask then its a sharedExportMask
        if (exportMaskHostInitiatorsMap.size() > 1) {
            sharedExportMask = exportMask;
        }
    }
    return sharedExportMask;
}
Also used : ExportMask(com.emc.storageos.db.client.model.ExportMask) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) URI(java.net.URI)

Aggregations

ExportMask (com.emc.storageos.db.client.model.ExportMask)368 URI (java.net.URI)274 ArrayList (java.util.ArrayList)224 Initiator (com.emc.storageos.db.client.model.Initiator)155 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)140 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)134 HashMap (java.util.HashMap)128 HashSet (java.util.HashSet)121 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)107 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)102 List (java.util.List)79 StringSet (com.emc.storageos.db.client.model.StringSet)68 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)65 Map (java.util.Map)65 StringMap (com.emc.storageos.db.client.model.StringMap)60 BlockObject (com.emc.storageos.db.client.model.BlockObject)56 NamedURI (com.emc.storageos.db.client.model.NamedURI)56 Workflow (com.emc.storageos.workflow.Workflow)54 Set (java.util.Set)51 Volume (com.emc.storageos.db.client.model.Volume)44