Search in sources :

Example 1 with CreateVolumeCloneExternalDeviceJob

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);
        }
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StoragePool(com.emc.storageos.db.client.model.StoragePool) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ArrayList(java.util.ArrayList) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IOException(java.io.IOException) DriverTask(com.emc.storageos.storagedriver.DriverTask) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) Volume(com.emc.storageos.db.client.model.Volume) CreateVolumeCloneExternalDeviceJob(com.emc.storageos.volumecontroller.impl.externaldevice.job.CreateVolumeCloneExternalDeviceJob) VolumeClone(com.emc.storageos.storagedriver.model.VolumeClone) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) BlockObject(com.emc.storageos.db.client.model.BlockObject) StorageBlockObject(com.emc.storageos.storagedriver.model.StorageBlockObject) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver)

Aggregations

BlockObject (com.emc.storageos.db.client.model.BlockObject)1 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)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 StorageBlockObject (com.emc.storageos.storagedriver.model.StorageBlockObject)1 StorageVolume (com.emc.storageos.storagedriver.model.StorageVolume)1 VolumeClone (com.emc.storageos.storagedriver.model.VolumeClone)1 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)1 CreateVolumeCloneExternalDeviceJob (com.emc.storageos.volumecontroller.impl.externaldevice.job.CreateVolumeCloneExternalDeviceJob)1 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1