Search in sources :

Example 31 with TaskList

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

the class BlockService method stopContinuousCopies.

/**
 * Stop continuous copies.
 *
 * @prereq none
 *
 * @param id
 *            the URN of a ViPR Source volume
 * @param param
 *            List of copies to stop
 *
 * @brief Stop continuous copies.
 * @return TaskList
 *
 * @throws ControllerException
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/stop")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList stopContinuousCopies(@PathParam("id") URI id, CopiesParam param) throws ControllerException {
    TaskResourceRep taskResp = null;
    TaskList taskList = new TaskList();
    // Validate the source volume URI
    ArgValidator.checkFieldUriType(id, Volume.class, "id");
    Volume volume = _dbClient.queryObject(Volume.class, id);
    // Make sure that we don't have some pending
    // operation against the volume
    checkForPendingTasks(Arrays.asList(volume.getTenant().getURI()), Arrays.asList(volume));
    boolean vplexVolume = checkIfVolumeIsForVplex(id);
    // Validate the list of copies
    ArgValidator.checkFieldNotEmpty(param.getCopies(), "copies");
    // Verify that the copy IDs are either all specified or none are specified
    // for a particular protection type. Combinations are not allowed
    verifyCopyIDs(param);
    // Validate for SRDF Stop operation
    validateSRDFStopOperation(id, param);
    // Process the list of copies
    for (Copy copy : param.getCopies()) {
        // If copyID is not set all copies are stopped
        URI copyID = copy.getCopyID();
        if (!URIUtil.isValid(copyID)) {
            copyID = null;
        }
        // Validate a copy type was passed
        ArgValidator.checkFieldNotEmpty(copy.getType(), "type");
        // If copyID is null all copies are stopped
        if (copy.getType().equalsIgnoreCase(TechnologyType.RP.toString())) {
            taskResp = performProtectionAction(id, copy, ProtectionOp.STOP.getRestOp());
            taskList.getTaskList().add(taskResp);
        } else if (!vplexVolume && copy.getType().equalsIgnoreCase(TechnologyType.NATIVE.toString())) {
            taskList = stopMirrors(id, copyID);
        } else if (vplexVolume && copy.getType().equalsIgnoreCase(TechnologyType.NATIVE.toString())) {
            taskList = stopVplexMirrors(id, copyID);
        } else if (copy.getType().equalsIgnoreCase(TechnologyType.SRDF.toString())) {
            id = VPlexSrdfUtil.getSrdfIdFromVolumeId(_dbClient, id);
            copy.setCopyID(VPlexSrdfUtil.getSrdfIdFromVolumeId(_dbClient, copy.getCopyID()));
            taskResp = performSRDFProtectionAction(id, copy, ProtectionOp.STOP.getRestOp());
            taskList.getTaskList().add(taskResp);
        } else {
            throw APIException.badRequests.invalidCopyType(copy.getType());
        }
        // If copyID is null, we have already stopped all copies
        if (copyID == null) {
            return taskList;
        }
    }
    return taskList;
}
Also used : MapVolume(com.emc.storageos.api.mapper.functions.MapVolume) Volume(com.emc.storageos.db.client.model.Volume) Copy(com.emc.storageos.model.block.Copy) TaskList(com.emc.storageos.model.TaskList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 32 with TaskList

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

the class BlockService method createVolumeTaskList.

/**
 * A method that pre-creates task and volume objects to return to the caller of the API.
 *
 * @param size
 *            size of the volume
 * @param project
 *            project of the volume
 * @param varray
 *            virtual array of the volume
 * @param vpool
 *            virtual pool of the volume
 * @param label
 *            label
 * @param task
 *            task string
 * @param volumeCount
 *            number of volumes requested
 * @return a list of tasks associated with this request
 */
private TaskList createVolumeTaskList(String size, Project project, VirtualArray varray, VirtualPool vpool, String label, String task, Integer volumeCount) {
    TaskList taskList = new TaskList();
    try {
        // For each volume requested, pre-create a volume object/task object
        long lsize = SizeUtil.translateSize(size);
        for (int i = 0; i < volumeCount; i++) {
            Volume volume = StorageScheduler.prepareEmptyVolume(_dbClient, lsize, project, varray, vpool, label, i, volumeCount);
            Operation op = _dbClient.createTaskOpStatus(Volume.class, volume.getId(), task, ResourceOperationTypeEnum.CREATE_BLOCK_VOLUME);
            volume.getOpStatus().put(task, op);
            TaskResourceRep volumeTask = toTask(volume, task, op);
            taskList.getTaskList().add(volumeTask);
            _log.info(String.format("Volume and Task Pre-creation Objects [Init]--  Source Volume: %s, Task: %s, Op: %s", volume.getId(), volumeTask.getId(), task));
        }
    } catch (APIException ex) {
        // Mark the dummy objects inactive
        String errMsg = "Caught Exception while creating Volume and Task objects. Marking pre-created Objects inactive";
        _log.error(errMsg, ex);
        for (TaskResourceRep taskObj : taskList.getTaskList()) {
            taskObj.setMessage(String.format("%s. %s", errMsg, ex.getMessage()));
            taskObj.setState(Operation.Status.error.name());
            URI volumeURI = taskObj.getResource().getId();
            _dbClient.error(Volume.class, volumeURI, task, ex);
            // Set the volumes to inactive
            Volume volume = _dbClient.queryObject(Volume.class, volumeURI);
            volume.setInactive(true);
            _dbClient.updateObject(volume);
        }
        // throw the Exception to the caller
        throw ex;
    }
    return taskList;
}
Also used : APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) MapVolume(com.emc.storageos.api.mapper.functions.MapVolume) Volume(com.emc.storageos.db.client.model.Volume) TaskList(com.emc.storageos.model.TaskList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint)

Example 33 with TaskList

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

the class BlockService method failoverProtection.

/**
 * Request to failover the protection link associated with the param.copyID.
 *
 * NOTE: This is an asynchronous operation.
 *
 * If volume is srdf protected, then invoking failover internally triggers
 * SRDF SWAP on volume pairs.
 *
 * @prereq none
 *
 * @param id
 *            the URN of a ViPR Source volume
 * @param param
 *            Copy to failover to
 *
 * @brief Failover the volume protection link
 * @return TaskList
 *
 * @throws ControllerException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/failover")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList failoverProtection(@PathParam("id") URI id, CopiesParam param) throws ControllerException {
    TaskResourceRep taskResp = null;
    TaskList taskList = new TaskList();
    // Validate the source volume URI
    ArgValidator.checkFieldUriType(id, Volume.class, "id");
    boolean vplexVolume = checkIfVolumeIsForVplex(id);
    // Validate the list of copies
    ArgValidator.checkFieldNotEmpty(param.getCopies(), "copies");
    List<Copy> copies = param.getCopies();
    if (copies.size() != 1) {
        throw APIException.badRequests.failoverCopiesParamCanOnlyBeOne();
    }
    Copy copy = copies.get(0);
    if (vplexVolume && copy.getType().equalsIgnoreCase(TechnologyType.NATIVE.toString())) {
        throw APIException.badRequests.actionNotApplicableForVplexVolumeMirrors(ProtectionOp.FAILOVER.getRestOp());
    }
    ArgValidator.checkFieldNotEmpty(copy.getType(), "type");
    if (copy.getType().equalsIgnoreCase(TechnologyType.RP.toString())) {
        taskResp = performProtectionAction(id, copy, ProtectionOp.FAILOVER.getRestOp());
        taskList.getTaskList().add(taskResp);
    } else if (copy.getType().equalsIgnoreCase(TechnologyType.SRDF.toString())) {
        id = VPlexSrdfUtil.getSrdfIdFromVolumeId(_dbClient, id);
        copy.setCopyID(VPlexSrdfUtil.getSrdfIdFromVolumeId(_dbClient, copy.getCopyID()));
        taskResp = performSRDFProtectionAction(id, copy, ProtectionOp.FAILOVER.getRestOp());
        taskList.getTaskList().add(taskResp);
    } else {
        throw APIException.badRequests.invalidCopyType(copy.getType());
    }
    return taskList;
}
Also used : Copy(com.emc.storageos.model.block.Copy) TaskList(com.emc.storageos.model.TaskList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 34 with TaskList

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

the class BlockService method resumeContinuousCopies.

/**
 * Resume continuous copies for given source volume
 *
 * NOTE: This is an asynchronous operation.
 *
 * @prereq none
 *
 * @param id
 *            the URN of a ViPR Source volume
 * @param param
 *            List of copies to resume
 *
 * @brief Resume continuous copies
 * @return TaskList
 *
 * @throws ControllerException
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/resume")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList resumeContinuousCopies(@PathParam("id") URI id, CopiesParam param) throws ControllerException {
    TaskResourceRep taskResp = null;
    TaskList taskList = new TaskList();
    // Validate the source volume URI
    ArgValidator.checkFieldUriType(id, Volume.class, "id");
    boolean vplexVolume = checkIfVolumeIsForVplex(id);
    // Validate the list of copies
    ArgValidator.checkFieldNotEmpty(param.getCopies(), "copies");
    // Verify that the copy IDs are either all specified or none are specified
    // for a particular protection type. Combinations are not allowed
    verifyCopyIDs(param);
    // Process the list of copies
    for (Copy copy : param.getCopies()) {
        // If copyID is not set all copies are resumed
        URI copyID = copy.getCopyID();
        if (!URIUtil.isValid(copyID)) {
            copyID = null;
        }
        // Validate a copy type was passed
        ArgValidator.checkFieldNotEmpty(copy.getType(), "type");
        // If copyID is null all copies are paused
        if (copy.getType().equalsIgnoreCase(TechnologyType.RP.toString())) {
            taskResp = performProtectionAction(id, copy, ProtectionOp.RESUME.getRestOp());
            taskList.getTaskList().add(taskResp);
        } else if (!vplexVolume && copy.getType().equalsIgnoreCase(TechnologyType.NATIVE.toString())) {
            TaskList resumeTaskList = resumeMirrors(id, copyID);
            taskList.getTaskList().addAll(resumeTaskList.getTaskList());
        } else if (copy.getType().equalsIgnoreCase(TechnologyType.SRDF.toString())) {
            id = VPlexSrdfUtil.getSrdfIdFromVolumeId(_dbClient, id);
            copy.setCopyID(VPlexSrdfUtil.getSrdfIdFromVolumeId(_dbClient, copy.getCopyID()));
            taskResp = performSRDFProtectionAction(id, copy, ProtectionOp.RESUME.getRestOp());
            taskList.getTaskList().add(taskResp);
        } else if (vplexVolume && copy.getType().equalsIgnoreCase(TechnologyType.NATIVE.toString())) {
            throw APIException.badRequests.actionNotApplicableForVplexVolumeMirrors(ProtectionOp.RESUME.getRestOp());
        } else {
            throw APIException.badRequests.invalidCopyType(copy.getType());
        }
        // If copyID is null, we have already resumed all copies
        if (copyID == null) {
            return taskList;
        }
    }
    return taskList;
}
Also used : Copy(com.emc.storageos.model.block.Copy) TaskList(com.emc.storageos.model.TaskList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 35 with TaskList

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

the class BlockService method failoverTest.

/**
 * Request to test failover of the protection link associated with the param.copyID.
 *
 * NOTE: This is an asynchronous operation.
 *
 * If volume is srdf protected, then invoking failover-test ends in no-op.
 * failoverTest is being replaced by failover
 *
 * @prereq none
 *
 * @param id
 *            the URN of a ViPR Source volume
 * @param param
 *            Copy to test failover on
 *
 * @brief Test volume protection link failover
 * @return TaskList
 *
 * @throws ControllerException
 *
 * @deprecated failoverTest is being replaced by failover.
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/failover-test")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
@Deprecated
public TaskList failoverTest(@PathParam("id") URI id, CopiesParam param) throws ControllerException {
    TaskResourceRep taskResp = null;
    TaskList taskList = new TaskList();
    // Validate the source volume URI
    ArgValidator.checkFieldUriType(id, Volume.class, "id");
    boolean vplexVolume = checkIfVolumeIsForVplex(id);
    // Validate the list of copies
    ArgValidator.checkFieldNotEmpty(param.getCopies(), "copies");
    List<Copy> copies = param.getCopies();
    if (copies.size() != 1) {
        throw APIException.badRequests.failoverCopiesParamCanOnlyBeOne();
    }
    Copy copy = copies.get(0);
    if (vplexVolume && copy.getType().equalsIgnoreCase(TechnologyType.NATIVE.toString())) {
        throw APIException.badRequests.actionNotApplicableForVplexVolumeMirrors(ProtectionOp.FAILOVER_TEST.getRestOp());
    }
    ArgValidator.checkFieldUriType(copy.getCopyID(), Volume.class, "id");
    ArgValidator.checkFieldNotEmpty(copy.getType(), "type");
    if (copy.getType().equalsIgnoreCase(TechnologyType.RP.toString())) {
        taskResp = performProtectionAction(id, copy, ProtectionOp.FAILOVER_TEST.getRestOp());
        taskList.getTaskList().add(taskResp);
    } else if (copy.getType().equalsIgnoreCase(TechnologyType.SRDF.toString())) {
        id = VPlexSrdfUtil.getSrdfIdFromVolumeId(_dbClient, id);
        copy.setCopyID(VPlexSrdfUtil.getSrdfIdFromVolumeId(_dbClient, copy.getCopyID()));
        taskResp = performSRDFProtectionAction(id, copy, ProtectionOp.FAILOVER_TEST.getRestOp());
        taskList.getTaskList().add(taskResp);
    } else {
        throw APIException.badRequests.invalidCopyType(copy.getType());
    }
    return taskList;
}
Also used : Copy(com.emc.storageos.model.block.Copy) TaskList(com.emc.storageos.model.TaskList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

TaskList (com.emc.storageos.model.TaskList)159 ArrayList (java.util.ArrayList)84 URI (java.net.URI)83 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)82 Volume (com.emc.storageos.db.client.model.Volume)66 Produces (javax.ws.rs.Produces)62 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)57 Operation (com.emc.storageos.db.client.model.Operation)55 POST (javax.ws.rs.POST)55 Path (javax.ws.rs.Path)54 Consumes (javax.ws.rs.Consumes)44 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)43 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)35 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)33 NamedURI (com.emc.storageos.db.client.model.NamedURI)28 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)27 NullColumnValueGetter.isNullURI (com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)27 Tasks (com.emc.vipr.client.Tasks)27 List (java.util.List)26 WaitForTasks (com.emc.sa.service.vipr.tasks.WaitForTasks)23