Search in sources :

Example 31 with Copy

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

the class BlockConsistencyGroupService method changeAccessMode.

/**
 * Request to change the access mode on the provided copy.
 *
 * NOTE: This is an asynchronous operation.
 *
 * Currently only supported for RecoverPoint protected volumes. If volume is SRDF protected,
 * then we do nothing and return the task.
 *
 * @prereq none
 *
 * @param id the URN of a ViPR Source volume
 * @param param Copy to change access mode on
 *
 * @brief Change the access mode for a copy.
 * @return TaskList
 *
 * @throws ControllerException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/accessmode")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList changeAccessMode(@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");
    List<Copy> copies = param.getCopies();
    if (copies.size() != 1) {
        // Change access mode operations can only be performed on a single copy
        throw APIException.badRequests.changeAccessCopiesParamCanOnlyBeOne();
    }
    Copy copy = copies.get(0);
    ArgValidator.checkFieldNotEmpty(copy.getType(), "type");
    ArgValidator.checkFieldNotEmpty(copy.getAccessMode(), "accessMode");
    if (copy.getType().equalsIgnoreCase(TechnologyType.RP.toString())) {
        taskResp = performProtectionAction(id, copy, ProtectionOp.CHANGE_ACCESS_MODE.getRestOp());
        taskList.getTaskList().add(taskResp);
    } else if (copy.getType().equalsIgnoreCase(TechnologyType.SRDF.toString())) {
        _log.warn("Changing access mode is currently not supported for SRDF.  Returning empty task list (no-op).");
        return taskList;
    } 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 32 with Copy

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

the class BlockConsistencyGroupService method performSRDFProtectionAction.

/**
 * Performs the SRDF Protection operation.
 *
 * @param consistencyGroupId the URI of the BlockConsistencyGroup to perform the protection action against.
 * @param copy the copy to operate on
 * @param op operation to perform (pause, stop, failover, etc)
 * @return task resource rep
 * @throws InternalException
 */
private TaskResourceRep performSRDFProtectionAction(URI consistencyGroupId, Copy copy, String op) throws InternalException {
    URI targetVarrayId = copy.getCopyID();
    ArgValidator.checkFieldUriType(targetVarrayId, VirtualArray.class, "copyID");
    ArgValidator.checkFieldUriType(consistencyGroupId, BlockConsistencyGroup.class, "id");
    // Get the BlockConsistencyGroup and target VirtualArray associated with the request.
    final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(consistencyGroupId);
    final VirtualArray targetVirtualArray = _permissionsHelper.getObjectById(targetVarrayId, VirtualArray.class);
    ArgValidator.checkEntity(consistencyGroup, consistencyGroupId, true);
    ArgValidator.checkEntity(targetVirtualArray, targetVarrayId, true);
    // The consistency group needs to be associated with SRDF in order to perform the operation.
    if (!consistencyGroup.checkForType(Types.SRDF)) {
        // Attempting to perform an SRDF operation on a non-SRDF consistency group
        throw APIException.badRequests.consistencyGroupMustBeSRDFProtected(consistencyGroupId);
    }
    // Get the block service implementation
    BlockServiceApi blockServiceApiImpl = getBlockServiceImpl(consistencyGroup);
    // Get a list of CG volumes.
    List<Volume> volumeList = BlockConsistencyGroupUtils.getActiveVolumesInCG(consistencyGroup, _dbClient, null);
    if (volumeList == null || volumeList.isEmpty()) {
        throw APIException.badRequests.consistencyGroupContainsNoVolumes(consistencyGroup.getId());
    }
    Volume srcVolume = null;
    // Find a source volume in the SRDF local CG
    for (Volume volume : volumeList) {
        if (volume.getPersonality() != null && volume.getPersonality().equals(PersonalityTypes.SOURCE.name())) {
            srcVolume = volume;
            break;
        }
    }
    if (srcVolume == null) {
        // CG contains no source volumes.
        throw APIException.badRequests.srdfCgContainsNoSourceVolumes(consistencyGroup.getId());
    }
    // Find the target volume that corresponds to the source whose Virtual Array matches
    // the specified target Virtual Array. From that, obtain the remote SRDF CG.
    BlockConsistencyGroup targetCg = null;
    if (srcVolume.getSrdfTargets() != null && !srcVolume.getSrdfTargets().isEmpty()) {
        for (String uri : srcVolume.getSrdfTargets()) {
            Volume target = _dbClient.queryObject(Volume.class, URI.create(uri));
            if (target.getVirtualArray().equals(targetVarrayId)) {
                targetCg = _dbClient.queryObject(BlockConsistencyGroup.class, target.getConsistencyGroup());
                break;
            }
        }
    }
    // Get all target CG target volumes for validation
    List<Volume> targetVolumes = getTargetVolumes(targetCg, targetVarrayId);
    for (Volume tgtVolume : targetVolumes) {
        if (!Volume.isSRDFProtectedVolume(tgtVolume)) {
            // protected.
            throw APIException.badRequests.volumeMustBeSRDFProtected(tgtVolume.getId());
        }
    }
    if (targetVolumes == null || targetVolumes.isEmpty()) {
        // The supplied target varray is not referenced by any target volumes in the CG.
        throw APIException.badRequests.targetVirtualArrayDoesNotMatch(targetCg.getId(), targetVarrayId);
    }
    // Get the first volume
    Volume targetVolume = targetVolumes.get(0);
    // COP-25377. We need to block failover and swap operations for SRDF ACTIVE COPY MODE
    if (Mode.ACTIVE.toString().equalsIgnoreCase(targetVolume.getSrdfCopyMode()) && (op.equalsIgnoreCase(ProtectionOp.FAILOVER_CANCEL.getRestOp()) || op.equalsIgnoreCase(ProtectionOp.FAILOVER.getRestOp()) || op.equalsIgnoreCase(ProtectionOp.SWAP.getRestOp()))) {
        throw BadRequestException.badRequests.operationNotPermittedOnSRDFActiveCopyMode(op);
    }
    String task = UUID.randomUUID().toString();
    Operation status = new Operation();
    status.setResourceType(ProtectionOp.getResourceOperationTypeEnum(op));
    _dbClient.createTaskOpStatus(BlockConsistencyGroup.class, targetCg.getId(), task, status);
    if (op.equalsIgnoreCase(ProtectionOp.FAILOVER_TEST_CANCEL.getRestOp()) || op.equalsIgnoreCase(ProtectionOp.FAILOVER_TEST.getRestOp())) {
        _dbClient.ready(BlockConsistencyGroup.class, targetCg.getId(), task);
        return toTask(targetCg, task, status);
    }
    /*
         * CTRL-6972: In the absence of a /restore API, we re-use /sync with a syncDirection parameter for
         * specifying either SMI-S Resume or Restore:
         * SOURCE_TO_TARGET -> ViPR Resume -> SMI-S Resume -> SRDF Incremental Establish (R1 overwrites R2)
         * TARGET_TO_SOURCE -> ViPR Sync -> SMI-S Restore -> SRDF Full Restore (R2 overwrites R1)
         */
    if (op.equalsIgnoreCase(ProtectionOp.SYNC.getRestOp()) && SOURCE_TO_TARGET.toString().equalsIgnoreCase(copy.getSyncDirection())) {
        op = ProtectionOp.RESUME.getRestOp();
    } else if (BlockService.isSuspendCopyRequest(op, copy)) {
        op = ProtectionOp.SUSPEND.getRestOp();
    }
    StorageSystem system = _dbClient.queryObject(StorageSystem.class, targetVolume.getStorageController());
    ProtectionOrchestrationController controller = getController(ProtectionOrchestrationController.class, ProtectionOrchestrationController.PROTECTION_ORCHESTRATION_DEVICE);
    // Create a new duplicate copy of the original copy. Update the copyId field to be the
    // ID of the target volume. Existing SRDF controller logic needs the target volume
    // to operate off of, not the virtual array.
    Copy updatedCopy = new Copy(copy.getType(), copy.getSync(), targetVolume.getId(), copy.getName(), copy.getCount());
    controller.performSRDFProtectionOperation(system.getId(), updatedCopy, op, task);
    return toTask(targetCg, task, status);
}
Also used : VirtualArray(com.emc.storageos.db.client.model.VirtualArray) ProtectionOrchestrationController(com.emc.storageos.protectionorchestrationcontroller.ProtectionOrchestrationController) Volume(com.emc.storageos.db.client.model.Volume) Copy(com.emc.storageos.model.block.Copy) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) MapBlockConsistencyGroup(com.emc.storageos.api.mapper.functions.MapBlockConsistencyGroup) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

Copy (com.emc.storageos.model.block.Copy)32 TaskList (com.emc.storageos.model.TaskList)17 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)17 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)17 POST (javax.ws.rs.POST)17 Path (javax.ws.rs.Path)17 Produces (javax.ws.rs.Produces)17 CopiesParam (com.emc.storageos.model.block.CopiesParam)12 URI (java.net.URI)10 Consumes (javax.ws.rs.Consumes)10 NullColumnValueGetter.isNullURI (com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)8 Volume (com.emc.storageos.db.client.model.Volume)6 MapVolume (com.emc.storageos.api.mapper.functions.MapVolume)5 MapBlockConsistencyGroup (com.emc.storageos.api.mapper.functions.MapBlockConsistencyGroup)4 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)4 BlockMirror (com.emc.storageos.db.client.model.BlockMirror)2 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)2 ArrayList (java.util.ArrayList)2 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)1 Constraint (com.emc.storageos.db.client.constraint.Constraint)1