Search in sources :

Example 66 with TaskResourceRep

use of com.emc.storageos.model.TaskResourceRep in project coprhd-controller by CoprHD.

the class AbstractBlockFullCopyApiImpl method getTasksForCreateFullCopy.

/**
 * returns the list of tasks required for create the full copy volumes.
 *
 * @param fcSourceObj
 *            A reference to a full copy source.
 * @param fullCopyVolumes
 *            A list of the prepared full copy volumes.
 * @param taskId
 *            The unique task identifier
 *
 * @return TaskList
 */
protected TaskList getTasksForCreateFullCopy(BlockObject fcSourceObj, List<Volume> fullCopyVolumes, String taskId) {
    if (fcSourceObj == null) {
        throw APIException.badRequests.fullCopyInternalError("create");
    }
    TaskList taskList = new TaskList();
    for (Volume volume : fullCopyVolumes) {
        Operation op = _dbClient.createTaskOpStatus(Volume.class, volume.getId(), taskId, ResourceOperationTypeEnum.CREATE_VOLUME_FULL_COPY);
        volume.getOpStatus().put(taskId, op);
        TaskResourceRep volumeTask = TaskMapper.toTask(volume, taskId, op);
        taskList.getTaskList().add(volumeTask);
    }
    // if Volume is part of Application (COPY type VolumeGroup)
    VolumeGroup volumeGroup = (fcSourceObj instanceof Volume) ? ((Volume) fcSourceObj).getApplication(_dbClient) : null;
    if (volumeGroup != null && !ControllerUtils.checkVolumeForVolumeGroupPartialRequest(_dbClient, (Volume) fcSourceObj)) {
        Operation op = _dbClient.createTaskOpStatus(VolumeGroup.class, volumeGroup.getId(), taskId, ResourceOperationTypeEnum.CREATE_VOLUME_GROUP_FULL_COPY);
        taskList.getTaskList().add(TaskMapper.toTask(volumeGroup, taskId, op));
        // get all volumes to create tasks for all CGs involved
        List<Volume> volumes = ControllerUtils.getVolumeGroupVolumes(_dbClient, volumeGroup);
        addConsistencyGroupTasks(volumes, taskList, taskId, ResourceOperationTypeEnum.CREATE_CONSISTENCY_GROUP_FULL_COPY);
    } else {
        addConsistencyGroupTasks(Arrays.asList(fcSourceObj), taskList, taskId, ResourceOperationTypeEnum.CREATE_CONSISTENCY_GROUP_FULL_COPY);
    }
    return taskList;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) TaskList(com.emc.storageos.model.TaskList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation)

Example 67 with TaskResourceRep

use of com.emc.storageos.model.TaskResourceRep in project coprhd-controller by CoprHD.

the class DefaultBlockFullCopyApiImpl method resynchronizeCopy.

/**
 * {@inheritDoc}
 */
@Override
public TaskList resynchronizeCopy(Volume sourceVolume, Volume fullCopyVolume) {
    // Create the task list.
    TaskList taskList = new TaskList();
    // Create a unique task id.
    String taskId = UUID.randomUUID().toString();
    // If the source is in a CG, then we will resynchronize the corresponding
    // full copies for all the volumes in the CG. Since we did not allow
    // full copies for volumes or snaps in CGs prior to Jedi, there should
    // be a full copy for all volumes in the CG.
    Map<URI, Volume> fullCopyMap = getFullCopySetMap(sourceVolume, fullCopyVolume);
    Set<URI> fullCopyURIs = fullCopyMap.keySet();
    // Get the id of the source volume.
    URI sourceVolumeURI = sourceVolume.getId();
    // Get the storage system for the source volume.
    StorageSystem sourceSystem = _dbClient.queryObject(StorageSystem.class, sourceVolume.getStorageController());
    URI sourceSystemURI = sourceSystem.getId();
    // Create the resynchronize task on the full copy volumes.
    for (URI fullCopyURI : fullCopyURIs) {
        Operation op = _dbClient.createTaskOpStatus(Volume.class, fullCopyURI, taskId, ResourceOperationTypeEnum.RESYNCHRONIZE_VOLUME_FULL_COPY);
        fullCopyMap.get(fullCopyURI).getOpStatus().put(taskId, op);
        TaskResourceRep fullCopyVolumeTask = TaskMapper.toTask(fullCopyMap.get(fullCopyURI), taskId, op);
        taskList.getTaskList().add(fullCopyVolumeTask);
    }
    addConsistencyGroupTasks(Arrays.asList(sourceVolume), taskList, taskId, ResourceOperationTypeEnum.RESYNCHRONIZE_CONSISTENCY_GROUP_FULL_COPY);
    // Invoke the controller.
    try {
        BlockController controller = getController(BlockController.class, sourceSystem.getSystemType());
        controller.resyncFullCopy(sourceSystemURI, new ArrayList<URI>(fullCopyURIs), Boolean.TRUE, taskId);
    } catch (InternalException ie) {
        s_logger.error(String.format("Failed to resynchronize full copy %s from source %s", fullCopyVolume.getId(), sourceVolumeURI), ie);
        handleFailedRequest(taskId, taskList, new ArrayList<Volume>(fullCopyMap.values()), ie, false);
    }
    return taskList;
}
Also used : BlockController(com.emc.storageos.volumecontroller.BlockController) TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Volume(com.emc.storageos.db.client.model.Volume) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 68 with TaskResourceRep

use of com.emc.storageos.model.TaskResourceRep in project coprhd-controller by CoprHD.

the class VPlexBlockFullCopyApiImpl method detach.

/**
 * {@inheritDoc}
 */
@Override
public TaskList detach(BlockObject fcSourceObj, Volume fullCopyVolume) {
    // If full copy volume is already detached or was never
    // activated, return detach action is completed successfully
    // as done in base class. Otherwise, send detach full copy
    // request to controller.
    TaskList taskList = new TaskList();
    String taskId = UUID.randomUUID().toString();
    if ((BlockFullCopyUtils.isFullCopyDetached(fullCopyVolume, _dbClient)) || (BlockFullCopyUtils.isFullCopyInactive(fullCopyVolume, _dbClient))) {
        super.detach(fcSourceObj, fullCopyVolume);
    } else {
        // You cannot create a full copy of a VPLEX snapshot, so
        // the source will be a volume.
        Volume sourceVolume = (Volume) fcSourceObj;
        // If the source is in a CG, then we will detach the corresponding
        // full copies for all the volumes in the CG. Since we did not allow
        // full copies for volumes or snaps in CGs prior to Jedi, there should
        // be a full copy for all volumes in the CG.
        Map<URI, Volume> fullCopyMap = getFullCopySetMap(sourceVolume, fullCopyVolume);
        Set<URI> fullCopyURIs = fullCopyMap.keySet();
        // Get the storage system for the source volume.
        StorageSystem sourceSystem = _dbClient.queryObject(StorageSystem.class, sourceVolume.getStorageController());
        URI sourceSystemURI = sourceSystem.getId();
        // Create the detach task on the full copy volumes.
        for (URI fullCopyURI : fullCopyURIs) {
            Operation op = _dbClient.createTaskOpStatus(Volume.class, fullCopyURI, taskId, ResourceOperationTypeEnum.DETACH_VOLUME_FULL_COPY);
            fullCopyMap.get(fullCopyURI).getOpStatus().put(taskId, op);
            TaskResourceRep fullCopyVolumeTask = TaskMapper.toTask(fullCopyMap.get(fullCopyURI), taskId, op);
            taskList.getTaskList().add(fullCopyVolumeTask);
        }
        addConsistencyGroupTasks(Arrays.asList(sourceVolume), taskList, taskId, ResourceOperationTypeEnum.DETACH_CONSISTENCY_GROUP_FULL_COPY);
        // Invoke the controller.
        try {
            VPlexController controller = getController(VPlexController.class, DiscoveredDataObject.Type.vplex.toString());
            controller.detachFullCopy(sourceSystemURI, new ArrayList<>(fullCopyURIs), taskId);
        } catch (InternalException ie) {
            s_logger.error("Controller error: Failed to detach volume full copy {}", fullCopyVolume.getId(), ie);
            handleFailedRequest(taskId, taskList, new ArrayList<>(fullCopyMap.values()), ie, false);
        }
    }
    return taskList;
}
Also used : VPlexController(com.emc.storageos.vplexcontroller.VPlexController) TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Volume(com.emc.storageos.db.client.model.Volume) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 69 with TaskResourceRep

use of com.emc.storageos.model.TaskResourceRep 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;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) 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) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Project(com.emc.storageos.db.client.model.Project) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 70 with TaskResourceRep

use of com.emc.storageos.model.TaskResourceRep 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;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) 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) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Project(com.emc.storageos.db.client.model.Project) SnapshotSessionUnlinkTargetParam(com.emc.storageos.model.block.SnapshotSessionUnlinkTargetParam) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Aggregations

TaskResourceRep (com.emc.storageos.model.TaskResourceRep)160 URI (java.net.URI)85 TaskList (com.emc.storageos.model.TaskList)82 Operation (com.emc.storageos.db.client.model.Operation)68 Produces (javax.ws.rs.Produces)59 ArrayList (java.util.ArrayList)56 Volume (com.emc.storageos.db.client.model.Volume)55 Path (javax.ws.rs.Path)54 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)53 POST (javax.ws.rs.POST)50 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)49 Consumes (javax.ws.rs.Consumes)36 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)35 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)32 NamedURI (com.emc.storageos.db.client.model.NamedURI)30 NullColumnValueGetter.isNullURI (com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)23 Project (com.emc.storageos.db.client.model.Project)20 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)18 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)17 Copy (com.emc.storageos.model.block.Copy)17