Search in sources :

Example 6 with SnapshotList

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

the class FileService method getSnapshots.

/**
 * Get file system snapshots
 *
 * @param id
 *            the URN of a ViPR File system
 * @brief List file system snapshots
 * @return List of snapshots
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public SnapshotList getSnapshots(@PathParam("id") URI id) {
    List<URI> snapIDList = _dbClient.queryByConstraint(ContainmentConstraint.Factory.getFileshareSnapshotConstraint(id));
    _log.debug("getSnapshots: FS {}: {} ", id.toString(), snapIDList.toString());
    List<Snapshot> snapList = _dbClient.queryObject(Snapshot.class, snapIDList);
    SnapshotList list = new SnapshotList();
    for (Snapshot snap : snapList) {
        list.getSnapList().add(toNamedRelatedResource(snap));
    }
    return list;
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) ScheduleSnapshotList(com.emc.storageos.model.file.ScheduleSnapshotList) SnapshotList(com.emc.storageos.model.SnapshotList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 7 with SnapshotList

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

the class VolumeGroupService method getVolumeGroupSnapshots.

/**
 * List snapshots for a volume group
 *
 * @prereq none
 * @param volumeGroupId The URI of the volume group.
 * @brief List snapshots for a volume group
 * @return SnapshotList
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public SnapshotList getVolumeGroupSnapshots(@PathParam("id") final URI volumeGroupId) {
    // query volume group
    final VolumeGroup volumeGroup = (VolumeGroup) queryResource(volumeGroupId);
    // validate replica operation for volume group
    validateCopyOperationForVolumeGroup(volumeGroup, ReplicaTypeEnum.SNAPSHOT);
    // get all volumes
    List<Volume> volumes = ControllerUtils.getVolumeGroupVolumes(_dbClient, volumeGroup);
    // get the snapshots for each volume in the group
    SnapshotList snapshotList = new SnapshotList();
    for (Volume volume : volumes) {
        if (volume.isVPlexVolume(_dbClient)) {
            volume = VPlexUtil.getVPLEXBackendVolume(volume, true, _dbClient);
            if (volume == null || volume.getInactive()) {
                log.warn("Cannot find backend volume for VPLEX volume {}", volume.getLabel());
            }
        }
        URIQueryResultList snapshotURIs = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getVolumeSnapshotConstraint(volume.getId()), snapshotURIs);
        if (!snapshotURIs.iterator().hasNext()) {
            continue;
        }
        List<BlockSnapshot> snapshots = _dbClient.queryObject(BlockSnapshot.class, snapshotURIs);
        for (BlockSnapshot snapshot : snapshots) {
            if (snapshot != null && !snapshot.getInactive()) {
                snapshotList.getSnapList().add(toNamedRelatedResource(snapshot));
            }
        }
    }
    return snapshotList;
}
Also used : SnapshotList(com.emc.storageos.model.SnapshotList) Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 8 with SnapshotList

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

the class VolumeGroupService method validateSnapshotOperation.

/**
 * Validates a snapshot operation and throws and exception if the operation cannot be done:
 *      - checks for pending tasks
 *      - for deactivate snapshot, check for any exported snapshots
 *
 * @param volumeGroupId
 * @param snapsetToSnapshots
 * @param opType
 */
private void validateSnapshotOperation(URI volumeGroupId, Map<String, List<BlockSnapshot>> snapsetToSnapshots, OperationTypeEnum opType) {
    // Check for pending tasks
    VolumeGroup volumeGroup = _dbClient.queryObject(VolumeGroup.class, volumeGroupId);
    if (opType == OperationTypeEnum.RESTORE_VOLUME_GROUP_SNAPSHOT) {
        checkForApplicationPendingTasks(volumeGroup, _dbClient, true);
    } else {
        checkForApplicationPendingTasks(volumeGroup, _dbClient, false);
        if (opType == OperationTypeEnum.DEACTIVATE_VOLUME_GROUP_SNAPSHOT) {
            for (Entry<String, List<BlockSnapshot>> entry : snapsetToSnapshots.entrySet()) {
                String snapsetName = entry.getKey();
                List<BlockSnapshot> snapshotList = entry.getValue();
                for (BlockSnapshot snapshot : snapshotList) {
                    if (snapshot.isSnapshotExported(_dbClient)) {
                        throw APIException.badRequests.cannotDeleteApplicationSnapshotExportExists(volumeGroup.getLabel(), snapsetName);
                    }
                }
            }
        }
    }
}
Also used : VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) 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)

Example 9 with SnapshotList

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

the class BlockService method getSnapshots.

/**
 * List volume snapshots
 *
 * @prereq none
 *
 * @param id
 *            the URN of a ViPR Volume to list snapshots
 *
 * @brief List volume snapshots
 * @return Volume snapshot response containing list of snapshot identifiers
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public SnapshotList getSnapshots(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, Volume.class, "id");
    Volume requestedVolume = queryVolumeResource(id);
    // Get the block service implementation for the volume.
    BlockServiceApi blockServiceApiImpl = getBlockServiceImpl(requestedVolume);
    // Get and return the snapshots.
    List<BlockSnapshot> snapList = blockServiceApiImpl.getSnapshots(requestedVolume);
    SnapshotList list = new SnapshotList();
    list.setSnapList(new ArrayList<NamedRelatedResourceRep>());
    List<NamedRelatedResourceRep> activeSnaps = new ArrayList<NamedRelatedResourceRep>();
    List<NamedRelatedResourceRep> inactiveSnaps = new ArrayList<NamedRelatedResourceRep>();
    for (BlockSnapshot snap : snapList) {
        if (snap.getInactive()) {
            inactiveSnaps.add(toNamedRelatedResource(snap));
        } else {
            activeSnaps.add(toNamedRelatedResource(snap));
        }
    }
    list.getSnapList().addAll(activeSnaps);
    list.getSnapList().addAll(inactiveSnaps);
    return list;
}
Also used : SnapshotList(com.emc.storageos.model.SnapshotList) MapVolume(com.emc.storageos.api.mapper.functions.MapVolume) Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ArrayList(java.util.ArrayList) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) 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 10 with SnapshotList

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

the class BlockConsistencyGroupService method createConsistencyGroupSnapshot.

/**
 * Creates a consistency group snapshot
 *
 * @prereq none
 *
 * @param consistencyGroupId
 *            - Consistency group URI
 * @param param
 *
 * @brief Create consistency 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 createConsistencyGroupSnapshot(@PathParam("id") final URI consistencyGroupId, final BlockConsistencyGroupSnapshotCreate param) {
    ArgValidator.checkFieldUriType(consistencyGroupId, BlockConsistencyGroup.class, "id");
    // Query Consistency Group
    final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(consistencyGroupId);
    // system types.
    if (!consistencyGroup.created()) {
        throw APIException.badRequests.consistencyGroupNotCreated();
    }
    // RP CG's must use applications to create snapshots
    if (isIdEmbeddedInURL(consistencyGroupId) && consistencyGroup.checkForType(Types.RP)) {
        throw APIException.badRequests.snapshotsNotSupportedForRPCGs();
    }
    // Validate CG information in the request
    validateVolumesInReplicationGroups(consistencyGroup, param.getVolumes(), _dbClient);
    // Get the block service implementation
    BlockServiceApi blockServiceApiImpl = getBlockServiceImpl(consistencyGroup);
    Table<URI, String, List<Volume>> storageRgToVolumes = null;
    if (!param.getVolumes().isEmpty()) {
        // Volume group snapshot
        // group volumes by backend storage system and replication group
        storageRgToVolumes = BlockServiceUtils.getReplicationGroupVolumes(param.getVolumes(), consistencyGroupId, _dbClient, uriInfo);
    } else {
        // CG snapshot
        storageRgToVolumes = BlockServiceUtils.getReplicationGroupVolumes(blockServiceApiImpl.getActiveCGVolumes(consistencyGroup), _dbClient);
    }
    // Validation replication group volumes to ensure there aren't mixed meta and non-meta devices
    validateReplicationGroupDevices(storageRgToVolumes);
    TaskList taskList = new TaskList();
    for (Cell<URI, String, List<Volume>> cell : storageRgToVolumes.cellSet()) {
        List<Volume> volumeList = cell.getValue();
        if (volumeList == null || volumeList.isEmpty()) {
            _log.warn(String.format("No volume in replication group %s", cell.getColumnKey()));
            continue;
        }
        // Generate task id
        String taskId = UUID.randomUUID().toString();
        // Set snapshot type.
        String snapshotType = BlockSnapshot.TechnologyType.NATIVE.toString();
        // Validate the snapshot request.
        String snapshotName = TimeUtils.formatDateForCurrent(param.getName());
        // Set the read only flag.
        final Boolean readOnly = param.getReadOnly() == null ? Boolean.FALSE : param.getReadOnly();
        // Set the create inactive flag.
        final Boolean createInactive = param.getCreateInactive() == null ? Boolean.FALSE : param.getCreateInactive();
        blockServiceApiImpl.validateCreateSnapshot(volumeList.get(0), volumeList, snapshotType, snapshotName, readOnly, getFullCopyManager());
        // Prepare and create the snapshots for the group.
        List<URI> snapIdList = new ArrayList<URI>();
        List<BlockSnapshot> snapshotList = new ArrayList<BlockSnapshot>();
        snapshotList.addAll(blockServiceApiImpl.prepareSnapshots(volumeList, snapshotType, snapshotName, snapIdList, taskId));
        for (BlockSnapshot snapshot : snapshotList) {
            taskList.getTaskList().add(toTask(snapshot, taskId));
        }
        addConsistencyGroupTask(consistencyGroup, taskList, taskId, ResourceOperationTypeEnum.CREATE_CONSISTENCY_GROUP_SNAPSHOT);
        try {
            blockServiceApiImpl.createSnapshot(volumeList.get(0), snapIdList, snapshotType, createInactive, readOnly, taskId);
            auditBlockConsistencyGroup(OperationTypeEnum.CREATE_CONSISTENCY_GROUP_SNAPSHOT, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, param.getName(), consistencyGroup.getId().toString());
        } catch (Exception ex) {
            _log.error("Unexpected Exception occurred when creating snapshot for replication group {}", cell.getColumnKey(), ex);
        }
    }
    return taskList;
}
Also used : TaskList(com.emc.storageos.model.TaskList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException) MapBlockConsistencyGroup(com.emc.storageos.api.mapper.functions.MapBlockConsistencyGroup) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) Volume(com.emc.storageos.db.client.model.Volume) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) BlockSnapshotSessionList(com.emc.storageos.model.block.BlockSnapshotSessionList) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) NamedVolumesList(com.emc.storageos.model.block.NamedVolumesList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) 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

SnapshotList (com.emc.storageos.model.SnapshotList)10 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)6 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)5 Volume (com.emc.storageos.db.client.model.Volume)5 ArrayList (java.util.ArrayList)4 GET (javax.ws.rs.GET)4 NamedURI (com.emc.storageos.db.client.model.NamedURI)3 VolumeGroup (com.emc.storageos.db.client.model.VolumeGroup)3 NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)3 NamedVolumesList (com.emc.storageos.model.block.NamedVolumesList)3 URI (java.net.URI)3 TaskList (com.emc.storageos.model.TaskList)2 VolumeGroupCopySetParam (com.emc.storageos.model.application.VolumeGroupCopySetParam)2 BlockSnapshotRestRep (com.emc.storageos.model.block.BlockSnapshotRestRep)2 BlockSnapshotSessionList (com.emc.storageos.model.block.BlockSnapshotSessionList)2 SOURCE_TO_TARGET (com.emc.storageos.model.block.Copy.SyncDirection.SOURCE_TO_TARGET)2 VolumeRestRep (com.emc.storageos.model.block.VolumeRestRep)2