Search in sources :

Example 1 with Position

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

Aggregations

Position (com.emc.storageos.hp3par.command.Position)1 VirtualLun (com.emc.storageos.hp3par.command.VirtualLun)1 VirtualLunsList (com.emc.storageos.hp3par.command.VirtualLunsList)1 Initiator (com.emc.storageos.storagedriver.model.Initiator)1 StorageVolume (com.emc.storageos.storagedriver.model.StorageVolume)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 MutableBoolean (org.apache.commons.lang.mutable.MutableBoolean)1