Search in sources :

Example 6 with VolumeGroupCopySetList

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

the class VolumeGroupService method createVolumeGroupSnapshotSession.

/**
 * Creates a volume group snapshot session
 * - Creates snapshot session for all the array replication groups within this Application.
 * - If partial flag is specified, it creates snapshot session 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 session.
 *
 * @prereq none
 *
 * @param volumeGroupId the URI of the Volume Group
 *            - Volume group URI
 * @param param VolumeGroupSnapshotSessionCreateParam
 *
 * @brief Create volume group snapshot session
 * @return TaskList
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshot-sessions")
@CheckPermission(roles = { Role.SYSTEM_ADMIN }, acls = { ACL.ANY })
public TaskList createVolumeGroupSnapshotSession(@PathParam("id") final URI volumeGroupId, VolumeGroupSnapshotSessionCreateParam param) {
    ArgValidator.checkFieldUriType(volumeGroupId, VolumeGroup.class, ID_FIELD);
    // Query volume group
    final VolumeGroup volumeGroup = (VolumeGroup) queryResource(volumeGroupId);
    // validate replica operation for volume group
    validateCopyOperationForVolumeGroup(volumeGroup, ReplicaTypeEnum.SNAPSHOT_SESSION);
    // validate name
    String name = TimeUtils.formatDateForCurrent(param.getName());
    ArgValidator.checkFieldNotEmpty(name, NAME_FIELD);
    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_SESSION.toString());
    }
    // check name provided is not duplicate
    VolumeGroupCopySetList sessionSet = getVolumeGroupSnapsetSessionSets(volumeGroup);
    if (sessionSet.getCopySets().contains(name)) {
        // duplicate name
        throw APIException.badRequests.duplicateCopySetName(param.getName(), ReplicaTypeEnum.SNAPSHOT_SESSION.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 Session requested for subset of array groups in Application.");
        // validate that at least one volume URI is provided
        ArgValidator.checkFieldNotEmpty(partialVolumeList, VOLUMES_FIELD);
        // validate the 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_SESSION.toString(), volume.getLabel());
            }
            volumes.add(volume);
        }
    } else {
        log.info("Snapshot Session 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_SESSION.toString());
        }
    }
    // Check for pending tasks
    checkForApplicationPendingTasks(volumeGroup, _dbClient, false);
    auditOp(OperationTypeEnum.CREATE_VOLUME_GROUP_SNAPSHOT_SESSION, true, AuditLogManager.AUDITOP_BEGIN, volumeGroupId.toString(), name);
    TaskList taskList = new TaskList();
    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 session for consistency group {}, volumes {}", cgUri, Joiner.on(',').join(entry.getValue()));
        try {
            SnapshotSessionCreateParam cgSnapshotSessionParam = new SnapshotSessionCreateParam(name, param.getNewLinkedTargets(), entry.getValue());
            taskList.getTaskList().addAll(_blockConsistencyGroupService.createConsistencyGroupSnapshotSession(cgUri, cgSnapshotSessionParam).getTaskList());
        } catch (Exception ex) {
            log.error("Unexpected Exception occurred when creating snapshot session for consistency group {}", cgUri, ex);
        }
    }
    auditOp(OperationTypeEnum.CREATE_VOLUME_GROUP_SNAPSHOT_SESSION, true, AuditLogManager.AUDITOP_END, volumeGroupId.toString(), name);
    return taskList;
}
Also used : SnapshotSessionCreateParam(com.emc.storageos.model.block.SnapshotSessionCreateParam) VolumeGroupSnapshotSessionCreateParam(com.emc.storageos.model.application.VolumeGroupSnapshotSessionCreateParam) TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) 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) Entry(java.util.Map.Entry) 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 7 with VolumeGroupCopySetList

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

the class VolumeGroupService method getVolumeGroupSnapsetSessionSets.

/*
     * get all snapshot session set names associated with the volume group
     */
private VolumeGroupCopySetList getVolumeGroupSnapsetSessionSets(VolumeGroup volumeGroup) {
    VolumeGroupCopySetList copySetList = new VolumeGroupCopySetList();
    Set<String> copySets = copySetList.getCopySets();
    // get all snapshot sessions for the volume group
    List<BlockSnapshotSession> volumeGroupSessions = getVolumeGroupSnapshotSessions(volumeGroup);
    for (BlockSnapshotSession session : volumeGroupSessions) {
        String sessionsetLabel = session.getSessionSetName();
        if (NullColumnValueGetter.isNotNullValue(sessionsetLabel)) {
            copySets.add(sessionsetLabel);
        }
    }
    return copySetList;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) VolumeGroupCopySetList(com.emc.storageos.model.application.VolumeGroupCopySetList)

Aggregations

VolumeGroupCopySetList (com.emc.storageos.model.application.VolumeGroupCopySetList)7 Volume (com.emc.storageos.db.client.model.Volume)5 VolumeGroup (com.emc.storageos.db.client.model.VolumeGroup)5 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 Consumes (javax.ws.rs.Consumes)4 POST (javax.ws.rs.POST)4 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)3 BlockSnapshotSessionList (com.emc.storageos.model.block.BlockSnapshotSessionList)3 NamedVolumesList (com.emc.storageos.model.block.NamedVolumesList)3 BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)2 NullColumnValueGetter.isNullURI (com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)2 SnapshotList (com.emc.storageos.model.SnapshotList)2 TaskList (com.emc.storageos.model.TaskList)2 VolumeGroupList (com.emc.storageos.model.application.VolumeGroupList)2 VolumeGroupSnapshotSessionCreateParam (com.emc.storageos.model.application.VolumeGroupSnapshotSessionCreateParam)2 NamedVolumeGroupsList (com.emc.storageos.model.block.NamedVolumeGroupsList)2 SnapshotSessionCreateParam (com.emc.storageos.model.block.SnapshotSessionCreateParam)2 HostList (com.emc.storageos.model.host.HostList)2