Search in sources :

Example 1 with RestoreFromSnapshotExternalDeviceJob

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

the class ExternalBlockStorageDevice method doRestoreFromSnapshot.

@Override
public void doRestoreFromSnapshot(StorageSystem storageSystem, URI volume, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    String storageSystemNativeId = storageSystem.getNativeId();
    _log.info("Snapshot Restore..... Started");
    BlockConsistencyGroup parentVolumeConsistencyGroup = null;
    try {
        List<BlockSnapshot> snapshotsToRestore = new ArrayList<>();
        BlockSnapshot blockSnapshot = dbClient.queryObject(BlockSnapshot.class, snapshot);
        List<BlockSnapshot> groupSnapshots = ControllerUtils.getSnapshotsPartOfReplicationGroup(blockSnapshot, dbClient);
        if (groupSnapshots.size() > 1 && ControllerUtils.checkSnapshotsInConsistencyGroup(Arrays.asList(blockSnapshot), dbClient, taskCompleter)) {
            // make sure we restore only snapshots from the same consistency group
            for (BlockSnapshot snap : groupSnapshots) {
                if (snap.getConsistencyGroup().equals(blockSnapshot.getConsistencyGroup())) {
                    snapshotsToRestore.add(snap);
                }
            }
            URI cgUri = blockSnapshot.getConsistencyGroup();
            parentVolumeConsistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, cgUri);
            _log.info("Restore group snapshot: group {}, snapshot set: {}, snapshots to restore: " + Joiner.on("\t").join(snapshotsToRestore), parentVolumeConsistencyGroup.getNativeId(), blockSnapshot.getReplicationGroupInstance());
        } else {
            Volume sourceVolume = getSnapshotParentVolume(blockSnapshot);
            snapshotsToRestore.add(blockSnapshot);
            _log.info("Restore single volume snapshot: volume {}, snapshot: {}", sourceVolume.getNativeId(), blockSnapshot.getNativeId());
        }
        // Prepare driver snapshots
        List<VolumeSnapshot> driverSnapshots = new ArrayList<>();
        for (BlockSnapshot snap : snapshotsToRestore) {
            VolumeSnapshot driverSnapshot = new VolumeSnapshot();
            Volume sourceVolume = getSnapshotParentVolume(snap);
            driverSnapshot.setParentId(sourceVolume.getNativeId());
            driverSnapshot.setNativeId(snap.getNativeId());
            driverSnapshot.setStorageSystemId(storageSystemNativeId);
            driverSnapshot.setDisplayName(snap.getLabel());
            if (parentVolumeConsistencyGroup != null) {
                driverSnapshot.setConsistencyGroup(snap.getReplicationGroupInstance());
            }
            driverSnapshots.add(driverSnapshot);
        }
        // Call driver to execute this request
        BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
        DriverTask task = driver.restoreSnapshot(driverSnapshots);
        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 call the completer as
            // appropriate based on the result of the request.
            RestoreFromSnapshotExternalDeviceJob job = new RestoreFromSnapshotExternalDeviceJob(storageSystem.getId(), snapshot, task.getTaskId(), taskCompleter);
            ControllerServiceImpl.enqueueJob(new QueueJob(job));
        } else if (task.getStatus() == DriverTask.TaskStatus.READY) {
            String msg = String.format("doRestoreFromSnapshot -- Restored snapshots: %s .", task.getMessage());
            _log.info(msg);
            taskCompleter.ready(dbClient);
        } else {
            String errorMsg = String.format("doRestoreFromSnapshot -- Failed to restore from snapshots: %s .", task.getMessage());
            _log.error(errorMsg);
            ServiceError serviceError = ExternalDeviceException.errors.restoreFromSnapshotFailed("doRestoreFromSnapshot", errorMsg);
            taskCompleter.error(dbClient, serviceError);
        }
    } catch (Exception e) {
        String message = String.format("IO exception when trying to restore from snapshots on array %s", storageSystem.getSerialNumber());
        _log.error(message, e);
        ServiceError error = ExternalDeviceException.errors.restoreFromSnapshotFailed("doRestoreFromSnapshot", e.getMessage());
        taskCompleter.error(dbClient, error);
    }
    _log.info("Snapshot Restore..... End");
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) RestoreFromSnapshotExternalDeviceJob(com.emc.storageos.volumecontroller.impl.externaldevice.job.RestoreFromSnapshotExternalDeviceJob) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ArrayList(java.util.ArrayList) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IOException(java.io.IOException) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) DriverTask(com.emc.storageos.storagedriver.DriverTask) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) Volume(com.emc.storageos.db.client.model.Volume) VolumeSnapshot(com.emc.storageos.storagedriver.model.VolumeSnapshot) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver)

Aggregations

BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)1 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)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 StorageVolume (com.emc.storageos.storagedriver.model.StorageVolume)1 VolumeSnapshot (com.emc.storageos.storagedriver.model.VolumeSnapshot)1 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)1 RestoreFromSnapshotExternalDeviceJob (com.emc.storageos.volumecontroller.impl.externaldevice.job.RestoreFromSnapshotExternalDeviceJob)1 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)1 IOException (java.io.IOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1