Search in sources :

Example 31 with StorageVolume

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

the class DellSCDiscovery method getStorageVolumes.

/**
 * Discover storage volumes.
 *
 * @param storageSystem The storage system on which to discover.
 * @param storageVolumes The discovered storage volumes.
 * @param token Used for paging. Input 0 indicates that the first page should be returned. Output 0 indicates
 *            that last page was returned
 * @return The discovery task.
 */
public DriverTask getStorageVolumes(StorageSystem storageSystem, List<StorageVolume> storageVolumes, MutableInt token) {
    LOG.info("Getting volumes from {}", storageSystem.getNativeId());
    DellSCDriverTask task = new DellSCDriverTask("getVolumes");
    try {
        StorageCenterAPI api = connectionManager.getConnection(storageSystem.getNativeId());
        Map<ScReplayProfile, List<String>> cgInfo = util.getGCInfo(api, storageSystem.getNativeId());
        ScVolume[] volumes = api.getAllVolumes(storageSystem.getNativeId());
        for (ScVolume volume : volumes) {
            if (volume.inRecycleBin || volume.liveVolume || volume.cmmDestination || volume.replicationDestination) {
                continue;
            }
            StorageVolume driverVol = util.getStorageVolumeFromScVolume(api, volume, cgInfo);
            storageVolumes.add(driverVol);
        }
        task.setStatus(TaskStatus.READY);
    } catch (DellSCDriverException | StorageCenterAPIException e) {
        String msg = String.format("Error getting volume info: %s", e);
        LOG.warn(msg);
        task.setFailed(msg);
    }
    return task;
}
Also used : ScVolume(com.emc.storageos.driver.dellsc.scapi.objects.ScVolume) StorageCenterAPI(com.emc.storageos.driver.dellsc.scapi.StorageCenterAPI) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) DellSCDriverException(com.emc.storageos.driver.dellsc.DellSCDriverException) DellSCDriverTask(com.emc.storageos.driver.dellsc.DellSCDriverTask) ScReplayProfile(com.emc.storageos.driver.dellsc.scapi.objects.ScReplayProfile) StorageCenterAPIException(com.emc.storageos.driver.dellsc.scapi.StorageCenterAPIException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 32 with StorageVolume

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

the class DellSCProvisioning method exportVolumesToInitiators.

/**
 * Export volumes to initiators through a given set of ports. If ports are
 * not provided, use port requirements from ExportPathsServiceOption
 * storage capability.
 *
 * @param initiators The initiators to export to.
 * @param volumes The volumes to export.
 * @param volumeToHLUMap Map of volume nativeID to requested HLU. HLU
 *            value of -1 means that HLU is not defined and will
 *            be assigned by array.
 * @param recommendedPorts List of storage ports recommended for the export.
 *            Optional.
 * @param availablePorts List of ports available for the export.
 * @param capabilities The storage capabilities.
 * @param usedRecommendedPorts True if driver used recommended and only
 *            recommended ports for the export, false
 *            otherwise.
 * @param selectedPorts Ports selected for the export (if recommended ports
 *            have not been used).
 * @return The export task.
 * @throws DellSCDriverException
 */
public DriverTask exportVolumesToInitiators(List<Initiator> initiators, List<StorageVolume> volumes, Map<String, String> volumeToHLUMap, List<StoragePort> recommendedPorts, List<StoragePort> availablePorts, StorageCapabilities capabilities, MutableBoolean usedRecommendedPorts, List<StoragePort> selectedPorts) {
    LOG.info("Exporting volumes to inititators");
    DellSCDriverTask task = new DellSCDriverTask("exportVolumes");
    ScServer server = null;
    List<ScServerHba> preferredHbas = new ArrayList<>();
    StringBuilder errBuffer = new StringBuilder();
    int volumesMapped = 0;
    Set<StoragePort> usedPorts = new HashSet<>();
    String preferredController = null;
    // Cache of controller port instance IDs to StoragePort objects
    Map<String, StoragePort> discoveredPorts = new HashMap<>();
    // See if a max port count has been specified
    int maxPaths = -1;
    List<ExportPathsServiceOption> pathOptions = capabilities.getCommonCapabilitis().getExportPathParams();
    for (ExportPathsServiceOption pathOption : pathOptions) {
        // List but appears to only ever have one option?
        maxPaths = pathOption.getMaxPath();
    }
    // Get the recommended server ports to use
    List<String> recommendedServerPorts = new ArrayList<>();
    for (StoragePort port : recommendedPorts) {
        recommendedServerPorts.add(port.getNativeId());
    }
    for (StorageVolume volume : volumes) {
        String ssn = volume.getStorageSystemId();
        try {
            StorageCenterAPI api = connectionManager.getConnection(ssn);
            // Find our actual volume
            ScVolume scVol = null;
            int dotCount = StringUtils.countMatches(volume.getNativeId(), ".");
            if (dotCount == 2) {
                // Not actually a volume
                scVol = api.createReplayView(volume.getNativeId(), String.format("View of %s", volume.getNativeId()));
            } else {
                // Normal volume instance ID
                scVol = api.getVolume(volume.getNativeId());
            }
            if (scVol == null) {
                throw new DellSCDriverException(String.format("Unable to find volume %s", volume.getNativeId()));
            }
            // Look up the server if needed
            if (server == null) {
                server = createOrFindScServer(api, ssn, initiators, preferredHbas);
            }
            if (server == null) {
                // Unable to find or create the server, can't continue
                throw new DellSCDriverException(SERVER_CREATE_FAIL_MSG);
            }
            // See if we have a preferred controller
            if (preferredController == null && scVol.active) {
                // At least first volume is active somewhere, so we need to try to
                // use that controller for all mappings
                ScVolumeConfiguration volConfig = api.getVolumeConfig(scVol.instanceId);
                if (volConfig != null) {
                    preferredController = volConfig.controller.instanceId;
                }
            }
            // Next try to get a preferred controller based on what's requested
            if (preferredController == null && !recommendedPorts.isEmpty()) {
                try {
                    ScControllerPort scPort = api.getControllerPort(recommendedPorts.get(0).getNativeId());
                    preferredController = scPort.controller.instanceId;
                } catch (Exception e) {
                    LOG.warn("Failed to get recommended port controller.", e);
                }
            }
            int preferredLun = -1;
            if (volumeToHLUMap.containsKey(volume.getNativeId())) {
                String hlu = volumeToHLUMap.get(volume.getNativeId());
                try {
                    preferredLun = Integer.parseInt(hlu);
                } catch (NumberFormatException e) {
                    LOG.warn("Unable to parse preferred LUN {}", hlu);
                }
            }
            ScMappingProfile profile;
            // See if the volume is already mapped
            ScMappingProfile[] mappingProfiles = api.getServerVolumeMapping(scVol.instanceId, server.instanceId);
            if (mappingProfiles.length > 0) {
                // This one is already mapped
                profile = mappingProfiles[0];
            } else {
                profile = api.createVolumeMappingProfile(scVol.instanceId, server.instanceId, preferredLun, new String[0], maxPaths, preferredController);
            }
            ScMapping[] maps = api.getMappingProfileMaps(profile.instanceId);
            for (ScMapping map : maps) {
                volumeToHLUMap.put(volume.getNativeId(), String.valueOf(map.lun));
                StoragePort port;
                if (discoveredPorts.containsKey(map.controllerPort.instanceId)) {
                    port = discoveredPorts.get(map.controllerPort.instanceId);
                } else {
                    ScControllerPort scPort = api.getControllerPort(map.controllerPort.instanceId);
                    port = util.getStoragePortForControllerPort(api, scPort);
                    discoveredPorts.put(map.controllerPort.instanceId, port);
                }
                usedPorts.add(port);
            }
            volumesMapped++;
            LOG.info("Volume '{}' exported to server '{}'", scVol.name, server.name);
        } catch (StorageCenterAPIException | DellSCDriverException dex) {
            String error = String.format("Error mapping volume %s: %s", volume.getDisplayName(), dex);
            LOG.error(error);
            errBuffer.append(String.format("%s%n", error));
            if (SERVER_CREATE_FAIL_MSG.equals(dex.getMessage())) {
                // Game over
                break;
            }
        }
    }
    // See if we were able to use all of the recommended ports
    // TODO: Expand this to do more accurate checking
    usedRecommendedPorts.setValue(recommendedPorts.size() == usedPorts.size());
    if (!usedRecommendedPorts.isTrue()) {
        selectedPorts.addAll(usedPorts);
    }
    task.setMessage(errBuffer.toString());
    if (volumesMapped == volumes.size()) {
        task.setStatus(TaskStatus.READY);
    } else if (volumesMapped == 0) {
        task.setStatus(TaskStatus.FAILED);
    } else {
        task.setStatus(TaskStatus.PARTIALLY_FAILED);
    }
    return task;
}
Also used : StorageCenterAPI(com.emc.storageos.driver.dellsc.scapi.StorageCenterAPI) HashMap(java.util.HashMap) DellSCDriverTask(com.emc.storageos.driver.dellsc.DellSCDriverTask) ArrayList(java.util.ArrayList) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) DellSCDriverException(com.emc.storageos.driver.dellsc.DellSCDriverException) ScVolumeConfiguration(com.emc.storageos.driver.dellsc.scapi.objects.ScVolumeConfiguration) ScMapping(com.emc.storageos.driver.dellsc.scapi.objects.ScMapping) HashSet(java.util.HashSet) ScServer(com.emc.storageos.driver.dellsc.scapi.objects.ScServer) ScMappingProfile(com.emc.storageos.driver.dellsc.scapi.objects.ScMappingProfile) StorageCenterAPIException(com.emc.storageos.driver.dellsc.scapi.StorageCenterAPIException) StoragePort(com.emc.storageos.storagedriver.model.StoragePort) ScServerHba(com.emc.storageos.driver.dellsc.scapi.objects.ScServerHba) DellSCDriverException(com.emc.storageos.driver.dellsc.DellSCDriverException) StorageCenterAPIException(com.emc.storageos.driver.dellsc.scapi.StorageCenterAPIException) ScVolume(com.emc.storageos.driver.dellsc.scapi.objects.ScVolume) ScControllerPort(com.emc.storageos.driver.dellsc.scapi.objects.ScControllerPort) ExportPathsServiceOption(com.emc.storageos.storagedriver.storagecapabilities.ExportPathsServiceOption)

Example 33 with StorageVolume

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

the class ExpandVolumeSimulatorOperation method updateOnAsynchronousSuccess.

@Override
public void updateOnAsynchronousSuccess() {
    ExpandVolumeDriverTask expandVolumeTask = (ExpandVolumeDriverTask) _task;
    StorageVolume volume = expandVolumeTask.getStorageVolume();
    long newCapacity = expandVolumeTask.getExpandedCapacity();
    updateVolumeInfo(volume, newCapacity);
}
Also used : StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) ExpandVolumeDriverTask(com.emc.storageos.storagedriver.task.ExpandVolumeDriverTask)

Example 34 with StorageVolume

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

the class ExpandVolumeSimulatorOperation method getSuccessMessage.

@Override
public String getSuccessMessage(Object... args) {
    StorageVolume volume;
    if ((args != null) && (args.length > 0)) {
        volume = (StorageVolume) args[0];
    } else {
        // Must be asynchronous, so updated volume is in the task.
        ExpandVolumeDriverTask expandVolumeTask = (ExpandVolumeDriverTask) _task;
        volume = expandVolumeTask.getStorageVolume();
    }
    return String.format("StorageDriver: expandVolume information for storage system %s, volume nativeIds %s, new capacity %s - end", volume.getStorageSystemId(), volume.toString(), volume.getRequestedCapacity());
}
Also used : StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) ExpandVolumeDriverTask(com.emc.storageos.storagedriver.task.ExpandVolumeDriverTask)

Example 35 with StorageVolume

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

the class HP3PARCGHelper method addOrRemoveConsistencyGroupVolume.

public DriverTask addOrRemoveConsistencyGroupVolume(List<StorageVolume> volumes, DriverTask task, Registry driverRegistry, int action) {
    String storageSystemId = null;
    HP3PARApi hp3parApi = null;
    for (StorageVolume volume : volumes) {
        try {
            _log.info("3PARDriver: removeConsistencyGroupVolume for storage system  id {}, display name {} , native id {}, device lable id {} , cosistency group id {}", volume.getStorageSystemId(), volume.getDisplayName(), volume.getNativeId(), volume.getDeviceLabel(), volume.getConsistencyGroup());
            String localStorageSystemId = volume.getStorageSystemId();
            // get Api client
            if (storageSystemId == null || storageSystemId != localStorageSystemId) {
                storageSystemId = localStorageSystemId;
                hp3parApi = hp3parUtil.getHP3PARDeviceFromNativeId(localStorageSystemId, driverRegistry);
            }
            // update VV Set / Consistency Group
            hp3parApi.updateVVset(volume.getConsistencyGroup(), volume.getDisplayName(), action);
            task.setStatus(DriverTask.TaskStatus.READY);
        } catch (Exception e) {
            String msg = String.format("3PARDriver: Unable to create consistency group name %s in storage system native id is %s; Error: %s.\n", volume.getDisplayName(), volume.getStorageSystemId(), e.getMessage());
            _log.error(msg);
            task.setMessage(msg);
            task.setStatus(DriverTask.TaskStatus.PARTIALLY_FAILED);
            e.printStackTrace();
        }
    }
    return task;
}
Also used : StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume)

Aggregations

StorageVolume (com.emc.storageos.storagedriver.model.StorageVolume)38 ArrayList (java.util.ArrayList)17 DriverTask (com.emc.storageos.storagedriver.DriverTask)15 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)12 BlockStorageDriver (com.emc.storageos.storagedriver.BlockStorageDriver)11 URI (java.net.URI)11 HashMap (java.util.HashMap)11 Volume (com.emc.storageos.db.client.model.Volume)9 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)9 Initiator (com.emc.storageos.storagedriver.model.Initiator)7 HashSet (java.util.HashSet)7 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)6 ExportMask (com.emc.storageos.db.client.model.ExportMask)6 DellSCDriverException (com.emc.storageos.driver.dellsc.DellSCDriverException)6 DellSCDriverTask (com.emc.storageos.driver.dellsc.DellSCDriverTask)6 StorageCenterAPI (com.emc.storageos.driver.dellsc.scapi.StorageCenterAPI)6 StorageCenterAPIException (com.emc.storageos.driver.dellsc.scapi.StorageCenterAPIException)6 StoragePort (com.emc.storageos.storagedriver.model.StoragePort)6 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)5 CommonStorageCapabilities (com.emc.storageos.storagedriver.storagecapabilities.CommonStorageCapabilities)5