bug 7553: Virtual Router service offering

This commit is contained in:
Abhinandan Prateek 2011-05-19 16:59:23 +05:30 committed by root
parent 9de370be61
commit 770e317218
16 changed files with 108 additions and 12 deletions

View File

@ -111,6 +111,7 @@ public class ApiConstants {
public static final String NEW_NAME = "newname";
public static final String NUM_RETRIES = "numretries";
public static final String OFFER_HA = "offerha";
public static final String IS_SYSTEM_OFFERING = "issystem";
public static final String OP = "op";
public static final String OS_CATEGORY_ID = "oscategoryid";
public static final String OS_TYPE_ID = "ostypeid";

View File

@ -71,6 +71,9 @@ public class CreateServiceOfferingCmd extends BaseCmd {
@Parameter(name=ApiConstants.HOST_TAGS, type=CommandType.STRING, description="the host tag for this service offering.")
private String hostTag;
@Parameter(name=ApiConstants.IS_SYSTEM_OFFERING, type=CommandType.BOOLEAN, description="is this a system vm offering")
private Boolean isSystem;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -118,7 +121,12 @@ public class CreateServiceOfferingCmd extends BaseCmd {
public String getHostTag() {
return hostTag;
}
}
public Boolean getIsSystem() {
return isSystem == null ? false : isSystem;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////

View File

@ -53,6 +53,11 @@ public class ListServiceOfferingsCmd extends BaseListCmd {
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the ID of the domain associated with the service offering")
private Long domainId;
@Parameter(name=ApiConstants.IS_SYSTEM_OFFERING, type=CommandType.BOOLEAN, description="is this a system vm offering")
private Boolean isSystem;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -72,6 +77,11 @@ public class ListServiceOfferingsCmd extends BaseListCmd {
public Long getDomainId(){
return domainId;
}
public Boolean getIsSystem() {
return isSystem == null ? false : isSystem;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////

View File

@ -20,6 +20,8 @@ package com.cloud.api.response;
import java.util.Date;
import com.cloud.api.ApiConstants;
import com.cloud.api.Parameter;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
@ -64,7 +66,11 @@ public class ServiceOfferingResponse extends BaseResponse {
private String domain;
@SerializedName(ApiConstants.HOST_TAGS) @Param(description="the host tag for the service offering")
private String hostTag;
private String hostTag;
@Parameter(name=ApiConstants.IS_SYSTEM_OFFERING, type=CommandType.BOOLEAN, description="is this a system vm offering")
private Boolean isSystem;
public Long getId() {
return id;
@ -81,6 +87,15 @@ public class ServiceOfferingResponse extends BaseResponse {
public void setName(String name) {
this.name = name;
}
public Boolean getIsSystem() {
return isSystem;
}
public void setIsSystemOffering(Boolean isSystem) {
this.isSystem = isSystem;
}
public String getDisplayText() {
return displayText;

View File

@ -36,7 +36,8 @@ public class EventTypes {
public static final String EVENT_ROUTER_START = "ROUTER.START";
public static final String EVENT_ROUTER_STOP = "ROUTER.STOP";
public static final String EVENT_ROUTER_REBOOT = "ROUTER.REBOOT";
public static final String EVENT_ROUTER_HA = "ROUTER.HA";
public static final String EVENT_ROUTER_HA = "ROUTER.HA";
public static final String EVENT_ROUTER_UPGRADE = "ROUTER.UPGRADE";
// Console proxy
public static final String EVENT_PROXY_CREATE = "PROXY.CREATE";

View File

@ -32,6 +32,12 @@ public interface ServiceOffering {
String getTags();
/**
* @return Is this a system VM offering?
*/
boolean getIsSystem();
/**
* @return user readable description
*/

View File

@ -497,5 +497,5 @@ public interface ManagementService {
* @return Pair<List<? extends Host>, List<Long>> List of all Hosts in VM's cluster and list of HostIds with enough capacity
*/
Pair<List<? extends Host>, List<Long>> listHostsForMigrationOfVM(UserVm vm, Long startIndex, Long pageSize);
}

View File

@ -401,6 +401,7 @@ public class ApiResponseHelper implements ResponseGenerator {
ServiceOfferingResponse offeringResponse = new ServiceOfferingResponse();
offeringResponse.setId(offering.getId());
offeringResponse.setName(offering.getName());
offeringResponse.setIsSystemOffering(offering.getIsSystem());
offeringResponse.setDisplayText(offering.getDisplayText());
offeringResponse.setCpuNumber(offering.getCpu());
offeringResponse.setCpuSpeed(offering.getSpeed());

View File

@ -70,7 +70,7 @@ public interface ConfigurationManager extends ConfigurationService, Manager {
* @param hostTag
* @return ID
*/
ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean limitResourceUse, String tags, Long domainId, String hostTag);
ServiceOfferingVO createServiceOffering(long userId, boolean isSystem, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean limitResourceUse, String tags, Long domainId, String hostTag);
/**
* Creates a new disk offering

View File

@ -1470,7 +1470,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
throw new InvalidParameterValueException("Please specify a valid domain id");
}
}
boolean localStorageRequired = false;
String storageType = cmd.getStorageType();
if (storageType == null) {
@ -1493,16 +1493,16 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
limitCpuUse = false;
}
return createServiceOffering(userId, cmd.getServiceOfferingName(), cpuNumber.intValue(), memory.intValue(), cpuSpeed.intValue(), cmd.getDisplayText(), localStorageRequired, offerHA,
return createServiceOffering(userId, cmd.getIsSystem(), cmd.getServiceOfferingName(), cpuNumber.intValue(), memory.intValue(), cpuSpeed.intValue(), cmd.getDisplayText(), localStorageRequired, offerHA,
limitCpuUse, cmd.getTags(), cmd.getDomainId(), cmd.getHostTag());
}
@Override
@ActionEvent(eventType = EventTypes.EVENT_SERVICE_OFFERING_CREATE, eventDescription = "creating service offering")
public ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean limitResourceUse, String tags,
public ServiceOfferingVO createServiceOffering(long userId, boolean isSystem, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean limitResourceUse, String tags,
Long domainId, String hostTag) {
tags = cleanupTags(tags);
ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, null, null, offerHA, limitResourceUse, displayText, localStorageRequired, false, tags, false, domainId, hostTag);
ServiceOfferingVO offering = new ServiceOfferingVO(name, isSystem, cpu, ramSize, speed, null, null, offerHA, limitResourceUse, displayText, localStorageRequired, false, tags, false, domainId, hostTag);
if ((offering = _serviceOfferingDao.persist(offering)) != null) {
UserContext.current().setEventDetails("Service offering id=" + offering.getId());

View File

@ -59,6 +59,9 @@ public class ServiceOffering21VO extends DiskOffering21VO implements ServiceOffe
@Column(name="host_tag")
private String hostTag;
@Column(name="is_system")
private boolean isSystem=false;
protected ServiceOffering21VO() {
super();
@ -78,6 +81,12 @@ public class ServiceOffering21VO extends DiskOffering21VO implements ServiceOffe
public ServiceOffering21VO(String name, int cpu, int ramSize, int speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, String displayText, Network.GuestIpType guestIpType, boolean useLocalStorage, boolean recreatable, String tags, String hostTag) {
this(name, cpu, ramSize, speed, rateMbps, multicastRateMbps, offerHA, displayText, guestIpType, useLocalStorage, recreatable, tags);
this.hostTag = hostTag;
}
@Override
public boolean getIsSystem() {
return isSystem;
}
@Override

View File

@ -355,6 +355,11 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
if (newServiceOffering == null) {
throw new InvalidParameterValueException("Unable to find service offering with id " + serviceOfferingId);
}
// check if it is a system service offering, if yes return with error as it cannot be used for user vms
if (!newServiceOffering.getIsSystem()) {
throw new InvalidParameterValueException("Cannot upgrade router vm to a non system service offering " + serviceOfferingId);
}
// Check that the router is stopped
if (!router.getState().equals(State.Stopped)) {
@ -364,7 +369,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
}
ServiceOfferingVO currentServiceOffering = _serviceOfferingDao.findById(router.getServiceOfferingId());
// Check that the service offering being upgraded to has the same storage pool preference as the VM's current service
// offering
if (currentServiceOffering.getUseLocalStorage() != newServiceOffering.getUseLocalStorage()) {
throw new InvalidParameterValueException("Can't upgrade, due to new local storage status : " + newServiceOffering.getUseLocalStorage() + " is different from "
+ "curruent local storage status: " + currentServiceOffering.getUseLocalStorage());

View File

@ -56,6 +56,9 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
@Column(name="host_tag")
private String hostTag;
@Column(name="is_system")
private boolean isSystem;
protected ServiceOfferingVO() {
super();
@ -86,7 +89,24 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, boolean limitResourceUse, String displayText, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse, Long domainId, String hostTag) {
this(name, cpu, ramSize, speed, rateMbps, multicastRateMbps, offerHA, limitResourceUse, displayText, useLocalStorage, recreatable, tags, systemUse, domainId);
this.hostTag = hostTag;
}
}
public ServiceOfferingVO(String name, boolean isSystem, int cpu, int ramSize, int speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, boolean limitResourceUse, String displayText, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse, Long domainId, String hostTag) {
this(name, cpu, ramSize, speed, rateMbps, multicastRateMbps, offerHA, limitResourceUse, displayText, useLocalStorage, recreatable, tags, systemUse, domainId);
this.hostTag = hostTag;
this.isSystem = isSystem;
}
@Override
public boolean getIsSystem() {
return isSystem;
}
public void setIsSystemOffering(boolean isSystem) {
this.isSystem = isSystem;
}
@Override
public boolean getOfferHA() {

View File

@ -30,5 +30,6 @@ public interface ServiceOfferingDao extends GenericDao<ServiceOfferingVO, Long>
ServiceOfferingVO findByName(String name);
ServiceOfferingVO persistSystemServiceOffering(ServiceOfferingVO vo);
List<ServiceOfferingVO> findPublicServiceOfferings();
List<ServiceOfferingVO> findServiceOfferingByDomainId(Long domainId);
List<ServiceOfferingVO> findServiceOfferingByDomainId(Long domainId);
List<ServiceOfferingVO> findServiceOfferingByDomainIdAndIsSystem(Long domainId, Boolean isSystem);
}

View File

@ -37,6 +37,7 @@ public class ServiceOfferingDaoImpl extends GenericDaoBase<ServiceOfferingVO, Lo
protected final SearchBuilder<ServiceOfferingVO> UniqueNameSearch;
protected final SearchBuilder<ServiceOfferingVO> ServiceOfferingsByDomainIdSearch;
protected final SearchBuilder<ServiceOfferingVO> ServiceOfferingsByDomainIdAndIsSystemSearch;
protected final SearchBuilder<ServiceOfferingVO> ServiceOfferingsByKeywordSearch;
protected final SearchBuilder<ServiceOfferingVO> PublicServiceOfferingSearch;
@ -52,6 +53,12 @@ public class ServiceOfferingDaoImpl extends GenericDaoBase<ServiceOfferingVO, Lo
ServiceOfferingsByDomainIdSearch.and("domainId", ServiceOfferingsByDomainIdSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
ServiceOfferingsByDomainIdSearch.done();
ServiceOfferingsByDomainIdAndIsSystemSearch = createSearchBuilder();
ServiceOfferingsByDomainIdAndIsSystemSearch.and("domainId", ServiceOfferingsByDomainIdAndIsSystemSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
ServiceOfferingsByDomainIdAndIsSystemSearch.and("isSystem", ServiceOfferingsByDomainIdAndIsSystemSearch.entity().getIsSystem(), SearchCriteria.Op.EQ);
ServiceOfferingsByDomainIdAndIsSystemSearch.done();
PublicServiceOfferingSearch = createSearchBuilder();
PublicServiceOfferingSearch.and("domainId", PublicServiceOfferingSearch.entity().getDomainId(), SearchCriteria.Op.NULL);
PublicServiceOfferingSearch.and("system", PublicServiceOfferingSearch.entity().isSystemUse(), SearchCriteria.Op.EQ);
@ -103,6 +110,15 @@ public class ServiceOfferingDaoImpl extends GenericDaoBase<ServiceOfferingVO, Lo
return listBy(sc);
}
@Override
public List<ServiceOfferingVO> findServiceOfferingByDomainIdAndIsSystem(Long domainId, Boolean isSystem){
SearchCriteria<ServiceOfferingVO> sc = ServiceOfferingsByDomainIdAndIsSystemSearch.create();
sc.setParameters("domainId", domainId);
sc.setParameters("isSystem", isSystem);
return listBy(sc);
}
@Override
public List<ServiceOfferingVO> findPublicServiceOfferings(){
SearchCriteria<ServiceOfferingVO> sc = PublicServiceOfferingSearch.create();

View File

@ -1122,6 +1122,7 @@ CREATE TABLE `cloud`.`disk_offering` (
CREATE TABLE `cloud`.`service_offering` (
`id` bigint unsigned NOT NULL,
`is_system` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 'is a system vm offering',
`cpu` int(10) unsigned NOT NULL COMMENT '# of cores',
`speed` int(10) unsigned NOT NULL COMMENT 'speed per core in mhz',
`ram_size` bigint unsigned NOT NULL,