Search in sources :

Example 11 with Initiator

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

the class DellSCProvisioning method createOrFindScServer.

/**
 * Finds an existing server definition or creates a new one.
 *
 * @param ssn The Storage Center to check.
 * @param api The API connection.
 * @param initiators The list of initiators.
 * @param matchedHbas The ScServerHbas that matched the provided initiators.
 * @param createIfNotFound Whether to create the server if it's not found.
 * @return The server object or null.
 */
private ScServer createOrFindScServer(StorageCenterAPI api, String ssn, List<Initiator> initiators, List<ScServerHba> matchedHbas, boolean createIfNotFound) {
    ScServerOperatingSystem os = null;
    Map<String, ScServer> serverLookup = new HashMap<>();
    for (Initiator init : initiators) {
        if (os == null) {
            os = findOsType(api, ssn, init.getHostOsType());
        }
        if (os == null) {
            LOG.warn("Unable to find OS type for initiator {}, skipping...", init.getPort());
            continue;
        }
        String iqnOrWwn = init.getPort();
        if (init.getProtocol().equals(Protocol.FC)) {
            // Make sure it's in the format we expect
            iqnOrWwn = iqnOrWwn.replace(":", "").toUpperCase();
        }
        // Try our cache first
        ScServer individualServer = serverLookup.get(init.getHostName());
        if (individualServer == null) {
            individualServer = api.findServer(ssn, iqnOrWwn);
            if (individualServer != null) {
                serverLookup.put(init.getHostName(), individualServer);
            }
        }
        // See if we need to create it
        if (individualServer == null && createIfNotFound) {
            try {
                individualServer = api.createServer(ssn, init.getHostName(), init.getProtocol().equals(Protocol.iSCSI), os.instanceId);
            } catch (StorageCenterAPIException e) {
                // Well that's rather unfortunate
                LOG.warn(String.format("Error creating server: %s", e));
                continue;
            }
            // Need to add this initiator to existing server definition
            ScServerHba hba = api.addHbaToServer(individualServer.instanceId, iqnOrWwn, init.getProtocol().equals(Protocol.iSCSI));
            if (hba != null && !matchedHbas.contains(hba)) {
                matchedHbas.add(hba);
            }
        }
        if (individualServer != null) {
            serverLookup.put(init.getHostName(), individualServer);
        }
    }
    if (serverLookup.size() != 1) {
        LOG.warn("Looking for server returned {} servers.", serverLookup.size());
    }
    for (ScServer scServer : serverLookup.values()) {
        // Just return the first one
        return scServer;
    }
    return null;
}
Also used : ScServer(com.emc.storageos.driver.dellsc.scapi.objects.ScServer) HashMap(java.util.HashMap) Initiator(com.emc.storageos.storagedriver.model.Initiator) StorageCenterAPIException(com.emc.storageos.driver.dellsc.scapi.StorageCenterAPIException) ScServerOperatingSystem(com.emc.storageos.driver.dellsc.scapi.objects.ScServerOperatingSystem) ScServerHba(com.emc.storageos.driver.dellsc.scapi.objects.ScServerHba)

Example 12 with Initiator

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

the class StorageDriverSimulator method generateExportDataForVolume.

private void generateExportDataForVolume(String hostName, String storageSystemId, String volumeId, int volumeIndex, List<StoragePort> ports, int page) {
    Map<String, List<HostExportInfo>> volumeToExportInfoMap = arrayToVolumeToVolumeExportInfoMap.get(storageSystemId);
    if (volumeToExportInfoMap == null) {
        volumeToExportInfoMap = new HashMap<>();
        arrayToVolumeToVolumeExportInfoMap.put(storageSystemId, volumeToExportInfoMap);
    }
    List<HostExportInfo> volumeToHostExportInfoList = volumeToExportInfoMap.get(volumeId);
    if (volumeToHostExportInfoList == null) {
        volumeToHostExportInfoList = new ArrayList<>();
        volumeToExportInfoMap.put(volumeId, volumeToHostExportInfoList);
    }
    // build volume export info
    HostExportInfo exportInfo;
    // get volume info
    List<String> volumeIds = new ArrayList<>();
    volumeIds.add(volumeId);
    // for initiators we only know port network id and host name
    List<String> hostInitiatorIds = hostToInitiatorPortIdMap.get(hostName);
    List<Initiator> initiators = new ArrayList<>();
    for (String initiatorId : hostInitiatorIds) {
        Initiator initiator = new Initiator();
        initiator.setHostName(hostName);
        initiator.setPort(initiatorId);
        initiators.add(initiator);
    }
    // decide about ports.
    if (page % 2 == 1) {
        // for odd pages we generate invalid masks for volumes (to test negative scenarios)
        int portIndex = volumeIndex < ports.size() ? volumeIndex : ports.size() - 1;
        List<StoragePort> exportPorts = Collections.singletonList(ports.get(portIndex));
        exportInfo = new HostExportInfo(hostName, volumeIds, initiators, exportPorts);
    } else {
        exportInfo = new HostExportInfo(hostName, volumeIds, initiators, ports);
    }
    volumeToHostExportInfoList.add(exportInfo);
    _log.info("VolumeToHostExportInfo: " + volumeToHostExportInfoList);
}
Also used : ArrayList(java.util.ArrayList) StoragePort(com.emc.storageos.storagedriver.model.StoragePort) HostExportInfo(com.emc.storageos.storagedriver.HostExportInfo) Initiator(com.emc.storageos.storagedriver.model.Initiator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 13 with Initiator

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

the class HP3PARExpUnexpHelper method search3parHostName.

private HP3PARHostNameResult search3parHostName(List<Initiator> initiators, HostCommandResult hostRes) {
    String hp3parHost = null;
    HP3PARHostNameResult hp3parHostResult = new HP3PARHostNameResult();
    // for each host in the result
    for (HostMember hostMemb : hostRes.getMembers()) {
        // for each host initiator sent
        for (Initiator init : initiators) {
            // Is initiator FC
            if (Protocols.FC.toString().compareToIgnoreCase(init.getProtocol().toString()) == 0) {
                // verify in all FC ports with host
                for (FcPath fcPath : hostMemb.getFCPaths()) {
                    if (SanUtils.formatWWN(fcPath.getWwn()).compareToIgnoreCase(init.getPort()) == 0) {
                        hp3parHost = hostMemb.getName();
                        // Reference for residual initiator is present and there is no host name associated with this.
                        if (hp3parHost == null) {
                            continue;
                        }
                        hp3parHostResult.setHostName(hp3parHost);
                        // Confirm all initiators are present with this host
                        if (hostHasAllFcInitiators(initiators, hostMemb.getFCPaths())) {
                            _log.info("3PARDriver: get3parHostname FC initiator {} host {}", init.getPort(), hp3parHost);
                            hp3parHostResult.setAllInitiators(true);
                        } else {
                            // same FC can not be part of any other host; exit
                            hp3parHostResult.setAllInitiators(false);
                        }
                        return hp3parHostResult;
                    }
                }
            } else if (Protocols.iSCSI.toString().compareToIgnoreCase(init.getProtocol().toString()) == 0) {
                // verify in all iSCSI ports with host
                for (ISCSIPath scsiPath : hostMemb.getiSCSIPaths()) {
                    if (scsiPath.getName().compareToIgnoreCase(init.getPort()) == 0) {
                        hp3parHost = hostMemb.getName();
                        hp3parHostResult.setHostName(hp3parHost);
                        // Confirm all initiators are present with this host
                        if (hostHasAlliSCSIInitiators(initiators, hostMemb.getiSCSIPaths())) {
                            _log.info("3PARDriver: get3parHostname iSCSI initiator {} host {}", init.getPort(), hp3parHost);
                            hp3parHostResult.setAllInitiators(true);
                        } else {
                            // same iSCSI can not be part of any other host
                            hp3parHostResult.setAllInitiators(false);
                        }
                        return hp3parHostResult;
                    }
                }
            }
        // if FC or iSCSI
        }
    // each initiator
    }
    return null;
}
Also used : Initiator(com.emc.storageos.storagedriver.model.Initiator) HostMember(com.emc.storageos.hp3par.command.HostMember) ISCSIPath(com.emc.storageos.hp3par.command.ISCSIPath) FcPath(com.emc.storageos.hp3par.command.FcPath)

Example 14 with Initiator

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

the class HP3PARIngestHelper method getBlockObjectExportInfoForHosts.

public Map<String, HostExportInfo> getBlockObjectExportInfoForHosts(String storageSystemId, String wwn, String objectName, StorageBlockObject object, Registry registry) {
    try {
        _log.info("3PARDriver: getBlockObjectExportInfoForHosts Running");
        Map<String, HostExportInfo> resultMap = new HashMap<String, HostExportInfo>();
        // get the vlun associated with the volume at consideration.
        HP3PARApi hp3parApi = hp3parUtil.getHP3PARDeviceFromNativeId(storageSystemId, registry);
        VirtualLunsList vlunsOfVolume = hp3parApi.getVLunsOfVolume(wwn);
        // Check which of the storage ports discovered, matches the
        // node:portpos:cardport
        // combination of the VLUN
        List<StoragePort> storPortsOfStorage = new ArrayList<>();
        hp3parUtil.discoverStoragePortsById(storageSystemId, storPortsOfStorage, registry);
        // for (int index = 0; index < vlunsOfVolume.getTotal(); index++) {
        for (VirtualLun objVirtualLun : vlunsOfVolume.getMembers()) {
            if (!objVirtualLun.isActive()) {
                if (objVirtualLun.getType() == 5) {
                    String exportPath = storageSystemId + objectName + objVirtualLun.getHostname();
                    _log.info("3PARDriver:Ingestion {} for registry entry", exportPath);
                    // Make a registry entry for ingested volume if it is
                    // exported to host set
                    Map<String, List<String>> attributes = new HashMap<>();
                    List<String> expValue = new ArrayList<>();
                    List<String> lunValue = new ArrayList<>();
                    expValue.add(exportPath);
                    attributes.put("EXPORT_PATH", expValue);
                    lunValue.add(objVirtualLun.getLun().toString());
                    attributes.put(objectName, lunValue);
                    registry.setDriverAttributesForKey(HP3PARConstants.DRIVER_NAME, exportPath, attributes);
                    _log.info("3PARDriver:Ingestion {} for attributes entry", attributes);
                }
                continue;
            }
            _log.debug("objVirtualLun.toString() {}", objVirtualLun.toString());
            List<String> volumeIds = new ArrayList<>();
            List<Initiator> initiators = new ArrayList<Initiator>();
            List<StoragePort> storageports = new ArrayList<>();
            // To volumeIds we need to add the native id of volume
            // and for hp3par volume name would be the native id
            volumeIds.add(objVirtualLun.getVolumeName());
            Initiator hostInitiator = new Initiator();
            // hp3par returns remote name in the format like
            // 10000000C98F5C79.
            // we now convert this to the format 10:00:00:00:C9:8F:5C:79
            String portId = SanUtils.formatWWN(objVirtualLun.getRemoteName());
            String nativeId = String.format("%s:%s:%s", objVirtualLun.getPortPos().getNode(), objVirtualLun.getPortPos().getSlot(), objVirtualLun.getPortPos().getCardPort());
            for (StoragePort port : storPortsOfStorage) {
                if (port.getNativeId().equals(nativeId)) {
                    storageports.add(port);
                    break;
                }
            }
            hostInitiator.setHostName(objVirtualLun.getHostname());
            hostInitiator.setPort(portId);
            initiators.add(hostInitiator);
            HostExportInfo exportInfo = null;
            if (resultMap.containsKey(objVirtualLun.getHostname())) {
                exportInfo = resultMap.get(objVirtualLun.getHostname());
                for (int i1 = 0; i1 < storageports.size(); i1++) {
                    StoragePort ob1 = storageports.get(i1);
                    if (!exportInfo.getTargets().contains(ob1)) {
                        exportInfo.getTargets().add(ob1);
                    }
                }
                for (int i1 = 0; i1 < initiators.size(); i1++) {
                    Initiator ob1 = initiators.get(i1);
                    if (!exportInfo.getInitiators().contains(ob1)) {
                        exportInfo.getInitiators().add(ob1);
                    }
                }
            } else {
                exportInfo = new HostExportInfo(objVirtualLun.getHostname(), volumeIds, initiators, storageports);
            }
            resultMap.put(objVirtualLun.getHostname(), exportInfo);
        }
        _log.info("Resultmap of GetVolumeExportInfo {}", resultMap);
        _log.info("3PARDriver: Leaving getBlockObjectExportInfoForHosts");
        return resultMap;
    } catch (Exception e) {
        String msg = String.format("3PARDriver: Unable to get export info of the storage objet %s in storage system native id is %s; Error: %s.\n", objectName, storageSystemId, e.getMessage());
        _log.error(msg);
        e.printStackTrace();
    }
    return null;
}
Also used : HashMap(java.util.HashMap) StoragePort(com.emc.storageos.storagedriver.model.StoragePort) ArrayList(java.util.ArrayList) HostExportInfo(com.emc.storageos.storagedriver.HostExportInfo) VirtualLunsList(com.emc.storageos.hp3par.command.VirtualLunsList) Initiator(com.emc.storageos.storagedriver.model.Initiator) ArrayList(java.util.ArrayList) VirtualLunsList(com.emc.storageos.hp3par.command.VirtualLunsList) List(java.util.List) VirtualLun(com.emc.storageos.hp3par.command.VirtualLun)

Example 15 with Initiator

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

the class StorageDriverSimulator method generateExportDataForVolumeReplica.

private void generateExportDataForVolumeReplica(StorageVolume volume, StorageBlockObject replica) {
    Map<String, List<HostExportInfo>> volumeToExportInfoMap = arrayToVolumeToVolumeExportInfoMap.get(volume.getStorageSystemId());
    if (volumeToExportInfoMap != null) {
        List<HostExportInfo> volumeExportInfoList = volumeToExportInfoMap.get(volume.getNativeId());
        if (volumeExportInfoList != null && !volumeExportInfoList.isEmpty()) {
            List<HostExportInfo> replicaExportInfoList = new ArrayList<>();
            // build replica export info from info of parent volume
            for (HostExportInfo hostExportInfo : volumeExportInfoList) {
                List<String> snapIds = new ArrayList<>();
                snapIds.add(replica.getNativeId());
                List<Initiator> hostInitiators = hostExportInfo.getInitiators();
                List<StoragePort> exportPorts = hostExportInfo.getTargets();
                HostExportInfo exportInfo = new HostExportInfo(hostExportInfo.getHostName(), snapIds, hostInitiators, exportPorts);
                replicaExportInfoList.add(exportInfo);
            }
            _log.info("Export Info for replica: {} --- {}", replica.getNativeId(), replicaExportInfoList);
            volumeToExportInfoMap.put(replica.getNativeId(), replicaExportInfoList);
        }
    }
}
Also used : Initiator(com.emc.storageos.storagedriver.model.Initiator) ArrayList(java.util.ArrayList) StoragePort(com.emc.storageos.storagedriver.model.StoragePort) HostExportInfo(com.emc.storageos.storagedriver.HostExportInfo) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Initiator (com.emc.storageos.storagedriver.model.Initiator)23 ArrayList (java.util.ArrayList)15 StoragePort (com.emc.storageos.storagedriver.model.StoragePort)12 URI (java.net.URI)9 HashMap (java.util.HashMap)9 ExportMask (com.emc.storageos.db.client.model.ExportMask)7 HostExportInfo (com.emc.storageos.storagedriver.HostExportInfo)7 StorageVolume (com.emc.storageos.storagedriver.model.StorageVolume)7 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)6 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)6 BlockStorageDriver (com.emc.storageos.storagedriver.BlockStorageDriver)6 DriverTask (com.emc.storageos.storagedriver.DriverTask)6 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)6 List (java.util.List)6 StringSet (com.emc.storageos.db.client.model.StringSet)5 HashSet (java.util.HashSet)5 ScServer (com.emc.storageos.driver.dellsc.scapi.objects.ScServer)4 CommonStorageCapabilities (com.emc.storageos.storagedriver.storagecapabilities.CommonStorageCapabilities)4 MutableBoolean (org.apache.commons.lang.mutable.MutableBoolean)4 ExportPathParams (com.emc.storageos.db.client.model.ExportPathParams)3