Search in sources :

Example 36 with ServiceCodeException

use of com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException in project coprhd-controller by CoprHD.

the class BlockService method performSRDFProtectionAction.

/**
 * perform SRDF Protection APIs
 *
 * @param id
 *            the URN of a ViPR volume associated
 * @param copy
 * @param op
 * @return
 * @throws InternalException
 */
private TaskResourceRep performSRDFProtectionAction(URI id, Copy copy, String op) throws InternalException {
    URI copyID = copy.getCopyID();
    ArgValidator.checkFieldUriType(copyID, Volume.class, "copyID");
    // Get the volume associated with the URI
    Volume volume = queryVolumeResource(id);
    Volume copyVolume = null;
    if (null == copyID) {
        copyVolume = volume;
    } else {
        copyVolume = queryVolumeResource(copyID);
    }
    ArgValidator.checkEntity(volume, id, true);
    ArgValidator.checkEntity(copyVolume, copyID, true);
    // passed in source volume
    if (!copyVolume.getSrdfParent().getURI().equals(id) && !copyVolume.getId().equals(id)) {
        throw APIException.badRequests.protectionVolumeInvalidTargetOfVolume(copyID, id);
    }
    // Make sure that we don't have some pending
    // operation against the volume
    checkForPendingTasks(Arrays.asList(volume.getTenant().getURI()), Arrays.asList(volume));
    if (Volume.isSRDFProtectedVolume(copyVolume)) {
        if (op.equalsIgnoreCase(ProtectionOp.FAILOVER_TEST_CANCEL.getRestOp()) || op.equalsIgnoreCase(ProtectionOp.FAILOVER_TEST.getRestOp())) {
            String task = UUID.randomUUID().toString();
            Operation status = new Operation();
            status.setResourceType(ProtectionOp.getResourceOperationTypeEnum(op));
            _dbClient.createTaskOpStatus(Volume.class, volume.getId(), task, status);
            _dbClient.ready(Volume.class, volume.getId(), task);
            return toTask(volume, task, status);
        }
        if (PersonalityTypes.SOURCE.name().equalsIgnoreCase(copyVolume.getPersonality())) {
            if (op.equalsIgnoreCase(ProtectionOp.FAILOVER_CANCEL.getRestOp()) || op.equalsIgnoreCase(ProtectionOp.FAILOVER.getRestOp()) || op.equalsIgnoreCase(ProtectionOp.SWAP.getRestOp())) {
                throw new ServiceCodeException(ServiceCode.IO_ERROR, "Expected SRDF Target R2 volume, instead R1 {0} is being passed, hence cannot proceed with failover or failback.", new Object[] { copyVolume.getNativeGuid() });
            } else if (copyVolume.getSrdfTargets() == null || copyVolume.getSrdfTargets().isEmpty()) {
                throw new ServiceCodeException(ServiceCode.IO_ERROR, "Target Volume Empty for a given source R1 {0}, hence cannot proceed with failover or failback.", new Object[] { copyVolume.getNativeGuid() });
            } else if (PersonalityTypes.TARGET.name().equalsIgnoreCase(copyVolume.getPersonality()) && RemoteDirectorGroup.SupportedCopyModes.ADAPTIVECOPY.name().equalsIgnoreCase(copyVolume.getSrdfCopyMode())) {
                if (ProtectionOp.CHANGE_COPY_MODE.getRestOp().equalsIgnoreCase(op)) {
                    validateVpoolCopyModeSetting(volume, copy.getCopyMode());
                }
            }
        }
        // COP-25377. We need to block failover and swap operations for SRDF ACTIVE COPY MODE
        if (Mode.ACTIVE.toString().equalsIgnoreCase(copyVolume.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(Volume.class, volume.getId(), 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 (isSuspendCopyRequest(op, copy)) {
            op = ProtectionOp.SUSPEND.getRestOp();
        }
        ProtectionOrchestrationController protectionController = getController(ProtectionOrchestrationController.class, ProtectionOrchestrationController.PROTECTION_ORCHESTRATION_DEVICE);
        StorageSystem system = _dbClient.queryObject(StorageSystem.class, copyVolume.getStorageController());
        protectionController.performSRDFProtectionOperation(system.getId(), copy, op, task);
        return toTask(volume, task, status);
    } else {
        throw new ServiceCodeException(ServiceCode.IO_ERROR, "Volume {0} is not SRDF protected", new Object[] { copyVolume.getNativeGuid() });
    }
}
Also used : ProtectionOrchestrationController(com.emc.storageos.protectionorchestrationcontroller.ProtectionOrchestrationController) MapVolume(com.emc.storageos.api.mapper.functions.MapVolume) Volume(com.emc.storageos.db.client.model.Volume) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException) BlockObject(com.emc.storageos.db.client.model.BlockObject) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) DataObject(com.emc.storageos.db.client.model.DataObject) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 37 with ServiceCodeException

use of com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException in project coprhd-controller by CoprHD.

the class BlockSnapshotService method activate.

/**
 * Call will activate this snapshot, essentially establishing the synchronization
 * between the source and target. The "heavy lifting" of getting the snapshot
 * to the point where it can be activated should have been done by the create.
 *
 * @prereq Create snapshot as inactive
 * @param id [required] - the URN of a ViPR block snapshot to restore from
 * @brief Activate snapshot
 * @return TaskResourceRep - Task resource object for tracking this operation
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
@Path("/{id}/activate")
public TaskResourceRep activate(@PathParam("id") URI id) {
    Operation op = new Operation();
    op.setResourceType(ResourceOperationTypeEnum.ACTIVATE_VOLUME_SNAPSHOT);
    ArgValidator.checkFieldUriType(id, BlockSnapshot.class, "id");
    BlockSnapshot snapshot = (BlockSnapshot) queryResource(id);
    // Get the block service API implementation for the snapshot parent volume.
    Volume parentVolume = _permissionsHelper.getObjectById(snapshot.getParent(), Volume.class);
    // Make sure that we don't have some pending
    // operation against the parent volume
    checkForPendingTasks(Arrays.asList(parentVolume.getTenant().getURI()), Arrays.asList(parentVolume));
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, snapshot.getStorageController());
    BlockController controller = getController(BlockController.class, device.getSystemType());
    String task = UUID.randomUUID().toString();
    // another request to activate it again.
    if (snapshot.getIsSyncActive()) {
        op.ready("Snapshot is already active");
        _dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), task, op);
        return toTask(snapshot, task, op);
    }
    _dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), task, op);
    List<URI> snapshotList = new ArrayList<URI>();
    if (!NullColumnValueGetter.isNullURI(snapshot.getConsistencyGroup())) {
        List<BlockSnapshot> snapshots = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshot, _dbClient);
        for (BlockSnapshot snap : snapshots) {
            snapshotList.add(snap.getId());
        }
    } else {
        snapshotList.add(id);
    }
    // If the volume is under protection
    if (snapshot.getEmName() != null) {
        // RP snapshots cannot be activated so throw exception
        throw new ServiceCodeException(API_BAD_REQUEST, "RecoverPoint snapshots cannot be activated.", null);
    } else {
        controller.activateSnapshot(device.getId(), snapshotList, task);
    }
    auditOp(OperationTypeEnum.ACTIVATE_VOLUME_SNAPSHOT, true, AuditLogManager.AUDITOP_BEGIN, snapshot.getId().toString(), snapshot.getLabel());
    return toTask(snapshot, task, op);
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) BlockController(com.emc.storageos.volumecontroller.BlockController) MapBlockSnapshot(com.emc.storageos.api.mapper.functions.MapBlockSnapshot) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ArrayList(java.util.ArrayList) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) 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

ServiceCodeException (com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException)37 BaseServiceCodeExceptionTest (com.emc.storageos.svcs.errorhandling.mappers.BaseServiceCodeExceptionTest)27 Test (org.junit.Test)27 URI (java.net.URI)10 Operation (com.emc.storageos.db.client.model.Operation)5 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)5 ArrayList (java.util.ArrayList)5 DataObject (com.emc.storageos.db.client.model.DataObject)4 Volume (com.emc.storageos.db.client.model.Volume)4 BlockObject (com.emc.storageos.db.client.model.BlockObject)3 DiscoveredDataObject (com.emc.storageos.db.client.model.DiscoveredDataObject)3 NamedURI (com.emc.storageos.db.client.model.NamedURI)3 MapVolume (com.emc.storageos.api.mapper.functions.MapVolume)2 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)2 StringMap (com.emc.storageos.db.client.model.StringMap)2 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)2 NullColumnValueGetter.isNullURI (com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)2 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 HashMap (java.util.HashMap)2 List (java.util.List)2