Search in sources :

Example 1 with CinderSnapshot

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

the class SnapshotService method getSnapShot.

/**
 * Get the details of a specific snapshot
 *
 * @prereq none
 *
 * @param tenant_id
 *            the URN of the tenant
 * @param snapshot_id
 *            the URN of the snapshot
 *
 * @brief Show snapshot
 * @return snapshot details
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{snapshot_id}")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public Response getSnapShot(@PathParam("tenant_id") String openstack_tenant_id, @PathParam("snapshot_id") String snapshot_id, @HeaderParam("X-Cinder-V1-Call") String isV1Call, @Context HttpHeaders header) {
    CinderSnapshot response = new CinderSnapshot();
    _log.info("START get snapshot with id {}", snapshot_id);
    BlockSnapshot snapshot = findSnapshot(snapshot_id, openstack_tenant_id);
    if (snapshot == null) {
        _log.error("Invalid snapshot ID ={} ", snapshot_id);
        return CinderApiUtils.createErrorResponse(400, "Bad Request : Invalid snapshot " + snapshot_id);
    }
    response = getSnapshotDetail(snapshot, isV1Call, openstack_tenant_id);
    return CinderApiUtils.getCinderResponse(response, header, true, CinderConstants.STATUS_OK);
}
Also used : CinderSnapshot(com.emc.storageos.cinder.model.CinderSnapshot) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with CinderSnapshot

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

the class SnapshotService method createSnapshot.

/**
 * The snapshot of a volume in Block Store is a point in time copy of the
 * volume. This API allows the user to create snapshot of a volume
 * NOTE: This is an asynchronous operation.
 *
 * @prereq none
 *
 * @param param
 *            POST data containing the snapshot creation information.
 *
 * @brief Create snapshot
 * @return Details of the newly created snapshot
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response createSnapshot(@PathParam("tenant_id") String openstack_tenant_id, SnapshotCreateRequestGen param, @Context HttpHeaders header, @HeaderParam("X-Cinder-V1-Call") String isV1Call) throws InternalException {
    // Step 1: Parameter validation
    String snapshotName = null;
    String snapshotDescription = null;
    if (isV1Call != null) {
        snapshotName = param.snapshot.display_name;
        snapshotDescription = param.snapshot.display_description;
    } else {
        snapshotName = param.snapshot.name;
        snapshotDescription = param.snapshot.description;
    }
    // if snapshot name is empty create random name
    if (snapshotName == null) {
        snapshotName = "snapshot-" + RandomStringUtils.random(10);
    }
    if (snapshotName == null || (snapshotName.length() <= 2)) {
        throw APIException.badRequests.parameterIsNotValid(param.snapshot.name);
    }
    URI volumeUri = null;
    Volume volume = null;
    volumeUri = URI.create(param.snapshot.volume_id);
    volume = queryVolumeResource(volumeUri, openstack_tenant_id);
    if (volume == null) {
        _log.error("Invalid source volume id to create snapshot ={} ", param.snapshot.volume_id);
        return CinderApiUtils.createErrorResponse(404, "Not Found : Invalid source volume id " + param.snapshot.volume_id);
    }
    VirtualPool pool = _dbClient.queryObject(VirtualPool.class, volume.getVirtualPool());
    if (pool == null) {
        _log.info("Virtual Pool corresponding to the volume does not exist.");
        throw APIException.badRequests.parameterIsNotValid(volume.getVirtualPool().toString());
    }
    if (!validateSnapshotCreate(openstack_tenant_id, pool, volume.getProvisionedCapacity())) {
        _log.info("The volume can not be created because of insufficient quota for virtual pool.");
        throw APIException.badRequests.insufficientQuotaForVirtualPool(pool.getLabel(), "virtual pool");
    }
    if (!validateSnapshotCreate(openstack_tenant_id, null, volume.getProvisionedCapacity())) {
        _log.info("The volume can not be created because of insufficient quota for Project.");
        throw APIException.badRequests.insufficientQuotaForProject(pool.getLabel(), "project");
    }
    BlockFullCopyManager fcManager = new BlockFullCopyManager(_dbClient, _permissionsHelper, _auditMgr, _coordinator, _placementManager, sc, uriInfo, _request, _tenantsService);
    VolumeIngestionUtil.checkOperationSupportedOnIngestedVolume(volume, ResourceOperationTypeEnum.CREATE_VOLUME_SNAPSHOT, _dbClient);
    // Don't operate on VPLEX backend volumes or RP journal volumes.
    BlockServiceUtils.validateNotAnInternalBlockObject(volume, false);
    validateSourceVolumeHasExported(volume);
    String snapshotType = TechnologyType.NATIVE.toString();
    Boolean createInactive = Boolean.FALSE;
    Boolean readOnly = Boolean.FALSE;
    BlockServiceApi api = getBlockServiceImpl(pool, _dbClient);
    List<Volume> volumesToSnap = new ArrayList<Volume>();
    volumesToSnap.addAll(api.getVolumesToSnap(volume, snapshotType));
    api.validateCreateSnapshot(volume, volumesToSnap, snapshotType, snapshotName, readOnly, fcManager);
    String taskId = UUID.randomUUID().toString();
    List<URI> snapshotURIs = new ArrayList<URI>();
    List<BlockSnapshot> snapshots = api.prepareSnapshots(volumesToSnap, snapshotType, snapshotName, snapshotURIs, taskId);
    TaskList response = new TaskList();
    for (BlockSnapshot snapshot : snapshots) {
        response.getTaskList().add(toTask(snapshot, taskId));
    }
    // Update the task status for the volumes task.
    _dbClient.createTaskOpStatus(Volume.class, volume.getId(), taskId, ResourceOperationTypeEnum.CREATE_VOLUME_SNAPSHOT);
    // Invoke the block service API implementation to create the snapshot
    api.createSnapshot(volume, snapshotURIs, snapshotType, createInactive, readOnly, taskId);
    SnapshotCreateResponse snapCreateResp = new SnapshotCreateResponse();
    for (TaskResourceRep rep : response.getTaskList()) {
        URI snapshotUri = rep.getResource().getId();
        BlockSnapshot snap = _dbClient.queryObject(BlockSnapshot.class, snapshotUri);
        if (snap != null) {
            StringMap extensions = snap.getExtensions();
            if (extensions == null)
                extensions = new StringMap();
            extensions.put("display_description", (snapshotDescription == null) ? "" : snapshotDescription);
            extensions.put("taskid", rep.getId().toString());
            _log.debug("Create snapshot : stored description");
            snap.setExtensions(extensions);
            ScopedLabelSet tagSet = new ScopedLabelSet();
            snap.setTag(tagSet);
            String[] splits = snapshotUri.toString().split(":");
            String tagName = splits[3];
            // this check will verify whether  retrieved data is not corrupted
            if (tagName == null || tagName.isEmpty() || tagName.length() < 2) {
                throw APIException.badRequests.parameterTooShortOrEmpty("Tag", 2);
            }
            Volume parentVol = _permissionsHelper.getObjectById(snap.getParent(), Volume.class);
            URI tenantOwner = parentVol.getTenant().getURI();
            ScopedLabel tagLabel = new ScopedLabel(tenantOwner.toString(), tagName);
            tagSet.add(tagLabel);
            _dbClient.updateObject(snap);
            if (isV1Call != null) {
                _log.debug("Inside V1 call");
                return CinderApiUtils.getCinderResponse(getSnapshotDetail(snap, isV1Call, openstack_tenant_id), header, true, CinderConstants.STATUS_OK);
            } else {
                return CinderApiUtils.getCinderResponse(getSnapshotDetail(snap, isV1Call, openstack_tenant_id), header, true, CinderConstants.STATUS_ACCEPT);
            }
        }
    }
    return CinderApiUtils.getCinderResponse(new CinderSnapshot(), header, true, CinderConstants.STATUS_ACCEPT);
}
Also used : SnapshotCreateResponse(com.emc.storageos.cinder.model.SnapshotCreateResponse) StringMap(com.emc.storageos.db.client.model.StringMap) TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) BlockServiceApi(com.emc.storageos.api.service.impl.resource.BlockServiceApi) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) BlockFullCopyManager(com.emc.storageos.api.service.impl.resource.fullcopy.BlockFullCopyManager) CinderSnapshot(com.emc.storageos.cinder.model.CinderSnapshot) Volume(com.emc.storageos.db.client.model.Volume) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 3 with CinderSnapshot

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

the class SnapshotService method getSnapshotDetail.

// INTERNAL FUNCTIONS
protected CinderSnapshot getSnapshotDetail(BlockSnapshot snapshot, String isV1Call, String openstack_tenant_id) {
    CinderSnapshot detail = new CinderSnapshot();
    detail.id = getCinderHelper().trimId(snapshot.getId().toString());
    detail.volume_id = getCinderHelper().trimId(snapshot.getParent().getURI().toString());
    detail.created_at = date(snapshot.getCreationTime().getTimeInMillis());
    detail.project_id = openstack_tenant_id;
    detail.size = (int) ((snapshot.getProvisionedCapacity() + HALF_GB) / GB);
    StringMap extensions = snapshot.getExtensions();
    String description = null;
    Map<String, String> metaMap = new HashMap<String, String>();
    if (extensions != null) {
        description = extensions.get("display_description");
        _log.debug("Retreiving the tasks for snapshot id {}", snapshot.getId());
        List<Task> taskLst = TaskUtils.findResourceTasks(_dbClient, snapshot.getId());
        _log.debug("Retreived the tasks for snapshot id {}", snapshot.getId());
        String taskInProgressId = null;
        if (snapshot.getExtensions().containsKey("taskid")) {
            taskInProgressId = snapshot.getExtensions().get("taskid");
            // Task acttask = TaskUtils.findTaskForRequestId(_dbClient, snapshot.getId(), taskInProgressId);
            for (Task tsk : taskLst) {
                if (tsk.getId().toString().equals(taskInProgressId)) {
                    if (tsk.getStatus().equals("ready")) {
                        detail.status = CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase();
                        snapshot.getExtensions().put("status", CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase());
                        snapshot.getExtensions().remove("taskid");
                        _dbClient.updateObject(snapshot);
                    } else if (tsk.getStatus().equals("pending")) {
                        if (tsk.getDescription().equals(ResourceOperationTypeEnum.CREATE_VOLUME_SNAPSHOT.getDescription())) {
                            detail.status = CinderConstants.ComponentStatus.CREATING.getStatus().toLowerCase();
                        } else if (tsk.getDescription().equals(ResourceOperationTypeEnum.DELETE_VOLUME_SNAPSHOT.getDescription())) {
                            detail.status = CinderConstants.ComponentStatus.DELETING.getStatus().toLowerCase();
                        }
                    } else if (tsk.getStatus().equals("error")) {
                        detail.status = CinderConstants.ComponentStatus.ERROR.getStatus().toLowerCase();
                        snapshot.getExtensions().put("status", CinderConstants.ComponentStatus.ERROR.getStatus().toLowerCase());
                        snapshot.getExtensions().remove("taskid");
                        _dbClient.updateObject(snapshot);
                    }
                    break;
                }
            }
        } else if (snapshot.getExtensions().containsKey("status") && !snapshot.getExtensions().get("status").toString().toLowerCase().equals("")) {
            detail.status = snapshot.getExtensions().get("status").toString().toLowerCase();
        } else {
            // "available";
            detail.status = CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase();
        }
        for (String mapEntry : extensions.keySet()) {
            if (mapEntry.startsWith("METADATA_")) {
                String value = extensions.get(mapEntry);
                metaMap.put(mapEntry.substring("METADATA_".length()), value);
            }
        }
    }
    if (isV1Call != null) {
        detail.display_name = snapshot.getLabel();
        detail.display_description = (description == null) ? "" : description;
    } else {
        detail.name = snapshot.getLabel();
        detail.description = (description == null) ? "" : description;
    }
    // default
    detail.progress = ZERO_PERCENT_COMPLETION;
    if ((detail.status == CinderConstants.ComponentStatus.CREATING.getStatus().toLowerCase()) || (detail.status == CinderConstants.ComponentStatus.DELETING.getStatus().toLowerCase()) || (detail.status == CinderConstants.ComponentStatus.ERROR.getStatus().toLowerCase()) || (detail.status == CinderConstants.ComponentStatus.ERROR_DELETING.getStatus().toLowerCase())) {
        detail.progress = ZERO_PERCENT_COMPLETION;
    } else if (detail.status == CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase()) {
        detail.progress = HUNDRED_PERCENT_COMPLETION;
    }
    detail.metadata = metaMap;
    return detail;
}
Also used : CinderSnapshot(com.emc.storageos.cinder.model.CinderSnapshot) StringMap(com.emc.storageos.db.client.model.StringMap) Task(com.emc.storageos.db.client.model.Task) TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask) HashMap(java.util.HashMap)

Example 4 with CinderSnapshot

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

the class SnapshotService method getSnapshotList.

/**
 * Get the summary list of all snapshots for the given tenant
 *
 * @prereq none
 *
 * @param tenant_id
 *            the URN of the tenant
 *
 * @brief List snapshots
 * @return Snapshot list
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/detail")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public Response getSnapshotList(@PathParam("tenant_id") String openstack_tenant_id, @HeaderParam("X-Cinder-V1-Call") String isV1Call, @Context HttpHeaders header) {
    CinderSnapshotListRestResp snapshots = new CinderSnapshotListRestResp();
    URIQueryResultList uris = getSnapshotUris(openstack_tenant_id);
    if (uris != null) {
        while (uris.iterator().hasNext()) {
            URI snapshotUri = uris.iterator().next();
            BlockSnapshot snap = _dbClient.queryObject(BlockSnapshot.class, snapshotUri);
            if (snap != null && !snap.getInactive()) {
                CinderSnapshot cinder_snapshot = getSnapshotDetail(snap, isV1Call, openstack_tenant_id);
                snapshots.getSnapshots().add(cinder_snapshot);
            }
        }
    }
    return CinderApiUtils.getCinderResponse(snapshots, header, false, CinderConstants.STATUS_OK);
}
Also used : CinderSnapshot(com.emc.storageos.cinder.model.CinderSnapshot) CinderSnapshotListRestResp(com.emc.storageos.cinder.model.CinderSnapshotListRestResp) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI) 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)

Aggregations

CinderSnapshot (com.emc.storageos.cinder.model.CinderSnapshot)4 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)3 Produces (javax.ws.rs.Produces)3 StringMap (com.emc.storageos.db.client.model.StringMap)2 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 URI (java.net.URI)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 TaskMapper.toTask (com.emc.storageos.api.mapper.TaskMapper.toTask)1 BlockServiceApi (com.emc.storageos.api.service.impl.resource.BlockServiceApi)1 BlockFullCopyManager (com.emc.storageos.api.service.impl.resource.fullcopy.BlockFullCopyManager)1 CinderSnapshotListRestResp (com.emc.storageos.cinder.model.CinderSnapshotListRestResp)1 SnapshotCreateResponse (com.emc.storageos.cinder.model.SnapshotCreateResponse)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 ScopedLabel (com.emc.storageos.db.client.model.ScopedLabel)1 ScopedLabelSet (com.emc.storageos.db.client.model.ScopedLabelSet)1 Task (com.emc.storageos.db.client.model.Task)1 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)1 Volume (com.emc.storageos.db.client.model.Volume)1 TaskList (com.emc.storageos.model.TaskList)1