Search in sources :

Example 1 with VolumeClone

use of com.emc.storageos.storagedriver.model.VolumeClone 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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RestoreFromGroupCloneExternalDeviceJob(com.emc.storageos.volumecontroller.impl.externaldevice.job.RestoreFromGroupCloneExternalDeviceJob) 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) VolumeClone(com.emc.storageos.storagedriver.model.VolumeClone) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver) BlockObject(com.emc.storageos.db.client.model.BlockObject) StorageBlockObject(com.emc.storageos.storagedriver.model.StorageBlockObject)

Example 2 with VolumeClone

use of com.emc.storageos.storagedriver.model.VolumeClone in project coprhd-controller by CoprHD.

the class ExternalDeviceUnManagedVolumeDiscoverer method getExportInfoForManagedVolumeReplicas.

/**
 * Get export info for replicas (snaps and clones) of managed volume.
 * We expect that all replicas of managed volume should be managed (known to the system) ---
 * enforced by  ingest framework, plus we do not support coexistence .
 * Warning log message is generated for each replica which is unmanaged.
 *
 * @param managedVolumeNativeIdToUriMap    [OUT], map: key --- managed volume native id, value: volume uri.
 * @param hostToManagedVolumeExportInfoMap [OUT], map: key --- host name, value: list of export infos for volumes exported
 *                                         to this host.
 * @param dbClient                         reference to db client [IN]
 * @param storageSystem                    storage system [IN]
 * @param systemVolume                     system volume  [IN]
 * @param driverVolume                     native volume [IN]
 * @param driver                           reference to driver [IN]
 * @throws Exception
 */
private void getExportInfoForManagedVolumeReplicas(Map<String, URI> managedVolumeNativeIdToUriMap, Map<String, List<HostExportInfo>> hostToManagedVolumeExportInfoMap, DbClient dbClient, com.emc.storageos.db.client.model.StorageSystem storageSystem, Volume systemVolume, StorageVolume driverVolume, BlockStorageDriver driver) throws Exception {
    // get export info for managed volume  snapshots
    log.info("Processing snapshots for managed volume {} ", systemVolume.getNativeGuid());
    List<VolumeSnapshot> driverSnapshots = driver.getVolumeSnapshots(driverVolume);
    if (driverSnapshots == null || driverSnapshots.isEmpty()) {
        log.info("There are no snapshots for volume {} ", systemVolume.getNativeGuid());
    } else {
        log.info("Snapshots for managed volume {}:" + Joiner.on("\t").join(driverSnapshots), systemVolume.getNativeGuid());
        for (VolumeSnapshot driverSnapshot : driverSnapshots) {
            String managedSnapNativeGuid = NativeGUIDGenerator.generateNativeGuidForVolumeOrBlockSnapShot(storageSystem.getNativeGuid(), driverSnapshot.getNativeId());
            BlockSnapshot systemSnap = DiscoveryUtils.checkBlockSnapshotExistsInDB(dbClient, managedSnapNativeGuid);
            if (systemSnap == null) {
                log.warn("Found unmanaged snapshot of managed volume --- this is unexpected! Skipping this snapshot {}.", driverSnapshot.getNativeId());
                continue;
            } else {
                log.info("Processing managed {} snapshot of managed volume ().", systemSnap.getNativeId(), systemVolume.getNativeGuid());
            }
            // get export data for the snapshot
            managedVolumeNativeIdToUriMap.put(driverSnapshot.getNativeId(), systemSnap.getId());
            getSnapshotExportInfo(driver, driverSnapshot, hostToManagedVolumeExportInfoMap);
        }
    }
    // get export info for managed volume  clones
    log.info("Processing clones for managed volume {} ", systemVolume.getNativeGuid());
    List<VolumeClone> driverClones = driver.getVolumeClones(driverVolume);
    if (driverClones == null || driverClones.isEmpty()) {
        log.info("There are no clones for volume {} ", systemVolume.getNativeGuid());
    } else {
        log.info("Clones for managed volume {}:" + Joiner.on("\t").join(driverClones), systemVolume.getNativeGuid());
        for (VolumeClone driverClone : driverClones) {
            String managedCloneNativeGuid = NativeGUIDGenerator.generateNativeGuidForVolumeOrBlockSnapShot(storageSystem.getNativeGuid(), driverClone.getNativeId());
            Volume systemClone = DiscoveryUtils.checkStorageVolumeExistsInDB(dbClient, managedCloneNativeGuid);
            if (systemClone == null) {
                log.warn("Found unmanaged clone of managed volume --- this is unexpected! Skipping this clone {}.", driverClone.getNativeId());
                continue;
            } else {
                log.info("Processing managed {} clone of managed volume ().", systemClone.getNativeId(), systemVolume.getNativeGuid());
            }
            // get export data for the clone
            managedVolumeNativeIdToUriMap.put(driverClone.getNativeId(), systemClone.getId());
            getCloneExportInfo(driver, driverClone, hostToManagedVolumeExportInfoMap);
        }
    }
}
Also used : StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VolumeClone(com.emc.storageos.storagedriver.model.VolumeClone) VolumeSnapshot(com.emc.storageos.storagedriver.model.VolumeSnapshot)

Example 3 with VolumeClone

use of com.emc.storageos.storagedriver.model.VolumeClone in project coprhd-controller by CoprHD.

the class CreateVolumeCloneExternalDeviceJob method doTaskSucceeded.

/**
 * {@inheritDoc}
 */
@Override
protected void doTaskSucceeded(DriverTask driverTask, DbClient dbClient) throws Exception {
    // Get the ViPR volume representing the clone.
    s_logger.info(String.format("Successfully created volume clone %s:%s", _volumeURI, driverTask.getMessage()));
    Volume volume = dbClient.queryObject(Volume.class, _volumeURI);
    if (volume == null) {
        s_logger.error(String.format("Failed to find volume %s", _volumeURI));
        throw DeviceControllerException.exceptions.objectNotFound(_volumeURI);
    }
    // Update the ViPR clone with the driver clone information.
    // Note that we know ViPR only allows creation of a single
    // in a given request.
    CreateVolumeCloneDriverTask createCloneDriverTask = (CreateVolumeCloneDriverTask) driverTask;
    List<VolumeClone> updatedClones = createCloneDriverTask.getClones();
    VolumeClone updatedClone = updatedClones.get(0);
    ExternalDeviceUtils.updateNewlyCreatedClone(volume, updatedClone, dbClient);
    try {
        // Update storage pool capacity in database.
        ExternalDeviceUtils.updateStoragePoolCapacityAfterOperationComplete(volume.getPool(), _storageSystemURI, Collections.singletonList(_volumeURI), dbClient);
    } catch (Exception ex) {
        s_logger.error("Failed to update storage pool {} after create clone operation completion.", volume.getPool(), ex);
    }
}
Also used : CreateVolumeCloneDriverTask(com.emc.storageos.storagedriver.task.CreateVolumeCloneDriverTask) Volume(com.emc.storageos.db.client.model.Volume) VolumeClone(com.emc.storageos.storagedriver.model.VolumeClone) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 4 with VolumeClone

use of com.emc.storageos.storagedriver.model.VolumeClone in project coprhd-controller by CoprHD.

the class RestoreFromGroupCloneExternalDeviceJob method doTaskSucceeded.

/**
 * {@inheritDoc}
 */
@Override
protected void doTaskSucceeded(DriverTask driverTask, DbClient dbClient) throws Exception {
    s_logger.info(String.format("Successfully restored group clone: %s", driverTask.getMessage()));
    // Update the ViPR volumes representing the clones with the
    // corresponding driver clone.
    List<Volume> updatedVolumes = new ArrayList<>();
    for (URI volumeURI : _volumeURIs) {
        Volume volume = dbClient.queryObject(Volume.class, volumeURI);
        if (volume == null) {
            s_logger.error(String.format("Failed to find volume %s", volumeURI));
            throw DeviceControllerException.exceptions.objectNotFound(volumeURI);
        }
        // Update the ViPR clone with the driver clone information.
        RestoreFromCloneDriverTask restoreDriverTask = (RestoreFromCloneDriverTask) driverTask;
        List<VolumeClone> updatedClones = restoreDriverTask.getClones();
        for (VolumeClone updatedClone : updatedClones) {
            if (ExternalDeviceUtils.isVolumeExternalDeviceClone(volume, updatedClone, dbClient)) {
                ExternalDeviceUtils.updateRestoredClone(volume, updatedClone, dbClient, false);
                updatedVolumes.add(volume);
                break;
            }
        }
    }
    dbClient.updateObject(updatedVolumes);
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) RestoreFromCloneDriverTask(com.emc.storageos.storagedriver.task.RestoreFromCloneDriverTask) ArrayList(java.util.ArrayList) VolumeClone(com.emc.storageos.storagedriver.model.VolumeClone) URI(java.net.URI)

Example 5 with VolumeClone

use of com.emc.storageos.storagedriver.model.VolumeClone 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

VolumeClone (com.emc.storageos.storagedriver.model.VolumeClone)27 Volume (com.emc.storageos.db.client.model.Volume)13 StorageVolume (com.emc.storageos.storagedriver.model.StorageVolume)10 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)9 ArrayList (java.util.ArrayList)9 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)7 BlockStorageDriver (com.emc.storageos.storagedriver.BlockStorageDriver)7 DriverTask (com.emc.storageos.storagedriver.DriverTask)7 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)7 IOException (java.io.IOException)7 BlockObject (com.emc.storageos.db.client.model.BlockObject)6 StorageBlockObject (com.emc.storageos.storagedriver.model.StorageBlockObject)6 VolumeDetailsCommandResult (com.emc.storageos.hp3par.command.VolumeDetailsCommandResult)4 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)4 URI (java.net.URI)4 HashMap (java.util.HashMap)4 CreateGroupCloneDriverTask (com.emc.storageos.storagedriver.task.CreateGroupCloneDriverTask)3 RestoreFromCloneDriverTask (com.emc.storageos.storagedriver.task.RestoreFromCloneDriverTask)3 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)2 StoragePool (com.emc.storageos.db.client.model.StoragePool)2