Search in sources :

Example 66 with TaskList

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

the class BlockService method deactivateMirror.

/**
 * Deactivate 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 deactivate
 * @param type {@link DefaultValue} FULL
 *            Possible type of deletion
 *            <ul>
 *            <li>FULL</li>
 *            <li>VIPR_ONLY</li>
 *            </ul>
 *            if type is FULL, ViPR deletes the continuous copy from storage array and removes from ViPR data base.
 *            if type is VIPR_ONLY, ViPR removes the continuous copy only from ViPR data base and leaves the continuous copy on storage
 *            array as it is.
 *
 * @brief Delete continuous copies
 * @return TaskList
 *
 * @throws ControllerException
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/deactivate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList deactivateMirror(@PathParam("id") URI id, CopiesParam param, @DefaultValue("FULL") @QueryParam("type") String deleteType) throws ControllerException {
    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));
    // Validate the list of copies
    ArgValidator.checkFieldNotEmpty(param.getCopies(), "copies");
    boolean vplexVolume = checkIfVolumeIsForVplex(id);
    // Process the list of copies
    for (Copy copy : param.getCopies()) {
        // Validate the copy ID
        URI copyID = copy.getCopyID();
        ArgValidator.checkUri(copyID);
        // Validate a copy type was passed
        ArgValidator.checkFieldNotEmpty(copy.getType(), "type");
        if (TechnologyType.NATIVE.toString().equalsIgnoreCase(copy.getType())) {
            String task = UUID.randomUUID().toString();
            StorageSystem device;
            String mirrorLabel;
            URI mirrorURI;
            BlockServiceApi blockServiceApi;
            if (vplexVolume) {
                VplexMirror mirror = queryVplexMirror(copyID);
                ArgValidator.checkEntity(mirror, mirror.getId(), isIdEmbeddedInURL(copyID));
                if (!mirror.getSource().getURI().equals(id)) {
                    throw APIException.badRequests.mirrorDoesNotBelongToVolume(copyID, id);
                }
                mirrorLabel = mirror.getLabel();
                mirrorURI = mirror.getId();
                device = _dbClient.queryObject(StorageSystem.class, mirror.getStorageController());
                blockServiceApi = getBlockServiceImpl(DiscoveredDataObject.Type.vplex.name());
            } else {
                BlockMirror mirror = queryMirror(copyID);
                ArgValidator.checkEntity(mirror, mirror.getId(), isIdEmbeddedInURL(copyID));
                if (!mirror.getSource().getURI().equals(id)) {
                    throw APIException.badRequests.mirrorDoesNotBelongToVolume(copyID, id);
                }
                mirrorLabel = mirror.getLabel();
                mirrorURI = mirror.getId();
                device = _dbClient.queryObject(StorageSystem.class, mirror.getStorageController());
                blockServiceApi = getBlockServiceImpl("mirror");
            }
            // Deactivate the mirror
            TaskList deactivateTaskList = blockServiceApi.deactivateMirror(device, mirrorURI, task, deleteType);
            // Create the audit log message
            String opStage = VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(deleteType) ? null : AuditLogManager.AUDITOP_BEGIN;
            boolean opStatus = true;
            for (TaskResourceRep resultTask : deactivateTaskList.getTaskList()) {
                if (Operation.Status.error.name().equals(resultTask.getState())) {
                    opStatus = false;
                    break;
                }
            }
            auditOp(OperationTypeEnum.DEACTIVATE_VOLUME_MIRROR, opStatus, opStage, copyID.toString(), mirrorLabel);
            // Add tasks for this copy
            taskList.getTaskList().addAll(deactivateTaskList.getTaskList());
        } else {
            throw APIException.badRequests.invalidCopyType(copy.getType());
        }
    }
    return taskList;
}
Also used : BlockMirror(com.emc.storageos.db.client.model.BlockMirror) 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) VplexMirror(com.emc.storageos.db.client.model.VplexMirror) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 67 with TaskList

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

the class BlockConsistencyGroupService method deactivateConsistencyGroupSnapshot.

/**
 * Deactivate the specified Consistency Group Snapshot
 *
 * @prereq none
 *
 * @param consistencyGroupId
 *            - Consistency group URI
 * @param snapshotId
 *            - Consistency group snapshot URI
 *
 * @brief Deactivate consistency group snapshot session
 * @return TaskResourceRep
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots/{sid}/deactivate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskList deactivateConsistencyGroupSnapshot(@PathParam("id") final URI consistencyGroupId, @PathParam("sid") final URI snapshotId) {
    final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(consistencyGroupId);
    // Snapshots of RecoverPoint consistency groups is not supported.
    if (isIdEmbeddedInURL(consistencyGroupId) && consistencyGroup.checkForType(Types.RP)) {
        throw APIException.badRequests.snapshotsNotSupportedForRPCGs();
    }
    // check for backend CG
    if (BlockConsistencyGroupUtils.getLocalSystemsInCG(consistencyGroup, _dbClient).isEmpty()) {
        _log.error("{} Group Snapshot operations not supported when there is no backend CG", consistencyGroup.getId());
        throw APIException.badRequests.cannotCreateSnapshotOfCG();
    }
    final BlockSnapshot snapshot = (BlockSnapshot) queryResource(snapshotId);
    verifySnapshotIsForConsistencyGroup(snapshot, consistencyGroup);
    // We can ignore dependencies on BlockSnapshotSession. In this case
    // the BlockSnapshot instance is a linked target for a BlockSnapshotSession
    // and we will unlink the snapshot from the session and delete it.
    List<Class<? extends DataObject>> excludeTypes = new ArrayList<Class<? extends DataObject>>();
    excludeTypes.add(BlockSnapshotSession.class);
    ArgValidator.checkReference(BlockSnapshot.class, snapshotId, checkForDelete(snapshot, excludeTypes));
    // Snapshot session linked targets must be unlinked instead.
    BlockSnapshotSession session = BlockSnapshotSessionUtils.getLinkedTargetSnapshotSession(snapshot, _dbClient);
    if (session != null) {
        return deactivateAndUnlinkTargetVolumesForSession(session, snapshot);
    }
    // Generate task id
    final String task = UUID.randomUUID().toString();
    TaskList response = new TaskList();
    // Not an error if the snapshot we try to delete is already deleted
    if (snapshot.getInactive()) {
        Operation op = new Operation();
        op.ready("The consistency group snapshot has already been deactivated");
        op.setResourceType(ResourceOperationTypeEnum.DELETE_CONSISTENCY_GROUP_SNAPSHOT);
        _dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), task, op);
        response.getTaskList().add(toTask(snapshot, task, op));
        return response;
    }
    List<BlockSnapshot> snapshots = new ArrayList<BlockSnapshot>();
    snapshots = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshot, _dbClient);
    // Get the snapshot parent volume.
    Volume parentVolume = _permissionsHelper.getObjectById(snapshot.getParent(), Volume.class);
    // Check that there are no pending tasks for these snapshots.
    checkForPendingTasks(Arrays.asList(parentVolume.getTenant().getURI()), snapshots);
    for (BlockSnapshot snap : snapshots) {
        Operation snapOp = _dbClient.createTaskOpStatus(BlockSnapshot.class, snap.getId(), task, ResourceOperationTypeEnum.DEACTIVATE_VOLUME_SNAPSHOT);
        response.getTaskList().add(toTask(snap, task, snapOp));
    }
    addConsistencyGroupTask(consistencyGroup, response, task, ResourceOperationTypeEnum.DEACTIVATE_CONSISTENCY_GROUP_SNAPSHOT);
    try {
        BlockServiceApi blockServiceApiImpl = BlockService.getBlockServiceImpl(parentVolume, _dbClient);
        blockServiceApiImpl.deleteSnapshot(snapshot, snapshots, task, VolumeDeleteTypeEnum.FULL.name());
    } catch (APIException | InternalException e) {
        String errorMsg = String.format("Exception attempting to delete snapshot %s: %s", snapshot.getId(), e.getMessage());
        _log.error(errorMsg);
        for (TaskResourceRep taskResourceRep : response.getTaskList()) {
            taskResourceRep.setState(Operation.Status.error.name());
            taskResourceRep.setMessage(errorMsg);
            @SuppressWarnings({ "unchecked" }) Class<? extends DataObject> clazz = URIUtil.getModelClass(taskResourceRep.getResource().getId());
            _dbClient.error(clazz, taskResourceRep.getResource().getId(), task, e);
        }
        throw e;
    } catch (Exception e) {
        String errorMsg = String.format("Exception attempting to delete snapshot %s: %s", snapshot.getId(), e.getMessage());
        _log.error(errorMsg);
        APIException apie = APIException.internalServerErrors.genericApisvcError(errorMsg, e);
        for (TaskResourceRep taskResourceRep : response.getTaskList()) {
            taskResourceRep.setState(Operation.Status.error.name());
            taskResourceRep.setMessage(apie.getMessage());
            @SuppressWarnings("unchecked") Class<? extends DataObject> clazz = URIUtil.getModelClass(taskResourceRep.getResource().getId());
            _dbClient.error(clazz, taskResourceRep.getResource().getId(), task, apie);
        }
        throw apie;
    }
    auditBlockConsistencyGroup(OperationTypeEnum.DELETE_CONSISTENCY_GROUP_SNAPSHOT, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, snapshot.getId().toString(), snapshot.getLabel());
    return response;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) TaskList(com.emc.storageos.model.TaskList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException) MapBlockConsistencyGroup(com.emc.storageos.api.mapper.functions.MapBlockConsistencyGroup) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) DataObject(com.emc.storageos.db.client.model.DataObject) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) Volume(com.emc.storageos.db.client.model.Volume) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 68 with TaskList

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

the class BlockConsistencyGroupService method failoverProtection.

/**
 * Request to failover the protection link associated with the copy. The target
 * copy is specified by identifying the virtual array in 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 URI of a BlockConsistencyGroup
 * @param param Copy to failover to
 *
 * @brief Failover the 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 consistency group URI
    ArgValidator.checkFieldUriType(id, BlockConsistencyGroup.class, "id");
    // Validate the list of copies
    ArgValidator.checkFieldNotEmpty(param.getCopies(), "copies");
    // Query Consistency Group
    final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(id);
    // system types.
    if (!consistencyGroup.created()) {
        throw APIException.badRequests.consistencyGroupNotCreated();
    }
    List<Copy> copies = param.getCopies();
    if (copies.size() > 1) {
        throw APIException.badRequests.failoverCopiesParamCanOnlyBeOne();
    }
    Copy copy = copies.get(0);
    ArgValidator.checkFieldUriType(copy.getCopyID(), VirtualArray.class, "copyId");
    ArgValidator.checkFieldNotEmpty(copy.getType(), "type");
    if (TechnologyType.RP.name().equalsIgnoreCase(copy.getType())) {
        taskResp = performProtectionAction(id, copy, ProtectionOp.FAILOVER.getRestOp());
        taskList.getTaskList().add(taskResp);
    } else if (TechnologyType.SRDF.name().equalsIgnoreCase(copy.getType())) {
        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) MapBlockConsistencyGroup(com.emc.storageos.api.mapper.functions.MapBlockConsistencyGroup) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) 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 69 with TaskList

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

the class BlockConsistencyGroupService method failoverCancel.

/**
 * Request to cancel fail over on already failed over consistency group.
 *
 * @prereq none
 *
 * @param id the URI of the BlockConsistencyGroup.
 * @param param Copy to fail back
 *
 * @brief Cancel a failover and return to source
 * @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-cancel")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList failoverCancel(@PathParam("id") URI id, CopiesParam param) throws ControllerException {
    TaskResourceRep taskResp = null;
    TaskList taskList = new TaskList();
    // Validate the source volume URI
    ArgValidator.checkFieldUriType(id, BlockConsistencyGroup.class, "id");
    // Validate the list of copies
    ArgValidator.checkFieldNotEmpty(param.getCopies(), "copies");
    // Query Consistency Group
    final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(id);
    // system types.
    if (!consistencyGroup.created()) {
        throw APIException.badRequests.consistencyGroupNotCreated();
    }
    List<Copy> copies = param.getCopies();
    if (copies.size() > 1) {
        throw APIException.badRequests.failOverCancelCopiesParamCanOnlyBeOne();
    }
    Copy copy = copies.get(0);
    ArgValidator.checkFieldUriType(copy.getCopyID(), VirtualArray.class, "copyId");
    ArgValidator.checkFieldNotEmpty(copy.getType(), "type");
    if (TechnologyType.RP.name().equalsIgnoreCase(copy.getType())) {
        taskResp = performProtectionAction(id, copy, ProtectionOp.FAILOVER_CANCEL.getRestOp());
        taskList.getTaskList().add(taskResp);
    } else if (TechnologyType.SRDF.name().equalsIgnoreCase(copy.getType())) {
        taskResp = performSRDFProtectionAction(id, copy, ProtectionOp.FAILOVER_CANCEL.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) MapBlockConsistencyGroup(com.emc.storageos.api.mapper.functions.MapBlockConsistencyGroup) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) 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 70 with TaskList

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

the class BlockConsistencyGroupService method swap.

/**
 * Request to reverse the replication direction, i.e. R1 and R2 are interchanged.
 *
 * @prereq none
 *
 * @param id the URI of a BlockConsistencyGroup
 * @param param Copy to swap
 *
 * @brief Reverse roles of source and target
 * @return TaskList
 *
 * @throws ControllerException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/swap")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList swap(@PathParam("id") URI id, CopiesParam param) throws ControllerException {
    TaskResourceRep taskResp = null;
    TaskList taskList = new TaskList();
    // Validate the source volume URI
    ArgValidator.checkFieldUriType(id, BlockConsistencyGroup.class, "id");
    // Validate the list of copies
    ArgValidator.checkFieldNotEmpty(param.getCopies(), "copies");
    // Query Consistency Group
    final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(id);
    // system types.
    if (!consistencyGroup.created()) {
        throw APIException.badRequests.consistencyGroupNotCreated();
    }
    List<Copy> copies = param.getCopies();
    if (copies.size() > 1) {
        throw APIException.badRequests.swapCopiesParamCanOnlyBeOne();
    }
    Copy copy = copies.get(0);
    ArgValidator.checkFieldUriType(copy.getCopyID(), VirtualArray.class, "copyId");
    ArgValidator.checkFieldNotEmpty(copy.getType(), "type");
    if (TechnologyType.RP.name().equalsIgnoreCase(copy.getType())) {
        taskResp = performProtectionAction(id, copy, ProtectionOp.SWAP.getRestOp());
        taskList.getTaskList().add(taskResp);
    } else if (TechnologyType.SRDF.name().equalsIgnoreCase(copy.getType())) {
        taskResp = performSRDFProtectionAction(id, copy, ProtectionOp.SWAP.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) MapBlockConsistencyGroup(com.emc.storageos.api.mapper.functions.MapBlockConsistencyGroup) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) 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)161 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)67 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