Search in sources :

Example 1 with SnapshotSessionNewTargetsParam

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);
}
Also used : SnapshotSessionNewTargetsParam(com.emc.storageos.model.block.SnapshotSessionNewTargetsParam) WaitForTasks(com.emc.sa.service.vipr.tasks.WaitForTasks) Tasks(com.emc.vipr.client.Tasks) VolumeGroupSnapshotSessionRelinkTargetsParam(com.emc.storageos.model.application.VolumeGroupSnapshotSessionRelinkTargetsParam) TaskList(com.emc.storageos.model.TaskList) VolumeGroupSnapshotSessionLinkTargetsParam(com.emc.storageos.model.application.VolumeGroupSnapshotSessionLinkTargetsParam)

Example 2 with SnapshotSessionNewTargetsParam

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;
}
Also used : NamedURI(com.emc.storageos.db.client.model.NamedURI) TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) SnapshotSessionNewTargetsParam(com.emc.storageos.model.block.SnapshotSessionNewTargetsParam) List(java.util.List) BlockSnapshotSessionList(com.emc.storageos.model.block.BlockSnapshotSessionList) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) BlockObject(com.emc.storageos.db.client.model.BlockObject) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Project(com.emc.storageos.db.client.model.Project) DataObject(com.emc.storageos.db.client.model.DataObject) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) Volume(com.emc.storageos.db.client.model.Volume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

TaskList (com.emc.storageos.model.TaskList)2 SnapshotSessionNewTargetsParam (com.emc.storageos.model.block.SnapshotSessionNewTargetsParam)2 WaitForTasks (com.emc.sa.service.vipr.tasks.WaitForTasks)1 BlockObject (com.emc.storageos.db.client.model.BlockObject)1 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)1 BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)1 DataObject (com.emc.storageos.db.client.model.DataObject)1 DiscoveredDataObject (com.emc.storageos.db.client.model.DiscoveredDataObject)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 Operation (com.emc.storageos.db.client.model.Operation)1 Project (com.emc.storageos.db.client.model.Project)1 Volume (com.emc.storageos.db.client.model.Volume)1 NullColumnValueGetter.isNullURI (com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)1 VolumeGroupSnapshotSessionLinkTargetsParam (com.emc.storageos.model.application.VolumeGroupSnapshotSessionLinkTargetsParam)1 VolumeGroupSnapshotSessionRelinkTargetsParam (com.emc.storageos.model.application.VolumeGroupSnapshotSessionRelinkTargetsParam)1 BlockSnapshotSessionList (com.emc.storageos.model.block.BlockSnapshotSessionList)1 ServiceCoded (com.emc.storageos.svcs.errorhandling.model.ServiceCoded)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)1 Tasks (com.emc.vipr.client.Tasks)1