Search in sources :

Example 16 with BlockStorageDriver

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

the class ExternalBlockStorageDevice method createVolumeSnapshots.

private void createVolumeSnapshots(StorageSystem storageSystem, List<BlockSnapshot> snapshots, Boolean createInactive, Boolean readOnly, TaskCompleter taskCompleter) {
    _log.info("Creating snapshots for volumes.....");
    List<VolumeSnapshot> driverSnapshots = new ArrayList<>();
    Map<VolumeSnapshot, BlockSnapshot> driverSnapshotToSnapshotMap = new HashMap<>();
    // Prepare driver snapshots
    String storageSystemNativeId = storageSystem.getNativeId();
    for (BlockSnapshot snapshot : snapshots) {
        Volume parent = dbClient.queryObject(Volume.class, snapshot.getParent().getURI());
        VolumeSnapshot driverSnapshot = new VolumeSnapshot();
        driverSnapshot.setParentId(parent.getNativeId());
        driverSnapshot.setStorageSystemId(storageSystemNativeId);
        driverSnapshot.setDisplayName(snapshot.getLabel());
        if (readOnly) {
            driverSnapshot.setAccessStatus(StorageObject.AccessStatus.READ_ONLY);
        } else {
            driverSnapshot.setAccessStatus(StorageObject.AccessStatus.READ_WRITE);
        }
        driverSnapshotToSnapshotMap.put(driverSnapshot, snapshot);
        driverSnapshots.add(driverSnapshot);
    }
    // call driver
    BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
    DriverTask task = driver.createVolumeSnapshot(Collections.unmodifiableList(driverSnapshots), null);
    // todo: need to implement support for async case.
    if (task.getStatus() == DriverTask.TaskStatus.READY) {
        // update snapshots
        for (VolumeSnapshot driverSnapshot : driverSnapshotToSnapshotMap.keySet()) {
            BlockSnapshot snapshot = driverSnapshotToSnapshotMap.get(driverSnapshot);
            snapshot.setNativeId(driverSnapshot.getNativeId());
            snapshot.setDeviceLabel(driverSnapshot.getDeviceLabel());
            snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storageSystem, snapshot));
            snapshot.setIsSyncActive(true);
            snapshot.setReplicationGroupInstance(driverSnapshot.getConsistencyGroup());
            if (driverSnapshot.getProvisionedCapacity() > 0) {
                snapshot.setProvisionedCapacity(driverSnapshot.getProvisionedCapacity());
            }
            if (driverSnapshot.getAllocatedCapacity() > 0) {
                snapshot.setAllocatedCapacity(driverSnapshot.getAllocatedCapacity());
            }
        }
        dbClient.updateObject(driverSnapshotToSnapshotMap.values());
        String msg = String.format("createVolumeSnapshots -- Created snapshots: %s .", task.getMessage());
        _log.info(msg);
        taskCompleter.ready(dbClient);
    } else {
        for (BlockSnapshot snapshot : snapshots) {
            snapshot.setInactive(true);
        }
        dbClient.updateObject(snapshots);
        String errorMsg = String.format("doCreateSnapshot -- Failed to create snapshots: %s .", task.getMessage());
        _log.error(errorMsg);
        ServiceError serviceError = ExternalDeviceException.errors.createSnapshotsFailed("doCreateSnapshot", errorMsg);
        taskCompleter.error(dbClient, serviceError);
    }
}
Also used : DriverTask(com.emc.storageos.storagedriver.DriverTask) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) Volume(com.emc.storageos.db.client.model.Volume) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VolumeSnapshot(com.emc.storageos.storagedriver.model.VolumeSnapshot) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver)

Example 17 with BlockStorageDriver

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

the class ExternalBlockStorageDevice method getDriver.

public synchronized BlockStorageDriver getDriver(String driverType) {
    // look up driver
    BlockStorageDriver storageDriver = blockDrivers.get(driverType);
    if (storageDriver != null) {
        return storageDriver;
    } else {
        // init driver
        AbstractStorageDriver driver = drivers.get(driverType);
        if (driver == null) {
            _log.error("No driver entry defined for device type: {} . ", driverType);
            throw ExternalDeviceException.exceptions.noDriverDefinedForDevice(driverType);
        }
        init(driver);
        blockDrivers.put(driverType, (BlockStorageDriver) driver);
        return (BlockStorageDriver) driver;
    }
}
Also used : AbstractStorageDriver(com.emc.storageos.storagedriver.AbstractStorageDriver) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver)

Example 18 with BlockStorageDriver

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

the class ExternalDeviceExportOperations method removeInitiators.

@Override
public void removeInitiators(StorageSystem storage, URI exportMaskUri, List<URI> volumeURIList, List<com.emc.storageos.db.client.model.Initiator> initiatorList, List<URI> targetURIList, TaskCompleter taskCompleter) throws DeviceControllerException {
    log.info("{} removeInitiators START...", storage.getSerialNumber());
    try {
        log.info("removeInitiators: Export mask id: {}", exportMaskUri);
        if (volumeURIList != null) {
            log.info("removeInitiators: volumes : {}", Joiner.on(',').join(volumeURIList));
        }
        log.info("removeInitiators: initiators : {}", Joiner.on(',').join(initiatorList));
        log.info("removeInitiators: targets : {}", Joiner.on(',').join(targetURIList));
        BlockStorageDriver driver = externalDevice.getDriver(storage.getSystemType());
        ExportMask exportMask = (ExportMask) dbClient.queryObject(exportMaskUri);
        List<URI> volumeUris = ExportMaskUtils.getVolumeURIs(exportMask);
        log.info("Export mask existing volumes: {} ", volumeUris);
        // Prepare volumes
        List<StorageVolume> driverVolumes = new ArrayList<>();
        prepareVolumes(storage, volumeUris, driverVolumes);
        // Prepare initiators
        List<Initiator> driverInitiators = new ArrayList<>();
        // Get export group uri from task completer
        URI exportGroupUri = taskCompleter.getId();
        ExportGroup exportGroup = (ExportGroup) dbClient.queryObject(exportGroupUri);
        prepareInitiators(initiatorList, exportGroup.forCluster(), driverInitiators);
        // Ready to call driver
        DriverTask task = driver.unexportVolumesFromInitiators(driverInitiators, driverVolumes);
        // todo: need to implement support for async case.
        if (task.getStatus() == DriverTask.TaskStatus.READY) {
            String msg = String.format("Removed initiators from export mask: %s.", task.getMessage());
            log.info(msg);
            taskCompleter.ready(dbClient);
        } else {
            String errorMsg = String.format("Failed to remove initiators from export mask: %s .", task.getMessage());
            log.error(errorMsg);
            ServiceError serviceError = ExternalDeviceException.errors.removeInitiatorsFromExportMaskFailed("removeInitiators", errorMsg);
            taskCompleter.error(dbClient, serviceError);
        }
    } catch (Exception ex) {
        log.error("Problem in removeInitiators: ", ex);
        String errorMsg = String.format("Failed to remove initiators from export mask: %s .", ex.getMessage());
        log.error(errorMsg);
        ServiceError serviceError = ExternalDeviceException.errors.removeInitiatorsFromExportMaskFailed("removeInitiators", errorMsg);
        taskCompleter.error(dbClient, serviceError);
    }
    log.info("{} removeInitiators END...", storage.getSerialNumber());
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) 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) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver)

Example 19 with BlockStorageDriver

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

the class ExternalDeviceExportOperations method addInitiators.

@Override
public void addInitiators(StorageSystem storage, URI exportMaskUri, List<URI> volumeURIs, List<com.emc.storageos.db.client.model.Initiator> initiatorList, List<URI> targetURIList, TaskCompleter taskCompleter) throws DeviceControllerException {
    log.info("{} addInitiators START...", storage.getSerialNumber());
    try {
        log.info("addInitiators: Export mask id: {}", exportMaskUri);
        if (volumeURIs != null) {
            log.info("addInitiators: volumes : {}", Joiner.on(',').join(volumeURIs));
        }
        log.info("addInitiators: initiators : {}", Joiner.on(',').join(initiatorList));
        log.info("addInitiators: targets : {}", 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);
        List<URI> volumeUris = ExportMaskUtils.getVolumeURIs(exportMask);
        // Prepare volumes
        List<StorageVolume> driverVolumes = new ArrayList<>();
        Map<String, String> driverVolumeToHLUMap = new HashMap<>();
        Map<String, String> volumeNativeIdToUriMap = new HashMap<>();
        prepareVolumes(storage, exportMask.getVolumes(), 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
        prepareCapabilitiesForAddInitiators(pathParams, exportMask.getZoningMap(), exportGroup.getVirtualArray(), initiatorList, 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("addInitiators -- Added initiators: %s . Used recommended ports: %s .", task.getMessage(), usedRecommendedPorts);
            log.info(msg);
            if (usedRecommendedPorts.isFalse()) {
                // process driver selected ports
                log.info("Ports selected by driver: {}", selectedPorts);
                if (validateSelectedPorts(availablePorts, selectedPorts, pathParams.getPathsPerInitiator())) {
                    List<com.emc.storageos.db.client.model.StoragePort> selectedPortsForMask = new ArrayList<>();
                    URI varrayUri = exportGroup.getVirtualArray();
                    for (StoragePort driverPort : selectedPorts) {
                        com.emc.storageos.db.client.model.StoragePort port = nativeIdToAvailablePortMap.get(driverPort.getNativeId());
                        selectedPortsForMask.add(port);
                    }
                    updateStoragePortsForAddInitiators((ExportMaskAddInitiatorCompleter) taskCompleter, storage, exportMask, initiatorList, selectedPortsForMask, varrayUri, pathParams);
                    taskCompleter.ready(dbClient);
                } else {
                    // selected ports are not valid. failure
                    String errorMsg = "addInitiators -- Ports selected by driver failed validation.";
                    log.error("addInitiators -- Ports selected by driver failed validation.");
                    ServiceError serviceError = ExternalDeviceException.errors.addInitiatorsToExportMaskFailed("addInitiators", errorMsg);
                    taskCompleter.error(dbClient, serviceError);
                }
            } else {
                // Used recommended ports.
                taskCompleter.ready(dbClient);
            }
        } else {
            String errorMsg = String.format("addInitiators -- Failed to add initiators to export mask: %s .", task.getMessage());
            log.error(errorMsg);
            ServiceError serviceError = ExternalDeviceException.errors.addInitiatorsToExportMaskFailed("addInitiators", errorMsg);
            taskCompleter.error(dbClient, serviceError);
        }
    } catch (Exception ex) {
        log.error("addInitiators -- Failed to add initiators to export mask. ", ex);
        ServiceError serviceError = ExternalDeviceException.errors.addInitiatorsToExportMaskFailed("addInitiators", ex.getMessage());
        taskCompleter.error(dbClient, serviceError);
    }
    log.info("{} addInitiators 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) 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) ExportPathParams(com.emc.storageos.db.client.model.ExportPathParams)

Example 20 with BlockStorageDriver

use of com.emc.storageos.storagedriver.BlockStorageDriver 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)

Aggregations

BlockStorageDriver (com.emc.storageos.storagedriver.BlockStorageDriver)30 DriverTask (com.emc.storageos.storagedriver.DriverTask)26 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)22 StorageVolume (com.emc.storageos.storagedriver.model.StorageVolume)22 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)22 ArrayList (java.util.ArrayList)18 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)16 IOException (java.io.IOException)16 Volume (com.emc.storageos.db.client.model.Volume)15 URI (java.net.URI)12 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)9 HashMap (java.util.HashMap)9 VolumeClone (com.emc.storageos.storagedriver.model.VolumeClone)7 BlockObject (com.emc.storageos.db.client.model.BlockObject)6 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)6 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)6 ExportMask (com.emc.storageos.db.client.model.ExportMask)6 Initiator (com.emc.storageos.storagedriver.model.Initiator)6 StorageBlockObject (com.emc.storageos.storagedriver.model.StorageBlockObject)6 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)6