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