Search in sources :

Example 1 with CephClient

use of com.emc.storageos.ceph.CephClient in project coprhd-controller by CoprHD.

the class CephSnapshotOperations method createSingleVolumeSnapshot.

@Override
public void createSingleVolumeSnapshot(StorageSystem storage, URI snapshot, Boolean createInactive, Boolean readOnly, TaskCompleter taskCompleter) throws DeviceControllerException {
    try (CephClient cephClient = getClient(storage)) {
        BlockSnapshot blockSnapshot = _dbClient.queryObject(BlockSnapshot.class, snapshot);
        Volume volume = _dbClient.queryObject(Volume.class, blockSnapshot.getParent().getURI());
        StoragePool pool = _dbClient.queryObject(StoragePool.class, volume.getPool());
        String id = CephUtils.createNativeId(blockSnapshot);
        cephClient.createSnap(pool.getPoolName(), volume.getNativeId(), id);
        blockSnapshot.setNativeId(id);
        blockSnapshot.setDeviceLabel(blockSnapshot.getLabel());
        blockSnapshot.setIsSyncActive(true);
        _dbClient.updateObject(blockSnapshot);
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        _log.error("Snapshot creation failed", e);
        ServiceError error = DeviceControllerErrors.ceph.operationFailed("createSingleVolumeSnapshot", e.getMessage());
        taskCompleter.error(_dbClient, error);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StoragePool(com.emc.storageos.db.client.model.StoragePool) Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) CephClient(com.emc.storageos.ceph.CephClient) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 2 with CephClient

use of com.emc.storageos.ceph.CephClient in project coprhd-controller by CoprHD.

the class CephSnapshotOperations method deleteSingleVolumeSnapshot.

@Override
public void deleteSingleVolumeSnapshot(StorageSystem storage, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    try (CephClient cephClient = getClient(storage)) {
        BlockSnapshot blockSnapshot = _dbClient.queryObject(BlockSnapshot.class, snapshot);
        Volume volume = _dbClient.queryObject(Volume.class, blockSnapshot.getParent().getURI());
        StoragePool pool = _dbClient.queryObject(StoragePool.class, volume.getPool());
        cephClient.deleteSnap(pool.getPoolName(), volume.getNativeId(), blockSnapshot.getNativeId());
        blockSnapshot.setInactive(true);
        _dbClient.updateObject(blockSnapshot);
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        _log.error("Snapshot deletion failed", e);
        ServiceError error = DeviceControllerErrors.ceph.operationFailed("deleteSingleVolumeSnapshot", e.getMessage());
        taskCompleter.error(_dbClient, error);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StoragePool(com.emc.storageos.db.client.model.StoragePool) Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) CephClient(com.emc.storageos.ceph.CephClient) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 3 with CephClient

use of com.emc.storageos.ceph.CephClient in project coprhd-controller by CoprHD.

the class CephCloneOperations method detachSingleClone.

@Override
public void detachSingleClone(StorageSystem storageSystem, URI cloneVolume, TaskCompleter taskCompleter) {
    _log.info("START detachSingleClone operation");
    try (CephClient cephClient = getClient(storageSystem)) {
        Volume cloneObject = _dbClient.queryObject(Volume.class, cloneVolume);
        String cloneId = cloneObject.getNativeId();
        StoragePool pool = _dbClient.queryObject(StoragePool.class, cloneObject.getPool());
        String poolId = pool.getPoolName();
        BlockSnapshot sourceSnapshot = _dbClient.queryObject(BlockSnapshot.class, cloneObject.getAssociatedSourceVolume());
        String snapshotId = sourceSnapshot.getNativeId();
        Volume parentVolume = _dbClient.queryObject(Volume.class, sourceSnapshot.getParent());
        String parentVolumeId = parentVolume.getNativeId();
        try {
            // Flatten image (detach Ceph volume from Ceph snapshot)
            // http://docs.ceph.com/docs/master/rbd/rbd-snapshot/#getting-started-with-layering
            cephClient.flattenImage(poolId, cloneId);
            // Detach links
            ReplicationUtils.removeDetachedFullCopyFromSourceFullCopiesList(cloneObject, _dbClient);
            cloneObject.setAssociatedSourceVolume(NullColumnValueGetter.getNullURI());
            cloneObject.setReplicaState(ReplicationState.DETACHED.name());
            _dbClient.updateObject(cloneObject);
            // Un-protect snapshot if it was the last child and delete internal interim snapshot
            List<String> children = cephClient.getChildren(poolId, parentVolumeId, snapshotId);
            if (children.isEmpty()) {
                // Unprotect snapshot to enable deleting
                if (cephClient.snapIsProtected(poolId, parentVolumeId, snapshotId)) {
                    cephClient.unprotectSnap(poolId, parentVolumeId, snapshotId);
                }
                // and should be deleted at the step of detaching during full copy creation workflow
                if (sourceSnapshot.checkInternalFlags(Flag.INTERNAL_OBJECT)) {
                    cephClient.deleteSnap(poolId, parentVolumeId, snapshotId);
                    // Set to null to prevent handling in cleanUpCloneObjects
                    snapshotId = null;
                    _dbClient.markForDeletion(sourceSnapshot);
                }
            } else if (sourceSnapshot.checkInternalFlags(Flag.INTERNAL_OBJECT)) {
                // If the snapshot (not interim) still has children, it may be used for another cloning right now
                // So that log the warning for interim snapshot only
                _log.warn("Could not delete interim snapshot {} because its Ceph snapshot {}@{} unexpectedly had another child", sourceSnapshot.getId(), parentVolumeId, snapshotId);
            }
            taskCompleter.ready(_dbClient);
        } catch (Exception e) {
            // Although detachSingleClone may be again called on error, it is better to remove objects now.
            cleanUpCloneObjects(cephClient, poolId, cloneId, snapshotId, parentVolumeId, sourceSnapshot);
            throw e;
        }
    } catch (Exception e) {
        BlockObject obj = BlockObject.fetch(_dbClient, cloneVolume);
        if (obj != null) {
            obj.setInactive(true);
            _dbClient.updateObject(obj);
        }
        _log.error("Encountered an exception", e);
        ServiceCoded code = DeviceControllerErrors.ceph.operationFailed("detachSingleClone", e.getMessage());
        taskCompleter.error(_dbClient, code);
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) Volume(com.emc.storageos.db.client.model.Volume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) CephClient(com.emc.storageos.ceph.CephClient) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 4 with CephClient

use of com.emc.storageos.ceph.CephClient in project coprhd-controller by CoprHD.

the class CephCloneOperations method createSingleClone.

@Override
public void createSingleClone(StorageSystem storageSystem, URI source, URI cloneVolume, Boolean createInactive, TaskCompleter taskCompleter) {
    _log.info("START createSingleClone operation");
    try (CephClient cephClient = getClient(storageSystem)) {
        Volume cloneObject = _dbClient.queryObject(Volume.class, cloneVolume);
        BlockObject sourceObject = BlockObject.fetch(_dbClient, source);
        BlockSnapshot sourceSnapshot = null;
        Volume parentVolume = null;
        if (sourceObject instanceof BlockSnapshot) {
            // Use source snapshot as clone source
            sourceSnapshot = (BlockSnapshot) sourceObject;
            parentVolume = _dbClient.queryObject(Volume.class, sourceSnapshot.getParent());
        } else if (sourceObject instanceof Volume) {
            // Use interim snapshot as clone source, since Ceph can clone snapshots only
            // http://docs.ceph.com/docs/master/rbd/rbd-snapshot/#getting-started-with-layering
            parentVolume = (Volume) sourceObject;
            sourceSnapshot = prepareInternalSnapshotForVolume(parentVolume);
        } else {
            String msg = String.format("Unsupported block object type URI %s", source);
            ServiceCoded code = DeviceControllerErrors.ceph.operationFailed("createSingleClone", msg);
            taskCompleter.error(_dbClient, code);
            return;
        }
        StoragePool pool = _dbClient.queryObject(StoragePool.class, parentVolume.getPool());
        String poolId = pool.getPoolName();
        String parentVolumeId = parentVolume.getNativeId();
        String snapshotId = sourceSnapshot.getNativeId();
        String cloneId = null;
        try {
            if (snapshotId == null || snapshotId.isEmpty()) {
                // Create Ceph snapshot of volume requested to clone
                snapshotId = CephUtils.createNativeId(sourceSnapshot);
                cephClient.createSnap(poolId, parentVolumeId, snapshotId);
                sourceSnapshot.setNativeId(snapshotId);
                sourceSnapshot.setDeviceLabel(snapshotId);
                sourceSnapshot.setIsSyncActive(true);
                sourceSnapshot.setParent(new NamedURI(parentVolume.getId(), parentVolume.getLabel()));
                _dbClient.updateObject(sourceSnapshot);
                _log.info("Interim shapshot {} created for clone {}", sourceSnapshot.getId(), cloneObject.getId());
            }
            // Ceph requires cloning snapshot to be protected (from deleting)
            if (!cephClient.snapIsProtected(poolId, parentVolumeId, snapshotId)) {
                cephClient.protectSnap(poolId, parentVolumeId, snapshotId);
            }
            // Do cloning
            String cloneVolumeId = CephUtils.createNativeId(cloneObject);
            cephClient.cloneSnap(poolId, parentVolumeId, snapshotId, cloneVolumeId);
            cloneId = cloneVolumeId;
            // Update clone object
            cloneObject.setDeviceLabel(cloneId);
            cloneObject.setNativeId(cloneId);
            cloneObject.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(_dbClient, cloneObject));
            cloneObject.setProvisionedCapacity(parentVolume.getProvisionedCapacity());
            cloneObject.setAllocatedCapacity(parentVolume.getAllocatedCapacity());
            cloneObject.setAssociatedSourceVolume(sourceSnapshot.getId());
            _dbClient.updateObject(cloneObject);
            // Finish task
            taskCompleter.ready(_dbClient);
        } catch (Exception e) {
            // Clean up created objects
            cleanUpCloneObjects(cephClient, poolId, cloneId, snapshotId, parentVolumeId, sourceSnapshot);
            throw e;
        }
    } catch (Exception e) {
        BlockObject obj = BlockObject.fetch(_dbClient, cloneVolume);
        if (obj != null) {
            obj.setInactive(true);
            _dbClient.updateObject(obj);
        }
        _log.error("Encountered an exception", e);
        ServiceCoded code = DeviceControllerErrors.ceph.operationFailed("createSingleClone", e.getMessage());
        taskCompleter.error(_dbClient, code);
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) Volume(com.emc.storageos.db.client.model.Volume) NamedURI(com.emc.storageos.db.client.model.NamedURI) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) CephClient(com.emc.storageos.ceph.CephClient) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 5 with CephClient

use of com.emc.storageos.ceph.CephClient in project coprhd-controller by CoprHD.

the class CephUtils method ensureConnectToCeph.

private static void ensureConnectToCeph(StorageProvider storageProvider) throws Exception {
    CephClientFactory factory = new CephClientFactory();
    CephClient cephClient = factory.getClient(storageProvider.getIPAddress(), storageProvider.getUserName(), storageProvider.getPassword());
    cephClient.close();
}
Also used : CephClientFactory(com.emc.storageos.ceph.CephClientFactory) CephClient(com.emc.storageos.ceph.CephClient)

Aggregations

CephClient (com.emc.storageos.ceph.CephClient)10 StoragePool (com.emc.storageos.db.client.model.StoragePool)6 Volume (com.emc.storageos.db.client.model.Volume)6 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)5 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)4 ServiceCoded (com.emc.storageos.svcs.errorhandling.model.ServiceCoded)4 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)3 CephException (com.emc.storageos.ceph.CephException)2 ClusterInfo (com.emc.storageos.ceph.model.ClusterInfo)2 BlockObject (com.emc.storageos.db.client.model.BlockObject)2 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)2 CephClientFactory (com.emc.storageos.ceph.CephClientFactory)1 PoolInfo (com.emc.storageos.ceph.model.PoolInfo)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 StorageHADomain (com.emc.storageos.db.client.model.StorageHADomain)1 StoragePort (com.emc.storageos.db.client.model.StoragePort)1 StorageProvider (com.emc.storageos.db.client.model.StorageProvider)1 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)1 StorageSystemViewObject (com.emc.storageos.plugins.StorageSystemViewObject)1 URI (java.net.URI)1