Search in sources :

Example 11 with BlockConsistencyGroup

use of com.emc.storageos.db.client.model.BlockConsistencyGroup 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 12 with BlockConsistencyGroup

use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.

the class BlockConsistencyGroupService method getConsistencyGroupSnapshotSessions.

/**
 * List snapshot sessions in the consistency group
 *
 * @prereq none
 *
 * @param consistencyGroupId
 *            - Consistency group URI
 *
 * @brief List snapshot sessions in the consistency group
 * @return The list of snapshot sessions in the consistency group
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshot-sessions")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public BlockSnapshotSessionList getConsistencyGroupSnapshotSessions(@PathParam("id") final URI consistencyGroupId) {
    ArgValidator.checkUri(consistencyGroupId);
    BlockConsistencyGroup consistencyGroup = _permissionsHelper.getObjectById(consistencyGroupId, BlockConsistencyGroup.class);
    ArgValidator.checkEntityNotNull(consistencyGroup, consistencyGroupId, isIdEmbeddedInURL(consistencyGroupId));
    return getSnapshotSessionManager().getSnapshotSessionsForConsistencyGroup(consistencyGroup);
}
Also used : MapBlockConsistencyGroup(com.emc.storageos.api.mapper.functions.MapBlockConsistencyGroup) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) SOURCE_TO_TARGET(com.emc.storageos.model.block.Copy.SyncDirection.SOURCE_TO_TARGET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 13 with BlockConsistencyGroup

use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.

the class BlockConsistencyGroupService method getConsistencyGroup.

/**
 * Show details for a specific consistency group
 *
 * @prereq none
 *
 * @param id the URN of a ViPR Consistency group
 *
 * @brief Show consistency group
 * @return Consistency group
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public BlockConsistencyGroupRestRep getConsistencyGroup(@PathParam("id") final URI id) {
    ArgValidator.checkFieldUriType(id, BlockConsistencyGroup.class, "id");
    // Query for the consistency group
    final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(id);
    // Get the implementation for the CG.
    BlockServiceApi blockServiceApiImpl = getBlockServiceImpl(consistencyGroup);
    // Get the CG volumes
    List<Volume> volumes = BlockConsistencyGroupUtils.getActiveVolumesInCG(consistencyGroup, _dbClient, null);
    // If no volumes, just return the consistency group
    if (volumes.isEmpty()) {
        return map(consistencyGroup, null, _dbClient);
    }
    Set<URI> volumeURIs = new HashSet<URI>();
    for (Volume volume : volumes) {
        volumeURIs.add(volume.getId());
    }
    return map(consistencyGroup, volumeURIs, _dbClient);
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) 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) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) SOURCE_TO_TARGET(com.emc.storageos.model.block.Copy.SyncDirection.SOURCE_TO_TARGET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 14 with BlockConsistencyGroup

use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.

the class BlockConsistencyGroupService method activateConsistencyGroupSnapshot.

/**
 * Activate the specified Consistency Group Snapshot
 *
 * @prereq Create consistency group snapshot as inactive
 *
 * @param consistencyGroupId
 *            - Consistency group URI
 * @param snapshotId
 *            - Consistency group snapshot URI
 *
 * @brief Activate consistency group snapshot
 * @return TaskResourceRep
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots/{sid}/activate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskResourceRep activateConsistencyGroupSnapshot(@PathParam("id") final URI consistencyGroupId, @PathParam("sid") final URI snapshotId) {
    Operation op = new Operation();
    op.setResourceType(ResourceOperationTypeEnum.ACTIVATE_CONSISTENCY_GROUP_SNAPSHOT);
    final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(consistencyGroupId);
    final BlockSnapshot snapshot = (BlockSnapshot) queryResource(snapshotId);
    verifySnapshotIsForConsistencyGroup(snapshot, consistencyGroup);
    // 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 StorageSystem device = _dbClient.queryObject(StorageSystem.class, snapshot.getStorageController());
    final BlockController controller = getController(BlockController.class, device.getSystemType());
    final String task = UUID.randomUUID().toString();
    // activate it again.
    if (snapshot.getIsSyncActive()) {
        op.ready();
        op.setMessage("The consistency group 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);
    try {
        final List<URI> snapshotList = new ArrayList<URI>();
        // Query all the snapshots by snapshot label
        final List<BlockSnapshot> snaps = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshot, _dbClient);
        // Build a URI list with all the snapshots ids
        for (BlockSnapshot snap : snaps) {
            snapshotList.add(snap.getId());
        }
        // Activate snapshots
        controller.activateSnapshot(device.getId(), snapshotList, task);
    } catch (final ControllerException e) {
        throw new ServiceCodeException(CONTROLLER_ERROR, e, "An exception occurred when activating consistency group snapshot {0}. Caused by: {1}", new Object[] { snapshotId, e.getMessage() });
    }
    auditBlockConsistencyGroup(OperationTypeEnum.ACTIVATE_CONSISTENCY_GROUP_SNAPSHOT, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, snapshot.getId().toString(), snapshot.getLabel());
    return toTask(snapshot, task, op);
}
Also used : ControllerException(com.emc.storageos.volumecontroller.ControllerException) BlockController(com.emc.storageos.volumecontroller.BlockController) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) 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) MapBlockConsistencyGroup(com.emc.storageos.api.mapper.functions.MapBlockConsistencyGroup) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) BlockObject(com.emc.storageos.db.client.model.BlockObject) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) DataObject(com.emc.storageos.db.client.model.DataObject) 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 15 with BlockConsistencyGroup

use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.

the class BlockConsistencyGroupService method updateConsistencyGroup.

/**
 * Update the specified consistency group
 *
 * @prereq none
 *
 * @param id the URN of a ViPR Consistency group
 *
 * @brief Update consistency group
 * @return TaskResourceRep
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep updateConsistencyGroup(@PathParam("id") final URI id, final BlockConsistencyGroupUpdate param) {
    // Get the consistency group.
    BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(id);
    StorageDriverManager storageDriverManager = (StorageDriverManager) StorageDriverManager.getApplicationContext().getBean(StorageDriverManager.STORAGE_DRIVER_MANAGER);
    // Verify a volume was specified to be added or removed.
    if (!param.hasEitherAddOrRemoveVolumes()) {
        throw APIException.badRequests.noVolumesToBeAddedRemovedFromCG();
    }
    // TODO require a check if requested list contains all volumes/replicas?
    // For replicas, check replica count with volume count in CG
    StorageSystem cgStorageSystem = null;
    // Throw exception if the operation is attempted on volumes that are in RP CG.
    if (consistencyGroup.isRPProtectedCG()) {
        throw APIException.badRequests.operationNotAllowedOnRPVolumes();
    }
    // This method also supports adding volumes or replicas to CG (VMAX - SMIS 8.0.x)
    if ((!consistencyGroup.created() || NullColumnValueGetter.isNullURI(consistencyGroup.getStorageController())) && param.hasVolumesToAdd()) {
        // we just need to check the case of add volumes in this case
        BlockObject bo = BlockObject.fetch(_dbClient, param.getAddVolumesList().getVolumes().get(0));
        cgStorageSystem = _permissionsHelper.getObjectById(bo.getStorageController(), StorageSystem.class);
    } else {
        cgStorageSystem = _permissionsHelper.getObjectById(consistencyGroup.getStorageController(), StorageSystem.class);
    }
    // IBMXIV, XtremIO, VPlex, VNX, ScaleIO, and VMax volumes only
    String systemType = cgStorageSystem.getSystemType();
    if (!storageDriverManager.isDriverManaged(cgStorageSystem.getSystemType())) {
        if (!systemType.equals(DiscoveredDataObject.Type.vplex.name()) && !systemType.equals(DiscoveredDataObject.Type.vnxblock.name()) && !systemType.equals(DiscoveredDataObject.Type.vmax.name()) && !systemType.equals(DiscoveredDataObject.Type.vnxe.name()) && !systemType.equals(DiscoveredDataObject.Type.unity.name()) && !systemType.equals(DiscoveredDataObject.Type.ibmxiv.name()) && !systemType.equals(DiscoveredDataObject.Type.scaleio.name()) && !systemType.equals(DiscoveredDataObject.Type.xtremio.name())) {
            throw APIException.methodNotAllowed.notSupported();
        }
    }
    // Get the specific BlockServiceApiImpl based on the storage system type.
    BlockServiceApi blockServiceApiImpl = getBlockServiceImpl(cgStorageSystem);
    List<URI> volIds = null;
    Set<URI> addSet = new HashSet<URI>();
    boolean isReplica = true;
    if (param.hasVolumesToAdd()) {
        volIds = param.getAddVolumesList().getVolumes();
        addSet.addAll(volIds);
        URI volId = volIds.get(0);
        if (URIUtil.isType(volId, Volume.class)) {
            Volume volume = _permissionsHelper.getObjectById(volId, Volume.class);
            ArgValidator.checkEntity(volume, volId, false);
            if (!BlockFullCopyUtils.isVolumeFullCopy(volume, _dbClient)) {
                isReplica = false;
            }
        }
    }
    List<Volume> cgVolumes = blockServiceApiImpl.getActiveCGVolumes(consistencyGroup);
    // check if add volume list is same as existing volumes in CG
    boolean volsAlreadyInCG = false;
    if (!isReplica && cgVolumes != null && !cgVolumes.isEmpty()) {
        Collection<URI> cgVolIds = transform(cgVolumes, fctnDataObjectToID());
        if (addSet.size() == cgVolIds.size()) {
            volsAlreadyInCG = addSet.containsAll(cgVolIds);
        }
    }
    // Verify that the add and remove lists do not contain the same volume.
    if (param.hasBothAddAndRemoveVolumes()) {
        /*
             * Make sure the add and remove lists are unique by getting the intersection and
             * verifying the size is 0.
             */
        Set<URI> removeSet = new HashSet<URI>(param.getRemoveVolumesList().getVolumes());
        addSet.retainAll(removeSet);
        if (!addSet.isEmpty()) {
            throw APIException.badRequests.sameVolumesInAddRemoveList();
        }
    }
    if (cgStorageSystem.getUsingSmis80() && cgStorageSystem.deviceIsType(Type.vmax)) {
        // CG can have replicas
        if (_log.isDebugEnabled()) {
            _log.debug("CG can have replicas for VMAX with SMI-S 8.x");
        }
    } else if (param.hasVolumesToRemove() || (!isReplica && !volsAlreadyInCG)) {
        // CG cannot have replicas when adding/removing volumes to/from CG
        // Check snapshots
        // Adding/removing volumes to/from a consistency group
        // is not supported when the consistency group has active
        // snapshots.
        URIQueryResultList cgSnapshotsResults = new URIQueryResultList();
        _dbClient.queryByConstraint(getBlockSnapshotByConsistencyGroup(id), cgSnapshotsResults);
        Iterator<URI> cgSnapshotsIter = cgSnapshotsResults.iterator();
        while (cgSnapshotsIter.hasNext()) {
            BlockSnapshot cgSnapshot = _dbClient.queryObject(BlockSnapshot.class, cgSnapshotsIter.next());
            if ((cgSnapshot != null) && (!cgSnapshot.getInactive())) {
                throw APIException.badRequests.notAllowedWhenCGHasSnapshots();
            }
        }
        // VNX group clones and mirrors are just list of replicas, no corresponding group on array side
        if (!cgStorageSystem.deviceIsType(Type.vnxblock)) {
            // is not supported when existing volumes in CG have mirrors.
            if (cgVolumes != null && !cgVolumes.isEmpty()) {
                Volume firstVolume = cgVolumes.get(0);
                StringSet mirrors = firstVolume.getMirrors();
                if (mirrors != null && !mirrors.isEmpty()) {
                    throw APIException.badRequests.notAllowedWhenCGHasMirrors();
                }
            }
            // Check clones
            // Adding/removing volumes to/from a consistency group
            // is not supported when the consistency group has
            // volumes with full copies to which they are still
            // attached or has volumes that are full copies that
            // are still attached to their source volumes.
            getFullCopyManager().verifyConsistencyGroupCanBeUpdated(consistencyGroup, cgVolumes);
        }
    }
    // Verify the volumes to be removed.
    List<URI> removeVolumesList = new ArrayList<URI>();
    if (param.hasVolumesToRemove()) {
        for (URI volumeURI : param.getRemoveVolumesList().getVolumes()) {
            // Validate the volume to be removed exists.
            if (URIUtil.isType(volumeURI, Volume.class)) {
                Volume volume = _permissionsHelper.getObjectById(volumeURI, Volume.class);
                ArgValidator.checkEntity(volume, volumeURI, false);
                /**
                 * Remove SRDF volume from CG is not supported.
                 */
                if (volume.checkForSRDF()) {
                    throw APIException.badRequests.notAllowedOnSRDFConsistencyGroups();
                }
                if (!BlockFullCopyUtils.isVolumeFullCopy(volume, _dbClient)) {
                    blockServiceApiImpl.verifyRemoveVolumeFromCG(volume, cgVolumes);
                }
            }
            removeVolumesList.add(volumeURI);
        }
    }
    URI xivPoolURI = null;
    if (systemType.equals(DiscoveredDataObject.Type.ibmxiv.name()) && !cgVolumes.isEmpty()) {
        Volume firstVolume = cgVolumes.get(0);
        xivPoolURI = firstVolume.getPool();
    }
    // Verify the volumes to be added.
    List<URI> addVolumesList = new ArrayList<URI>();
    List<Volume> volumes = new ArrayList<Volume>();
    if (param.hasVolumesToAdd()) {
        for (URI volumeURI : param.getAddVolumesList().getVolumes()) {
            // Validate the volume to be added exists.
            Volume volume = null;
            if (!isReplica) {
                volume = _permissionsHelper.getObjectById(volumeURI, Volume.class);
                ArgValidator.checkEntity(volume, volumeURI, false);
                blockServiceApiImpl.verifyAddVolumeToCG(volume, consistencyGroup, cgVolumes, cgStorageSystem);
                volumes.add(volume);
            } else {
                verifyAddReplicaToCG(volumeURI, consistencyGroup, cgStorageSystem);
            }
            // IBM XIV specific checking
            if (systemType.equals(DiscoveredDataObject.Type.ibmxiv.name())) {
                // all volumes should be on the same storage pool
                if (xivPoolURI == null) {
                    xivPoolURI = volume.getPool();
                } else {
                    if (!xivPoolURI.equals(volume.getPool())) {
                        throw APIException.badRequests.invalidParameterIBMXIVConsistencyGroupVolumeNotInPool(volumeURI, xivPoolURI);
                    }
                }
            }
            // Add the volume to list.
            addVolumesList.add(volumeURI);
        }
        if (!volumes.isEmpty()) {
            blockServiceApiImpl.verifyReplicaCount(volumes, cgVolumes, volsAlreadyInCG);
        }
    }
    // Create the task id;
    String taskId = UUID.randomUUID().toString();
    // Call the block service API to update the consistency group.
    return blockServiceApiImpl.updateConsistencyGroup(cgStorageSystem, cgVolumes, consistencyGroup, addVolumesList, removeVolumesList, taskId);
}
Also used : BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) MapBlockConsistencyGroup(com.emc.storageos.api.mapper.functions.MapBlockConsistencyGroup) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) StorageDriverManager(com.emc.storageos.services.util.StorageDriverManager) Volume(com.emc.storageos.db.client.model.Volume) Iterator(java.util.Iterator) StringSet(com.emc.storageos.db.client.model.StringSet) BlockObject(com.emc.storageos.db.client.model.BlockObject) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)253 Volume (com.emc.storageos.db.client.model.Volume)134 URI (java.net.URI)134 ArrayList (java.util.ArrayList)102 NamedURI (com.emc.storageos.db.client.model.NamedURI)88 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)71 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)71 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)49 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)46 StringSet (com.emc.storageos.db.client.model.StringSet)45 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)43 ControllerException (com.emc.storageos.volumecontroller.ControllerException)43 BlockObject (com.emc.storageos.db.client.model.BlockObject)37 Project (com.emc.storageos.db.client.model.Project)33 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)31 HashMap (java.util.HashMap)31 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)29 List (java.util.List)29 HashSet (java.util.HashSet)28 Produces (javax.ws.rs.Produces)28