Search in sources :

Example 1 with RestoreFromCloneExternalDeviceJob

use of com.emc.storageos.volumecontroller.impl.externaldevice.job.RestoreFromCloneExternalDeviceJob 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)

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 RestoreFromCloneExternalDeviceJob (com.emc.storageos.volumecontroller.impl.externaldevice.job.RestoreFromCloneExternalDeviceJob)1 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)1 IOException (java.io.IOException)1