Search in sources :

Example 6 with Initiator

use of com.emc.storageos.storagedriver.model.Initiator 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 7 with Initiator

use of com.emc.storageos.storagedriver.model.Initiator in project coprhd-controller by CoprHD.

the class HP3PARExpUnexpHelper method doHostProcessing.

private String doHostProcessing(List<Initiator> initiators, List<StorageVolume> volumes, Registry driverRegistry, LockManager driverLockManager) {
    // will point host name in exclusive export and cluster name in shared export
    String host = null;
    String hostArray = null;
    String clustArray = null;
    // all volumes belong to same storage system
    try {
        // all initiators belong to same host
        if (initiators.get(0).getInitiatorType().equals(Type.Host)) {
            // Exclusive-Host export
            // Some code is repeated with cluster for simplicity
            HP3PARHostNameResult hostNameResult = get3parHostname(initiators, volumes.get(0).getStorageSystemId(), driverRegistry);
            if (hostNameResult == null || hostNameResult.getAllInitiators() == false) {
                // create a new host or add initiator to existing host
                HP3PARApi hp3parApi = hp3parUtil.getHP3PARDeviceFromNativeId(volumes.get(0).getStorageSystemId(), driverRegistry);
                ArrayList<String> portIds = new ArrayList<>();
                for (Initiator init : initiators) {
                    portIds.add(init.getPort());
                }
                Integer persona = getPersona(initiators.get(0).getHostOsType());
                if (hostNameResult != null && hostNameResult.getHostName() != null) {
                    // if 3PAR registered host is found
                    host = hostNameResult.getHostName();
                    hp3parApi.updateHost(host, portIds);
                } else {
                    // use CoprHD host name for new host
                    host = initiators.get(0).getHostName();
                    hp3parApi.createHost(host, portIds, persona);
                }
            } else {
                host = hostNameResult.getHostName();
            }
        // Host available
        } else if (initiators.get(0).getInitiatorType().equals(Type.Cluster)) {
            // Shared-Cluster export
            clustArray = initiators.get(0).getClusterName();
            HP3PARApi hp3parApi = hp3parUtil.getHP3PARDeviceFromNativeId(volumes.get(0).getStorageSystemId(), driverRegistry);
            // Check if host exists, otherwise create
            HP3PARHostNameResult hostNameResult = get3parHostname(initiators, volumes.get(0).getStorageSystemId(), driverRegistry);
            if (hostNameResult == null || hostNameResult.getAllInitiators() == false) {
                // create a new host or add initiator to existing host
                ArrayList<String> portIds = new ArrayList<>();
                for (Initiator init : initiators) {
                    portIds.add(init.getPort());
                }
                Integer persona = getPersona(initiators.get(0).getHostOsType());
                if (hostNameResult != null && hostNameResult.getHostName() != null) {
                    // if 3PAR registered host is found
                    hostArray = hostNameResult.getHostName();
                } else {
                    // use CoprHD host name
                    hostArray = initiators.get(0).getHostName();
                }
                hp3parApi.createHost(hostArray, portIds, persona);
            } else {
                hostArray = hostNameResult.getHostName();
            }
            // only one thread across all nodes should create cluster;
            String lockName = volumes.get(0).getStorageSystemId() + clustArray;
            if (driverLockManager.acquireLock(lockName, 10, TimeUnit.MINUTES)) {
                // Check if cluster exists, otherwise create=>Cluster with +one host at a time
                HostSetDetailsCommandResult hostsetRes = hp3parApi.getHostSetDetails(clustArray);
                if (hostsetRes == null) {
                    hp3parApi.createHostSet(clustArray, initiators.get(0).getHostName());
                } else {
                    // if this host is not part of the cluster add it
                    boolean present = false;
                    for (String setMember : hostsetRes.getSetmembers()) {
                        if (hostArray.compareTo(setMember) == 0) {
                            present = true;
                            break;
                        }
                    }
                    if (!present) {
                        // update cluster with this host
                        hp3parApi.updateHostSet(clustArray, hostArray);
                    }
                }
                // Cluster available
                host = "set:" + clustArray;
                driverLockManager.releaseLock(lockName);
            } else {
                _log.error("3PARDriver:doHostProcessing error: could not acquire thread lock to create cluster");
                throw new HP3PARException("3PARDriver:doHostProcessing error: could not acquire thread lock to create cluster");
            }
        // lock
        } else {
            _log.error("3PARDriver:exportVolumesToInitiators error: Host/Cluster type not supported");
            throw new HP3PARException("3PARDriver:exportVolumesToInitiators error: Host/Cluster type not supported");
        }
    } catch (Exception e) {
        String msg = String.format("3PARDriver: Unable to export, error: %s", e);
        _log.error(msg);
        _log.error(CompleteError.getStackTrace(e));
        return null;
    }
    return host;
}
Also used : HostSetDetailsCommandResult(com.emc.storageos.hp3par.command.HostSetDetailsCommandResult) Initiator(com.emc.storageos.storagedriver.model.Initiator) ArrayList(java.util.ArrayList)

Example 8 with Initiator

use of com.emc.storageos.storagedriver.model.Initiator in project coprhd-controller by CoprHD.

the class DellSCProvisioning method getInitiatorInfo.

/**
 * Gets Initiator details from servers and ports.
 *
 * @param api The Storage Center API connection.
 * @param server The ScServer.
 * @param hba The server HBA.
 * @return The initiator.
 */
private Initiator getInitiatorInfo(StorageCenterAPI api, ScServer server, ScServerHba hba) {
    Initiator result = new Initiator();
    ScServer cluster = null;
    if (server.type.contains("Physical")) {
        ScPhysicalServer physicalServer = api.getPhysicalServerDefinition(server.instanceId);
        if (physicalServer != null && physicalServer.parent != null && physicalServer.parent.instanceId != null) {
            cluster = api.getServerDefinition(physicalServer.parent.instanceId);
        }
    }
    result.setHostName(server.name);
    result.setInitiatorType(Type.Host);
    if (cluster != null) {
        result.setClusterName(cluster.name);
        result.setInitiatorType(Type.Cluster);
    }
    result.setNativeId(hba.instanceId);
    result.setPort(hba.instanceId);
    Protocol protocol = Protocol.iSCSI;
    if ("FibreChannel".equals(hba.portType)) {
        protocol = Protocol.FC;
    }
    result.setProtocol(protocol);
    return result;
}
Also used : ScServer(com.emc.storageos.driver.dellsc.scapi.objects.ScServer) Initiator(com.emc.storageos.storagedriver.model.Initiator) ScPhysicalServer(com.emc.storageos.driver.dellsc.scapi.objects.ScPhysicalServer) Protocol(com.emc.storageos.storagedriver.model.Initiator.Protocol)

Example 9 with Initiator

use of com.emc.storageos.storagedriver.model.Initiator in project coprhd-controller by CoprHD.

the class DellSCProvisioning method populateVolumeExportInfo.

/**
 * Fills in export information for a specific volume mapping.
 *
 * @param volumeId The volume instance ID.
 * @param map The mapping.
 * @param result The export info map.
 * @param serverCache The server cache.
 * @param serverPortCache The server HBA cache.
 * @param portCache The controller port cache.
 * @throws StorageCenterAPIException
 */
private void populateVolumeExportInfo(StorageCenterAPI api, String volumeId, ScMapping map, Map<String, HostExportInfo> result, Map<String, ScServer> serverCache, Map<String, Initiator> serverPortCache, Map<String, StoragePort> portCache) throws StorageCenterAPIException {
    ScServer server;
    Initiator initiator;
    StoragePort port;
    // Get our server info
    if (serverCache.containsKey(map.server.instanceId)) {
        server = serverCache.get(map.server.instanceId);
    } else {
        server = api.getServerDefinition(map.server.instanceId);
        serverCache.put(server.instanceId, server);
    }
    // Find the server HBA
    if (serverPortCache.containsKey(map.serverHba.instanceId)) {
        initiator = serverPortCache.get(map.serverHba.instanceId);
    } else {
        ScServerHba hba = api.getServerHba(map.serverHba.instanceId);
        initiator = getInitiatorInfo(api, server, hba);
        serverPortCache.put(hba.instanceId, initiator);
    }
    // Get the controller port info
    if (portCache.containsKey(map.controllerPort.instanceId)) {
        port = portCache.get(map.controllerPort.instanceId);
    } else {
        ScControllerPort scPort = api.getControllerPort(map.controllerPort.instanceId);
        port = util.getStoragePortForControllerPort(api, scPort);
        portCache.put(scPort.instanceId, port);
    }
    String hostName = initiator.getHostName();
    if (initiator.getInitiatorType() == Type.Cluster) {
        hostName = initiator.getClusterName();
    }
    HostExportInfo exportInfo;
    if (result.containsKey(hostName)) {
        exportInfo = result.get(hostName);
    } else {
        exportInfo = new HostExportInfo(hostName, new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
    }
    // Now populate all the info
    if (!exportInfo.getStorageObjectNativeIds().contains(volumeId)) {
        exportInfo.getStorageObjectNativeIds().add(volumeId);
    }
    if (!exportInfo.getTargets().contains(port)) {
        exportInfo.getTargets().add(port);
    }
    if (!exportInfo.getInitiators().contains(initiator)) {
        exportInfo.getInitiators().add(initiator);
    }
    result.put(hostName, exportInfo);
}
Also used : ScControllerPort(com.emc.storageos.driver.dellsc.scapi.objects.ScControllerPort) ScServer(com.emc.storageos.driver.dellsc.scapi.objects.ScServer) Initiator(com.emc.storageos.storagedriver.model.Initiator) StoragePort(com.emc.storageos.storagedriver.model.StoragePort) ArrayList(java.util.ArrayList) HostExportInfo(com.emc.storageos.storagedriver.HostExportInfo) ScServerHba(com.emc.storageos.driver.dellsc.scapi.objects.ScServerHba)

Example 10 with Initiator

use of com.emc.storageos.storagedriver.model.Initiator in project coprhd-controller by CoprHD.

the class DellSCProvisioning method getVolumeExportInfo.

/**
 * Gets the mapping information for a volume to initiators.
 *
 * @param volumeId The volume instance ID.
 * @param systemId The storage system ID.
 * @return The mapping details. Map of HostName:HostExportInfo
 */
public Map<String, HostExportInfo> getVolumeExportInfo(String volumeId, String systemId) {
    Map<String, HostExportInfo> result = new HashMap<>();
    Map<String, ScServer> serverCache = new HashMap<>();
    Map<String, Initiator> serverPortCache = new HashMap<>();
    Map<String, StoragePort> portCache = new HashMap<>();
    try {
        StorageCenterAPI api = connectionManager.getConnection(systemId);
        ScVolume scVol = api.getVolume(volumeId);
        if (scVol == null) {
            throw new DellSCDriverException(String.format("Volume %s could not be found.", volumeId));
        }
        ScMapping[] maps = api.getVolumeMaps(scVol.instanceId);
        for (ScMapping map : maps) {
            populateVolumeExportInfo(api, volumeId, map, result, serverCache, serverPortCache, portCache);
        }
    } catch (StorageCenterAPIException | DellSCDriverException dex) {
        String message = String.format("Error getting export info for volume %s: %s", volumeId, dex);
        LOG.warn(message);
    }
    return result;
}
Also used : StorageCenterAPI(com.emc.storageos.driver.dellsc.scapi.StorageCenterAPI) ScServer(com.emc.storageos.driver.dellsc.scapi.objects.ScServer) HashMap(java.util.HashMap) StorageCenterAPIException(com.emc.storageos.driver.dellsc.scapi.StorageCenterAPIException) StoragePort(com.emc.storageos.storagedriver.model.StoragePort) HostExportInfo(com.emc.storageos.storagedriver.HostExportInfo) ScVolume(com.emc.storageos.driver.dellsc.scapi.objects.ScVolume) DellSCDriverException(com.emc.storageos.driver.dellsc.DellSCDriverException) Initiator(com.emc.storageos.storagedriver.model.Initiator) ScMapping(com.emc.storageos.driver.dellsc.scapi.objects.ScMapping)

Aggregations

Initiator (com.emc.storageos.storagedriver.model.Initiator)23 ArrayList (java.util.ArrayList)15 StoragePort (com.emc.storageos.storagedriver.model.StoragePort)12 URI (java.net.URI)9 HashMap (java.util.HashMap)9 ExportMask (com.emc.storageos.db.client.model.ExportMask)7 HostExportInfo (com.emc.storageos.storagedriver.HostExportInfo)7 StorageVolume (com.emc.storageos.storagedriver.model.StorageVolume)7 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)6 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)6 BlockStorageDriver (com.emc.storageos.storagedriver.BlockStorageDriver)6 DriverTask (com.emc.storageos.storagedriver.DriverTask)6 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)6 List (java.util.List)6 StringSet (com.emc.storageos.db.client.model.StringSet)5 HashSet (java.util.HashSet)5 ScServer (com.emc.storageos.driver.dellsc.scapi.objects.ScServer)4 CommonStorageCapabilities (com.emc.storageos.storagedriver.storagecapabilities.CommonStorageCapabilities)4 MutableBoolean (org.apache.commons.lang.mutable.MutableBoolean)4 ExportPathParams (com.emc.storageos.db.client.model.ExportPathParams)3