use of com.emc.storageos.db.client.model.BlockObject in project coprhd-controller by CoprHD.
the class BlockSnapshotSessionDeleteWorkflowCompleter method complete.
/**
* {@inheritDoc}
*/
@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
URI snapSessionURI = getId();
try {
BlockSnapshotSession snapSession = dbClient.queryObject(BlockSnapshotSession.class, snapSessionURI);
List<BlockObject> allSources = getAllSources(snapSession, dbClient);
BlockObject sourceObj = allSources.get(0);
// Record the results.
recordBlockSnapshotSessionOperation(dbClient, OperationTypeEnum.DELETE_SNAPSHOT_SESSION, status, snapSession, sourceObj);
// Update the status map of the snapshot session.
switch(status) {
case error:
setErrorOnDataObject(dbClient, BlockSnapshotSession.class, snapSessionURI, coded);
break;
case suspended_error:
setSuspendedErrorOnDataObject(dbClient, BlockSnapshotSession.class, snapSessionURI, coded);
break;
case suspended_no_error:
setSuspendedNoErrorOnDataObject(dbClient, BlockSnapshotSession.class, snapSessionURI);
break;
case ready:
setReadyOnDataObject(dbClient, BlockSnapshotSession.class, snapSessionURI);
// Mark snapshot session inactive.
snapSession.setInactive(true);
dbClient.updateObject(snapSession);
break;
default:
String errMsg = String.format("Unexpected status %s for completer for task %s", status.name(), getOpId());
s_logger.info(errMsg);
throw DeviceControllerException.exceptions.unexpectedCondition(errMsg);
}
s_logger.info("Done delete snapshot session task {} with status: {}", getOpId(), status.name());
} catch (Exception e) {
s_logger.error("Failed updating status for delete snapshot session task {}", getOpId(), e);
} finally {
super.complete(dbClient, status, coded);
}
}
use of com.emc.storageos.db.client.model.BlockObject 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);
}
}
use of com.emc.storageos.db.client.model.BlockObject 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);
}
}
use of com.emc.storageos.db.client.model.BlockObject in project coprhd-controller by CoprHD.
the class CephStorageDevice method mapVolumes.
/**
* Map volumes to hosts on the hosts themselves.
*
* @param storage
* [in] - Storage System object
* @param volumeMap
* [in] - Volume URI to Integer LUN map
* @param initiators
* [in] - Collection of Initiator objects
* @param completer
* [in] - TaskCompleter
*/
private void mapVolumes(StorageSystem storage, Map<URI, Integer> volumeMap, Collection<Initiator> initiators, TaskCompleter completer) {
_log.info("mapVolumes: volumeMap: {}", volumeMap);
_log.info("mapVolumes: initiators: {}", initiators);
try {
for (Map.Entry<URI, Integer> volMapEntry : volumeMap.entrySet()) {
URI objectUri = volMapEntry.getKey();
BlockObject object = Volume.fetchExportMaskBlockObject(_dbClient, objectUri);
String monitorAddress = storage.getSmisProviderIP();
String monitorUser = storage.getSmisUserName();
String monitorKey = storage.getSmisPassword();
RBDMappingOptions rbdOptions = new RBDMappingOptions(object);
for (Initiator initiator : initiators) {
Host host = _dbClient.queryObject(Host.class, initiator.getHost());
if (initiator.getProtocol().equalsIgnoreCase(HostInterface.Protocol.RBD.name())) {
_log.info(String.format("mapVolume: host %s pool %s volume %s", host.getHostName(), rbdOptions.poolName, rbdOptions.volumeName));
LinuxSystemCLI linuxClient = getLinuxClient(host);
linuxClient.mapRBD(monitorAddress, monitorUser, monitorKey, rbdOptions.poolName, rbdOptions.volumeName, rbdOptions.snapshotName);
} else {
String msg = String.format("Unexpected initiator protocol %s, port %s, pool %s, volume %s", initiator.getProtocol(), initiator.getInitiatorPort(), rbdOptions.poolName, rbdOptions.volumeName);
ServiceCoded code = DeviceControllerErrors.ceph.operationFailed("mapVolumes", msg);
completer.error(_dbClient, code);
return;
}
}
}
completer.ready(_dbClient);
} catch (Exception e) {
_log.error("Encountered an exception", e);
ServiceCoded code = DeviceControllerErrors.ceph.operationFailed("mapVolumes", e.getMessage());
completer.error(_dbClient, code);
}
}
use of com.emc.storageos.db.client.model.BlockObject in project coprhd-controller by CoprHD.
the class CinderCloneOperations method createSingleClone.
/*
* (non-Javadoc)
*
* @see com.emc.storageos.volumecontroller.CloneOperations#createSingleClone(
* com.emc.storageos.db.client.model.StorageSystem, java.net.URI, java.net.URI,
* java.lang.Boolean,
* com.emc.storageos.volumecontroller.TaskCompleter)
*/
@Override
public void createSingleClone(StorageSystem storageSystem, URI sourceObject, URI cloneVolume, Boolean createInactive, TaskCompleter taskCompleter) {
log.info("START createSingleClone operation");
boolean isVolumeClone = true;
try {
BlockObject sourceObj = BlockObject.fetch(dbClient, sourceObject);
URI tenantUri = null;
if (sourceObj instanceof BlockSnapshot) {
// In case of snapshot, get the tenant from its parent volume
NamedURI parentVolUri = ((BlockSnapshot) sourceObj).getParent();
Volume parentVolume = dbClient.queryObject(Volume.class, parentVolUri);
tenantUri = parentVolume.getTenant().getURI();
isVolumeClone = false;
} else {
// This is a default flow
tenantUri = ((Volume) sourceObj).getTenant().getURI();
isVolumeClone = true;
}
Volume cloneObj = dbClient.queryObject(Volume.class, cloneVolume);
StoragePool targetPool = dbClient.queryObject(StoragePool.class, cloneObj.getPool());
TenantOrg tenantOrg = dbClient.queryObject(TenantOrg.class, tenantUri);
// String cloneLabel = generateLabel(tenantOrg, cloneObj);
CinderEndPointInfo ep = CinderUtils.getCinderEndPoint(storageSystem.getActiveProviderURI(), dbClient);
log.info("Getting the cinder APi for the provider with id " + storageSystem.getActiveProviderURI());
CinderApi cinderApi = cinderApiFactory.getApi(storageSystem.getActiveProviderURI(), ep);
String volumeId = "";
if (isVolumeClone) {
volumeId = cinderApi.cloneVolume(cloneObj.getLabel(), (cloneObj.getCapacity() / (1024 * 1024 * 1024)), targetPool.getNativeId(), sourceObj.getNativeId());
} else {
volumeId = cinderApi.createVolumeFromSnapshot(cloneObj.getLabel(), (cloneObj.getCapacity() / (1024 * 1024 * 1024)), targetPool.getNativeId(), sourceObj.getNativeId());
}
log.debug("Creating volume with the id " + volumeId + " on Openstack cinder node");
if (volumeId != null) {
// Cinder volume/snapshot clones are not sync with source, so
// set the replication state as DETACHED
cloneObj.setReplicaState(ReplicationState.DETACHED.name());
dbClient.persistObject(cloneObj);
Map<String, URI> volumeIds = new HashMap<String, URI>();
volumeIds.put(volumeId, cloneObj.getId());
ControllerServiceImpl.enqueueJob(new QueueJob(new CinderSingleVolumeCreateJob(volumeId, cloneObj.getLabel(), storageSystem.getId(), CinderConstants.ComponentType.volume.name(), ep, taskCompleter, targetPool.getId(), volumeIds)));
}
} catch (InternalException e) {
String errorMsg = String.format(CREATE_ERROR_MSG_FORMAT, sourceObject, cloneVolume);
log.error(errorMsg, e);
taskCompleter.error(dbClient, e);
} catch (Exception e) {
String errorMsg = String.format(CREATE_ERROR_MSG_FORMAT, sourceObject, cloneVolume);
log.error(errorMsg, e);
ServiceError serviceError = DeviceControllerErrors.cinder.operationFailed("createSingleClone", e.getMessage());
taskCompleter.error(dbClient, serviceError);
}
}
Aggregations