Search in sources :

Example 1 with RestoreFromGroupCloneExternalDeviceJob

use of com.emc.storageos.volumecontroller.impl.externaldevice.job.RestoreFromGroupCloneExternalDeviceJob in project coprhd-controller by CoprHD.

the class ExternalBlockStorageDevice method doRestoreFromGroupClone.

@Override
public void doRestoreFromGroupClone(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("Restore from group clone on storage system {}, clones: {} .", 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.restoreFromClone(Collections.unmodifiableList(driverClones));
        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.
            RestoreFromGroupCloneExternalDeviceJob job = new RestoreFromGroupCloneExternalDeviceJob(storageSystem.getId(), cloneVolumes, task.getTaskId(), taskCompleter);
            ControllerServiceImpl.enqueueJob(new QueueJob(job));
        } else if (task.getStatus() == DriverTask.TaskStatus.READY) {
            for (Map.Entry<VolumeClone, Volume> entry : driverCloneToCloneMap.entrySet()) {
                VolumeClone driverClone = entry.getKey();
                Volume clone = entry.getValue();
                ExternalDeviceUtils.updateRestoredClone(clone, driverClone, dbClient, false);
            }
            String msg = String.format("doRestoreFromGroupClone -- Restore from group clone: %s .", task.getMessage());
            _log.info(msg);
            dbClient.updateObject(clones);
            taskCompleter.ready(dbClient);
        } else {
            String msg = String.format("Failed to restore from group clone on storage system %s, clones: %s .", storageSystem.getNativeId(), clones.toString());
            _log.error(msg);
            ServiceError serviceError = ExternalDeviceException.errors.restoreVolumesFromClonesFailed("doRestoreFromGroupClone", msg);
            taskCompleter.error(dbClient, serviceError);
        }
    } catch (Exception e) {
        String msg = String.format("Failed to restore from group clone on storage system %s, clones: %s .", storageSystem.getNativeId(), clones.toString());
        _log.error(msg, e);
        ServiceError serviceError = ExternalDeviceException.errors.restoreVolumesFromClonesFailed("doRestoreFromGroupClone", msg);
        taskCompleter.error(dbClient, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RestoreFromGroupCloneExternalDeviceJob(com.emc.storageos.volumecontroller.impl.externaldevice.job.RestoreFromGroupCloneExternalDeviceJob) 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) 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)

Aggregations

BlockObject (com.emc.storageos.db.client.model.BlockObject)1 Volume (com.emc.storageos.db.client.model.Volume)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)1 BlockStorageDriver (com.emc.storageos.storagedriver.BlockStorageDriver)1 DriverTask (com.emc.storageos.storagedriver.DriverTask)1 StorageBlockObject (com.emc.storageos.storagedriver.model.StorageBlockObject)1 StorageVolume (com.emc.storageos.storagedriver.model.StorageVolume)1 VolumeClone (com.emc.storageos.storagedriver.model.VolumeClone)1 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)1 RestoreFromGroupCloneExternalDeviceJob (com.emc.storageos.volumecontroller.impl.externaldevice.job.RestoreFromGroupCloneExternalDeviceJob)1 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1