Search in sources :

Example 1 with CreateGroupCloneExternalDeviceJob

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);
        }
    }
}
Also used : VolumeConsistencyGroup(com.emc.storageos.storagedriver.model.VolumeConsistencyGroup) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StoragePool(com.emc.storageos.db.client.model.StoragePool) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IOException(java.io.IOException) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) DriverTask(com.emc.storageos.storagedriver.DriverTask) CreateGroupCloneExternalDeviceJob(com.emc.storageos.volumecontroller.impl.externaldevice.job.CreateGroupCloneExternalDeviceJob) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) Volume(com.emc.storageos.db.client.model.Volume) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) VolumeClone(com.emc.storageos.storagedriver.model.VolumeClone) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver) HashSet(java.util.HashSet)

Aggregations

URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)1 StoragePool (com.emc.storageos.db.client.model.StoragePool)1 Volume (com.emc.storageos.db.client.model.Volume)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)1 BlockStorageDriver (com.emc.storageos.storagedriver.BlockStorageDriver)1 DriverTask (com.emc.storageos.storagedriver.DriverTask)1 StorageVolume (com.emc.storageos.storagedriver.model.StorageVolume)1 VolumeClone (com.emc.storageos.storagedriver.model.VolumeClone)1 VolumeConsistencyGroup (com.emc.storageos.storagedriver.model.VolumeConsistencyGroup)1 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)1 CreateGroupCloneExternalDeviceJob (com.emc.storageos.volumecontroller.impl.externaldevice.job.CreateGroupCloneExternalDeviceJob)1 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)1 IOException (java.io.IOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1