use of org.apache.cloudstack.api.response.VolumeResponse in project cloudstack by apache.
the class VolumeJoinDaoImpl method newVolumeResponse.
@Override
public VolumeResponse newVolumeResponse(ResponseView view, VolumeJoinVO volume) {
VolumeResponse volResponse = new VolumeResponse();
volResponse.setId(volume.getUuid());
if (volume.getName() != null) {
volResponse.setName(volume.getName());
} else {
volResponse.setName("");
}
volResponse.setZoneId(volume.getDataCenterUuid());
volResponse.setZoneName(volume.getDataCenterName());
if (volume.getVolumeType() != null) {
volResponse.setVolumeType(volume.getVolumeType().toString());
}
volResponse.setDeviceId(volume.getDeviceId());
long instanceId = volume.getVmId();
if (instanceId > 0 && volume.getState() != Volume.State.Destroy) {
volResponse.setVirtualMachineId(volume.getVmUuid());
volResponse.setVirtualMachineName(volume.getVmName());
if (volume.getVmState() != null) {
volResponse.setVirtualMachineState(volume.getVmState().toString());
}
if (volume.getVmDisplayName() != null) {
volResponse.setVirtualMachineDisplayName(volume.getVmDisplayName());
} else {
volResponse.setVirtualMachineDisplayName(volume.getVmName());
}
}
if (volume.getProvisioningType() != null) {
volResponse.setProvisioningType(volume.getProvisioningType().toString());
}
// Show the virtual size of the volume
volResponse.setSize(volume.getSize());
volResponse.setMinIops(volume.getMinIops());
volResponse.setMaxIops(volume.getMaxIops());
volResponse.setCreated(volume.getCreated());
if (volume.getState() != null) {
volResponse.setState(volume.getState().toString());
}
if (volume.getState() == Volume.State.UploadOp) {
// com.cloud.storage.VolumeHostVO volumeHostRef =
// ApiDBUtils.findVolumeHostRef(volume.getId(),
// volume.getDataCenterId());
volResponse.setSize(volume.getVolumeStoreSize());
volResponse.setCreated(volume.getCreatedOnStore());
if (view == ResponseView.Full)
volResponse.setHypervisor(ApiDBUtils.getHypervisorTypeFromFormat(volume.getDataCenterId(), volume.getFormat()).toString());
if (volume.getDownloadState() != Status.DOWNLOADED) {
String volumeStatus = "Processing";
if (volume.getDownloadState() == VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS) {
if (volume.getDownloadPercent() == 100) {
volumeStatus = "Checking Volume";
} else {
volumeStatus = volume.getDownloadPercent() + "% Uploaded";
}
volResponse.setState("Uploading");
} else {
volumeStatus = volume.getErrorString();
if (volume.getDownloadState() == VMTemplateHostVO.Status.NOT_DOWNLOADED) {
volResponse.setState("UploadNotStarted");
} else {
volResponse.setState("UploadError");
}
}
volResponse.setStatus(volumeStatus);
} else if (volume.getDownloadState() == VMTemplateHostVO.Status.DOWNLOADED) {
volResponse.setStatus("Upload Complete");
volResponse.setState("Uploaded");
} else {
volResponse.setStatus("Successfully Installed");
}
}
if (view == ResponseView.Full) {
volResponse.setPath(volume.getPath());
}
// populate owner.
ApiResponseHelper.populateOwner(volResponse, volume);
// ApiDBUtils.findDiskOfferingById(volume.getDiskOfferingId());
if (volume.getDiskOfferingId() > 0) {
boolean isServiceOffering = false;
if (volume.getVolumeType().equals(Volume.Type.ROOT)) {
isServiceOffering = true;
} else {
// can't rely on the fact that the volume is the datadisk as it might have been created as a root, and
// then detached later
long offeringId = volume.getDiskOfferingId();
if (ApiDBUtils.findDiskOfferingById(offeringId) == null) {
isServiceOffering = true;
}
}
if (isServiceOffering) {
volResponse.setServiceOfferingId(volume.getDiskOfferingUuid());
volResponse.setServiceOfferingName(volume.getDiskOfferingName());
volResponse.setServiceOfferingDisplayText(volume.getDiskOfferingDisplayText());
} else {
volResponse.setDiskOfferingId(volume.getDiskOfferingUuid());
volResponse.setDiskOfferingName(volume.getDiskOfferingName());
volResponse.setDiskOfferingDisplayText(volume.getDiskOfferingDisplayText());
}
volResponse.setStorageType(volume.isUseLocalStorage() ? ServiceOffering.StorageType.local.toString() : ServiceOffering.StorageType.shared.toString());
volResponse.setBytesReadRate(volume.getBytesReadRate());
volResponse.setBytesWriteRate(volume.getBytesReadRate());
volResponse.setIopsReadRate(volume.getIopsWriteRate());
volResponse.setIopsWriteRate(volume.getIopsWriteRate());
}
// return hypervisor and storage pool info for ROOT and Resource domain only
if (view == ResponseView.Full) {
if (volume.getState() != Volume.State.UploadOp) {
if (volume.getHypervisorType() != null) {
volResponse.setHypervisor(volume.getHypervisorType().toString());
} else {
volResponse.setHypervisor(ApiDBUtils.getHypervisorTypeFromFormat(volume.getDataCenterId(), volume.getFormat()).toString());
}
}
Long poolId = volume.getPoolId();
String poolName = (poolId == null) ? "none" : volume.getPoolName();
volResponse.setStoragePoolName(poolName);
volResponse.setStoragePoolId(volume.getPoolUuid());
}
volResponse.setAttached(volume.getAttached());
volResponse.setDestroyed(volume.getState() == Volume.State.Destroy);
boolean isExtractable = true;
if (volume.getVolumeType() != Volume.Type.DATADISK) {
// dependence.
if (volume.getTemplateId() > 0) {
// For ISO based volumes template
// = null and we allow extraction
// of all ISO based volumes
isExtractable = volume.isExtractable() && volume.getTemplateType() != Storage.TemplateType.SYSTEM;
}
}
// update tag information
long tag_id = volume.getTagId();
if (tag_id > 0) {
addTagInformation(volume, volResponse);
}
volResponse.setExtractable(isExtractable);
volResponse.setDisplayVolume(volume.isDisplayVolume());
volResponse.setChainInfo(volume.getChainInfo());
volResponse.setTemplateId(volume.getTemplateUuid());
volResponse.setTemplateName(volume.getTemplateName());
volResponse.setTemplateDisplayText(volume.getTemplateDisplayText());
volResponse.setIsoId(volume.getIsoUuid());
volResponse.setIsoName(volume.getIsoName());
volResponse.setIsoDisplayText(volume.getIsoDisplayText());
// set async job
if (volume.getJobId() != null) {
volResponse.setJobId(volume.getJobUuid());
volResponse.setJobStatus(volume.getJobStatus());
}
volResponse.setObjectName("volume");
return volResponse;
}
use of org.apache.cloudstack.api.response.VolumeResponse in project cloudstack by apache.
the class CreateVolumeCmdByAdmin method execute.
@Override
public void execute() {
CallContext.current().setEventDetails("Volume Id: " + getEntityId() + ((getSnapshotId() == null) ? "" : " from snapshot: " + getSnapshotId()));
Volume volume = _volumeService.createVolume(this);
if (volume != null) {
VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, volume);
//FIXME - have to be moved to ApiResponseHelper
if (getSnapshotId() != null) {
Snapshot snap = _entityMgr.findById(Snapshot.class, getSnapshotId());
if (snap != null) {
// if the volume was
response.setSnapshotId(snap.getUuid());
// created from a
// snapshot,
// snapshotId will
// be set so we pass
// it back in the
// response
}
}
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a volume");
}
}
use of org.apache.cloudstack.api.response.VolumeResponse in project cloudstack by apache.
the class MigrateVolumeCmdByAdmin method execute.
@Override
public void execute() {
Volume result;
result = _volumeService.migrateVolume(this);
if (result != null) {
VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, result);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to migrate volume");
}
}
use of org.apache.cloudstack.api.response.VolumeResponse in project cloudstack by apache.
the class UpdateVolumeCmdByAdmin method execute.
@Override
public void execute() {
CallContext.current().setEventDetails("Volume Id: " + getId());
Volume result = _volumeService.updateVolume(getId(), getPath(), getState(), getStorageId(), getDisplayVolume(), getCustomId(), getEntityOwnerId(), getChainInfo());
if (result != null) {
VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, result);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update volume");
}
}
use of org.apache.cloudstack.api.response.VolumeResponse in project cloudstack by apache.
the class ResizeVolumeCmd method execute.
@Override
public void execute() throws ResourceAllocationException {
Volume volume = null;
try {
CallContext.current().setEventDetails("Volume Id: " + getEntityId() + " to size " + getSize() + "G");
volume = _volumeService.resizeVolume(this);
} catch (InvalidParameterValueException ex) {
s_logger.info(ex.getMessage());
throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, ex.getMessage());
}
if (volume != null) {
VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Restricted, volume);
//FIXME - have to be moved to ApiResponseHelper
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to resize volume");
}
}
Aggregations