Search in sources :

Example 71 with StoragePort

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

the class ExportUtils method getStoragePorts.

/**
 * Fetches and returns the storage ports for an export mask
 *
 * @param exportMask the export mask
 * @param dbClient an instance of {@link DbClient}
 * @return a list of active storage ports used by the export mask
 */
private static List<StoragePort> getStoragePorts(ExportMask exportMask, DbClient dbClient) {
    List<StoragePort> ports = new ArrayList<StoragePort>();
    StoragePort port = null;
    if (exportMask.getStoragePorts() != null) {
        for (String initUri : exportMask.getStoragePorts()) {
            port = dbClient.queryObject(StoragePort.class, URI.create(initUri));
            if (port != null && !port.getInactive()) {
                ports.add(port);
            }
        }
    }
    _log.debug("Found {} stoarge ports in export mask {}", ports.size(), exportMask.getMaskName());
    return ports;
}
Also used : StoragePort(com.emc.storageos.db.client.model.StoragePort) ArrayList(java.util.ArrayList)

Example 72 with StoragePort

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

the class ExportUtils method getBlockObjectInitiatorTargets.

/**
 * Returns initiators-to-target-storage-ports pairing for all initiators to which
 * the block object (volume or snapshot) was exported.
 *
 * @param id the URN of a ViPR block object
 * @param dbClient dbClient an instance of {@link DbClient}
 * @param idEmbeddedInURL
 * @return initiators-to-target-storage-ports pairing for all initiators to which
 *         the block object (volume or snapshot) was exported.
 */
public static ITLRestRepList getBlockObjectInitiatorTargets(URI id, DbClient dbClient, boolean idEmbeddedInURL) {
    BlockObject blockObject = getBlockObject(id, dbClient);
    ArgValidator.checkEntityNotNull(blockObject, id, idEmbeddedInURL);
    ITLRestRepList list = new ITLRestRepList();
    Map<ExportMask, List<ExportGroup>> exportMasks = getBlockObjectExportMasks(blockObject, dbClient);
    Collection<Initiator> initiators = null;
    List<StoragePort> ports = null;
    List<StoragePort> initiatorPorts = null;
    BlockObject bo = Volume.fetchExportMaskBlockObject(dbClient, blockObject.getId());
    if (bo != null) {
        Map<StoragePort, List<FCZoneReference>> zoneRefs = null;
        for (ExportMask exportMask : exportMasks.keySet()) {
            // now process the initiators - Every initiator must see the volume
            initiators = getInitiators(exportMask, dbClient);
            _log.debug("Found {} initiators in export mask {}", initiators.size(), exportMask.getMaskName());
            ports = getStoragePorts(exportMask, dbClient);
            _log.debug("Found {} storage ports in export mask {}", ports.size(), exportMask.getMaskName());
            String hlu = exportMask.getVolumes().get(bo.getId().toString());
            _log.debug("Start pairing initiators and targets in export mask {}.", exportMask.getMaskName());
            for (Initiator initiator : initiators) {
                initiatorPorts = getInitiatorPorts(exportMask, initiator, ports, dbClient);
                zoneRefs = getInitiatorsZoneReferencesForBlockObject(initiator, initiatorPorts, bo, dbClient);
                list.getExportList().addAll(getItlsForMaskInitiator(dbClient, exportMasks.get(exportMask), exportMask, initiator, hlu, blockObject, initiatorPorts, zoneRefs));
            }
        }
    }
    _log.info("{} ITLs were found for block object {}.", list.getExportList().size(), blockObject.getLabel());
    return list;
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) ExportMask(com.emc.storageos.db.client.model.ExportMask) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) StoragePort(com.emc.storageos.db.client.model.StoragePort) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 73 with StoragePort

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

the class ExportUtils method getZoneReferences.

/**
 * Find the san zone information for the initiator/block object.
 *
 * @param blockObjectUri the block object URI
 * @param initiator the initiator
 * @param ports the target ports
 * @param refs a map of port-to-zone-reference
 * @return the list of san zones created for the initiator if any were created. Otherwise, an returns empty map.
 */
private static Map<StoragePort, FCZoneReference> getZoneReferences(URI blockObjectUri, Initiator initiator, List<StoragePort> ports, Map<StoragePort, List<FCZoneReference>> refs) {
    Map<StoragePort, FCZoneReference> targetPortReferences = new HashMap<StoragePort, FCZoneReference>();
    if (initiator.getProtocol().equals(Block.FC.name())) {
        for (StoragePort port : ports) {
            for (FCZoneReference ref : refs.get(port)) {
                if (ref != null && !ref.getInactive() && blockObjectUri.equals(ref.getVolumeUri())) {
                    targetPortReferences.put(port, ref);
                    // there should be one only
                    break;
                }
            }
        }
    }
    _log.debug("Found {} san zone references for initiator {} and block object {}", new Object[] { targetPortReferences.size(), initiator.getInitiatorPort(), blockObjectUri });
    return targetPortReferences;
}
Also used : HashMap(java.util.HashMap) StoragePort(com.emc.storageos.db.client.model.StoragePort) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference)

Example 74 with StoragePort

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

the class ExportUtils method getInitiatorsZoneReferences.

/**
 * Find the san zone information for the initiator and storage ports. Returns
 * a map of zone references per port.
 *
 * @param initiator the initiator
 * @param ports the target ports
 * @param dbClient an instance of {@link DbClient}
 * @return a map of san zones created for the initiator grouped by port for
 *         the list of target ports. Otherwise, an returns empty map.
 */
private static Map<StoragePort, List<FCZoneReference>> getInitiatorsZoneReferences(Initiator initiator, List<StoragePort> ports, DbClient dbClient) {
    Map<StoragePort, List<FCZoneReference>> targetPortReferences = new HashMap<StoragePort, List<FCZoneReference>>();
    if (initiator.getProtocol().equals(Block.FC.name())) {
        List<FCZoneReference> refs = null;
        for (StoragePort port : ports) {
            String key = FCZoneReference.makeEndpointsKey(Arrays.asList(initiator.getInitiatorPort(), port.getPortNetworkId()));
            refs = new ArrayList<FCZoneReference>();
            targetPortReferences.put(port, refs);
            URIQueryResultList queryList = new URIQueryResultList();
            dbClient.queryByConstraint(AlternateIdConstraint.Factory.getFCZoneReferenceKeyConstraint(key), queryList);
            Iterator<FCZoneReference> refsUris = dbClient.queryIterativeObjects(FCZoneReference.class, iteratorToList(queryList));
            FCZoneReference ref = null;
            while (refsUris.hasNext()) {
                ref = refsUris.next();
                if (ref != null && !ref.getInactive()) {
                    refs.add(ref);
                }
            }
        }
    }
    return targetPortReferences;
}
Also used : HashMap(java.util.HashMap) StoragePort(com.emc.storageos.db.client.model.StoragePort) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference)

Example 75 with StoragePort

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

the class ExportUtils method getItlsForMaskInitiator.

/**
 * For a volume/snapshot-initiator pair find the target ports for the initiator in the list of
 * ports and find the zone name if zoning was performed. Return a list of ITLs for
 * each volume-initiator-target found.
 *
 * @param dbClient db client
 * @param exportMask the export mask the initiator is in
 * @param initiator the initiator
 * @param hlu the lun Id used by the initiator for the volume
 * @param blockObject the volume or snapshot
 * @param initiatorPorts ports to which the initiator is zoned in the export mask
 * @param zoneRefs a map of port-to-zone-reference
 * @param exportGroup the export groups in this export mask
 * @return all ITLs for a volume/snapshot-initiator pair.
 */
private static List<ITLRestRep> getItlsForMaskInitiator(DbClient dbClient, List<ExportGroup> exportGroups, ExportMask exportMask, Initiator initiator, String hlu, BlockObject blockObject, List<StoragePort> initiatorPorts, Map<StoragePort, List<FCZoneReference>> zoneRefs) {
    List<ITLRestRep> list = new ArrayList<ITLRestRep>();
    Map<StoragePort, FCZoneReference> initiatorZoneRefs = null;
    // Find the block object that would appear in the Export Mask
    BlockObject bo = Volume.fetchExportMaskBlockObject(dbClient, blockObject.getId());
    if (bo != null) {
        _log.debug("Finding target ports for initiator {} and block object {}", initiator.getInitiatorPort(), bo.getNativeGuid());
        initiatorZoneRefs = getZoneReferences(bo.getId(), initiator, initiatorPorts, zoneRefs);
        _log.debug("{} target ports and {} SAN zones were found for initiator {} and block object {}", new Object[] { initiatorPorts.size(), initiatorZoneRefs.size(), initiator.getInitiatorPort(), bo.getNativeGuid() });
        // TODO - Should we add special handling of iscsi initiators?
        for (ExportGroup exportGroup : exportGroups) {
            if (exportGroup.getVolumes() != null && exportGroup.getVolumes().containsKey(blockObject.getId().toString()) && exportGroup.getInitiators() != null && exportGroup.getInitiators().contains(initiator.getId().toString())) {
                // We want to check if there are any ports in this export group for this initiator
                List<StoragePort> portsInExportGroupVarray = filterPortsInVarray(exportGroup, exportMask.getStorageDevice(), initiatorPorts);
                if (!portsInExportGroupVarray.isEmpty()) {
                    for (StoragePort port : portsInExportGroupVarray) {
                        list.add(createInitiatorTargetRefRep(exportGroup, blockObject, hlu, initiator, port, initiatorZoneRefs.get(port)));
                    }
                } else {
                    list.add(createInitiatorTargetRefRep(exportGroup, blockObject, hlu, initiator, null, null));
                }
            }
        }
    }
    return list;
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) ArrayList(java.util.ArrayList) StoragePort(com.emc.storageos.db.client.model.StoragePort) ITLRestRep(com.emc.storageos.model.block.export.ITLRestRep) BlockObject(com.emc.storageos.db.client.model.BlockObject) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference)

Aggregations

StoragePort (com.emc.storageos.db.client.model.StoragePort)477 URI (java.net.URI)285 ArrayList (java.util.ArrayList)261 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)143 HashMap (java.util.HashMap)134 List (java.util.List)130 NetworkLite (com.emc.storageos.util.NetworkLite)110 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)107 StringSet (com.emc.storageos.db.client.model.StringSet)92 PortAllocationContext (com.emc.storageos.volumecontroller.placement.StoragePortsAllocator.PortAllocationContext)84 HashSet (java.util.HashSet)81 Initiator (com.emc.storageos.db.client.model.Initiator)78 Map (java.util.Map)64 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)62 StoragePool (com.emc.storageos.db.client.model.StoragePool)51 IOException (java.io.IOException)48 StringMap (com.emc.storageos.db.client.model.StringMap)45 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)43 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)42 StorageHADomain (com.emc.storageos.db.client.model.StorageHADomain)34