Search in sources :

Example 26 with BlockStorageDriver

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

the class ExternalBlockStorageDevice method doRestoreFromClone.

@Override
public void doRestoreFromClone(StorageSystem storageSystem, URI cloneVolume, TaskCompleter taskCompleter) {
    BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
    DriverTask task = null;
    Volume clone = dbClient.queryObject(Volume.class, cloneVolume);
    _log.info("Restore from volume clone on storage system {}, clone: {} .", storageSystem.getNativeId(), clone.toString());
    try {
        BlockObject sourceVolume = BlockObject.fetch(dbClient, clone.getAssociatedSourceVolume());
        VolumeClone driverClone = new VolumeClone();
        driverClone.setStorageSystemId(storageSystem.getNativeId());
        driverClone.setNativeId(clone.getNativeId());
        driverClone.setParentId(sourceVolume.getNativeId());
        driverClone.setConsistencyGroup(clone.getReplicationGroupInstance());
        // Call driver
        task = driver.restoreFromClone(Collections.unmodifiableList(Collections.singletonList(driverClone)));
        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 clone
            // volume replica state and call the completer as appropriate based on the result
            // of the request.
            RestoreFromCloneExternalDeviceJob job = new RestoreFromCloneExternalDeviceJob(storageSystem.getId(), cloneVolume, task.getTaskId(), taskCompleter);
            ControllerServiceImpl.enqueueJob(new QueueJob(job));
        } else if (task.getStatus() == DriverTask.TaskStatus.READY) {
            String msg = String.format("doRestoreFromClone -- Restored volume from clone: %s .", task.getMessage());
            _log.info(msg);
            ExternalDeviceUtils.updateRestoredClone(clone, driverClone, dbClient, true);
            taskCompleter.ready(dbClient);
        } else {
            String msg = String.format("Failed to restore volume from clone on storage system %s, clone: %s .", storageSystem.getNativeId(), clone.toString());
            _log.error(msg);
            // todo: add error
            ServiceError serviceError = ExternalDeviceException.errors.restoreVolumesFromClonesFailed("doRestoreFromClone", msg);
            taskCompleter.error(dbClient, serviceError);
        }
    } catch (Exception e) {
        String msg = String.format("Failed to restore volume from clone on storage system %s, clone: %s .", storageSystem.getNativeId(), clone.toString());
        _log.error(msg, e);
        ServiceError serviceError = ExternalDeviceException.errors.restoreVolumesFromClonesFailed("doRestoreFromClone", msg);
        taskCompleter.error(dbClient, serviceError);
    }
}
Also used : DriverTask(com.emc.storageos.storagedriver.DriverTask) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) RestoreFromCloneExternalDeviceJob(com.emc.storageos.volumecontroller.impl.externaldevice.job.RestoreFromCloneExternalDeviceJob) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) Volume(com.emc.storageos.db.client.model.Volume) VolumeClone(com.emc.storageos.storagedriver.model.VolumeClone) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver) BlockObject(com.emc.storageos.db.client.model.BlockObject) StorageBlockObject(com.emc.storageos.storagedriver.model.StorageBlockObject) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IOException(java.io.IOException)

Example 27 with BlockStorageDriver

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

the class ExternalBlockStorageDevice method doDetachGroupClone.

@Override
public void doDetachGroupClone(StorageSystem storageSystem, List<URI> cloneVolumes, TaskCompleter taskCompleter) {
    BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
    DriverTask task = null;
    List<Volume> clones = dbClient.queryObject(Volume.class, cloneVolumes);
    _log.info("Detaching group clones on storage system {}, clone: {} .", storageSystem.getNativeId(), clones.toString());
    try {
        Map<VolumeClone, Volume> driverCloneToCloneMap = new HashMap<>();
        List<VolumeClone> driverClones = new ArrayList<>();
        for (Volume clone : clones) {
            BlockObject sourceVolume = BlockObject.fetch(dbClient, clone.getAssociatedSourceVolume());
            VolumeClone driverClone = new VolumeClone();
            driverClone.setStorageSystemId(storageSystem.getNativeId());
            driverClone.setNativeId(clone.getNativeId());
            driverClone.setParentId(sourceVolume.getNativeId());
            driverClone.setConsistencyGroup(clone.getReplicationGroupInstance());
            driverClones.add(driverClone);
            driverCloneToCloneMap.put(driverClone, clone);
        }
        // Call driver
        task = driver.detachVolumeClone(Collections.unmodifiableList(driverClones));
        // todo: need to implement support for async case.
        if (task.getStatus() == DriverTask.TaskStatus.READY) {
            for (Map.Entry<VolumeClone, Volume> entry : driverCloneToCloneMap.entrySet()) {
                VolumeClone driverClone = entry.getKey();
                Volume clone = entry.getValue();
                ReplicationUtils.removeDetachedFullCopyFromSourceFullCopiesList(clone, dbClient);
                clone.setAssociatedSourceVolume(NullColumnValueGetter.getNullURI());
                clone.setReplicaState(Volume.ReplicationState.DETACHED.name());
            }
            String msg = String.format("doDetachGroupClone -- Detached group clone: %s .", task.getMessage());
            _log.info(msg);
            dbClient.updateObject(clones);
            taskCompleter.ready(dbClient);
        } else {
            String msg = String.format("Failed to detach group clone on storage system %s, clones: %s .", storageSystem.getNativeId(), clones.toString());
            _log.error(msg);
            // todo: add error
            ServiceError serviceError = ExternalDeviceException.errors.detachVolumeCloneFailed("doDetachGroupClone", msg);
            taskCompleter.error(dbClient, serviceError);
        }
    } catch (Exception e) {
        String msg = String.format("Failed to detach group clone on storage system %s, clones: %s .", storageSystem.getNativeId(), clones.toString());
        _log.error(msg, e);
        // todo: add error
        ServiceError serviceError = ExternalDeviceException.errors.detachVolumeCloneFailed("doDetachGroupClone", msg);
        taskCompleter.error(dbClient, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) 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) Volume(com.emc.storageos.db.client.model.Volume) VolumeClone(com.emc.storageos.storagedriver.model.VolumeClone) Map(java.util.Map) HashMap(java.util.HashMap) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver) BlockObject(com.emc.storageos.db.client.model.BlockObject) StorageBlockObject(com.emc.storageos.storagedriver.model.StorageBlockObject)

Example 28 with BlockStorageDriver

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

the class ExternalBlockStorageDevice method doDisconnect.

@Override
public void doDisconnect(StorageSystem storageSystem) {
    try {
        _log.info("doDisconnect {} - start", storageSystem.getId());
        com.emc.storageos.storagedriver.model.StorageSystem driverStorageSystem = ExternalDeviceCommunicationInterface.initStorageSystem(storageSystem);
        BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
        DriverTask task = driver.stopManagement(driverStorageSystem);
        if (task.getStatus() == DriverTask.TaskStatus.READY) {
            _log.info("doDisconnect -- Disconnected Storage System: {}", task.getMessage());
        } else {
            _log.error("doDisconnect failed. ", task.getMessage());
            throw ExternalDeviceException.exceptions.doDisconnectFailed("doDisconnect", task.getMessage());
        }
        _log.info("doDisconnect %1$s - Complete", storageSystem.getId());
    } catch (Exception e) {
        _log.error("doDisconnect failed. ", e.getMessage());
        throw ExternalDeviceException.exceptions.doDisconnectFailed("doDisconnect", e.getMessage());
    }
}
Also used : DriverTask(com.emc.storageos.storagedriver.DriverTask) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IOException(java.io.IOException)

Example 29 with BlockStorageDriver

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

the class ExternalBlockStorageDevice method updateStoragePoolCapacity.

/**
 * Update storage pool capacity to the most recent values from  driver.
 * Release reserved capacity in the pool for set of reservedObjects.
 *
 * @param dbPool storage pool to update capacity
 * @param dbSystem storage system where the pool is located
 * @param reservedObjects list of reserved object (volumes/clones/mirrors)
 * @param dbClient db client
 */
public static void updateStoragePoolCapacity(StoragePool dbPool, StorageSystem dbSystem, List<URI> reservedObjects, DbClient dbClient) {
    _log.info(String.format("Update storage pool capacity for pool %s, system %s ", dbPool.getId(), dbSystem.getId()));
    BlockStorageDriver driver = getBlockStorageDriver(dbSystem.getSystemType());
    // refresh the pool
    dbPool = dbClient.queryObject(StoragePool.class, dbPool.getId());
    // rediscover driver storage pool
    com.emc.storageos.storagedriver.model.StoragePool driverPool = driver.getStorageObject(dbSystem.getNativeId(), dbPool.getNativeId(), com.emc.storageos.storagedriver.model.StoragePool.class);
    // update pool capacity in db
    if (driverPool != null) {
        _log.info(String.format("Driver pool %s info: free capacity %s, subscribed capacity %s ", driverPool.getNativeId(), driverPool.getFreeCapacity(), driverPool.getSubscribedCapacity()));
        dbPool.setFreeCapacity(driverPool.getFreeCapacity());
        dbPool.setSubscribedCapacity(driverPool.getSubscribedCapacity());
    } else {
        _log.error("Driver pool for storage pool {} and storage system {} is null.", dbPool.getNativeId(), dbSystem.getNativeId());
    }
    // release reserved capacity
    dbPool.removeReservedCapacityForVolumes(URIUtil.asStrings(reservedObjects));
    dbClient.updateObject(dbPool);
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver)

Example 30 with BlockStorageDriver

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

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