diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index a3e6e5365ab..3781748771e 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -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"; diff --git a/api/src/com/cloud/api/commands/CreateServiceOfferingCmd.java b/api/src/com/cloud/api/commands/CreateServiceOfferingCmd.java index 00cacff8f2b..d80baac80e2 100644 --- a/api/src/com/cloud/api/commands/CreateServiceOfferingCmd.java +++ b/api/src/com/cloud/api/commands/CreateServiceOfferingCmd.java @@ -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/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/com/cloud/api/commands/ListServiceOfferingsCmd.java b/api/src/com/cloud/api/commands/ListServiceOfferingsCmd.java index a6aa8cbdf6d..320f21434e4 100644 --- a/api/src/com/cloud/api/commands/ListServiceOfferingsCmd.java +++ b/api/src/com/cloud/api/commands/ListServiceOfferingsCmd.java @@ -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/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/com/cloud/api/response/ServiceOfferingResponse.java b/api/src/com/cloud/api/response/ServiceOfferingResponse.java index 640b1e017ab..ad5634d7612 100644 --- a/api/src/com/cloud/api/response/ServiceOfferingResponse.java +++ b/api/src/com/cloud/api/response/ServiceOfferingResponse.java @@ -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; diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java index 8684585d631..4c1d5c76622 100755 --- a/api/src/com/cloud/event/EventTypes.java +++ b/api/src/com/cloud/event/EventTypes.java @@ -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"; diff --git a/api/src/com/cloud/offering/ServiceOffering.java b/api/src/com/cloud/offering/ServiceOffering.java index d15c1151b5b..561a8649658 100755 --- a/api/src/com/cloud/offering/ServiceOffering.java +++ b/api/src/com/cloud/offering/ServiceOffering.java @@ -32,6 +32,12 @@ public interface ServiceOffering { String getTags(); + + /** + * @return Is this a system VM offering? + */ + boolean getIsSystem(); + /** * @return user readable description */ diff --git a/api/src/com/cloud/server/ManagementService.java b/api/src/com/cloud/server/ManagementService.java index b8e134392bc..3cef9faa9e0 100644 --- a/api/src/com/cloud/server/ManagementService.java +++ b/api/src/com/cloud/server/ManagementService.java @@ -497,5 +497,5 @@ public interface ManagementService { * @return Pair, List> List of all Hosts in VM's cluster and list of HostIds with enough capacity */ Pair, List> listHostsForMigrationOfVM(UserVm vm, Long startIndex, Long pageSize); - + } diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 7157640c86a..3a6d6199600 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -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()); diff --git a/server/src/com/cloud/configuration/ConfigurationManager.java b/server/src/com/cloud/configuration/ConfigurationManager.java index ae1850beff9..562c8b4e363 100644 --- a/server/src/com/cloud/configuration/ConfigurationManager.java +++ b/server/src/com/cloud/configuration/ConfigurationManager.java @@ -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 diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index a55816aaf27..1677ed86c36 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -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()); diff --git a/server/src/com/cloud/migration/ServiceOffering21VO.java b/server/src/com/cloud/migration/ServiceOffering21VO.java index b431f19307f..1745e80c20f 100644 --- a/server/src/com/cloud/migration/ServiceOffering21VO.java +++ b/server/src/com/cloud/migration/ServiceOffering21VO.java @@ -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 diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 05de6edf42c..c1f0692af01 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -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()); diff --git a/server/src/com/cloud/service/ServiceOfferingVO.java b/server/src/com/cloud/service/ServiceOfferingVO.java index ba46638433d..49e29f6b5af 100644 --- a/server/src/com/cloud/service/ServiceOfferingVO.java +++ b/server/src/com/cloud/service/ServiceOfferingVO.java @@ -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() { diff --git a/server/src/com/cloud/service/dao/ServiceOfferingDao.java b/server/src/com/cloud/service/dao/ServiceOfferingDao.java index 9e823c2a01c..316c39094b4 100644 --- a/server/src/com/cloud/service/dao/ServiceOfferingDao.java +++ b/server/src/com/cloud/service/dao/ServiceOfferingDao.java @@ -30,5 +30,6 @@ public interface ServiceOfferingDao extends GenericDao ServiceOfferingVO findByName(String name); ServiceOfferingVO persistSystemServiceOffering(ServiceOfferingVO vo); List findPublicServiceOfferings(); - List findServiceOfferingByDomainId(Long domainId); + List findServiceOfferingByDomainId(Long domainId); + List findServiceOfferingByDomainIdAndIsSystem(Long domainId, Boolean isSystem); } diff --git a/server/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java b/server/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java index 6ae9650adbe..a7bf97c10f9 100644 --- a/server/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java +++ b/server/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java @@ -37,6 +37,7 @@ public class ServiceOfferingDaoImpl extends GenericDaoBase UniqueNameSearch; protected final SearchBuilder ServiceOfferingsByDomainIdSearch; + protected final SearchBuilder ServiceOfferingsByDomainIdAndIsSystemSearch; protected final SearchBuilder ServiceOfferingsByKeywordSearch; protected final SearchBuilder PublicServiceOfferingSearch; @@ -52,6 +53,12 @@ public class ServiceOfferingDaoImpl extends GenericDaoBase findServiceOfferingByDomainIdAndIsSystem(Long domainId, Boolean isSystem){ + SearchCriteria sc = ServiceOfferingsByDomainIdAndIsSystemSearch.create(); + sc.setParameters("domainId", domainId); + sc.setParameters("isSystem", isSystem); + return listBy(sc); + } + @Override public List findPublicServiceOfferings(){ SearchCriteria sc = PublicServiceOfferingSearch.create(); diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 351bbd224a2..777807878f2 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -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,