Search in sources :

Example 1 with VlunResult

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

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

the class HP3PARApi method createVlun.

public VlunResult createVlun(String volumeName, int hlu, String hostName, String portId) throws Exception {
    _log.info("3PARDriver:createVlun enter");
    ClientResponse clientResp = null;
    Integer lun = (hlu == -1) ? 0 : hlu;
    boolean autoLun = (lun == 0) ? true : false;
    String body = "{\"volumeName\":\"" + volumeName + "\", \"lun\":" + lun.toString() + ", " + "\"hostname\":\"" + hostName + "\"" + ", \"autoLun\":" + autoLun + ", \"maxAutoLun\": 0";
    // only matched-set export is supported
    if (portId != null) {
        String[] pos = portId.split(":");
        String portPos = String.format(", \"portPos\":{\"node\":%s, \"slot\":%s, \"cardPort\":%s}", pos[0], pos[1], pos[2]);
        body = body.concat(portPos);
    }
    body = body.concat("}");
    _log.info("3PARDriver: createVlun body is {}", body);
    try {
        clientResp = post(URI_CREATE_VLUN, 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() != 201) {
            String errResp = getResponseDetails(clientResp);
            throw new HP3PARException(errResp);
        } else {
            String responseString = getHeaderFieldValue(clientResp, "Location");
            _log.info("3PARDriver:createVlun 3PAR response is Location: {}", responseString);
            String[] resp = responseString.split(",");
            VlunResult result = new VlunResult();
            result.setAssignedLun(resp[1]);
            result.setStatus(true);
            return result;
        }
    } catch (Exception e) {
        _log.error(e.getMessage());
        return null;
    } finally {
        if (clientResp != null) {
            clientResp.close();
        }
        _log.info("3PARDriver:createVlun leave");
    }
// end try/catch/finally
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) VlunResult(com.emc.storageos.hp3par.command.VlunResult)

Aggregations

VlunResult (com.emc.storageos.hp3par.command.VlunResult)2 HostMember (com.emc.storageos.hp3par.command.HostMember)1 VirtualLunsList (com.emc.storageos.hp3par.command.VirtualLunsList)1 StoragePort (com.emc.storageos.storagedriver.model.StoragePort)1 StorageVolume (com.emc.storageos.storagedriver.model.StorageVolume)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1