bug 10046: size in diskofferingVO is in type now

status 10046: resolved fixed
This commit is contained in:
anthony 2011-05-26 13:48:10 -07:00
parent 82ab4fcde4
commit 7a266b9321
9 changed files with 36 additions and 33 deletions

View File

@ -39,9 +39,7 @@ public interface DiskOffering {
boolean getSystemUse();
String getDisplayText();
long getDiskSizeInBytes();
public String getTags();
public String[] getTagsArray();
@ -51,4 +49,6 @@ public interface DiskOffering {
long getDiskSize();
boolean isCustomized();
void setDiskSize(long diskSize);
}

View File

@ -202,12 +202,8 @@ public class DiskOfferingVO implements DiskOffering {
public long getDiskSize(){
return diskSize;
}
@Override
public long getDiskSizeInBytes() {
return diskSize * 1024 * 1024;
}
@Override
public void setDiskSize(long diskSize) {
this.diskSize = diskSize;
}

View File

@ -362,7 +362,7 @@ public class ApiResponseHelper implements ResponseGenerator {
diskOfferingResponse.setName(offering.getName());
diskOfferingResponse.setDisplayText(offering.getDisplayText());
diskOfferingResponse.setCreated(offering.getCreated());
diskOfferingResponse.setDiskSize(offering.getDiskSize() / 1024);
diskOfferingResponse.setDiskSize(offering.getDiskSize() / (1024 * 1024 * 1024));
if (offering.getDomainId() != null) {
diskOfferingResponse.setDomain(ApiDBUtils.findDomainById(offering.getDomainId()).getName());
diskOfferingResponse.setDomainId(offering.getDomainId());

View File

@ -1589,7 +1589,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
}
if (numGibibytes != null) {
diskSize = numGibibytes * 1024;
diskSize = numGibibytes * 1024 * 1024 * 1024;
}
if (diskSize == 0) {

View File

@ -795,7 +795,8 @@ public class ConfigurationServerImpl implements ConfigurationServer {
}
private DiskOfferingVO createDiskOffering(Long domainId, String name, String description, int numGibibytes, String tags) {
long diskSize = numGibibytes * 1024;
long diskSize = numGibibytes;
diskSize = diskSize * 1024 * 1024 * 1024;
tags = cleanupTags(tags);
DiskOfferingVO newDiskOffering = new DiskOfferingVO(domainId, name, description, diskSize,tags,false);

View File

@ -446,7 +446,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
return new DiskProfile(volume.getId(), volume.getVolumeType(), volume.getName(), diskOffering.getId(), ss.getSize(), diskOffering.getTagsArray(), diskOffering.getUseLocalStorage(),
diskOffering.isRecreatable(), Storage.ImageFormat.ISO != template.getFormat() ? template.getId() : null);
} else {
return new DiskProfile(volume.getId(), volume.getVolumeType(), volume.getName(), diskOffering.getId(), diskOffering.getDiskSizeInBytes(), diskOffering.getTagsArray(),
return new DiskProfile(volume.getId(), volume.getVolumeType(), volume.getName(), diskOffering.getId(), diskOffering.getDiskSize(), diskOffering.getTagsArray(),
diskOffering.getUseLocalStorage(), diskOffering.isRecreatable(), null);
}
}
@ -662,7 +662,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
final HashSet<StoragePool> avoidPools = new HashSet<StoragePool>(avoids);
if (diskOffering != null && diskOffering.isCustomized()) {
diskOffering.setDiskSize(size / (1024 * 1024));
diskOffering.setDiskSize(size);
}
DiskProfile dskCh = null;
if (volume.getVolumeType() == Type.ROOT && Storage.ImageFormat.ISO != template.getFormat()) {
@ -1457,7 +1457,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
// Find a destination storage pool with the specified criteria
DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
DiskProfile dskCh = new DiskProfile(volume.getId(), volume.getVolumeType(), volume.getName(), diskOffering.getId(), diskOffering.getDiskSizeInBytes(), diskOffering.getTagsArray(),
DiskProfile dskCh = new DiskProfile(volume.getId(), volume.getVolumeType(), volume.getName(), diskOffering.getId(), diskOffering.getDiskSize(), diskOffering.getTagsArray(),
diskOffering.getUseLocalStorage(), diskOffering.isRecreatable(), null);
dskCh.setHyperType(dataDiskHyperType);
DataCenterVO destPoolDataCenter = _dcDao.findById(destPoolDcId);
@ -1582,7 +1582,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
}
diskOfferingId = cmd.getDiskOfferingId();
size = cmd.getSize();
size = cmd.getSize() * 1024 * 1024 * 1024; // user specify size in GB
if (diskOfferingId == null) {
throw new InvalidParameterValueException("Missing parameter(s),either a positive volume size or a valid disk offering id must be specified.");
}
@ -1605,19 +1605,13 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
} else {
_configMgr.checkDiskOfferingAccess(account, diskOffering);
}
if (!validateVolumeSizeRange(diskOffering.getDiskSize() / 1024)) {// convert size from mb to gb for validation
throw new InvalidParameterValueException("Invalid size for custom volume creation: " + size + " ,max volume size is:" + _maxVolumeSizeInGb);
}
if (diskOffering.getDiskSize() > 0) {
size = (diskOffering.getDiskSize() * 1024 * 1024);// the disk offering size is in MB, which needs to be
// converted into bytes
} else {
if (!validateVolumeSizeRange(size)) {
throw new InvalidParameterValueException("Invalid size for custom volume creation: " + size + " ,max volume size is:" + _maxVolumeSizeInGb);
}
size = (size * 1024 * 1024 * 1024);// custom size entered is in GB, to be converted to bytes
size = diskOffering.getDiskSize();
}
if (!validateVolumeSizeRange(size)) {// convert size from mb to gb for validation
throw new InvalidParameterValueException("Invalid size for custom volume creation: " + size + " ,max volume size is:" + _maxVolumeSizeInGb);
}
} else { // create volume from snapshot
Long snapshotId = cmd.getSnapshotId();
@ -2414,7 +2408,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
}
private boolean validateVolumeSizeRange(long size) {
if (size < 0 || (size > 0 && size < 1)) {
if (size < 0 || (size > 0 && size < (1024 * 1024 * 1024))) {
throw new InvalidParameterValueException("Please specify a size of at least 1 Gb.");
} else if (size > _maxVolumeSizeInGb) {
throw new InvalidParameterValueException("The maximum size allowed is " + _maxVolumeSizeInGb + " Gb.");
@ -2431,7 +2425,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
@Override
public <T extends VMInstanceVO> DiskProfile allocateRawVolume(Type type, String name, DiskOfferingVO offering, Long size, T vm, Account owner) {
if (size == null) {
size = offering.getDiskSizeInBytes();
size = offering.getDiskSize();
} else {
size = (size * 1024 * 1024 * 1024);
}

View File

@ -834,7 +834,8 @@ public class DatabaseConfig {
long domainId = Long.parseLong(_currentObjectParams.get("domainId"));
String name = _currentObjectParams.get("name");
String displayText = _currentObjectParams.get("displayText");
int diskSpace = Integer.parseInt(_currentObjectParams.get("diskSpace"));
long diskSpace = Long.parseLong(_currentObjectParams.get("diskSpace"));
diskSpace = diskSpace * 1024 * 1024;
// boolean mirroring = Boolean.parseBoolean(_currentObjectParams.get("mirrored"));
String tags = _currentObjectParams.get("tags");
String useLocal = _currentObjectParams.get("useLocal");
@ -852,7 +853,7 @@ public class DatabaseConfig {
newTags.delete(newTags.length() - 1, newTags.length());
tags = newTags.toString();
}
DiskOfferingVO diskOffering = new DiskOfferingVO(domainId, name, displayText, diskSpace, tags, false);
DiskOfferingVO diskOffering = new DiskOfferingVO(domainId, name, displayText, diskSpace , tags, false);
diskOffering.setUseLocalStorage(local);
DiskOfferingDaoImpl offering = ComponentLocator.inject(DiskOfferingDaoImpl.class);
try {

View File

@ -25,6 +25,8 @@ import com.cloud.dc.DataCenterVO;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.storage.DiskOfferingVO;
import com.cloud.storage.dao.DiskOfferingDao;
import com.cloud.storage.dao.SnapshotDao;
import com.cloud.utils.component.Inject;
import com.cloud.utils.exception.CloudRuntimeException;
@ -37,6 +39,8 @@ public class Upgrade225to226 implements DbUpgrade {
protected HostDao _hostDao;
@Inject
protected DataCenterDao _dcDao;
@Inject
protected DiskOfferingDao _diskOfferingDao;
@Override
public String[] getUpgradableVersionRange() {
@ -70,6 +74,13 @@ public class Upgrade225to226 implements DbUpgrade {
HostVO host = _hostDao.findSecondaryStorageHost(dc.getId());
_snapshotDao.updateSnapshotSecHost(dc.getId(), host.getId());
}
List<DiskOfferingVO> offerings = _diskOfferingDao.listAll();
for ( DiskOfferingVO offering : offerings ) {
if( offering.getDiskSize() <= 2 * 1024 * 1024) { // the unit is MB
offering.setDiskSize(offering.getDiskSize() * 1024 * 1024);
_diskOfferingDao.update(offering.getId(), offering);
}
}
}
@Override

View File

@ -1118,7 +1118,7 @@ CREATE TABLE `cloud`.`disk_offering` (
`domain_id` bigint unsigned,
`name` varchar(255) NOT NULL,
`display_text` varchar(4096) NULL COMMENT 'Descrianaption text set by the admin for display purpose only',
`disk_size` bigint unsigned NOT NULL COMMENT 'disk space in mbs',
`disk_size` bigint unsigned NOT NULL COMMENT 'disk space in byte',
`type` varchar(32) COMMENT 'inheritted by who?',
`tags` varchar(4096) COMMENT 'comma separated tags about the disk_offering',
`recreatable` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 'The root disk is always recreatable',