use of com.emc.storageos.cinder.model.VolumeDetail in project coprhd-controller by CoprHD.
the class VolumeService method getDetailedVolumeList.
/**
* Get the detailed list of all volumes for the given tenant
*
* @prereq none
*
* @param tenant_id the URN of the tenant
*
* @brief List volumes in detail
* @return Volume detailed list
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/detail")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public Response getDetailedVolumeList(@PathParam("tenant_id") String openstackTenantId, @HeaderParam("X-Cinder-V1-Call") String isV1Call, @Context HttpHeaders header) {
_log.debug("START get detailed volume list");
URIQueryResultList uris = getVolumeUris(openstackTenantId);
// convert to detailed format
VolumeDetails volumeDetails = new VolumeDetails();
if (uris != null) {
for (URI volumeUri : uris) {
Volume vol = _dbClient.queryObject(Volume.class, volumeUri);
if (vol != null && !vol.getInactive()) {
VolumeDetail volumeDetail = getVolumeDetail(vol, isV1Call, openstackTenantId);
volumeDetails.getVolumes().add(volumeDetail);
}
}
}
return CinderApiUtils.getCinderResponse(volumeDetails, header, false, STATUS_OK);
}
use of com.emc.storageos.cinder.model.VolumeDetail in project coprhd-controller by CoprHD.
the class VolumeService method getVolumeDetail.
// INTERNAL FUNCTIONS
protected VolumeDetail getVolumeDetail(Volume vol, String isV1Call, String openstackTenantId) {
VolumeDetail detail = new VolumeDetail();
int sizeInGB = (int) ((vol.getCapacity() + halfGB) / GB);
detail.size = sizeInGB;
detail.id = getCinderHelper().trimId(vol.getId().toString());
detail.host_name = getCinderHelper().trimId(vol.getStorageController().toString());
detail.tenant_id = openstackTenantId;
detail.attachments = new ArrayList<Attachment>();
if (vol.getInactive()) {
detail.status = "deleted";
} else {
if (vol.getExtensions() == null) {
vol.setExtensions(new StringMap());
}
if (vol.getProvisionedCapacity() == ZERO_BYTES) {
detail.status = CinderConstants.ComponentStatus.CREATING.getStatus().toLowerCase();
} else if (vol.getExtensions().containsKey("status") && vol.getExtensions().get("status").equals(CinderConstants.ComponentStatus.DELETING.getStatus().toLowerCase())) {
Task taskObj = null;
String task = vol.getExtensions().get(DELETE_TASK_ID).toString();
taskObj = TaskUtils.findTaskForRequestId(_dbClient, vol.getId(), task);
if (taskObj != null) {
if (taskObj.getStatus().equals("error")) {
_log.info(String.format("Error Deleting volume %s, but moving volume to original state so that it will be usable: ", detail.name));
vol.getExtensions().put("status", CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase());
vol.getExtensions().remove(DELETE_TASK_ID);
detail.status = CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase();
} else if (taskObj.getStatus().equals("pending")) {
detail.status = CinderConstants.ComponentStatus.DELETING.getStatus().toLowerCase();
}
_dbClient.updateObject(vol);
} else {
detail.status = CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase();
}
} else if (vol.getExtensions().containsKey("status") && vol.getExtensions().get("status").equals(CinderConstants.ComponentStatus.EXTENDING.getStatus().toLowerCase())) {
_log.info("Extending Volume {}", vol.getId().toString());
Task taskObj = null;
String task = vol.getExtensions().get("task_id").toString();
taskObj = TaskUtils.findTaskForRequestId(_dbClient, vol.getId(), task);
_log.debug("THE TASKOBJ is {}, task_id {}", taskObj.toString(), task);
_log.debug("THE TASKOBJ STATUS is {}", taskObj.getStatus().toString());
if (taskObj != null) {
if (taskObj.getStatus().equals("ready")) {
detail.status = CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase();
_log.debug(" STATUS is {}", detail.status);
vol.getExtensions().remove("task_id");
vol.getExtensions().put("status", "");
} else if (taskObj.getStatus().equals("error")) {
detail.status = CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase();
_log.info(String.format("Error in Extending volume %s, but moving volume to original state so that it will be usable: ", detail.name));
vol.getExtensions().remove("task_id");
vol.getExtensions().put("status", "");
} else {
detail.status = CinderConstants.ComponentStatus.EXTENDING.getStatus().toLowerCase();
_log.info("STATUS is {}", detail.status);
}
} else {
detail.status = CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase();
_log.info(String.format("Error in Extending volume %s, but moving volume to original state so that it will be usable: ", detail.name));
vol.getExtensions().remove("task_id");
vol.getExtensions().put("status", "");
}
_dbClient.updateObject(vol);
} else if (vol.getExtensions().containsKey("status") && !vol.getExtensions().get("status").equals("")) {
detail.status = vol.getExtensions().get("status").toString().toLowerCase();
} else {
detail.status = CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase();
}
}
detail.created_at = date(vol.getCreationTime().getTimeInMillis());
URI vpoolUri = vol.getVirtualPool();
VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, vpoolUri);
if (vpool != null) {
detail.volume_type = vpool.getLabel();
}
URI varrayUri = vol.getVirtualArray();
VirtualArray varray = _dbClient.queryObject(VirtualArray.class, varrayUri);
if (varray != null) {
detail.availability_zone = varray.getLabel();
}
if (vol.getExtensions().containsKey("bootable") && vol.getExtensions().get("bootable").equals(TRUE)) {
detail.bootable = true;
_log.debug("Volumes Bootable Flag is TRUE");
} else {
detail.bootable = false;
_log.debug("Volumes Bootable Flag is False");
}
detail.setLink(DbObjectMapper.toLink(vol));
detail.metadata = new HashMap<String, String>();
String description = null;
StringMap extensions = vol.getExtensions();
if (extensions != null) {
description = extensions.get("display_description");
}
if (isV1Call != null) {
detail.display_name = vol.getLabel();
detail.display_description = (description == null) ? "" : description;
detail.description = null;
detail.name = null;
} else {
detail.name = vol.getLabel();
detail.description = (description == null) ? "" : description;
detail.display_name = null;
detail.display_description = null;
}
if (vol.getExtensions().containsKey("readonly") && vol.getExtensions().get("readonly").equals(TRUE)) {
_log.debug("Volumes Readonly Flag is TRUE");
detail.metadata.put("readonly", "true");
} else {
_log.debug("Volumes Readonly Flag is FALSE");
detail.metadata.put("readonly", "false");
}
if (detail.status.equals("in-use")) {
if (vol.getExtensions() != null && vol.getExtensions().containsKey("OPENSTACK_NOVA_INSTANCE_ID")) {
detail.metadata.put("attached_mode", vol.getExtensions().get("OPENSTACK_ATTACH_MODE"));
detail.attachments = getVolumeAttachments(vol);
}
}
if (vol.getConsistencyGroup() != null) {
detail.consistencygroup_id = CinderApiUtils.splitString(vol.getConsistencyGroup().toString(), ":", 3);
}
return detail;
}
use of com.emc.storageos.cinder.model.VolumeDetail in project coprhd-controller by CoprHD.
the class VolumeService method createVolume.
/**
* The fundamental abstraction in the Block Store is a
* volume. A volume is a unit of block storage capacity that has been
* allocated by a consumer to a project. This API allows the user to
* create one or more volumes. The volumes are created in the same
* storage pool.
*
* NOTE: This is an asynchronous operation.
*
* @prereq none
*
* @param param POST data containing the volume creation information.
*
* @brief Create volume
* @return Details of the newly created volume
* @throws InternalException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response createVolume(@PathParam("tenant_id") String openstackTenantId, @HeaderParam("X-Cinder-V1-Call") String isV1Call, VolumeCreateRequestGen param, @Context HttpHeaders header) throws InternalException {
// Step 1: Parameter validation
Project project = getCinderHelper().getProject(openstackTenantId, getUserFromContext());
String snapshotId = param.volume.snapshot_id;
String sourceVolId = param.volume.source_volid;
String imageId = param.volume.imageRef;
String consistencygroup_id = param.volume.consistencygroup_id;
String volume_type = param.volume.volume_type;
boolean hasConsistencyGroup = false;
if (project == null) {
if (openstackTenantId != null) {
throw APIException.badRequests.projectWithTagNonexistent(openstackTenantId);
} else {
throw APIException.badRequests.parameterIsNullOrEmpty(PROJECT_TENANTID_NULL);
}
}
URI tenantUri = project.getTenantOrg().getURI();
TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, tenantUri);
if (tenant == null)
throw APIException.notFound.unableToFindUserScopeOfSystem();
_log.debug("Create volume: project = {}, tenant = {}", project.getLabel(), tenant.getLabel());
if (param.volume.size <= 0) {
_log.error("volume size should not be zero or negative ={} ", param.volume.size);
return CinderApiUtils.createErrorResponse(400, "Bad Request : Invalid Volume size");
}
long requestedSize = param.volume.size * GB;
// convert volume type from name to vpool
VirtualPool vpool = getVpool(param.volume.volume_type);
Volume sourceVolume = null;
if (vpool == null) {
if (sourceVolId != null) {
sourceVolume = findVolume(sourceVolId, openstackTenantId);
if (sourceVolume == null) {
_log.error("Invalid Source Volume ID ={} ", sourceVolId);
return CinderApiUtils.createErrorResponse(404, "Not Found : Invalid Source Volume ID " + sourceVolId);
}
vpool = _dbClient.queryObject(VirtualPool.class, sourceVolume.getVirtualPool());
} else {
_log.error("Invalid Volume Type ={} ", volume_type);
return CinderApiUtils.createErrorResponse(404, "Not Found : Invalid Volume Type " + volume_type);
}
}
if (!validateVolumeCreate(openstackTenantId, null, requestedSize)) {
_log.info("The volume can not be created because of insufficient project quota.");
throw APIException.badRequests.insufficientQuotaForProject(project.getLabel(), "volume");
} else if (!validateVolumeCreate(openstackTenantId, vpool, requestedSize)) {
_log.info("The volume can not be created because of insufficient quota for virtual pool.");
throw APIException.badRequests.insufficientQuotaForVirtualPool(vpool.getLabel(), "virtual pool");
}
_log.debug("Create volume: vpool = {}", vpool.getLabel());
VirtualArray varray = getCinderHelper().getVarray(param.volume.availability_zone, getUserFromContext());
if ((snapshotId == null) && (sourceVolId == null) && (varray == null)) {
// otherwise availability_zone exception will be thrown
throw APIException.badRequests.parameterIsNotValid(param.volume.availability_zone);
}
// Validating consistency group
URI blockConsistencyGroupId = null;
BlockConsistencyGroup blockConsistencyGroup = null;
if (consistencygroup_id != null) {
_log.info("Verifying for consistency group : " + consistencygroup_id);
blockConsistencyGroup = (BlockConsistencyGroup) getCinderHelper().queryByTag(URI.create(consistencygroup_id), getUserFromContext(), BlockConsistencyGroup.class);
if (getCinderHelper().verifyConsistencyGroupHasSnapshot(blockConsistencyGroup)) {
_log.error("Bad Request : Consistency Group has Snapshot ");
return CinderApiUtils.createErrorResponse(400, "Bad Request : Consistency Group has Snapshot ");
}
blockConsistencyGroupId = blockConsistencyGroup.getId();
if (blockConsistencyGroup.getTag() != null && consistencygroup_id.equals(blockConsistencyGroupId.toString().split(":")[3])) {
for (ScopedLabel tag : blockConsistencyGroup.getTag()) {
if (tag.getScope().equals("volume_types")) {
if (tag.getLabel().equals(volume_type)) {
hasConsistencyGroup = true;
} else {
return CinderApiUtils.createErrorResponse(404, "Invalid volume: No consistency group exist for volume : " + param.volume.display_name);
}
}
}
} else {
return CinderApiUtils.createErrorResponse(404, "Invalid Consistency Group Id : No Such Consistency group exists");
}
}
BlockSnapshot snapshot = null;
URI snapUri = null;
if (snapshotId != null) {
snapshot = (BlockSnapshot) getCinderHelper().queryByTag(URI.create(snapshotId), getUserFromContext(), BlockSnapshot.class);
if (snapshot == null) {
_log.error("Invalid snapshot id ={} ", snapshotId);
return CinderApiUtils.createErrorResponse(404, "Not Found : Invalid snapshot id" + snapshotId);
} else {
snapUri = snapshot.getId();
URI varrayUri = snapshot.getVirtualArray();
if (varray == null) {
varray = _dbClient.queryObject(VirtualArray.class, varrayUri);
}
}
}
if (varray != null)
_log.info("Create volume: varray = {}", varray.getLabel());
String name = null;
String description = null;
_log.info("is isV1Call {}", isV1Call);
_log.info("name = {}, description = {}", name, description);
if (isV1Call != null) {
name = param.volume.display_name;
description = param.volume.display_description;
} else {
name = param.volume.name;
description = param.volume.description;
}
if (name == null) {
name = "volume-" + RandomStringUtils.random(10);
}
_log.info("param.volume.name = {}, param.volume.display_name = {}", param.volume.name, param.volume.display_name);
_log.info("param.volume.description = {}, param.volume.display_description = {}", param.volume.description, param.volume.display_description);
if (name == null || (name.length() <= 2))
throw APIException.badRequests.parameterIsNotValid(name);
URI projectUri = project.getId();
checkForDuplicateName(name, Volume.class, projectUri, "project", _dbClient);
// Step 2: Check if the user has rights for volume create
verifyUserIsAuthorizedForRequest(project, vpool, varray);
// Step 3: Check capacity Quotas
_log.debug(" volume name = {}, size = {} GB", name, param.volume.size);
int volumeCount = 1;
VolumeCreate volumeCreate = new VolumeCreate(name, Long.toString(requestedSize), volumeCount, vpool.getId(), varray.getId(), project.getId());
BlockServiceApi api = getBlockServiceImpl(vpool, _dbClient);
CapacityUtils.validateQuotasForProvisioning(_dbClient, vpool, project, tenant, requestedSize, "volume");
// Step 4: Call out placementManager to get the recommendation for placement.
VirtualPoolCapabilityValuesWrapper capabilities = new VirtualPoolCapabilityValuesWrapper();
capabilities.put(VirtualPoolCapabilityValuesWrapper.RESOURCE_COUNT, volumeCount);
capabilities.put(VirtualPoolCapabilityValuesWrapper.SIZE, requestedSize);
// Create a unique task id if one is not passed in the request.
String task = UUID.randomUUID().toString();
TaskList tasklist = null;
BlockFullCopyManager blkFullCpManager = new BlockFullCopyManager(_dbClient, _permissionsHelper, _auditMgr, _coordinator, _placementManager, sc, uriInfo, _request, null);
if (hasConsistencyGroup && blockConsistencyGroupId != null) {
try {
checkForConsistencyGroup(vpool, blockConsistencyGroup, project, api, varray, capabilities, blkFullCpManager);
volumeCreate.setConsistencyGroup(blockConsistencyGroupId);
} catch (APIException exp) {
return CinderApiUtils.createErrorResponse(400, "Bad Request : can't create volume for the consistency group : " + blockConsistencyGroupId);
}
}
if (sourceVolId != null) {
_log.debug("Creating New Volume from Volume : Source volume ID ={}", sourceVolId);
if (sourceVolume != null) {
Volume vol = findVolume(sourceVolId, openstackTenantId);
if (vol == null) {
_log.debug("Creating Clone Volume failed : Invalid source volume id ");
return CinderApiUtils.createErrorResponse(404, "Not Found : Invalid source volume id" + sourceVolId);
}
tasklist = volumeClone(name, project, sourceVolId, varray, volumeCount, sourceVolume, blkFullCpManager);
} else {
_log.debug("Creating Clone Volume failed : Null Source volume ");
return CinderApiUtils.createErrorResponse(404, "Not Found : Null source volume ");
}
} else if (snapshotId != null) {
_log.debug("Creating New Volume from Snapshot ID ={}", snapshotId);
tasklist = volumeFromSnapshot(name, project, snapshotId, varray, param, volumeCount, blkFullCpManager, snapUri, snapshot);
} else if ((snapshotId == null) && (sourceVolId == null)) {
_log.debug("Creating New Volume where snapshotId and sourceVolId are null");
tasklist = newVolume(volumeCreate, project, api, capabilities, varray, task, vpool, param, volumeCount, requestedSize, name);
}
if (imageId != null) {
_log.debug("Creating New Volume from imageid ={}", imageId);
// will be implemented
tasklist = volumeFromImage(name, project, varray, param, volumeCount, blkFullCpManager, imageId);
}
if (!(tasklist.getTaskList().isEmpty())) {
for (TaskResourceRep rep : tasklist.getTaskList()) {
URI volumeUri = rep.getResource().getId();
Volume vol = _dbClient.queryObject(Volume.class, volumeUri);
if (vol != null) {
StringMap extensions = vol.getExtensions();
if (extensions == null)
extensions = new StringMap();
extensions.put("display_description", (description == null) ? "" : description);
vol.setExtensions(extensions);
ScopedLabelSet tagSet = new ScopedLabelSet();
vol.setTag(tagSet);
String[] splits = volumeUri.toString().split(":");
String tagName = splits[3];
if (tagName == null || tagName.isEmpty() || tagName.length() < 2) {
throw APIException.badRequests.parameterTooShortOrEmpty("Tag", 2);
}
URI tenantOwner = vol.getTenant().getURI();
ScopedLabel tagLabel = new ScopedLabel(tenantOwner.toString(), tagName);
tagSet.add(tagLabel);
_dbClient.updateAndReindexObject(vol);
if (isV1Call != null) {
_log.debug("Inside V1 call");
return CinderApiUtils.getCinderResponse(getVolumeDetail(vol, isV1Call, openstackTenantId), header, true, CinderConstants.STATUS_OK);
} else {
return CinderApiUtils.getCinderResponse(getVolumeDetail(vol, isV1Call, openstackTenantId), header, true, CinderConstants.STATUS_ACCEPT);
}
} else {
throw APIException.badRequests.parameterIsNullOrEmpty("Volume");
}
}
}
return CinderApiUtils.getCinderResponse(new VolumeDetail(), header, true, CinderConstants.STATUS_ACCEPT);
}
use of com.emc.storageos.cinder.model.VolumeDetail in project coprhd-controller by CoprHD.
the class VolumeService method getVolume.
/**
* Get the details of a specific volume
*
* @prereq none
*
* @param tenant_id the URN of the tenant
* @param volume_id the URN of the volume
*
* @brief Show volume
* @return Volume details
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{volume_id}")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public Response getVolume(@PathParam("tenant_id") String openstackTenantId, @PathParam("volume_id") String volumeId, @HeaderParam("X-Cinder-V1-Call") String isV1Call, @Context HttpHeaders header) {
VolumeDetail response = new VolumeDetail();
if (volumeId == null) {
_log.info("Volume id is empty ");
return CinderApiUtils.createErrorResponse(404, "Not Found : volume id is empty");
}
Volume vol = findVolume(volumeId, openstackTenantId);
if (vol != null) {
response = getVolumeDetail(vol, isV1Call, openstackTenantId);
} else {
_log.info("Invalid volume id ={} ", volumeId);
return CinderApiUtils.createErrorResponse(404, "Not Found : Invalid volume id");
}
return CinderApiUtils.getCinderResponse(response, header, true, STATUS_OK);
}
Aggregations