use of com.emc.storageos.db.client.model.BlockObject in project coprhd-controller by CoprHD.
the class BlockSnapshotSessionManager method relinkTargetVolumesToSnapshotSession.
/**
* Implements a request to relink the passed targets from the
* BlockSnapshotSession instance with the passed URI.
*
* @param snapSessionURI The URI of a BlockSnapshotSession instance.
* @param param The linked target information.
*
* @return A TaskList.
*/
public TaskList relinkTargetVolumesToSnapshotSession(URI snapSessionURI, SnapshotSessionRelinkTargetsParam param) {
s_logger.info("START relink targets to 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);
// Get the platform specific block snapshot session implementation.
BlockSnapshotSessionApi snapSessionApiImpl = determinePlatformSpecificImplForSource(snapSessionSourceObj);
// Get the target information.
List<URI> linkedTargetURIs = param.getLinkedTargetIds();
// Validate that the requested targets can be re-linked to the snapshot session.
snapSessionApiImpl.validateRelinkSnapshotSessionTargets(snapSessionSourceObj, snapSession, project, linkedTargetURIs, _uriInfo);
// Create a unique task identifier.
String taskId = UUID.randomUUID().toString();
// Create a task for the snapshot session.
Operation op = new Operation();
op.setResourceType(getRelinkResourceOperationTypeEnum(snapSession));
_dbClient.createTaskOpStatus(BlockSnapshotSession.class, snapSessionURI, taskId, op);
snapSession.getOpStatus().put(taskId, op);
TaskResourceRep response = toTask(snapSession, taskId);
TaskList taskList = new TaskList();
taskList.addTask(response);
// Re-link the targets to the snapshot session.
try {
snapSessionApiImpl.relinkTargetVolumesToSnapshotSession(snapSessionSourceObj, snapSession, linkedTargetURIs, taskId);
} catch (Exception e) {
String errorMsg = format("Failed to relink targets to 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(Arrays.asList(response), new ArrayList<DataObject>(), errorMsg, taskId, sc);
throw e;
}
// Create the audit log entry.
auditOp(OperationTypeEnum.RELINK_SNAPSHOT_SESSION_TARGET, true, AuditLogManager.AUDITOP_BEGIN, snapSessionURI.toString(), snapSessionSourceObj.getId().toString(), snapSessionSourceObj.getStorageController().toString());
s_logger.info("FINISH relink targets to snapshot session {}", snapSessionURI);
return taskList;
}
use of com.emc.storageos.db.client.model.BlockObject in project coprhd-controller by CoprHD.
the class BlockSnapshotSessionManager method unlinkTargetVolumesFromSnapshotSession.
/**
* Implements a request to unlink the passed targets from the
* BlockSnapshotSession instance with the passed URI.
*
* @param snapSessionURI The URI of a BlockSnapshotSession instance.
* @param param The linked target information.
* @param opType The operation type for the audit and event logs.
*
* @return A TaskResourceRep.
*/
public TaskResourceRep unlinkTargetVolumesFromSnapshotSession(URI snapSessionURI, SnapshotSessionUnlinkTargetsParam param, OperationTypeEnum opType) {
s_logger.info("START unlink targets from 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);
// Get the target information.
Map<URI, Boolean> targetMap = new HashMap<>();
for (SnapshotSessionUnlinkTargetParam targetInfo : param.getLinkedTargets()) {
URI targetURI = targetInfo.getId();
Boolean deleteTarget = targetInfo.getDeleteTarget();
if (deleteTarget == null) {
deleteTarget = Boolean.FALSE;
}
targetMap.put(targetURI, deleteTarget);
}
// Validate that the requested targets can be unlinked from the snapshot session.
snapSessionApiImpl.validateUnlinkSnapshotSessionTargets(snapSession, snapSessionSourceObj, project, targetMap, _uriInfo);
// Create a unique task identifier.
String taskId = UUID.randomUUID().toString();
// Create a task for the snapshot session.
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.UNLINK_SNAPSHOT_SESSION_TARGETS);
_dbClient.createTaskOpStatus(BlockSnapshotSession.class, snapSessionURI, taskId, op);
snapSession.getOpStatus().put(taskId, op);
TaskResourceRep response = toTask(snapSession, taskId);
// Unlink the targets from the snapshot session.
try {
snapSessionApiImpl.unlinkTargetVolumesFromSnapshotSession(snapSessionSourceObj, snapSession, targetMap, opType, taskId);
} catch (Exception e) {
String errorMsg = format("Failed to unlink targets from 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(Arrays.asList(response), new ArrayList<DataObject>(), errorMsg, taskId, sc);
throw e;
}
// Create the audit log entry.
auditOp(opType, true, AuditLogManager.AUDITOP_BEGIN, snapSessionURI.toString(), snapSessionSourceObj.getId().toString(), snapSessionSourceObj.getStorageController().toString());
s_logger.info("FINISH unlink targets from snapshot session {}", snapSessionURI);
return response;
}
use of com.emc.storageos.db.client.model.BlockObject in project coprhd-controller by CoprHD.
the class BlockSnapshotSessionManager method getAllSnapshotSessionSources.
private List<BlockObject> getAllSnapshotSessionSources(BlockSnapshotSession snapSession) {
if (snapSession.hasConsistencyGroup() && NullColumnValueGetter.isNotNullValue(snapSession.getReplicationGroupInstance())) {
BlockConsistencyGroup cg = _dbClient.queryObject(BlockConsistencyGroup.class, snapSession.getConsistencyGroup());
List<Volume> cgSources = BlockConsistencyGroupUtils.getAllCGVolumes(cg, _dbClient);
// return only those volumes belonging to session's RG
return ControllerUtils.getAllVolumesForRGInCG(cgSources, snapSession.getReplicationGroupInstance(), snapSession.getStorageController(), _dbClient);
} else {
BlockObject snapSessionSourceObj = BlockSnapshotSessionUtils.querySnapshotSessionSource(snapSession.getParent().getURI(), _uriInfo, true, _dbClient);
return Lists.newArrayList(snapSessionSourceObj);
}
}
use of com.emc.storageos.db.client.model.BlockObject 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.BlockObject in project coprhd-controller by CoprHD.
the class VolumeIngestionUtil method getVolumeObjects.
/**
* For a given set of Volume native GUIDs, this method will return a List of
* URIs for any Volumes that were actually found in the database for that GUID.
* If a Volume cannot be found in the database, then the IngestionRequestContext
* will be checked for any Volumes that were created but not saved yet.
*
* @param targets a list of Volume native GUIDs to look for
* @param requestContext the IngestionRequestContext to analyze for newly-created objects
* @param dbClient a reference to the database client
* @return a List of BlockObjects for the given native GUIDs
*/
public static List<BlockObject> getVolumeObjects(StringSet targets, IngestionRequestContext requestContext, DbClient dbClient) {
List<BlockObject> targetUriList = new ArrayList<BlockObject>();
for (String targetId : targets) {
List<URI> targetUris = dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeNativeGuidConstraint(targetId));
if (null != targetUris && !targetUris.isEmpty()) {
for (URI targetUri : targetUris) {
BlockObject bo = (BlockObject) dbClient.queryObject(targetUri);
_logger.info("found volume block object: " + bo);
if (null != bo) {
if (!bo.getInactive()) {
targetUriList.add(bo);
break;
} else {
_logger.warn("BlockObject {} was retrieved from the database but is in an inactive state. " + "there may be a stale BlockObject column family alternate id index entry present " + "for native guid {}", bo.forDisplay(), targetId);
}
}
}
} else {
_logger.info("Volume not ingested yet {}. Checking in the created object map", targetId);
// check in the created object map
BlockObject blockObject = requestContext.getRootIngestionRequestContext().findCreatedBlockObject(targetId);
if (blockObject != null) {
_logger.info("Found the volume in the created object map");
targetUriList.add(blockObject);
}
}
}
return targetUriList;
}
Aggregations