Search in sources :

Example 1 with BlockConsistencyGroupSnapshotCreate

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

the class VolumeGroupService method createVolumeGroupSnapshot.

/**
 * Creates a volume group snapshot
 * Creates snapshot for all the array replication groups within this Application.
 * If partial flag is specified, it creates snapshot only for set of array replication groups.
 * A Volume from each array replication group can be provided to indicate which array replication
 * groups are required to take snapshot.
 *
 * @prereq none
 *
 * @param volumeGroupId the URI of the Volume Group
 *            - Volume group URI
 * @param param VolumeGroupSnapshotCreateParam
 *
 * @brief Create volume group snapshot
 * @return TaskList
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots")
@CheckPermission(roles = { Role.SYSTEM_ADMIN }, acls = { ACL.ANY })
public TaskList createVolumeGroupSnapshot(@PathParam("id") final URI volumeGroupId, VolumeGroupSnapshotCreateParam param) {
    // Query volume group
    final VolumeGroup volumeGroup = (VolumeGroup) queryResource(volumeGroupId);
    // validate replica operation for volume group
    validateCopyOperationForVolumeGroup(volumeGroup, ReplicaTypeEnum.SNAPSHOT);
    // validate name
    String name = param.getName();
    ArgValidator.checkFieldNotEmpty(name, NAME_FIELD);
    name = TimeUtils.formatDateForCurrent(name);
    // snapsetLabel is normalized in RP, do it here too to avoid potential mismatch
    name = ResourceOnlyNameGenerator.removeSpecialCharsForName(name, SmisConstants.MAX_SNAPSHOT_NAME_LENGTH);
    if (StringUtils.isEmpty(name)) {
        // original name has special chars only
        throw APIException.badRequests.invalidCopySetName(param.getName(), ReplicaTypeEnum.SNAPSHOT.toString());
    }
    // check name provided is not duplicate
    VolumeGroupCopySetList copySetList = getVolumeGroupSnapshotSets(volumeGroup);
    if (copySetList.getCopySets().contains(name)) {
        // duplicate name
        throw APIException.badRequests.duplicateCopySetName(param.getName(), ReplicaTypeEnum.SNAPSHOT.toString());
    }
    // volumes to be processed
    List<Volume> volumes = new ArrayList<Volume>();
    List<URI> partialVolumeList = new ArrayList<URI>();
    boolean partial = isPartialRequest(param, volumeGroup, partialVolumeList);
    if (partial) {
        log.info("Snapshot requested for subset of array groups in Application.");
        // validate that at least one volume URI is provided
        ArgValidator.checkFieldNotEmpty(partialVolumeList, VOLUMES_FIELD);
        // validate that provided volumes
        for (URI volumeURI : partialVolumeList) {
            ArgValidator.checkFieldUriType(volumeURI, Volume.class, VOLUME_FIELD);
            // Get the volume
            Volume volume = _dbClient.queryObject(Volume.class, volumeURI);
            ArgValidator.checkEntity(volume, volumeURI, isIdEmbeddedInURL(volumeURI));
            // validate that provided volume is part of Volume Group
            if (!volume.getVolumeGroupIds().contains(volumeGroupId.toString())) {
                throw APIException.badRequests.replicaOperationNotAllowedVolumeNotInVolumeGroup(ReplicaTypeEnum.SNAPSHOT.toString(), volume.getLabel());
            }
            volumes.add(volume);
        }
    } else {
        log.info("Snapshot creation for entire Application");
        // get all volumes
        volumes.addAll(ControllerUtils.getVolumeGroupVolumes(_dbClient, volumeGroup));
        // validate that there should be some volumes in VolumeGroup
        if (volumes.isEmpty()) {
            throw APIException.badRequests.replicaOperationNotAllowedOnEmptyVolumeGroup(volumeGroup.getLabel(), ReplicaTypeEnum.SNAPSHOT.toString());
        }
    }
    // Check for pending tasks
    checkForApplicationPendingTasks(volumeGroup, _dbClient, false);
    auditOp(OperationTypeEnum.CREATE_VOLUME_GROUP_SNAPSHOT, true, AuditLogManager.AUDITOP_BEGIN, volumeGroupId.toString(), name);
    TaskList taskList = new TaskList();
    /**
     * If there are VMAX3 volumes in the request, we need to create snap session for them.
     * For others, create snapshot.
     *
     * vmax3Volumes - block VMAX3 or backend VMAX3 for VPLEX based on copy side requested
     * volumes - except volumes filtered out for above case
     */
    // TODO consider copyOnHaSide from user's request once the underlying implementation supports it.
    List<Volume> vmax3Volumes = getVMAX3Volumes(volumes, false);
    if (!vmax3Volumes.isEmpty()) {
        // check snap session name provided is not duplicate
        VolumeGroupCopySetList sessionSet = getVolumeGroupSnapsetSessionSets(volumeGroup);
        if (sessionSet.getCopySets().contains(name)) {
            // duplicate name
            throw APIException.badRequests.duplicateCopySetName(name, ReplicaTypeEnum.SNAPSHOT_SESSION.toString());
        }
    }
    // create snapshot
    Map<URI, List<URI>> cgToVolUris = ControllerUtils.groupVolumeURIsByCG(volumes);
    Set<Entry<URI, List<URI>>> entrySet = cgToVolUris.entrySet();
    for (Entry<URI, List<URI>> entry : entrySet) {
        URI cgUri = entry.getKey();
        log.info("Create snapshot with consistency group {}", cgUri);
        try {
            BlockConsistencyGroupSnapshotCreate cgSnapshotParam = new BlockConsistencyGroupSnapshotCreate(name, entry.getValue(), param.getCreateInactive(), param.getReadOnly());
            TaskList cgTaskList = _blockConsistencyGroupService.createConsistencyGroupSnapshot(cgUri, cgSnapshotParam);
            List<TaskResourceRep> taskResourceRepList = cgTaskList.getTaskList();
            if (taskResourceRepList != null && !taskResourceRepList.isEmpty()) {
                for (TaskResourceRep taskResRep : taskResourceRepList) {
                    taskList.addTask(taskResRep);
                }
            }
        } catch (InternalException | APIException e) {
            log.error("Exception when creating snapshot for consistency group {}", cgUri, e);
            BlockConsistencyGroup cg = _dbClient.queryObject(BlockConsistencyGroup.class, cgUri);
            TaskResourceRep task = BlockServiceUtils.createFailedTaskOnCG(_dbClient, cg, ResourceOperationTypeEnum.CREATE_CONSISTENCY_GROUP_SNAPSHOT, e);
            taskList.addTask(task);
        } catch (Exception ex) {
            log.error("Unexpected Exception occurred when creating snapshot for consistency group {}", cgUri, ex);
        }
    }
    // create snapshot session for VMAX3
    Map<URI, List<URI>> cgToV3VolUris = ControllerUtils.groupVolumeURIsByCG(vmax3Volumes);
    Set<Entry<URI, List<URI>>> entrySetV3 = cgToV3VolUris.entrySet();
    for (Entry<URI, List<URI>> entry : entrySetV3) {
        URI cgUri = entry.getKey();
        log.info("Create snapshot session for consistency group {}, volumes {}", cgUri, Joiner.on(',').join(entry.getValue()));
        try {
            // create snap session with No targets
            SnapshotSessionCreateParam cgSnapshotSessionParam = new SnapshotSessionCreateParam(name, null, entry.getValue());
            taskList.getTaskList().addAll(_blockConsistencyGroupService.createConsistencyGroupSnapshotSession(cgUri, cgSnapshotSessionParam).getTaskList());
        } catch (InternalException | APIException e) {
            log.error("Exception while creating snapshot session for consistency group {}: {}", cgUri, e);
            BlockConsistencyGroup cg = _dbClient.queryObject(BlockConsistencyGroup.class, cgUri);
            TaskResourceRep task = BlockServiceUtils.createFailedTaskOnCG(_dbClient, cg, ResourceOperationTypeEnum.CREATE_CONSISTENCY_GROUP_SNAPSHOT_SESSION, e);
            taskList.addTask(task);
        } catch (Exception ex) {
            log.error("Unexpected Exception occurred while creating snapshot session for consistency group {}: {}", cgUri, ex);
        }
    }
    auditOp(OperationTypeEnum.CREATE_VOLUME_GROUP_SNAPSHOT, true, AuditLogManager.AUDITOP_END, volumeGroupId.toString(), name);
    return taskList;
}
Also used : BlockConsistencyGroupSnapshotCreate(com.emc.storageos.model.block.BlockConsistencyGroupSnapshotCreate) SnapshotSessionCreateParam(com.emc.storageos.model.block.SnapshotSessionCreateParam) VolumeGroupSnapshotSessionCreateParam(com.emc.storageos.model.application.VolumeGroupSnapshotSessionCreateParam) TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) VolumeGroupCopySetList(com.emc.storageos.model.application.VolumeGroupCopySetList) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) Entry(java.util.Map.Entry) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) BlockSnapshotSessionList(com.emc.storageos.model.block.BlockSnapshotSessionList) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) NamedVolumeGroupsList(com.emc.storageos.model.block.NamedVolumeGroupsList) HostList(com.emc.storageos.model.host.HostList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ClusterList(com.emc.storageos.model.host.cluster.ClusterList) VolumeGroupList(com.emc.storageos.model.application.VolumeGroupList) List(java.util.List) NamedVolumesList(com.emc.storageos.model.block.NamedVolumesList) VolumeGroupCopySetList(com.emc.storageos.model.application.VolumeGroupCopySetList) SnapshotList(com.emc.storageos.model.SnapshotList) 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 2 with BlockConsistencyGroupSnapshotCreate

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

the class CreateConsistencyGroupSnapshot method doExecute.

@Override
protected Tasks<BlockConsistencyGroupRestRep> doExecute() throws Exception {
    BlockConsistencyGroupSnapshotCreate param = new BlockConsistencyGroupSnapshotCreate();
    param.setName(name);
    if (readOnly != null) {
        param.setReadOnly(readOnly);
    }
    return getClient().blockConsistencyGroups().createSnapshot(consistencyGroupId, param);
}
Also used : BlockConsistencyGroupSnapshotCreate(com.emc.storageos.model.block.BlockConsistencyGroupSnapshotCreate)

Aggregations

BlockConsistencyGroupSnapshotCreate (com.emc.storageos.model.block.BlockConsistencyGroupSnapshotCreate)2 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)1 Volume (com.emc.storageos.db.client.model.Volume)1 VolumeGroup (com.emc.storageos.db.client.model.VolumeGroup)1 NullColumnValueGetter.isNullURI (com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)1 SnapshotList (com.emc.storageos.model.SnapshotList)1 TaskList (com.emc.storageos.model.TaskList)1 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)1 VolumeGroupCopySetList (com.emc.storageos.model.application.VolumeGroupCopySetList)1 VolumeGroupList (com.emc.storageos.model.application.VolumeGroupList)1 VolumeGroupSnapshotSessionCreateParam (com.emc.storageos.model.application.VolumeGroupSnapshotSessionCreateParam)1 BlockSnapshotSessionList (com.emc.storageos.model.block.BlockSnapshotSessionList)1 NamedVolumeGroupsList (com.emc.storageos.model.block.NamedVolumeGroupsList)1 NamedVolumesList (com.emc.storageos.model.block.NamedVolumesList)1 SnapshotSessionCreateParam (com.emc.storageos.model.block.SnapshotSessionCreateParam)1 HostList (com.emc.storageos.model.host.HostList)1 ClusterList (com.emc.storageos.model.host.cluster.ClusterList)1 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1