Search in sources :

Example 1 with VirtualLun

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

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

Aggregations

VirtualLun (com.emc.storageos.hp3par.command.VirtualLun)2 VirtualLunsList (com.emc.storageos.hp3par.command.VirtualLunsList)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