Search in sources :

Example 1 with ITLRestRepList

use of com.emc.storageos.model.block.export.ITLRestRepList in project coprhd-controller by CoprHD.

the class ExportUtils method getItlsForInitiator.

/**
 * Gets the list of exports (ITL) for one initiator. The list contains all the volumes and snapshots
 * that are exported to the initiator together with the target ports and the zones when zoning
 * was performed.
 *
 * @param initiator the initiator
 * @param dbClient an instance of {@link DbClient}
 * @param permissionsHelper an instance of {@link PermissionsHelper}
 * @param user a pointer to the logged in user
 * @return the list of ITLs for one initiator
 */
public static ITLRestRepList getItlsForInitiator(Initiator initiator, DbClient dbClient, PermissionsHelper permissionsHelper, StorageOSUser user) throws DatabaseException {
    ITLRestRepList list = new ITLRestRepList();
    Map<ExportMask, List<ExportGroup>> exportMasks = null;
    exportMasks = getInitiatorExportMasks(initiator, dbClient, permissionsHelper, user);
    BlockObject blockObject = null;
    List<StoragePort> ports = null;
    List<StoragePort> initiatorPorts = null;
    Map<StoragePort, List<FCZoneReference>> zoneRefs = null;
    String hlu = "";
    Map<String, BlockObject> blockObjects = getBlockObjectsForMasks(exportMasks.keySet(), dbClient);
    for (ExportMask exportMask : exportMasks.keySet()) {
        _log.info("Finding ITLs for initiator {} in export mask {}", initiator.getInitiatorPort(), exportMask.getMaskName());
        ports = getStoragePorts(exportMask, dbClient);
        initiatorPorts = getInitiatorPorts(exportMask, initiator, ports, dbClient);
        zoneRefs = getInitiatorsZoneReferences(initiator, initiatorPorts, dbClient);
        for (String doUri : exportMask.getVolumes().keySet()) {
            hlu = exportMask.getVolumes().get(doUri);
            blockObject = blockObjects.get(doUri);
            if (blockObject != null) {
                list.getExportList().addAll(getItlsForMaskInitiator(dbClient, exportMasks.get(exportMask), exportMask, initiator, hlu, blockObject, initiatorPorts, zoneRefs));
            }
        }
    }
    _log.info("{} ITLs were found for initiator {}.", list.getExportList().size(), initiator.getInitiatorPort());
    return list;
}
Also used : 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 2 with ITLRestRepList

use of com.emc.storageos.model.block.export.ITLRestRepList 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 3 with ITLRestRepList

use of com.emc.storageos.model.block.export.ITLRestRepList in project coprhd-controller by CoprHD.

the class ExportUtils method getInitiatorsItls.

/**
 * For each initiator in the list, return all the volumes and snapshots that
 * have been exported to it together with the target ports and zone name when
 * zoning has been performed.
 *
 * @param networkPorts a list of initiator WWNs or IQNs
 * @param dbClient dbClient an instance of {@link DbClient}
 * @param permissionsHelper an instance of {@link PermissionsHelper}
 * @param user a pointer to the logged in user
 * @return all the volumes and snapshots that have been exported to the
 *         initiators together with the target ports and zone name when
 *         zoning has been performed.
 */
public static ITLRestRepList getInitiatorsItls(List<String> networkPorts, DbClient dbClient, PermissionsHelper permissionsHelper, StorageOSUser user) throws DatabaseException {
    ITLRestRepList list = new ITLRestRepList();
    List<String> invalidNetworkPorts = new ArrayList<String>();
    Map<String, Initiator> initiators = new HashMap<String, Initiator>();
    // get the initiators
    for (String networkPort : networkPorts) {
        Initiator initiator = null;
        if (initiators.containsKey(networkPort)) {
            continue;
        }
        initiator = getInitiator(networkPort, dbClient);
        if (initiator == null) {
            invalidNetworkPorts.add(networkPort);
        } else {
            initiators.put(networkPort, initiator);
        }
    }
    // check all the initiators exist and are active
    if (!invalidNetworkPorts.isEmpty()) {
        _log.warn("Could not find active initiator for the following initiator ports {}", invalidNetworkPorts);
    }
    for (Initiator initiator : initiators.values()) {
        list.getExportList().addAll(getItlsForInitiator(initiator, dbClient, permissionsHelper, user).getExportList());
    }
    _log.info("{} ITLs were found for the request.", list.getExportList().size());
    return list;
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) HashMap(java.util.HashMap) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) ArrayList(java.util.ArrayList)

Example 4 with ITLRestRepList

use of com.emc.storageos.model.block.export.ITLRestRepList in project coprhd-controller by CoprHD.

the class BlockExports method getExportsForInitiatorPorts.

/**
 * Gets the exports (initiator-target-lun) for the given initiator ports.
 * <p>
 * API Call: <tt>GET /block/exports?initiators={initiatorPort1},{initiatorPort2},...</tt>
 *
 * @param initiatorPorts
 *            the initiator ports.
 * @return the list of exports.
 */
public List<ITLRestRep> getExportsForInitiatorPorts(Collection<String> initiatorPorts) {
    UriBuilder builder = client.uriBuilder(baseUrl);
    StringBuilder ports = new StringBuilder();
    for (String initiatorPort : initiatorPorts) {
        if (ports.length() > 0) {
            ports.append(',');
        }
        ports.append(initiatorPort);
    }
    builder.queryParam("initiators", ports.toString());
    ITLRestRepList list = client.getURI(ITLRestRepList.class, builder.build());
    return defaultList(list.getExportList());
}
Also used : ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) UriBuilder(javax.ws.rs.core.UriBuilder)

Example 5 with ITLRestRepList

use of com.emc.storageos.model.block.export.ITLRestRepList in project coprhd-controller by CoprHD.

the class ExportService method populateIscsiConnectionInfo.

/*
     * Populate the connection info of the ISCSI volume after completing the 
     * export of volume to the host in ViPR
     */
private VolumeAttachResponse populateIscsiConnectionInfo(Volume vol) throws InterruptedException {
    ITLRestRepList listOfItls = ExportUtils.getBlockObjectInitiatorTargets(vol.getId(), _dbClient, isIdEmbeddedInURL(vol.getId()));
    VolumeAttachResponse objCinderInit = new VolumeAttachResponse();
    objCinderInit.connection_info = objCinderInit.new ConnectionInfo();
    objCinderInit.connection_info.data = objCinderInit.new Data();
    objCinderInit.connection_info.driver_volume_type = "iscsi";
    objCinderInit.connection_info.data.access_mode = "rw";
    objCinderInit.connection_info.data.target_discovered = false;
    for (ITLRestRep itl : listOfItls.getExportList()) {
        // TODO: user setter methods to set the values of object below.
        objCinderInit.connection_info.data.target_iqn = itl.getStoragePort().getPort();
        objCinderInit.connection_info.data.target_portal = itl.getStoragePort().getIpAddress() + ":" + itl.getStoragePort().getTcpPort();
        objCinderInit.connection_info.data.volume_id = getCinderHelper().trimId(vol.getId().toString());
        objCinderInit.connection_info.data.target_lun = itl.getHlu();
        _log.info(String.format("itl.getStoragePort().getPort() is %s: itl.getStoragePort().getIpAddress():%s,itl.getHlu() :%s, objCinderInit.toString():%s", itl.getStoragePort().getPort(), itl.getStoragePort().getIpAddress() + ":" + itl.getStoragePort().getTcpPort(), itl.getHlu(), objCinderInit.toString()));
        return objCinderInit;
    }
    return objCinderInit;
}
Also used : VolumeAttachResponse(com.emc.storageos.cinder.model.VolumeAttachResponse) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) ITLRestRep(com.emc.storageos.model.block.export.ITLRestRep)

Aggregations

ITLRestRepList (com.emc.storageos.model.block.export.ITLRestRepList)6 ArrayList (java.util.ArrayList)4 Initiator (com.emc.storageos.db.client.model.Initiator)3 List (java.util.List)3 VolumeAttachResponse (com.emc.storageos.cinder.model.VolumeAttachResponse)2 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 BlockObject (com.emc.storageos.db.client.model.BlockObject)2 ExportMask (com.emc.storageos.db.client.model.ExportMask)2 StoragePort (com.emc.storageos.db.client.model.StoragePort)2 ITLRestRep (com.emc.storageos.model.block.export.ITLRestRep)2 SearchedResRepList (com.emc.storageos.api.service.impl.response.SearchedResRepList)1 HashMap (java.util.HashMap)1 UriBuilder (javax.ws.rs.core.UriBuilder)1