making changes for disk offerings with a new column called customized being added, for the UI to cosume whilst deploying vm with an arbitrary volume size. The UI will use this value to set the right size and the offering will ensure the right tags are taken.

This commit is contained in:
abhishek 2010-11-03 17:40:40 -07:00
parent f813808817
commit 2303afe55c
12 changed files with 62 additions and 17 deletions

View File

@ -63,7 +63,7 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
}
public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, NetworkOffering.GuestIpType guestIpType, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse) {
super(name, displayText, false, tags, recreatable, useLocalStorage, systemUse);
super(name, displayText, false, tags, recreatable, useLocalStorage, systemUse,false);
this.cpu = cpu;
this.ramSize = ramSize;
this.speed = speed;

View File

@ -90,10 +90,13 @@ public class DiskOfferingVO implements DiskOffering {
@Column(name="system_use")
private boolean systemUse;
@Column(name="customized")
private boolean customized;
public DiskOfferingVO() {
}
public DiskOfferingVO(long domainId, String name, String displayText, long diskSize, String tags) {
public DiskOfferingVO(long domainId, String name, String displayText, long diskSize, String tags, Boolean isCustomized) {
this.domainId = domainId;
this.name = name;
this.displayText = displayText;
@ -101,10 +104,11 @@ public class DiskOfferingVO implements DiskOffering {
this.tags = tags;
this.recreatable = false;
this.type = Type.Disk;
this.useLocalStorage = false;
this.useLocalStorage = false;
this.customized = isCustomized;
}
public DiskOfferingVO(String name, String displayText, boolean mirrored, String tags, boolean recreatable, boolean useLocalStorage, boolean systemUse) {
public DiskOfferingVO(String name, String displayText, boolean mirrored, String tags, boolean recreatable, boolean useLocalStorage, boolean systemUse, boolean customized) {
this.domainId = null;
this.type = Type.Service;
this.name = name;
@ -114,6 +118,7 @@ public class DiskOfferingVO implements DiskOffering {
this.recreatable = recreatable;
this.useLocalStorage = useLocalStorage;
this.systemUse = systemUse;
this.customized = customized;
}
@Override
@ -121,7 +126,15 @@ public class DiskOfferingVO implements DiskOffering {
return id;
}
@Override
public boolean isCustomized() {
return customized;
}
public void setCustomized(boolean customized) {
this.customized = customized;
}
@Override
public String getUniqueName() {
return uniqueName;
}

View File

@ -39,6 +39,7 @@ public class ApiConstants {
public static final String CPU_NUMBER = "cpunumber";
public static final String CPU_SPEED = "cpuspeed";
public static final String CREATED = "created";
public static final String CUSTOMIZED = "customized";
public static final String DESCRIPTION = "description";
public static final String DESTINATION_ZONE_ID = "destzoneid";
public static final String DETAILS = "details";

View File

@ -246,6 +246,7 @@ public class ApiResponseHelper {
diskOfferingResponse.setDomainId(offering.getDomainId());
}
diskOfferingResponse.setTags(offering.getTags());
diskOfferingResponse.setCustomized(offering.isCustomized());
return diskOfferingResponse;
}

View File

@ -39,7 +39,7 @@ public class CreateDiskOfferingCmd extends BaseCmd {
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.DISK_SIZE, type=CommandType.LONG, required=true, description="disk size of the disk offering in GB")
@Parameter(name=ApiConstants.DISK_SIZE, type=CommandType.LONG, description="disk size of the disk offering in GB")
private Long diskSize;
@Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="alternate display text of the disk offering")
@ -54,6 +54,8 @@ public class CreateDiskOfferingCmd extends BaseCmd {
@Parameter(name=ApiConstants.TAGS, type=CommandType.STRING, description="tags for the disk offering")
private String tags;
@Parameter(name=ApiConstants.CUSTOMIZED, type=CommandType.BOOLEAN, description="whether disk offering is custom or not")
private Boolean customized;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -78,6 +80,10 @@ public class CreateDiskOfferingCmd extends BaseCmd {
return tags;
}
public Boolean isCustomized(){
return customized;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////

View File

@ -48,6 +48,9 @@ public class DiskOfferingResponse extends BaseResponse {
@SerializedName("ismirrored")
private Boolean mirrored;
@SerializedName("isCustomized")
private Boolean customized;
@SerializedName(ApiConstants.TAGS) @Param(description="the tags for the disk offering")
private String tags;
@ -122,4 +125,13 @@ public class DiskOfferingResponse extends BaseResponse {
public void setTags(String tags) {
this.tags = tags;
}
public Boolean isCustomized() {
return customized;
}
public void setCustomized(Boolean customized) {
this.customized = customized;
}
}

View File

@ -147,9 +147,10 @@ public interface ConfigurationManager extends Manager {
* @param description
* @param numGibibytes
* @param tags
* @param isCustomized
* @return newly created disk offering
*/
DiskOfferingVO createDiskOffering(long domainId, String name, String description, int numGibibytes, String tags);
DiskOfferingVO createDiskOffering(long domainId, String name, String description, Long numGibibytes, String tags, Boolean isCustomized);
/**
* Creates a new pod

View File

@ -1171,16 +1171,20 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
}
@Override
public DiskOfferingVO createDiskOffering(long domainId, String name, String description, int numGibibytes, String tags) throws InvalidParameterValueException {
if ((numGibibytes <= 0)) {
public DiskOfferingVO createDiskOffering(long domainId, String name, String description, Long numGibibytes, String tags, Boolean isCustomized) throws InvalidParameterValueException {
long diskSize = 0;//special case for custom disk offerings
if (numGibibytes != null && (numGibibytes <= 0)) {
throw new InvalidParameterValueException("Please specify a disk size of at least 1 Gb.");
} else if (numGibibytes > _maxVolumeSizeInGb) {
} else if (numGibibytes != null && (numGibibytes > _maxVolumeSizeInGb)) {
throw new InvalidParameterValueException("The maximum size for a disk is " + _maxVolumeSizeInGb + " Gb.");
}
long diskSize = numGibibytes * 1024;
if(numGibibytes != null){
diskSize = numGibibytes * 1024;
}
tags = cleanupTags(tags);
DiskOfferingVO newDiskOffering = new DiskOfferingVO(domainId, name, description, diskSize,tags);
DiskOfferingVO newDiskOffering = new DiskOfferingVO(domainId, name, description, diskSize,tags, isCustomized);
return _diskOfferingDao.persist(newDiskOffering);
}
@ -1189,14 +1193,15 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
Long domainId = cmd.getDomainId();
String name = cmd.getOfferingName();
String description = cmd.getDisplayText();
int numGibibytes = cmd.getDiskSize().intValue();
Long numGibibytes = cmd.getDiskSize();
Boolean isCustomized = cmd.isCustomized() != null ? cmd.isCustomized() : false; //false by default
String tags = cmd.getTags();
if (domainId == null) {
domainId = Long.valueOf(DomainVO.ROOT_DOMAIN);
}
return createDiskOffering(domainId, name, description, numGibibytes, tags);
return createDiskOffering(domainId, name, description, numGibibytes, tags, isCustomized);
}
@Override

View File

@ -643,7 +643,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
long diskSize = numGibibytes * 1024;
tags = cleanupTags(tags);
DiskOfferingVO newDiskOffering = new DiskOfferingVO(domainId, name, description, diskSize,tags);
DiskOfferingVO newDiskOffering = new DiskOfferingVO(domainId, name, description, diskSize,tags,false);
return _diskOfferingDao.persist(newDiskOffering);
}

View File

@ -1860,11 +1860,16 @@ public class ManagementServerImpl implements ManagementServer {
if (diskOfferingId != null) {
diskOffering = _diskOfferingDao.findById(diskOfferingId);
}
if (isIso && diskOffering == null) {
throw new InvalidParameterValueException("Please specify a valid disk offering ID.");
}
//if it is a custom disk offering,AND the size passed in here is <= 0; error out
if(diskOffering.isCustomized() && size <= 0){
throw new InvalidParameterValueException("Please specify a valid disk size for VM creation; custom disk offering has no size set");
}
// validate that the template is usable by the account
if (!template.isPublicTemplate()) {
Long templateOwner = template.getAccountId();

View File

@ -798,7 +798,7 @@ public class DatabaseConfig {
newTags.delete(newTags.length() - 1, newTags.length());
tags = newTags.toString();
}
DiskOfferingVO diskOffering = new DiskOfferingVO(domainId, name, displayText, diskSpace, tags);
DiskOfferingVO diskOffering = new DiskOfferingVO(domainId, name, displayText, diskSpace, tags, false);
diskOffering.setUseLocalStorage(local);
DiskOfferingDaoImpl offering = ComponentLocator.inject(DiskOfferingDaoImpl.class);
try {

View File

@ -887,6 +887,7 @@ CREATE TABLE `cloud`.`disk_offering` (
`use_local_storage` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 'Indicates whether local storage pools should be used',
`unique_name` varchar(32) UNIQUE COMMENT 'unique name',
`system_use` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 'is this offering for system used only',
`customized` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT '0 implies not customized by default',
`removed` datetime COMMENT 'date removed',
`created` datetime COMMENT 'date the disk offering was created',
PRIMARY KEY (`id`)