use of com.emc.storageos.model.block.SnapshotSessionNewTargetsParam in project coprhd-controller by CoprHD.
the class LinkSnapshotSessionForApplication method doExecute.
@Override
protected Tasks<TaskResourceRep> doExecute() throws Exception {
TaskList taskList = null;
if (linkedTargets != null && !linkedTargets.isEmpty()) {
VolumeGroupSnapshotSessionRelinkTargetsParam relinkParam = new VolumeGroupSnapshotSessionRelinkTargetsParam();
relinkParam.setLinkedTargetIds(linkedTargets);
relinkParam.setPartial(true);
relinkParam.setSnapshotSessions(snapSessions);
taskList = getClient().application().relinkApplicationSnapshotSession(applicationId, relinkParam);
} else {
VolumeGroupSnapshotSessionLinkTargetsParam input = new VolumeGroupSnapshotSessionLinkTargetsParam();
input.setSnapshotSessions(snapSessions);
input.setPartial(true);
SnapshotSessionNewTargetsParam newLinkedTargets = new SnapshotSessionNewTargetsParam();
newLinkedTargets.setCopyMode(copyMode);
newLinkedTargets.setCount(count);
newLinkedTargets.setTargetName(targetName);
input.setNewLinkedTargets(newLinkedTargets);
taskList = getClient().application().linkApplicationSnapshotSession(applicationId, input);
}
return new Tasks<TaskResourceRep>(getClient().auth().getClient(), taskList.getTaskList(), TaskResourceRep.class);
}
use of com.emc.storageos.model.block.SnapshotSessionNewTargetsParam in project coprhd-controller by CoprHD.
the class BlockSnapshotSessionManager method createSnapshotSession.
/**
* Implements a request to create a new block snapshot session.
*
* @param snapSessionSourceObjList The URI of the snapshot session source object.
* @param param A reference to the create session information.
* @param fcManager A reference to a full copy manager.
*
* @return TaskList A TaskList
*/
public TaskList createSnapshotSession(List<BlockObject> snapSessionSourceObjList, SnapshotSessionCreateParam param, BlockFullCopyManager fcManager) {
Collection<URI> sourceURIs = transform(snapSessionSourceObjList, fctnDataObjectToID());
s_logger.info("START create snapshot session for sources {}", Joiner.on(',').join(sourceURIs));
// Get the snapshot session label.
String snapSessionLabel = TimeUtils.formatDateForCurrent(param.getName());
// Get the target device information, if any.
int newLinkedTargetsCount = 0;
String newTargetsName = null;
String newTargetsCopyMode = BlockSnapshot.CopyMode.nocopy.name();
SnapshotSessionNewTargetsParam linkedTargetsParam = param.getNewLinkedTargets();
if (linkedTargetsParam != null) {
newLinkedTargetsCount = linkedTargetsParam.getCount().intValue();
newTargetsName = TimeUtils.formatDateForCurrent(linkedTargetsParam.getTargetName());
newTargetsCopyMode = linkedTargetsParam.getCopyMode();
}
BlockObject sourceObj = snapSessionSourceObjList.get(0);
// Get the project for the snapshot session source object.
Project project = BlockSnapshotSessionUtils.querySnapshotSessionSourceProject(sourceObj, _dbClient);
// Get the platform specific block snapshot session implementation.
BlockSnapshotSessionApi snapSessionApiImpl = determinePlatformSpecificImplForSource(sourceObj);
// Validate the create snapshot session request.
snapSessionApiImpl.validateSnapshotSessionCreateRequest(sourceObj, snapSessionSourceObjList, project, snapSessionLabel, newLinkedTargetsCount, newTargetsName, newTargetsCopyMode, false, fcManager);
// Create a unique task identifier.
String taskId = UUID.randomUUID().toString();
boolean inApplication = false;
if (sourceObj instanceof Volume && ((Volume) sourceObj).getApplication(_dbClient) != null) {
inApplication = true;
} else if (sourceObj instanceof BlockSnapshot) {
BlockSnapshot sourceSnap = (BlockSnapshot) sourceObj;
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;
}
}
}
// Prepare the ViPR BlockSnapshotSession instances and BlockSnapshot
// instances for any new targets to be created and linked to the
// snapshot sessions.
List<Map<URI, BlockSnapshot>> snapSessionSnapshots = new ArrayList<>();
BlockSnapshotSession snapSession = snapSessionApiImpl.prepareSnapshotSession(snapSessionSourceObjList, snapSessionLabel, newLinkedTargetsCount, newTargetsName, snapSessionSnapshots, taskId, inApplication);
// Populate the preparedObjects list and create tasks for each snapshot session.
TaskList response = new TaskList();
Operation snapSessionOp = _dbClient.createTaskOpStatus(BlockSnapshotSession.class, snapSession.getId(), taskId, getCreateResourceOperationTypeEnum(snapSession));
snapSession.getOpStatus().put(taskId, snapSessionOp);
response.getTaskList().add(toTask(snapSession, taskId, snapSessionOp));
if (snapSession.hasConsistencyGroup()) {
addConsistencyGroupTasks(snapSessionSourceObjList, response, taskId, getCreateResourceOperationTypeEnum(snapSession));
} else {
for (BlockObject sourceForTask : snapSessionSourceObjList) {
@SuppressWarnings("unchecked") Operation op = _dbClient.createTaskOpStatus(URIUtil.getModelClass(sourceForTask.getId()), sourceForTask.getId(), taskId, ResourceOperationTypeEnum.CREATE_SNAPSHOT_SESSION);
response.getTaskList().add(toTask(sourceForTask, taskId, op));
}
}
List<DataObject> preparedObjects = new ArrayList<>();
List<List<URI>> snapSessionSnapshotURIs = new ArrayList<>();
for (Map<URI, BlockSnapshot> snapshotMap : snapSessionSnapshots) {
// 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);
preparedObjects.add(snapSession);
// Create the snapshot sessions.
try {
snapSessionApiImpl.createSnapshotSession(sourceObj, snapSession.getId(), snapSessionSnapshotURIs, newTargetsCopyMode, taskId);
} catch (Exception e) {
String errorMsg = format("Failed to create snapshot sessions for source %s: %s", sourceObj.getId(), 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;
}
// Record a message in the audit log.
auditOp(OperationTypeEnum.CREATE_SNAPSHOT_SESSION, true, AuditLogManager.AUDITOP_BEGIN, snapSessionLabel, sourceObj.getId().toString(), sourceObj.getStorageController().toString());
s_logger.info("FINISH create snapshot session for source {}", sourceObj.getId());
return response;
}
Aggregations