use of com.emc.storageos.volumecontroller.impl.externaldevice.job.CreateVolumeCloneExternalDeviceJob in project coprhd-controller by CoprHD.
the class ExternalBlockStorageDevice method doCreateClone.
@Override
public void doCreateClone(StorageSystem storageSystem, URI volume, URI clone, Boolean createInactive, TaskCompleter taskCompleter) {
Volume cloneObject = null;
DriverTask task = null;
try {
cloneObject = dbClient.queryObject(Volume.class, clone);
BlockObject sourceVolume = BlockObject.fetch(dbClient, volume);
VolumeClone driverClone = new VolumeClone();
if (sourceVolume instanceof Volume) {
driverClone.setSourceType(VolumeClone.SourceType.VOLUME);
} else if (sourceVolume instanceof BlockSnapshot) {
driverClone.setSourceType(VolumeClone.SourceType.SNAPSHOT);
} else {
cloneObject.setInactive(true);
dbClient.updateObject(cloneObject);
String errorMsg = String.format("doCreateClone -- Failed to create volume clone: unexpected source type %s .", sourceVolume.getClass().getSimpleName());
_log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.createVolumeCloneFailed("doCreateClone", errorMsg);
taskCompleter.error(dbClient, serviceError);
return;
}
// Prepare driver clone
driverClone.setParentId(sourceVolume.getNativeId());
driverClone.setStorageSystemId(storageSystem.getNativeId());
driverClone.setDisplayName(cloneObject.getLabel());
driverClone.setRequestedCapacity(cloneObject.getCapacity());
driverClone.setThinlyProvisioned(cloneObject.getThinlyProvisioned());
// Call driver
BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
List<VolumeClone> driverClones = new ArrayList<>();
driverClones.add(driverClone);
task = driver.createVolumeClone(Collections.unmodifiableList(driverClones), null);
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 and call the completer as appropriate based on the result of the request.
CreateVolumeCloneExternalDeviceJob job = new CreateVolumeCloneExternalDeviceJob(storageSystem.getId(), clone, task.getTaskId(), taskCompleter);
ControllerServiceImpl.enqueueJob(new QueueJob(job));
} else if (task.getStatus() == DriverTask.TaskStatus.READY) {
// Update clone
String msg = String.format("doCreateClone -- Created volume clone: %s .", task.getMessage());
_log.info(msg);
VolumeClone driverCloneResult = driverClones.get(0);
ExternalDeviceUtils.updateNewlyCreatedClone(cloneObject, driverCloneResult, dbClient);
taskCompleter.ready(dbClient);
} else {
cloneObject.setInactive(true);
dbClient.updateObject(cloneObject);
String errorMsg = String.format("doCreateClone -- Failed to create volume clone: %s .", task.getMessage());
_log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.createVolumeCloneFailed("doCreateClone", errorMsg);
taskCompleter.error(dbClient, serviceError);
}
} catch (Exception e) {
if (cloneObject != null) {
cloneObject.setInactive(true);
dbClient.updateObject(cloneObject);
}
_log.error("Failed to create volume clone. ", e);
ServiceError serviceError = ExternalDeviceException.errors.createVolumeCloneFailed("doCreateClone", e.getMessage());
taskCompleter.error(dbClient, serviceError);
} finally {
try {
if (task == null || isTaskInTerminalState(task.getStatus())) {
StoragePool dbPool = dbClient.queryObject(StoragePool.class, cloneObject.getPool());
updateStoragePoolCapacity(dbPool, storageSystem, Collections.singletonList(clone), dbClient);
}
} catch (Exception ex) {
_log.error("Failed to update storage pool {} after create clone operation completion.", cloneObject.getPool(), ex);
}
}
}
Aggregations