use of com.emc.storageos.volumecontroller.impl.externaldevice.job.CreateGroupCloneExternalDeviceJob in project coprhd-controller by CoprHD.
the class ExternalBlockStorageDevice method doCreateGroupClone.
@Override
public void doCreateGroupClone(StorageSystem storageSystem, List<URI> cloneURIs, Boolean createInactive, TaskCompleter taskCompleter) {
BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
List<VolumeClone> driverClones = new ArrayList<>();
Map<VolumeClone, Volume> driverCloneToCloneMap = new HashMap<>();
Set<URI> consistencyGroups = new HashSet<>();
List<Volume> clones = null;
DriverTask task = null;
try {
clones = dbClient.queryObject(Volume.class, cloneURIs);
// We assume here that all volumes belong to the same consistency group
URI parentUri = clones.get(0).getAssociatedSourceVolume();
Volume parentVolume = dbClient.queryObject(Volume.class, parentUri);
BlockConsistencyGroup cg = null;
if (!NullColumnValueGetter.isNullURI(parentVolume.getConsistencyGroup())) {
cg = dbClient.queryObject(BlockConsistencyGroup.class, parentVolume.getConsistencyGroup());
} else {
String errorMsg = String.format("doCreateGroupClone -- Failed to create group clone, parent volumes do not belong to consistency group." + " Clones: %s .", cloneURIs);
_log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.createGroupCloneFailed("doCreateGroupClone", errorMsg);
taskCompleter.error(dbClient, serviceError);
return;
}
// Prepare driver consistency group of parent volume
VolumeConsistencyGroup driverCG = new VolumeConsistencyGroup();
driverCG.setDisplayName(cg.getLabel());
driverCG.setNativeId(cg.getNativeId());
driverCG.setStorageSystemId(storageSystem.getNativeId());
// Prepare driver clones
for (Volume clone : clones) {
URI sourceVolumeUri = clone.getAssociatedSourceVolume();
Volume sourceVolume = dbClient.queryObject(Volume.class, sourceVolumeUri);
VolumeClone driverClone = new VolumeClone();
driverClone.setParentId(sourceVolume.getNativeId());
driverClone.setStorageSystemId(storageSystem.getNativeId());
driverClone.setDisplayName(clone.getLabel());
driverClone.setRequestedCapacity(clone.getCapacity());
driverClone.setThinlyProvisioned(clone.getThinlyProvisioned());
driverClones.add(driverClone);
driverCloneToCloneMap.put(driverClone, clone);
}
// Call driver to create group snapshot
task = driver.createConsistencyGroupClone(driverCG, 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.
CreateGroupCloneExternalDeviceJob job = new CreateGroupCloneExternalDeviceJob(storageSystem.getId(), cloneURIs, parentVolume.getConsistencyGroup(), task.getTaskId(), taskCompleter);
ControllerServiceImpl.enqueueJob(new QueueJob(job));
} else if (task.getStatus() == DriverTask.TaskStatus.READY) {
// Update clone object with driver data
String msg = String.format("doCreateGroupClone -- Created group clone: %s .", task.getMessage());
_log.info(msg);
List<Volume> cloneObjects = new ArrayList<>();
for (VolumeClone driverCloneResult : driverClones) {
Volume cloneObject = driverCloneToCloneMap.get(driverCloneResult);
ExternalDeviceUtils.updateNewlyCreatedGroupClone(cloneObject, driverCloneResult, parentVolume.getConsistencyGroup(), dbClient);
cloneObjects.add(cloneObject);
}
dbClient.updateObject(cloneObjects);
taskCompleter.ready(dbClient);
} else {
// Process failure
for (Volume cloneObject : clones) {
cloneObject.setInactive(true);
}
dbClient.updateObject(clones);
String errorMsg = String.format("doCreateGroupClone -- Failed to create group clone: %s .", task.getMessage());
_log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.createGroupCloneFailed("doCreateGroupClone", errorMsg);
taskCompleter.error(dbClient, serviceError);
}
} catch (Exception e) {
if (clones != null) {
// Process failure
for (Volume cloneObject : clones) {
cloneObject.setInactive(true);
}
dbClient.updateObject(clones);
}
_log.error("Failed to create group clone. ", e);
ServiceError serviceError = ExternalDeviceException.errors.createGroupCloneFailed("doCreateGroupClone", e.getMessage());
taskCompleter.error(dbClient, serviceError);
} finally {
try {
if (task == null || isTaskInTerminalState(task.getStatus())) {
// post process storage pool capacity for clone's pools
// map clones to their storage pool
Map<URI, List<URI>> dbPoolToClone = new HashMap<>();
for (Volume clone : clones) {
URI dbPoolUri = clone.getPool();
List<URI> poolClones = dbPoolToClone.get(dbPoolUri);
if (poolClones == null) {
poolClones = new ArrayList<>();
dbPoolToClone.put(dbPoolUri, poolClones);
}
poolClones.add(clone.getId());
}
for (URI dbPoolUri : dbPoolToClone.keySet()) {
StoragePool dbPool = dbClient.queryObject(StoragePool.class, dbPoolUri);
updateStoragePoolCapacity(dbPool, storageSystem, dbPoolToClone.get(dbPoolUri), dbClient);
}
}
} catch (Exception ex) {
_log.error("Failed to update storage pool after create group clone operation completion.", ex);
}
}
}
Aggregations