Search in sources :

Example 36 with StorageVolume

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

the class ExternalBlockStorageDevice method hasExports.

/**
 * Check if block object has exports on device
 *
 * @param driver storage driver
 * @param driverBlockObject driver block object
 * @return true/false
 */
private boolean hasExports(BlockStorageDriver driver, StorageBlockObject driverBlockObject) {
    Map<String, HostExportInfo> blocObjectToHostExportInfo = null;
    // get HostExportInfo data for this block object from the driver
    if (driverBlockObject instanceof VolumeClone) {
        VolumeClone driverClone = (VolumeClone) driverBlockObject;
        blocObjectToHostExportInfo = driver.getCloneExportInfoForHosts(driverClone);
        _log.info("Export info for clone {} is {}:", driverClone, blocObjectToHostExportInfo);
    } else if (driverBlockObject instanceof VolumeSnapshot) {
        VolumeSnapshot driverSnapshot = (VolumeSnapshot) driverBlockObject;
        blocObjectToHostExportInfo = driver.getSnapshotExportInfoForHosts(driverSnapshot);
        _log.info("Export info for snapshot {} is {}:", driverSnapshot, blocObjectToHostExportInfo);
    } else if (driverBlockObject instanceof StorageVolume) {
        StorageVolume driverVolume = (StorageVolume) driverBlockObject;
        blocObjectToHostExportInfo = driver.getVolumeExportInfoForHosts(driverVolume);
        _log.info("Export info for volume {} is {}:", driverVolume, blocObjectToHostExportInfo);
    } else {
        // not supported type in this method
        String errorMsg = String.format("Method is not supported for %s objects.", driverBlockObject.getClass().getSimpleName());
        throw new RuntimeException(errorMsg);
    }
    return !(blocObjectToHostExportInfo == null || blocObjectToHostExportInfo.isEmpty());
}
Also used : StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) HostExportInfo(com.emc.storageos.storagedriver.HostExportInfo) VolumeClone(com.emc.storageos.storagedriver.model.VolumeClone) VolumeSnapshot(com.emc.storageos.storagedriver.model.VolumeSnapshot)

Example 37 with StorageVolume

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

the class ExternalBlockStorageDevice method doExpandVolume.

@Override
public void doExpandVolume(StorageSystem storageSystem, StoragePool storagePool, Volume volume, Long size, TaskCompleter taskCompleter) throws DeviceControllerException {
    _log.info("Volume expand ..... Started");
    BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
    DriverTask task = null;
    try {
        // Prepare driver volume
        StorageVolume driverVolume = new StorageVolume();
        driverVolume.setNativeId(volume.getNativeId());
        driverVolume.setDeviceLabel(volume.getDeviceLabel());
        driverVolume.setStorageSystemId(storageSystem.getNativeId());
        driverVolume.setStoragePoolId(storagePool.getNativeId());
        driverVolume.setRequestedCapacity(volume.getCapacity());
        driverVolume.setThinlyProvisioned(volume.getThinlyProvisioned());
        driverVolume.setDisplayName(volume.getLabel());
        driverVolume.setAllocatedCapacity(volume.getAllocatedCapacity());
        driverVolume.setProvisionedCapacity(volume.getProvisionedCapacity());
        driverVolume.setWwn(volume.getWWN());
        // call driver
        task = driver.expandVolume(driverVolume, size);
        if (!isTaskInTerminalState(task.getStatus())) {
            // If the task is not in a terminal state and will be completed asynchronously
            // create a job to monitor the progress of the request and update the volume and
            // call the completer as appropriate based on the result of the request.
            ExpandVolumeExternalDeviceJob job = new ExpandVolumeExternalDeviceJob(storageSystem.getId(), volume.getId(), task.getTaskId(), taskCompleter);
            ControllerServiceImpl.enqueueJob(new QueueJob(job));
        } else if (task.getStatus() == DriverTask.TaskStatus.READY) {
            String msg = String.format("doExpandVolume -- Expanded volume: %s .", task.getMessage());
            _log.info(msg);
            ExternalDeviceUtils.updateExpandedVolume(volume, driverVolume, dbClient);
            taskCompleter.ready(dbClient);
        } else {
            // operation failed
            String errorMsg = String.format("doExpandVolume -- Failed to expand volume: %s .", task.getMessage());
            _log.error(errorMsg);
            ServiceError serviceError = ExternalDeviceException.errors.expandVolumeFailed("doExpandVolume", errorMsg);
            taskCompleter.error(dbClient, serviceError);
        }
    } catch (Exception e) {
        _log.error("doExpandVolume -- Failed to expand volume. ", e);
        ServiceError serviceError = ExternalDeviceException.errors.expandVolumeFailed("doExpandVolume", e.getMessage());
        taskCompleter.error(dbClient, serviceError);
    } finally {
        try {
            if (task == null || isTaskInTerminalState(task.getStatus())) {
                updateStoragePoolCapacity(storagePool, storageSystem, URIUtil.toUris(Collections.singletonList(volume)), dbClient);
            }
        } catch (Exception ex) {
            _log.error("Failed to update storage pool {} after expand volume operation completion.", storagePool.getId(), ex);
        }
    }
}
Also used : DriverTask(com.emc.storageos.storagedriver.DriverTask) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IOException(java.io.IOException) ExpandVolumeExternalDeviceJob(com.emc.storageos.volumecontroller.impl.externaldevice.job.ExpandVolumeExternalDeviceJob)

Example 38 with StorageVolume

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

the class ExternalBlockStorageDevice method doDeleteVolumes.

/**
 * {@inheritDoc}
 */
@Override
public void doDeleteVolumes(StorageSystem storageSystem, String opId, List<Volume> volumes, TaskCompleter taskCompleter) throws DeviceControllerException {
    BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
    List<Volume> deletedVolumes = new ArrayList<>();
    List<String> failedToDeleteVolumes = new ArrayList<>();
    List<Volume> deletedClones = new ArrayList<>();
    List<String> failedToDeleteClones = new ArrayList<>();
    boolean exception = false;
    StringBuffer errorMsgForVolumes = new StringBuffer();
    StringBuffer errorMsgForClones = new StringBuffer();
    try {
        for (Volume volume : volumes) {
            DriverTask task = null;
            // Check if this is regular volume or this is volume clone
            if (!NullColumnValueGetter.isNullURI(volume.getAssociatedSourceVolume())) {
                // this is clone
                _log.info("Deleting volume clone on storage system {}, clone: {} .", storageSystem.getNativeId(), volume.getNativeId());
                BlockObject sourceVolume = BlockObject.fetch(dbClient, volume.getAssociatedSourceVolume());
                VolumeClone driverClone = new VolumeClone();
                driverClone.setStorageSystemId(storageSystem.getNativeId());
                driverClone.setNativeId(volume.getNativeId());
                driverClone.setDeviceLabel(volume.getDeviceLabel());
                driverClone.setParentId(sourceVolume.getNativeId());
                driverClone.setConsistencyGroup(volume.getReplicationGroupInstance());
                // check for exports
                if (hasExports(driver, driverClone)) {
                    failedToDeleteClones.add(volume.getNativeId());
                    String errorMsgClone = String.format("Cannot delete clone %s on storage system %s, clone has exports on array.", driverClone.getNativeId(), storageSystem.getNativeId());
                    _log.error(errorMsgClone);
                    errorMsgForClones.append(errorMsgClone + "\n");
                    continue;
                }
                task = driver.deleteVolumeClone(driverClone);
            } else {
                // this is regular volume
                _log.info("Deleting volume on storage system {}, volume: {} .", storageSystem.getNativeId(), volume.getNativeId());
                StorageVolume driverVolume = new StorageVolume();
                driverVolume.setStorageSystemId(storageSystem.getNativeId());
                driverVolume.setNativeId(volume.getNativeId());
                driverVolume.setDeviceLabel(volume.getDeviceLabel());
                driverVolume.setConsistencyGroup(volume.getReplicationGroupInstance());
                // check for exports
                if (hasExports(driver, driverVolume)) {
                    failedToDeleteVolumes.add(volume.getNativeId());
                    String errorMsgVolume = String.format("Cannot delete volume %s on storage system %s, volume has exports on array.", driverVolume.getNativeId(), storageSystem.getNativeId());
                    _log.error(errorMsgVolume);
                    errorMsgForVolumes.append(errorMsgVolume + "\n");
                    continue;
                }
                task = driver.deleteVolume(driverVolume);
            }
            if (task.getStatus() == DriverTask.TaskStatus.READY) {
                volume.setInactive(true);
                if (volume.getAssociatedSourceVolume() != null) {
                    deletedClones.add(volume);
                } else {
                    deletedVolumes.add(volume);
                }
            } else {
                if (volume.getAssociatedSourceVolume() != null) {
                    failedToDeleteClones.add(volume.getNativeId());
                } else {
                    failedToDeleteVolumes.add(volume.getNativeId());
                }
            }
        }
    } catch (Exception e) {
        exception = true;
        _log.error("doDeleteVolumes -- Failed to delete volumes. ", e);
        ServiceError serviceError = ExternalDeviceException.errors.deleteVolumesFailed("doDeleteVolumes", e.getMessage());
        taskCompleter.error(dbClient, serviceError);
    } finally {
        if (!deletedVolumes.isEmpty()) {
            _log.info("Deleted volumes on storage system {}, volumes: {} .", storageSystem.getNativeId(), deletedVolumes.toString());
            dbClient.updateObject(deletedVolumes);
        }
        if (!deletedClones.isEmpty()) {
            _log.info("Deleted volume clones on storage system {}, clones: {} .", storageSystem.getNativeId(), deletedClones.toString());
            dbClient.updateObject(deletedClones);
        }
        if (!(failedToDeleteVolumes.isEmpty() && failedToDeleteClones.isEmpty())) {
            if (!failedToDeleteVolumes.isEmpty()) {
                String errorMsgVolumes = String.format("Failed to delete volumes on storage system %s, volumes: %s . ", storageSystem.getNativeId(), failedToDeleteVolumes.toString());
                _log.error(errorMsgVolumes);
            } else {
                String errorMsgClones = String.format("Failed to delete volume clones on storage system %s, clones: %s .", storageSystem.getNativeId(), failedToDeleteClones.toString());
                _log.error(errorMsgClones);
            }
            ServiceError serviceError = ExternalDeviceException.errors.deleteVolumesFailed("doDeleteVolumes", errorMsgForVolumes.append(errorMsgForClones).toString());
            taskCompleter.error(dbClient, serviceError);
        } else if (!exception) {
            taskCompleter.ready(dbClient);
        }
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ArrayList(java.util.ArrayList) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IOException(java.io.IOException) DriverTask(com.emc.storageos.storagedriver.DriverTask) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) Volume(com.emc.storageos.db.client.model.Volume) VolumeClone(com.emc.storageos.storagedriver.model.VolumeClone) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver) BlockObject(com.emc.storageos.db.client.model.BlockObject) StorageBlockObject(com.emc.storageos.storagedriver.model.StorageBlockObject)

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