use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class BlockFullCopyUtils method queryFullCopySourceStoragePool.
/**
* Returns the vpool for the full copy source.
*
* @param fcSourceObj A reference to the Volume or BlockSnapshot instance.
* @param dbClient A reference to a database client.
*
* @return A reference to the vpool for the full copy source.
*/
public static StoragePool queryFullCopySourceStoragePool(BlockObject fcSourceObj, DbClient dbClient) {
URI fcSourceURI = fcSourceObj.getId();
URI poolURI = null;
if (URIUtil.isType(fcSourceURI, Volume.class)) {
poolURI = ((Volume) fcSourceObj).getPool();
} else if (URIUtil.isType(fcSourceURI, BlockSnapshot.class)) {
URI parentVolURI = ((BlockSnapshot) fcSourceObj).getParent().getURI();
Volume parentVolume = dbClient.queryObject(Volume.class, parentVolURI);
poolURI = parentVolume.getPool();
} else {
throw APIException.badRequests.invalidFullCopySource(fcSourceURI.toString());
}
StoragePool storagePool = null;
if (!NullColumnValueGetter.isNullURI(poolURI)) {
storagePool = dbClient.queryObject(StoragePool.class, poolURI);
}
return storagePool;
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class BlockFullCopyUtils method queryFullCopySourceVPool.
/**
* Returns the vpool for the full copy source.
*
* @param fcSourceObj A reference to the Volume or BlockSnapshot instance.
* @param dbClient A reference to a database client.
*
* @return A reference to the vpool for the full copy source.
*/
public static VirtualPool queryFullCopySourceVPool(BlockObject fcSourceObj, DbClient dbClient) {
URI fcSourceURI = fcSourceObj.getId();
URI vpoolURI = null;
if (URIUtil.isType(fcSourceURI, Volume.class)) {
vpoolURI = ((Volume) fcSourceObj).getVirtualPool();
} else if (URIUtil.isType(fcSourceURI, BlockSnapshot.class)) {
URI parentVolURI = ((BlockSnapshot) fcSourceObj).getParent().getURI();
Volume parentVolume = dbClient.queryObject(Volume.class, parentVolURI);
vpoolURI = parentVolume.getVirtualPool();
}
if (vpoolURI == null) {
throw APIException.badRequests.invalidFullCopySource(fcSourceURI.toString());
}
VirtualPool vpool = dbClient.queryObject(VirtualPool.class, vpoolURI);
return vpool;
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class BlockFullCopyUtils method queryFullCopySourceProject.
/**
* Returns the project for the full copy source.
*
* @param fcSourceObj A reference to the Volume or BlockSnapshot instance.
* @param dbClient A reference to a database client.
*
* @return A reference to the project for the full copy source.
*/
public static Project queryFullCopySourceProject(BlockObject fcSourceObj, DbClient dbClient) {
URI fcSourceURI = fcSourceObj.getId();
URI projectURI = null;
if (URIUtil.isType(fcSourceURI, Volume.class)) {
projectURI = ((Volume) fcSourceObj).getProject().getURI();
} else if (URIUtil.isType(fcSourceURI, BlockSnapshot.class)) {
projectURI = ((BlockSnapshot) fcSourceObj).getProject().getURI();
}
if (projectURI == null) {
throw APIException.badRequests.invalidFullCopySource(fcSourceURI.toString());
}
Project project = dbClient.queryObject(Project.class, projectURI);
return project;
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class BlockSnapshotSessionManager method linkTargetVolumesToSnapshotSession.
/**
* Implements a request to create and link new target volumes to the
* BlockSnapshotSession instance with the passed URI.
*
* @param snapSessionURI The URI of a BlockSnapshotSession instance.
* @param param The linked target information.
*
* @return A TaskResourceRep.
*/
public TaskList linkTargetVolumesToSnapshotSession(URI snapSessionURI, SnapshotSessionLinkTargetsParam param) {
s_logger.info("START link new targets for snapshot session {}", snapSessionURI);
// Get the snapshot session.
BlockSnapshotSession snapSession = BlockSnapshotSessionUtils.querySnapshotSession(snapSessionURI, _uriInfo, _dbClient, true);
BlockObject snapSessionSourceObj = null;
List<BlockObject> snapSessionSourceObjs = getAllSnapshotSessionSources(snapSession);
snapSessionSourceObj = snapSessionSourceObjs.get(0);
// Get the project for the snapshot session source object.
Project project = BlockSnapshotSessionUtils.querySnapshotSessionSourceProject(snapSessionSourceObj, _dbClient);
BlockSnapshotSessionApi snapSessionApiImpl = determinePlatformSpecificImplForSource(snapSessionSourceObj);
boolean inApplication = false;
if (snapSessionSourceObj instanceof Volume && ((Volume) snapSessionSourceObj).getApplication(_dbClient) != null) {
inApplication = true;
} else if (snapSessionSourceObj instanceof BlockSnapshot) {
BlockSnapshot sourceSnap = (BlockSnapshot) snapSessionSourceObj;
NamedURI namedUri = sourceSnap.getParent();
if (!NullColumnValueGetter.isNullNamedURI(namedUri)) {
Volume source = _dbClient.queryObject(Volume.class, namedUri.getURI());
if (source != null && source.getApplication(_dbClient) != null) {
inApplication = true;
}
}
}
// Get the target information.
int newLinkedTargetsCount = param.getNewLinkedTargets().getCount();
String newTargetsName = param.getNewLinkedTargets().getTargetName();
String newTargetsCopyMode = param.getNewLinkedTargets().getCopyMode();
if (newTargetsCopyMode == null) {
newTargetsCopyMode = BlockSnapshot.CopyMode.nocopy.name();
}
// Validate that the requested new targets can be linked to the snapshot session.
snapSessionApiImpl.validateLinkNewTargetsRequest(snapSessionSourceObj, project, newLinkedTargetsCount, newTargetsName, newTargetsCopyMode);
// Prepare the BlockSnapshot instances to represent the new linked targets.
List<Map<URI, BlockSnapshot>> snapshots = snapSessionApiImpl.prepareSnapshotsForSession(snapSessionSourceObjs, 0, newLinkedTargetsCount, newTargetsName, inApplication);
// Create a unique task identifier.
String taskId = UUID.randomUUID().toString();
TaskList response = new TaskList();
List<DataObject> preparedObjects = new ArrayList<>();
// Create a task for the snapshot session.
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.LINK_SNAPSHOT_SESSION_TARGETS);
_dbClient.createTaskOpStatus(BlockSnapshotSession.class, snapSessionURI, taskId, op);
snapSession.getOpStatus().put(taskId, op);
response.getTaskList().add(toTask(snapSession, taskId));
List<List<URI>> snapSessionSnapshotURIs = new ArrayList<>();
for (Map<URI, BlockSnapshot> snapshotMap : snapshots) {
// Set Copy Mode
for (Entry<URI, BlockSnapshot> entry : snapshotMap.entrySet()) {
entry.getValue().setCopyMode(newTargetsCopyMode);
}
preparedObjects.addAll(snapshotMap.values());
Set<URI> uris = snapshotMap.keySet();
snapSessionSnapshotURIs.add(Lists.newArrayList(uris));
}
// persist copyMode changes
_dbClient.updateObject(preparedObjects);
// Create and link new targets to the snapshot session.
try {
snapSessionApiImpl.linkNewTargetVolumesToSnapshotSession(snapSessionSourceObj, snapSession, snapSessionSnapshotURIs, newTargetsCopyMode, taskId);
} catch (Exception e) {
String errorMsg = format("Failed to link new targets for snapshot session %s: %s", snapSessionURI, e.getMessage());
ServiceCoded sc = null;
if (e instanceof ServiceCoded) {
sc = (ServiceCoded) e;
} else {
sc = APIException.internalServerErrors.genericApisvcError(errorMsg, e);
}
cleanupFailure(response.getTaskList(), preparedObjects, errorMsg, taskId, sc);
throw e;
}
// Create the audit log entry.
auditOp(OperationTypeEnum.LINK_SNAPSHOT_SESSION_TARGET, true, AuditLogManager.AUDITOP_BEGIN, snapSessionURI.toString(), snapSessionSourceObj.getId().toString(), snapSessionSourceObj.getStorageController().toString());
s_logger.info("FINISH link new targets for snapshot session {}", snapSessionURI);
return response;
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class VolumeIngestionUtil method getBlockObjectConsistencyGroup.
/**
* Creates a BlockConsistencyGroup if it doesn't exist only when we are ingesting the last volume in unmanaged consistencygroup.
*
* In case if the volume is protected by RP or VPLEX, we should not create CG.
*
* @param unManagedVolume - UnManagedVolume object.
* @param blockObj - Ingested BlockObject
* @param context - current unManagedVolume Ingestion context.
* @param dbClient - dbClient instance.
* @return BlockConsistencyGroup
*/
public static BlockConsistencyGroup getBlockObjectConsistencyGroup(UnManagedVolume unManagedVolume, BlockObject blockObj, IngestionRequestContext context, DbClient dbClient) {
UnManagedConsistencyGroup umcg = getUnManagedConsistencyGroup(unManagedVolume, dbClient);
if (umcg != null) {
// Check if the UnManagedConsistencyGroup is present in the volume context which should have the updated info
UnManagedConsistencyGroup umcgInContext = context.findUnManagedConsistencyGroup(umcg.getLabel());
if (umcgInContext != null) {
umcg = umcgInContext;
}
}
// CG ingestion support for such volumes.
if (umcg == null || umcg.getUnManagedVolumesMap() == null) {
_logger.info("There is no unmanaged consistency group associated with unmanaged volume {}, however " + "the volume has the IS_VOLUME_IN_CONSISTENCYGROUP flag set to true. Ignoring CG operation" + " as there is not enough information to put this volume in a CG by itself.", unManagedVolume.getNativeGuid());
return null;
}
List<UnManagedConsistencyGroup> umcgsToUpdate = context.getVolumeContext().getUmCGObjectsToUpdate();
boolean isLastUmvToIngest = isLastUnManagedVolumeToIngest(umcg, unManagedVolume);
boolean isVplexOrRPProtected = isRPOrVplexProtected(unManagedVolume);
if (isVplexOrRPProtected || !isLastUmvToIngest) {
_logger.info("Ignoring the CG creation as the volume is either isVplexRPProtected:{} or isLastUmvToIngest: {} exists to ingest.", isLastUmvToIngest, isVplexOrRPProtected);
_logger.info("Remaining volumes in CG to ingest: {}", umcg.getUnManagedVolumesMap());
// set ReplicationGroupInstance in the block object.
blockObj.setReplicationGroupInstance(umcg.getLabel());
if (blockObj instanceof BlockSnapshot) {
// Check if the unmanaged volume has SNAPSHOT_CONSISTENCY_GROUP_NAME property populated. If yes,
// use that for replicationGroupInstance
String snapsetName = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.SNAPSHOT_CONSISTENCY_GROUP_NAME.toString(), unManagedVolume.getVolumeInformation());
if (snapsetName != null && !snapsetName.isEmpty()) {
blockObj.setReplicationGroupInstance(snapsetName);
}
}
updateVolumeInUnManagedConsistencyGroup(umcg, unManagedVolume, blockObj);
umcgsToUpdate.add(umcg);
return null;
}
// If the UMV is last volume, mark the UnManagedConsistencyGroup inactive to true.
if (isLastUmvToIngest) {
umcg.setInactive(true);
umcgsToUpdate.add(umcg);
}
if (null == umcg || null == umcg.getLabel()) {
_logger.warn("UnManaged volume {} CG doesn't have label. Hence exiting", unManagedVolume.getNativeGuid());
return null;
}
String cgName = umcg.getLabel();
StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, unManagedVolume.getStorageSystemUri());
_logger.info("UnManagedVolume {} is added to consistency group {}", unManagedVolume.getLabel(), cgName);
URI projectUri = context.getProject().getId();
URI tenantUri = context.getTenant().getId();
URI varrayUri = context.getVarray(unManagedVolume).getId();
VirtualPool vpool = context.getVpool(unManagedVolume);
if (!vpool.getMultivolumeConsistency()) {
_logger.warn("The requested Virtual Pool {} does not have " + "the Multi-Volume Consistency flag set, and this volume " + "is part of a consistency group.", vpool.getLabel());
throw IngestionException.exceptions.unmanagedVolumeVpoolConsistencyGroupMismatch(vpool.getLabel(), unManagedVolume.getLabel());
} else {
List<BlockConsistencyGroup> groups = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, BlockConsistencyGroup.class, PrefixConstraint.Factory.getFullMatchConstraint(BlockConsistencyGroup.class, "label", cgName));
BlockConsistencyGroup potentialUnclaimedCg = null;
if (!groups.isEmpty()) {
for (BlockConsistencyGroup cg : groups) {
if (validateCGProjectDetails(cg, storageSystem, projectUri, tenantUri, varrayUri, unManagedVolume.getLabel(), cgName, dbClient)) {
return cg;
}
URI storageControllerUri = cg.getStorageController();
URI virtualArrayUri = cg.getVirtualArray();
if (NullColumnValueGetter.isNullURI(storageControllerUri) && NullColumnValueGetter.isNullURI(virtualArrayUri)) {
potentialUnclaimedCg = cg;
}
}
}
// used it yet in creating a volume
if (null != potentialUnclaimedCg) {
potentialUnclaimedCg.addConsistencyGroupTypes(Types.LOCAL.name());
potentialUnclaimedCg.setStorageController(storageSystem.getId());
potentialUnclaimedCg.setVirtualArray(varrayUri);
return potentialUnclaimedCg;
}
_logger.info(String.format("Did not find an existing CG named %s that is associated already with the requested device %s and Virtual Array %s. ViPR will create a new one.", cgName, storageSystem.getNativeGuid(), varrayUri));
// create a new consistency group
BlockConsistencyGroup cg = new BlockConsistencyGroup();
cg.setId(URIUtil.createId(BlockConsistencyGroup.class));
cg.setLabel(cgName);
if (NullColumnValueGetter.isNotNullValue(umcg.getNativeId())) {
cg.setNativeId(umcg.getNativeId());
}
cg.setProject(new NamedURI(projectUri, context.getProject().getLabel()));
cg.setTenant(context.getProject().getTenantOrg());
cg.addConsistencyGroupTypes(Types.LOCAL.name());
cg.addSystemConsistencyGroup(storageSystem.getId().toString(), cgName);
cg.setStorageController(storageSystem.getId());
cg.setVirtualArray(varrayUri);
cg.setArrayConsistency(false);
return cg;
}
}
Aggregations