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");
}
Aggregations