Search in sources :

Example 1 with VolumeGroupSnapshotSessionCreateParam

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

the class CreateSnapshotSessionForApplication method doExecute.

@Override
protected Tasks<TaskResourceRep> doExecute() throws Exception {
    VolumeGroupSnapshotSessionCreateParam input = new VolumeGroupSnapshotSessionCreateParam();
    input.setName(name);
    input.setVolumes(volumes);
    input.setPartial(true);
    TaskList taskList = getClient().application().createSnapshotSessionOfApplication(applicationId, input);
    return new Tasks<TaskResourceRep>(getClient().auth().getClient(), taskList.getTaskList(), TaskResourceRep.class);
}
Also used : WaitForTasks(com.emc.sa.service.vipr.tasks.WaitForTasks) Tasks(com.emc.vipr.client.Tasks) TaskList(com.emc.storageos.model.TaskList) VolumeGroupSnapshotSessionCreateParam(com.emc.storageos.model.application.VolumeGroupSnapshotSessionCreateParam)

Example 2 with VolumeGroupSnapshotSessionCreateParam

use of com.emc.storageos.model.application.VolumeGroupSnapshotSessionCreateParam 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)

Aggregations

TaskList (com.emc.storageos.model.TaskList)2 VolumeGroupSnapshotSessionCreateParam (com.emc.storageos.model.application.VolumeGroupSnapshotSessionCreateParam)2 WaitForTasks (com.emc.sa.service.vipr.tasks.WaitForTasks)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)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 VolumeGroupCopySetList (com.emc.storageos.model.application.VolumeGroupCopySetList)1 VolumeGroupList (com.emc.storageos.model.application.VolumeGroupList)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 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)1 Tasks (com.emc.vipr.client.Tasks)1