Search in sources :

Example 1 with VirtualLunsList

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

the class HP3PARExpUnexpHelper method unexportVolumesFromInitiators.

public DriverTask unexportVolumesFromInitiators(List<Initiator> initiators, List<StorageVolume> volumes, DriverTask task, Registry driverRegistry, LockManager driverLockManager) {
    _log.info("3PARDriver:unexportVolumesFromInitiators enter");
    String host = null;
    Boolean fullSuccess = true;
    boolean gotLock = false;
    String exportPath = null;
    if (initiators.isEmpty() || volumes.isEmpty()) {
        String msg = "3PARDriver:unexportVolumesFromInitiators error blank initiator and/or volumes";
        _log.error(msg);
        task.setMessage(msg);
        task.setStatus(DriverTask.TaskStatus.FAILED);
        return task;
    }
    HashMap<String, String> initiatorToHostMap = new HashMap<String, String>();
    // unexport each volume
    for (StorageVolume volume : volumes) {
        try {
            // get Api client for volume specific array
            HP3PARApi hp3parApi = hp3parUtil.getHP3PARDeviceFromNativeId(volume.getStorageSystemId(), driverRegistry);
            VirtualLunsList vlunRes = hp3parApi.getVLunsByVolumeName(volume.getNativeId());
            for (Initiator init : initiators) {
                if (initiatorToHostMap.containsKey(init.getPort())) {
                    host = initiatorToHostMap.get(init.getPort());
                } else {
                    ArrayList<Initiator> initList = new ArrayList<>();
                    initList.add(init);
                    HP3PARHostNameResult hostNameResult = get3parHostname(initList, volume.getStorageSystemId(), driverRegistry);
                    if (hostNameResult == null) {
                        fullSuccess = false;
                        String message = String.format("3PARDriver:unexportVolumesFromInitiators host not fond for " + "storage system %s, volume %s initiator %s", volume.getStorageSystemId(), volume.getNativeId(), init.getPort());
                        _log.warn(message);
                        task.setMessage(message);
                        task.setStatus(DriverTask.TaskStatus.PARTIALLY_FAILED);
                        continue;
                    } else {
                        host = hostNameResult.getHostName();
                        initiatorToHostMap.put(init.getPort(), host);
                    }
                }
                if (init.getInitiatorType().equals(Type.Host)) {
                    // get vlun and port details on this export
                    Integer lun = -1;
                    Position pos = null;
                    String portId = init.getPort();
                    portId = portId.replace(":", "");
                    Boolean found = false;
                    Integer vlunType = 0;
                    for (VirtualLun vLun : vlunRes.getMembers()) {
                        if (volume.getNativeId().compareTo(vLun.getVolumeName()) != 0 || (!vLun.isActive()) || vLun.getRemoteName() == null || portId.compareToIgnoreCase(vLun.getRemoteName()) != 0 || (vLun.getType() != HP3PARConstants.vLunType.MATCHED_SET.getValue() && vLun.getType() != HP3PARConstants.vLunType.HOST.getValue())) {
                            continue;
                        }
                        lun = vLun.getLun();
                        pos = vLun.getPortPos();
                        vlunType = vLun.getType();
                        found = true;
                        break;
                    }
                    if (found) {
                        String posStr = null;
                        if (vlunType == HP3PARConstants.vLunType.MATCHED_SET.getValue()) {
                            // port details for matched set; null for host-sees
                            posStr = String.format("%s:%s:%s", pos.getNode(), pos.getSlot(), pos.getCardPort());
                        }
                        try {
                            hp3parApi.deleteVlun(volume.getNativeId(), lun.toString(), host, posStr);
                        } catch (Exception e) {
                            if (e.getMessage().contains(HP3PARConstants.VLUN_DOES_NOT_EXIST)) {
                                _log.info("The VLUN(export info) does not exist on the 3PAR " + "array and hence this unexport will be treated as success");
                            } else {
                                throw e;
                            }
                        }
                    }
                    if (!found) {
                        // port could be inactive, remove vlun template
                        for (VirtualLun vLun : vlunRes.getMembers()) {
                            if (volume.getNativeId().compareTo(vLun.getVolumeName()) != 0 || vLun.getHostname() == null || host.compareToIgnoreCase(vLun.getHostname()) != 0 || (vLun.getType() != HP3PARConstants.vLunType.MATCHED_SET.getValue() && vLun.getType() != HP3PARConstants.vLunType.HOST.getValue())) {
                                continue;
                            }
                            lun = vLun.getLun();
                            pos = vLun.getPortPos();
                            vlunType = vLun.getType();
                            found = true;
                            if (found) {
                                String posStr = null;
                                if (vlunType == HP3PARConstants.vLunType.MATCHED_SET.getValue()) {
                                    // port details for matched set; null for host-sees
                                    posStr = String.format("%s:%s:%s", pos.getNode(), pos.getSlot(), pos.getCardPort());
                                }
                                _log.info("3PARDriver:unexportVolumesFromInitiators removing vlun template");
                                posStr = String.format("%s:%s:%s", pos.getNode(), pos.getSlot(), pos.getCardPort());
                                try {
                                    hp3parApi.deleteVlun(volume.getNativeId(), lun.toString(), host, posStr);
                                } catch (Exception e) {
                                    if (e.getMessage().contains(HP3PARConstants.VLUN_DOES_NOT_EXIST)) {
                                        _log.info("The VLUN(export info) does not exist on the 3PAR " + "array and hence this unexport will be treated as success");
                                    } else {
                                        throw e;
                                    }
                                }
                            }
                        // found
                        }
                    // end for all vlun templates
                    }
                } else if (init.getInitiatorType().equals(Type.Cluster)) {
                    // cluster unexport
                    String clusterName = "set:" + initiators.get(0).getClusterName();
                    exportPath = volume.getStorageSystemId() + volume.getNativeId() + clusterName;
                    gotLock = false;
                    if (driverLockManager.acquireLock(exportPath, 10, TimeUnit.MINUTES)) {
                        gotLock = true;
                        Map<String, List<String>> attributes = new HashMap<>();
                        List<String> expValue = new ArrayList<>();
                        List<String> lunValue = new ArrayList<>();
                        boolean regPresent = false;
                        String message = String.format("3PARDriver:unexportVolumesFromInitiators for " + "storage system %s, volume %s Cluster %s", volume.getStorageSystemId(), volume.getNativeId(), clusterName);
                        attributes = driverRegistry.getDriverAttributesForKey(HP3PARConstants.DRIVER_NAME, exportPath);
                        if (attributes != null) {
                            expValue = attributes.get("EXPORT_PATH");
                            if (expValue != null && expValue.get(0).compareTo(exportPath) == 0) {
                                lunValue = attributes.get(volume.getNativeId());
                                regPresent = true;
                                _log.info(message);
                                /*
                        			 * below operations are assumed to autonomic
                        			 */
                                hp3parApi.deleteVlun(volume.getNativeId(), lunValue.get(0), clusterName, null);
                                driverRegistry.clearDriverAttributesForKey(HP3PARConstants.DRIVER_NAME, exportPath);
                            }
                        }
                        if (!regPresent) {
                            // gracefully exit, nothing to be done
                            _log.info("3PARDriver: Already unexported, exiting gracefully" + message);
                        }
                        driverLockManager.releaseLock(exportPath);
                        gotLock = false;
                    } else {
                        // lock
                        _log.error("3PARDriver:unexportVolumesFromInitiators error: could not acquire thread lock");
                        throw new HP3PARException("3PARDriver:unexportVolumesFromInitiators error: could not acquire thread lock");
                    }
                }
            // if cluster
            }
        // for each initiator
        } catch (Exception e) {
            String msg = String.format("3PARDriver: Unable to unexport few volumes, error: %s", e);
            _log.error(msg);
            _log.error(CompleteError.getStackTrace(e));
            task.setMessage(msg);
            task.setStatus(DriverTask.TaskStatus.PARTIALLY_FAILED);
            e.printStackTrace();
            fullSuccess = false;
            if (gotLock && (exportPath != null)) {
                driverLockManager.releaseLock(exportPath);
            }
        }
    }
    if (fullSuccess) {
        task.setStatus(DriverTask.TaskStatus.READY);
    }
    _log.info("3PARDriver:unexportVolumesFromInitiatorss leave");
    return task;
}
Also used : HashMap(java.util.HashMap) Position(com.emc.storageos.hp3par.command.Position) ArrayList(java.util.ArrayList) VirtualLunsList(com.emc.storageos.hp3par.command.VirtualLunsList) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) Initiator(com.emc.storageos.storagedriver.model.Initiator) ArrayList(java.util.ArrayList) VirtualLunsList(com.emc.storageos.hp3par.command.VirtualLunsList) List(java.util.List) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) VirtualLun(com.emc.storageos.hp3par.command.VirtualLun) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with VirtualLunsList

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

the class HP3PARApi method getAllVlunDetails.

public VirtualLunsList getAllVlunDetails() throws Exception {
    _log.info("3PARDriver:getAllVlunDetails enter");
    ClientResponse clientResp = null;
    try {
        clientResp = get(URI_VLUNS);
        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:getAllVlunDetails 3PAR response is {}", responseString);
            VirtualLunsList vlunResult = new Gson().fromJson(sanitize(responseString), VirtualLunsList.class);
            return vlunResult;
        }
    } catch (Exception e) {
        throw e;
    } finally {
        if (clientResp != null) {
            clientResp.close();
        }
        _log.info("3PARDriver:getAllVlunDetails leave");
    }
// end try/catch/finally
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Gson(com.google.gson.Gson) VirtualLunsList(com.emc.storageos.hp3par.command.VirtualLunsList)

Example 3 with VirtualLunsList

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

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

the class HP3PARApi method getVLunsByVolumeName.

/**
 * Get all vluns, which are associated with a volume, snapshot or a clone.
 *
 * @param displayName
 * @return
 * @throws Exception
 */
public VirtualLunsList getVLunsByVolumeName(String volumeName) throws Exception {
    _log.info("3PARDriver: getVLunsOfVolume enter");
    ClientResponse clientResp = null;
    final String path = MessageFormat.format(URI_VLUNS_BY_VOlUME_NAME, volumeName);
    _log.info("getVLunsOfVolume path is {}", path);
    try {
        clientResp = get(path);
        if (clientResp == null) {
            _log.error("3PARDriver: getVLunsOfVolume There is no response from 3PAR");
            throw new HP3PARException("There is no response from 3PAR");
        } else if (clientResp.getStatus() != 200) {
            String errResp = getResponseDetails(clientResp);
            _log.error("3PARDriver: getVLunsOfVolume There is error response from 3PAR = {}", errResp);
            throw new HP3PARException(errResp);
        } else {
            String responseString = clientResp.getEntity(String.class);
            _log.info("3PARDriver: getVLunsOfVolume 3PAR response is {}", responseString);
            VirtualLunsList vlunsListResult = new Gson().fromJson(sanitize(responseString), VirtualLunsList.class);
            return vlunsListResult;
        }
    } catch (Exception e) {
        _log.info("getVLunsOfVolume exception is {}", e.getMessage());
        throw e;
    } finally {
        if (clientResp != null) {
            clientResp.close();
        }
        _log.info("3PARDriver: getVLunsOfVolume leave");
    }
// end try/catch/finally
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Gson(com.google.gson.Gson) VirtualLunsList(com.emc.storageos.hp3par.command.VirtualLunsList)

Example 5 with VirtualLunsList

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

the class HP3PARApi method getVLunsOfVolume.

/**
 * Get all vluns, which are associated with a volume, snapshot or a clone.
 *
 * @param displayName
 * @return
 * @throws Exception
 */
public VirtualLunsList getVLunsOfVolume(String volumeWWN) throws Exception {
    _log.info("3PARDriver: getVLunsOfVolume enter");
    ClientResponse clientResp = null;
    final String path = MessageFormat.format(URI_VLUNS_OF_VOLUME, volumeWWN);
    _log.info("getVLunsOfVolume path is {}", path);
    try {
        clientResp = get(path);
        if (clientResp == null) {
            _log.error("3PARDriver: getVLunsOfVolume There is no response from 3PAR");
            throw new HP3PARException("There is no response from 3PAR");
        } else if (clientResp.getStatus() != 200) {
            String errResp = getResponseDetails(clientResp);
            _log.error("3PARDriver: getVLunsOfVolume There is error response from 3PAR = {}", errResp);
            throw new HP3PARException(errResp);
        } else {
            String responseString = clientResp.getEntity(String.class);
            _log.info("3PARDriver: getVLunsOfVolume 3PAR response is {}", responseString);
            VirtualLunsList vlunsListResult = new Gson().fromJson(sanitize(responseString), VirtualLunsList.class);
            return vlunsListResult;
        }
    } catch (Exception e) {
        _log.info("getVLunsOfVolume exception is {}", e.getMessage());
        throw e;
    } finally {
        if (clientResp != null) {
            clientResp.close();
        }
        _log.info("3PARDriver: getVLunsOfVolume leave");
    }
// end try/catch/finally
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Gson(com.google.gson.Gson) VirtualLunsList(com.emc.storageos.hp3par.command.VirtualLunsList)

Aggregations

VirtualLunsList (com.emc.storageos.hp3par.command.VirtualLunsList)5 Gson (com.google.gson.Gson)3 ClientResponse (com.sun.jersey.api.client.ClientResponse)3 VirtualLun (com.emc.storageos.hp3par.command.VirtualLun)2 Initiator (com.emc.storageos.storagedriver.model.Initiator)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Position (com.emc.storageos.hp3par.command.Position)1 HostExportInfo (com.emc.storageos.storagedriver.HostExportInfo)1 StoragePort (com.emc.storageos.storagedriver.model.StoragePort)1 StorageVolume (com.emc.storageos.storagedriver.model.StorageVolume)1 Map (java.util.Map)1 MutableBoolean (org.apache.commons.lang.mutable.MutableBoolean)1