Search in sources :

Example 1 with HostMember

use of com.emc.storageos.hp3par.command.HostMember in project coprhd-controller by CoprHD.

the class HP3PARExpUnexpHelper method exportVolumesToInitiators.

/**
 *******USE CASES**********
 *
 *    EXCLUSIVE EXPORT: Will include port number of host
 *
 *    1 Export volume to existing host
 *    2 Export volume to non-existing host
 *    3 Add initiator to existing host
 *    4 Remove initiator from host
 *    5 Unexport volume
 *
 *    A 1-5 can be done with single/multiple volumes,initiators as applicable
 *    B Does not depend on host name
 *    C Adding an initiator in matched-set will not do anything further.
 *      All volumes have to be exported to new initiator explicitly.
 *      In host-sees 3PAR will automatically export the volumes to newly added initiator.
 *    -------------------------------------------
 *    SHARED EXPORT: Will not include port number, exported to all ports, the cluster can see
 *
 *    1 Export volume to existing cluster
 *    2 Export volume to non-existing cluster
 *    3 Add initiator to existing host in cluster
 *    4 Remove initiator from host in cluster
 *    5 Unexport volume from cluster
 *    6 Export a private volume to a host in a cluster
 *    7 Unexport a private volume from a host in a cluster
 *    8 Add a host to cluster
 *    9 Remove a host from a cluster
 *    10 Add a host having private export
 *    11 Remove a host having private export
 *    12 Move a host from one cluster to another
 *
 *    A 1-12 can be done with single/multiple volumes,initiators,hosts as applicable
 *    B Cluster name in ViPR and 3PAR has to be identical with case
 *    C Adding a new host to host-set will automatically export all volumes to the new host(initial export must have been host-set)
 */
/*
   * All volumes in the list will be exported to all initiators using recommended ports. If a volume can not be exported to 'n' 
   * initiators the same will be tried with available ports  
   */
public DriverTask exportVolumesToInitiators(List<Initiator> initiators, List<StorageVolume> volumes, Map<String, String> volumeToHLUMap, List<StoragePort> recommendedPorts, List<StoragePort> availablePorts, StorageCapabilities capabilities, MutableBoolean usedRecommendedPorts, List<StoragePort> selectedPorts, DriverTask task, Registry driverRegistry, LockManager driverLockManager) {
    _log.info("3PARDriver:exportVolumesToInitiators enter");
    String host = null;
    host = doHostProcessing(initiators, volumes, driverRegistry, driverLockManager);
    if (host == null) {
        task.setMessage("exportVolumesToInitiators error: Processing hosts, Unable to export");
        task.setStatus(DriverTask.TaskStatus.FAILED);
        return task;
    }
    /*
         Export will be done keeping volumes as the starting point
         */
    Integer totalExport = recommendedPorts.size();
    for (StorageVolume vol : volumes) {
        Integer currExport = 0;
        Integer hlu = Integer.parseInt(volumeToHLUMap.get(vol.getNativeId()));
        try {
            // volume could belong to different storage system; get specific api client;
            HP3PARApi hp3parApi = hp3parUtil.getHP3PARDeviceFromNativeId(vol.getStorageSystemId(), driverRegistry);
            /*
                 export for INDIVIDUAL HOST=exclusive 
                 Some code is repeated with cluster for simplicity
                 */
            if (!host.startsWith("set:")) {
                // try with recommended ports
                for (StoragePort port : recommendedPorts) {
                    // volume and port belong to same storage system
                    String message = String.format("3PARDriver:exportVolumesToInitiators using recommendedPorts for " + "storage system %s, volume %s host %s hlu %s port %s", port.getStorageSystemId(), vol.getNativeId(), host, hlu.toString(), port.getNativeId());
                    _log.info(message);
                    VlunResult vlunRes = hp3parApi.createVlun(vol.getNativeId(), hlu, host, port.getNativeId());
                    if (vlunRes != null && vlunRes.getStatus()) {
                        currExport++;
                        usedRecommendedPorts.setValue(true);
                        // update hlu obtained as lun from 3apr & add the selected port if required
                        volumeToHLUMap.put(vol.getNativeId(), vlunRes.getAssignedLun());
                        if (!selectedPorts.contains(port)) {
                            selectedPorts.add(port);
                        }
                    } else {
                        task.setStatus(DriverTask.TaskStatus.PARTIALLY_FAILED);
                        _log.warn("3PARDriver: Could not export " + message);
                    }
                }
                // now try with available ports
                for (StoragePort port : availablePorts) {
                    if (currExport == totalExport) {
                        task.setStatus(DriverTask.TaskStatus.READY);
                        break;
                    }
                    // Make sure this port is not used for earlier export
                    if (selectedPorts.contains(port)) {
                        continue;
                    }
                    // verify volume and port belong to same storage
                    if (!vol.getStorageSystemId().equalsIgnoreCase(port.getStorageSystemId())) {
                        continue;
                    }
                    String message = String.format("3PARDriver:exportVolumesToInitiators using availablePorts for " + "storage system %s, volume %s host %s hlu %s port %s", port.getStorageSystemId(), vol.getNativeId(), host, hlu.toString(), port.getNativeId());
                    _log.info(message);
                    VlunResult vlunRes = hp3parApi.createVlun(vol.getNativeId(), hlu, host, port.getNativeId());
                    if (vlunRes != null && vlunRes.getStatus()) {
                        currExport++;
                        usedRecommendedPorts.setValue(false);
                        // update hlu obtained as lun from 3apr & add the selected port if required
                        volumeToHLUMap.put(vol.getNativeId(), vlunRes.getAssignedLun());
                        if (!selectedPorts.contains(port)) {
                            selectedPorts.add(port);
                        }
                    } else {
                        task.setStatus(DriverTask.TaskStatus.PARTIALLY_FAILED);
                        _log.warn("3PARDriver: Could not export " + message);
                    }
                }
            // for available ports
            } else {
                /*
                      export for CLUSTER=shared 
                      Some code is repeated with cluster for simplicity
                      
                      Cluster export will be done as host-set in 3APR for entire cluster in one go.
                      Hence requests coming for rest of the individual host exports should gracefully exit
                     */
                String lockName = volumes.get(0).getStorageSystemId() + vol.getNativeId() + host;
                if (driverLockManager.acquireLock(lockName, 10, TimeUnit.MINUTES)) {
                    _log.info("3PARDriver: Acquired lock {} to examine vlun creation", lockName);
                    /*
                          If this is the first request key gets created with export operation. 
                          other requests will gracefully exit. key will be removed in unexport.
                         */
                    String message = String.format("3PARDriver:exportVolumesToInitiators " + "storage system %s, volume %s Cluster %s hlu %s ", vol.getStorageSystemId(), vol.getNativeId(), host, hlu.toString());
                    _log.info(message);
                    String exportPath = vol.getStorageSystemId() + vol.getNativeId() + host;
                    _log.info("3PARDriver:exportPath {} for registry entry", exportPath);
                    Map<String, List<String>> attributes = new HashMap<>();
                    List<String> expValue = new ArrayList<>();
                    List<String> lunValue = new ArrayList<>();
                    boolean doExport = true;
                    attributes = driverRegistry.getDriverAttributesForKey(HP3PARConstants.DRIVER_NAME, exportPath);
                    if (attributes != null) {
                        expValue = attributes.get("EXPORT_PATH");
                        if (expValue != null && expValue.get(0).compareTo(exportPath) == 0) {
                            doExport = false;
                            // Already exported, make hlu, port details; gracefully exit
                            lunValue = attributes.get(vol.getNativeId());
                            volumeToHLUMap.put(vol.getNativeId(), lunValue.get(0));
                            HP3PARHostNameResult hostNameResult = get3parHostname(initiators, vol.getStorageSystemId(), driverRegistry);
                            HostMember hostRes = hp3parApi.getHostDetails(hostNameResult.getHostName());
                            // get storage array ports for this host ports
                            List<StoragePort> clusterStoragePorts = new ArrayList<>();
                            getClusterStoragePorts(hostRes, availablePorts, vol.getStorageSystemId(), clusterStoragePorts);
                            for (StoragePort sp : clusterStoragePorts) {
                                // assign all these ports as selected ports
                                if (!selectedPorts.contains(sp)) {
                                    selectedPorts.add(sp);
                                }
                            }
                            // go thru all slectedports.
                            // if anyone is not part of the recommendedPorts set usedRecommendedPorts to false
                            usedRecommendedPorts.setValue(true);
                            for (StoragePort sp : selectedPorts) {
                                if (!recommendedPorts.contains(sp)) {
                                    usedRecommendedPorts.setValue(false);
                                    break;
                                }
                            }
                            task.setStatus(DriverTask.TaskStatus.READY);
                            _log.info("3PARDriver: Already exported, exiting " + message);
                        }
                    }
                    if (doExport) {
                        _log.info("3PARDriver: exporting volume {} as exportPath {} is not present in registry", vol.getNativeId(), exportPath);
                        /*
                             for cluster use host set method, We cannot specify port; 
                             determine the individual host ports used
                             */
                        VlunResult vlunRes = hp3parApi.createVlun(vol.getNativeId(), hlu, host, null);
                        if (vlunRes != null && vlunRes.getStatus()) {
                            // update hlu obtained as lun from 3apr & add the selected port if required
                            volumeToHLUMap.put(vol.getNativeId(), vlunRes.getAssignedLun());
                            HP3PARHostNameResult hostNameResult = get3parHostname(initiators, vol.getStorageSystemId(), driverRegistry);
                            HostMember hostRes = hp3parApi.getHostDetails(hostNameResult.getHostName());
                            // get storage array ports for this host ports
                            List<StoragePort> clusterStoragePorts = new ArrayList<>();
                            getClusterStoragePorts(hostRes, availablePorts, vol.getStorageSystemId(), clusterStoragePorts);
                            for (StoragePort sp : clusterStoragePorts) {
                                // assign all these ports as selected ports
                                if (!selectedPorts.contains(sp)) {
                                    selectedPorts.add(sp);
                                }
                            }
                            usedRecommendedPorts.setValue(true);
                            for (StoragePort sp : selectedPorts) {
                                if (!recommendedPorts.contains(sp)) {
                                    usedRecommendedPorts.setValue(false);
                                    break;
                                }
                            }
                            // Everything is successful, Set as exported in registry
                            attributes = new HashMap<>();
                            expValue = new ArrayList<>();
                            lunValue = new ArrayList<>();
                            expValue.add(exportPath);
                            attributes.put("EXPORT_PATH", expValue);
                            lunValue.add(vlunRes.getAssignedLun());
                            attributes.put(vol.getNativeId(), lunValue);
                            attributes.put(vol.getNativeId(), lunValue);
                            driverRegistry.setDriverAttributesForKey(HP3PARConstants.DRIVER_NAME, exportPath, attributes);
                            task.setMessage("Successful");
                            task.setStatus(DriverTask.TaskStatus.READY);
                        } else {
                            // end createVlun
                            task.setStatus(DriverTask.TaskStatus.PARTIALLY_FAILED);
                            _log.warn("3PARDriver: Could not export " + message);
                        }
                    }
                    // doExport
                    _log.info("3PARDriver: Releasing lock {} after examining vlun creation", lockName);
                    driverLockManager.releaseLock(lockName);
                } else {
                    _log.error("3PARDriver:exportVolumesToInitiators error: could not acquire thread lock");
                    throw new HP3PARException("3PARDriver:exportVolumesToInitiators error: could not acquire thread lock");
                }
            }
        // end cluster export
        } catch (Exception e) {
            String msg = String.format("3PARDriver: Unable to export few volumes, error: %s", e);
            _log.error(CompleteError.getStackTrace(e));
            _log.error(msg);
            task.setMessage(msg);
            task.setStatus(DriverTask.TaskStatus.PARTIALLY_FAILED);
            e.printStackTrace();
        }
    }
    // for each volume
    _log.info("3PARDriver:exportVolumesToInitiators leave");
    return task;
}
Also used : HashMap(java.util.HashMap) StoragePort(com.emc.storageos.storagedriver.model.StoragePort) ArrayList(java.util.ArrayList) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) HostMember(com.emc.storageos.hp3par.command.HostMember) VlunResult(com.emc.storageos.hp3par.command.VlunResult) ArrayList(java.util.ArrayList) VirtualLunsList(com.emc.storageos.hp3par.command.VirtualLunsList) List(java.util.List)

Example 2 with HostMember

use of com.emc.storageos.hp3par.command.HostMember in project coprhd-controller by CoprHD.

the class HP3PARApi method getHostDetails.

public HostMember getHostDetails(String name) throws Exception {
    _log.info("3PARDriver:getHostDetails enter");
    ClientResponse clientResp = null;
    final String path = MessageFormat.format(URI_HOST_DETAILS, name);
    _log.info("3PARDriver: getHostDetails path is {}", path);
    try {
        clientResp = get(path);
        if (clientResp == null) {
            _log.error("3PARDriver:There is no response from 3PAR");
            throw new HP3PARException("There is no response from 3PAR");
        } else if (clientResp.getStatus() != 200) {
            String errResp = getResponseDetails(clientResp);
            throw new HP3PARException(errResp);
        } else {
            String responseString = clientResp.getEntity(String.class);
            _log.info("3PARDriver:getHostDetails 3PAR response is {}", responseString);
            HostMember hostResult = new Gson().fromJson(sanitize(responseString), HostMember.class);
            return hostResult;
        }
    } catch (Exception e) {
        throw e;
    } finally {
        if (clientResp != null) {
            clientResp.close();
        }
        _log.info("3PARDriver:getHostDetails leave");
    }
// end try/catch/finally
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) HostMember(com.emc.storageos.hp3par.command.HostMember) Gson(com.google.gson.Gson)

Example 3 with HostMember

use of com.emc.storageos.hp3par.command.HostMember in project coprhd-controller by CoprHD.

the class HP3PARApi method updateHost.

public void updateHost(String name, ArrayList<String> portIdsNew) throws Exception {
    _log.info("3PARDriver:updateHost enter");
    ClientResponse clientResp = null;
    String portIdstr = "[";
    String body = null;
    final String path = MessageFormat.format(URI_HOST_DETAILS, name);
    ArrayList<String> portIdsNewFiltered = new ArrayList<>();
    ArrayList<String> existingFc = new ArrayList<>();
    try {
        // get existing host wwn/iqn;
        HostMember hostMemb = getHostDetails(name);
        if (portIdsNew.get(0).startsWith("iqn") == false) {
            for (FcPath fcPath : hostMemb.getFCPaths()) {
                existingFc.add(SanUtils.cleanWWN(fcPath.getWwn()));
            }
            // remove existing wwn/iqns in the list to be added
            for (String portId : portIdsNew) {
                if (existingFc.contains(SanUtils.cleanWWN(portId)) == false) {
                    portIdsNewFiltered.add(SanUtils.cleanWWN(portId));
                }
            }
        } else {
            for (ISCSIPath scPath : hostMemb.getiSCSIPaths()) {
                existingFc.add(scPath.getName());
            }
            // remove existing wwn/iqns in the list to be added
            for (String portId : portIdsNew) {
                if (existingFc.contains(portId) == false) {
                    portIdsNewFiltered.add(portId);
                }
            }
        }
        for (String Id : portIdsNewFiltered) {
            if (portIdstr.length() > 1) {
                portIdstr = portIdstr.concat(",");
            }
            portIdstr = portIdstr.concat("\"" + Id + "\"");
        }
        portIdstr = portIdstr.concat("]");
        if (portIdsNewFiltered.get(0).startsWith("iqn") == false) {
            body = "{\"FCWWNs\":" + portIdstr + ", \"pathOperation\":1}";
        } else {
            body = "{\"iSCSINames\":" + portIdstr + ", \"pathOperation\":1\"}";
        }
        _log.info("3PARDriver: updateHost path is {}, body is {}", path, body);
        clientResp = put(path, body);
        if (clientResp == null) {
            _log.error("3PARDriver:There is no response from 3PAR");
            throw new HP3PARException("There is no response from 3PAR");
        } else if (clientResp.getStatus() != 200) {
            String errResp = getResponseDetails(clientResp);
            throw new HP3PARException(errResp);
        } else {
            String responseString = getHeaderFieldValue(clientResp, "Location");
            _log.info("3PARDriver:updateHost 3PAR response is Location: {}", responseString);
        }
    } catch (Exception e) {
        throw e;
    } finally {
        if (clientResp != null) {
            clientResp.close();
        }
        _log.info("3PARDriver:updateHost leave");
    }
// end try/catch/finally
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) HostMember(com.emc.storageos.hp3par.command.HostMember) ISCSIPath(com.emc.storageos.hp3par.command.ISCSIPath) ArrayList(java.util.ArrayList) FcPath(com.emc.storageos.hp3par.command.FcPath)

Example 4 with HostMember

use of com.emc.storageos.hp3par.command.HostMember 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)

Aggregations

HostMember (com.emc.storageos.hp3par.command.HostMember)4 FcPath (com.emc.storageos.hp3par.command.FcPath)2 ISCSIPath (com.emc.storageos.hp3par.command.ISCSIPath)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 ArrayList (java.util.ArrayList)2 VirtualLunsList (com.emc.storageos.hp3par.command.VirtualLunsList)1 VlunResult (com.emc.storageos.hp3par.command.VlunResult)1 Initiator (com.emc.storageos.storagedriver.model.Initiator)1 StoragePort (com.emc.storageos.storagedriver.model.StoragePort)1 StorageVolume (com.emc.storageos.storagedriver.model.StorageVolume)1 Gson (com.google.gson.Gson)1 HashMap (java.util.HashMap)1 List (java.util.List)1