Search in sources :

Example 21 with Initiator

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

the class ExternalDeviceExportOperations method createExportMask.

@Override
public void createExportMask(StorageSystem storage, URI exportMaskUri, VolumeURIHLU[] volumeURIHLUs, List<URI> targetURIList, List<com.emc.storageos.db.client.model.Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
    log.info("{} createExportMask START...", storage.getSerialNumber());
    try {
        log.info("createExportMask: Export mask id: {}", exportMaskUri);
        log.info("createExportMask: volume-HLU pairs: {}", Joiner.on(',').join(volumeURIHLUs));
        log.info("createExportMask: initiators: {}", Joiner.on(',').join(initiatorList));
        log.info("createExportMask: assignments: {}", Joiner.on(',').join(targetURIList));
        BlockStorageDriver driver = externalDevice.getDriver(storage.getSystemType());
        ExportMask exportMask = (ExportMask) dbClient.queryObject(exportMaskUri);
        // Get export group uri from task completer
        URI exportGroupUri = taskCompleter.getId();
        ExportGroup exportGroup = (ExportGroup) dbClient.queryObject(exportGroupUri);
        Set<URI> volumeUris = new HashSet<>();
        for (VolumeURIHLU volumeURIHLU : volumeURIHLUs) {
            URI volumeURI = volumeURIHLU.getVolumeURI();
            volumeUris.add(volumeURI);
        }
        // Prepare volumes
        List<StorageVolume> driverVolumes = new ArrayList<>();
        Map<String, String> driverVolumeToHLUMap = new HashMap<>();
        Map<String, URI> volumeNativeIdToUriMap = new HashMap<>();
        prepareVolumes(storage, volumeURIHLUs, driverVolumes, driverVolumeToHLUMap, volumeNativeIdToUriMap);
        // Prepare initiators
        List<Initiator> driverInitiators = new ArrayList<>();
        prepareInitiators(initiatorList, exportGroup.forCluster(), driverInitiators);
        // Prepare target storage ports
        List<StoragePort> recommendedPorts = new ArrayList<>();
        List<StoragePort> availablePorts = new ArrayList<>();
        List<StoragePort> selectedPorts = new ArrayList<>();
        // Prepare ports for driver call. Populate lists of recommended and available ports.
        Map<String, com.emc.storageos.db.client.model.StoragePort> nativeIdToAvailablePortMap = new HashMap<>();
        preparePorts(storage, exportMaskUri, targetURIList, recommendedPorts, availablePorts, nativeIdToAvailablePortMap);
        ExportPathParams pathParams = blockScheduler.calculateExportPathParamForVolumes(volumeUris, exportGroup.getNumPaths(), storage.getId(), exportGroupUri);
        StorageCapabilities capabilities = new StorageCapabilities();
        // Prepare num paths to send to driver
        prepareCapabilities(pathParams, capabilities);
        MutableBoolean usedRecommendedPorts = new MutableBoolean(true);
        // Ready to call driver
        DriverTask task = driver.exportVolumesToInitiators(driverInitiators, driverVolumes, driverVolumeToHLUMap, recommendedPorts, availablePorts, capabilities, usedRecommendedPorts, selectedPorts);
        // todo: need to implement support for async case.
        if (task.getStatus() == DriverTask.TaskStatus.READY) {
            // If driver used recommended ports, we are done.
            // Otherwise, if driver did not use recommended ports, we have to get ports selected by driver
            // and use them in export mask and zones.
            // We will verify driver selected ports against available ports list.
            String msg = String.format("createExportMask -- Created export: %s . Used recommended ports: %s .", task.getMessage(), usedRecommendedPorts);
            log.info(msg);
            log.info("Recommended ports: {}", recommendedPorts);
            log.info("Available ports: {}", availablePorts);
            log.info("Selected ports: {}", selectedPorts);
            if (usedRecommendedPorts.isFalse()) {
                // process driver selected ports
                if (validateSelectedPorts(availablePorts, selectedPorts, pathParams.getMinPaths())) {
                    List<com.emc.storageos.db.client.model.StoragePort> selectedPortsForMask = new ArrayList<>();
                    for (StoragePort driverPort : selectedPorts) {
                        com.emc.storageos.db.client.model.StoragePort port = nativeIdToAvailablePortMap.get(driverPort.getNativeId());
                        selectedPortsForMask.add(port);
                    }
                    updateStoragePortsInExportMask(exportMask, exportGroup, selectedPortsForMask);
                    // Update volumes Lun Ids in export mask based on driver selection
                    for (String volumeNativeId : driverVolumeToHLUMap.keySet()) {
                        String targetLunId = driverVolumeToHLUMap.get(volumeNativeId);
                        URI volumeUri = volumeNativeIdToUriMap.get(volumeNativeId);
                        exportMask.getVolumes().put(volumeUri.toString(), targetLunId);
                    }
                    dbClient.updateObject(exportMask);
                    taskCompleter.ready(dbClient);
                } else {
                    // selected ports are not valid. failure
                    String errorMsg = "createExportMask -- Ports selected by driver failed validation.";
                    log.error("createExportMask -- Ports selected by driver failed validation.");
                    ServiceError serviceError = ExternalDeviceException.errors.createExportMaskFailed("createExportMask", errorMsg);
                    taskCompleter.error(dbClient, serviceError);
                }
            } else {
                // Update volumes Lun Ids in export mask based on driver selection
                for (String volumeNativeId : driverVolumeToHLUMap.keySet()) {
                    String targetLunId = driverVolumeToHLUMap.get(volumeNativeId);
                    URI volumeUri = volumeNativeIdToUriMap.get(volumeNativeId);
                    exportMask.getVolumes().put(volumeUri.toString(), targetLunId);
                }
                dbClient.updateObject(exportMask);
                taskCompleter.ready(dbClient);
            }
        } else {
            String errorMsg = String.format("createExportMask -- Failed to create export: %s .", task.getMessage());
            log.error(errorMsg);
            ServiceError serviceError = ExternalDeviceException.errors.createExportMaskFailed("createExportMask", errorMsg);
            taskCompleter.error(dbClient, serviceError);
        }
    } catch (Exception ex) {
        log.error("Problem in createExportMask: ", ex);
        log.error("createExportMask -- Failed to create export mask. ", ex);
        ServiceError serviceError = ExternalDeviceException.errors.createExportMaskFailed("createExportMask", ex.getMessage());
        taskCompleter.error(dbClient, serviceError);
    }
    log.info("{} createExportMask END...", storage.getSerialNumber());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) DriverTask(com.emc.storageos.storagedriver.DriverTask) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) CommonStorageCapabilities(com.emc.storageos.storagedriver.storagecapabilities.CommonStorageCapabilities) StorageCapabilities(com.emc.storageos.storagedriver.storagecapabilities.StorageCapabilities) Initiator(com.emc.storageos.storagedriver.model.Initiator) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver) HashSet(java.util.HashSet) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ExportMask(com.emc.storageos.db.client.model.ExportMask) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) StoragePort(com.emc.storageos.storagedriver.model.StoragePort) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) VolumeURIHLU(com.emc.storageos.volumecontroller.impl.VolumeURIHLU) ExportPathParams(com.emc.storageos.db.client.model.ExportPathParams)

Example 22 with Initiator

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

the class ExternalDeviceExportOperations method prepareCapabilitiesForAddInitiators.

private void prepareCapabilitiesForAddInitiators(ExportPathParams pathParams, StringSetMap existingZoningMap, URI varrayURI, List<com.emc.storageos.db.client.model.Initiator> initiators, StorageCapabilities capabilities) {
    int driverMaxPath;
    StringSetMap zoningMap = new StringSetMap();
    // Calculate existing paths (without new initiators).
    int existingPaths = 0;
    List<URI> initiatorUris = URIUtil.toUris(initiators);
    for (Map.Entry<String, AbstractChangeTrackingSet<String>> entry : existingZoningMap.entrySet()) {
        if (!initiatorUris.contains(URIUtil.uri(entry.getKey()))) {
            zoningMap.put(entry.getKey(), entry.getValue());
        }
    }
    Map<com.emc.storageos.db.client.model.Initiator, List<com.emc.storageos.db.client.model.StoragePort>> assignments = blockScheduler.generateInitiatorsToStoragePortsMap(zoningMap, varrayURI);
    existingPaths = assignments.values().size();
    log.info("Existing path number in the export mask is {}", existingPaths);
    // Otherwise we allocate the difference between max paths and existing paths
    if (existingPaths + pathParams.getPathsPerInitiator() > pathParams.getMaxPaths()) {
        // we always need at least path-per-initiator ports
        driverMaxPath = pathParams.getPathsPerInitiator();
    } else {
        driverMaxPath = pathParams.getMaxPaths() - existingPaths;
    }
    // We assume that masking view meets min path before new initiators are added. We pass ppi as a minPath
    // to driver, so we can zone at least one new initiator.
    ExportPathsServiceOption numPath = new ExportPathsServiceOption(pathParams.getPathsPerInitiator(), driverMaxPath);
    List<ExportPathsServiceOption> exportPathParams = new ArrayList<>();
    exportPathParams.add(numPath);
    CommonStorageCapabilities commonCapabilities = new CommonStorageCapabilities();
    commonCapabilities.setExportPathParams(exportPathParams);
    capabilities.setCommonCapabilitis(commonCapabilities);
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) CommonStorageCapabilities(com.emc.storageos.storagedriver.storagecapabilities.CommonStorageCapabilities) ArrayList(java.util.ArrayList) URI(java.net.URI) ExportPathsServiceOption(com.emc.storageos.storagedriver.storagecapabilities.ExportPathsServiceOption) Initiator(com.emc.storageos.storagedriver.model.Initiator) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringMap(com.emc.storageos.db.client.model.StringMap) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet)

Example 23 with Initiator

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

the class ExternalDeviceExportOperations method deleteExportMask.

@Override
public void deleteExportMask(StorageSystem storage, URI exportMaskUri, List<URI> volumeUrisList, List<URI> targetUris, List<com.emc.storageos.db.client.model.Initiator> initiators, TaskCompleter taskCompleter) throws DeviceControllerException {
    // Unexport export mask volumes from export mask initiators.
    log.info("{} deleteExportMask START...", storage.getSerialNumber());
    try {
        log.info("deleteExportMask: Export mask id: {}", exportMaskUri);
        if (volumeUrisList != null) {
            log.info("deleteExportMask: volumes:  {}", Joiner.on(',').join(volumeUrisList));
        }
        if (targetUris != null) {
            log.info("deleteExportMask: assignments: {}", Joiner.on(',').join(targetUris));
        }
        if (initiators != null) {
            log.info("deleteExportMask: initiators: {}", Joiner.on(',').join(initiators));
        }
        BlockStorageDriver driver = externalDevice.getDriver(storage.getSystemType());
        ExportMask exportMask = (ExportMask) dbClient.queryObject(exportMaskUri);
        List<URI> volumeUris = new ArrayList<>();
        StringMap maskVolumes = exportMask.getVolumes();
        if (maskVolumes != null) {
            for (String vol : maskVolumes.keySet()) {
                URI volumeURI = URI.create(vol);
                volumeUris.add(volumeURI);
            }
        }
        StringSet maskInitiatorUris = exportMask.getInitiators();
        List<String> initiatorUris = new ArrayList<>();
        for (String initiatorUri : maskInitiatorUris) {
            initiatorUris.add(initiatorUri);
        }
        log.info("Export mask existing initiators: {} ", Joiner.on(',').join(initiatorUris));
        StringMap volumes = exportMask.getVolumes();
        log.info("Export mask existing volumes: {} ", volumes != null ? Joiner.on(',').join(volumes.keySet()) : null);
        // Prepare volumes.
        List<StorageVolume> driverVolumes = new ArrayList<>();
        prepareVolumes(storage, volumeUris, driverVolumes);
        // Prepare initiators
        List<Initiator> driverInitiators = new ArrayList<>();
        Set<com.emc.storageos.db.client.model.Initiator> maskInitiators = ExportMaskUtils.getInitiatorsForExportMask(dbClient, exportMask, null);
        // Get export group uri from task completer
        URI exportGroupUri = taskCompleter.getId();
        ExportGroup exportGroup = (ExportGroup) dbClient.queryObject(exportGroupUri);
        prepareInitiators(maskInitiators, exportGroup.forCluster(), driverInitiators);
        // Ready to call driver
        log.info("Initiators to call driver: {} ", maskInitiators);
        log.info("Volumes to call driver: {} ", volumeUris);
        DriverTask task = driver.unexportVolumesFromInitiators(driverInitiators, driverVolumes);
        // todo: need to implement support for async case.
        if (task.getStatus() == DriverTask.TaskStatus.READY) {
            String msg = String.format("Deleted export mask: %s.", task.getMessage());
            log.info(msg);
            taskCompleter.ready(dbClient);
        } else {
            String errorMsg = String.format("Failed to delete export mask: %s .", task.getMessage());
            log.error(errorMsg);
            ServiceError serviceError = ExternalDeviceException.errors.deleteExportMaskFailed("deleteExportMask", errorMsg);
            taskCompleter.error(dbClient, serviceError);
        }
    } catch (Exception ex) {
        log.error("Problem in deleteExportMask: ", ex);
        String errorMsg = String.format("Failed to delete export mask: %s .", ex.getMessage());
        log.error(errorMsg);
        ServiceError serviceError = ExternalDeviceException.errors.deleteExportMaskFailed("deleteExportMask", errorMsg);
        taskCompleter.error(dbClient, serviceError);
    }
    log.info("{} deleteExportMask END...", storage.getSerialNumber());
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StringMap(com.emc.storageos.db.client.model.StringMap) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) DriverTask(com.emc.storageos.storagedriver.DriverTask) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Initiator(com.emc.storageos.storagedriver.model.Initiator) StringSet(com.emc.storageos.db.client.model.StringSet) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver)

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