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