bug 11260: Take networkRate for domR's guest and public interface from the corresponding system service offering

This commit is contained in:
alena 2011-08-25 14:04:29 -07:00
parent 6164da188c
commit 1c1ef85833
5 changed files with 56 additions and 50 deletions

View File

@ -25,7 +25,6 @@ import com.cloud.api.BaseCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.ServiceOfferingResponse;
import com.cloud.offering.ServiceOffering;
import com.cloud.user.Account;
@ -75,10 +74,10 @@ public class CreateServiceOfferingCmd extends BaseCmd {
@Parameter(name=ApiConstants.IS_SYSTEM_OFFERING, type=CommandType.BOOLEAN, description="is this a system vm offering")
private Boolean isSystem;
@Parameter(name=ApiConstants.SYSTEM_VM_TYPE, type=CommandType.STRING, description="the system VM type. Possible types are \"consoleproxy\" and \"secondarystoragevm\".")
@Parameter(name=ApiConstants.SYSTEM_VM_TYPE, type=CommandType.STRING, description="the system VM type. Possible types are \"domainrouter\", \"consoleproxy\" and \"secondarystoragevm\".")
private String systemVmType;
@Parameter(name=ApiConstants.NETWORKRATE, type=CommandType.INTEGER, description="data transfer rate in megabits per second allowed.")
@Parameter(name=ApiConstants.NETWORKRATE, type=CommandType.INTEGER, description="data transfer rate in megabits per second allowed. Supported only for non-System offering and system offerings having \"domainrouter\" systemvmtype")
private Integer networkRate;
/////////////////////////////////////////////////////

View File

@ -24,6 +24,11 @@ import java.util.Date;
* offered.
*/
public interface ServiceOffering {
public enum StorageType {
local,
shared
}
long getId();
String getDisplayText();

View File

@ -433,7 +433,7 @@ public class ApiResponseHelper implements ResponseGenerator {
offeringResponse.setCpuSpeed(offering.getSpeed());
offeringResponse.setMemory(offering.getRamSize());
offeringResponse.setCreated(offering.getCreated());
offeringResponse.setStorageType(offering.getUseLocalStorage() ? "local" : "shared");
offeringResponse.setStorageType(offering.getUseLocalStorage() ? ServiceOffering.StorageType.local.toString() : ServiceOffering.StorageType.shared.toString());
offeringResponse.setOfferHa(offering.getOfferHA());
offeringResponse.setLimitCpuUse(offering.getLimitCpuUse());
offeringResponse.setTags(offering.getTags());
@ -855,7 +855,7 @@ public class ApiResponseHelper implements ResponseGenerator {
storageType = "unknown";
}
} else {
storageType = ApiDBUtils.volumeIsOnSharedStorage(volume.getId()) ? "shared" : "local";
storageType = ApiDBUtils.volumeIsOnSharedStorage(volume.getId()) ? ServiceOffering.StorageType.shared.toString() : ServiceOffering.StorageType.local.toString();
}
} catch (InvalidParameterValueException e) {
s_logger.error(e.getMessage(), e);

View File

@ -1566,10 +1566,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
@Override
public ServiceOffering createServiceOffering(CreateServiceOfferingCmd cmd) {
Long userId = UserContext.current().getCallerUserId();
if (userId == null) {
userId = User.UID_SYSTEM;
}
String name = cmd.getServiceOfferingName();
if ((name == null) || (name.length() == 0)) {
throw new InvalidParameterValueException("Failed to create service offering: specify the name that has non-zero length");
@ -1596,23 +1593,18 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
}
// check if valid domain
if (cmd.getDomainId() != null) {
DomainVO domain = _domainDao.findById(cmd.getDomainId());
if (domain == null) {
throw new InvalidParameterValueException("Please specify a valid domain id");
}
if (cmd.getDomainId() != null && _domainDao.findById(cmd.getDomainId()) == null) {
throw new InvalidParameterValueException("Please specify a valid domain id");
}
boolean localStorageRequired = false;
String storageType = cmd.getStorageType();
if (storageType == null) {
localStorageRequired = false;
} else if (storageType.equals("local")) {
localStorageRequired = true;
} else if (storageType.equals("shared")) {
localStorageRequired = false;
} else {
throw new InvalidParameterValueException("Invalid storage type " + storageType + " specified, valid types are: 'local' and 'shared'");
if (storageType != null) {
if (storageType.equalsIgnoreCase(ServiceOffering.StorageType.local.toString())) {
localStorageRequired = true;
} else if (!storageType.equalsIgnoreCase(ServiceOffering.StorageType.shared.toString())) {
throw new InvalidParameterValueException("Invalid storage type " + storageType + " specified, valid types are: 'local' and 'shared'");
}
}
Boolean offerHA = cmd.getOfferHa();
@ -1624,24 +1616,30 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
if (limitCpuUse == null) {
limitCpuUse = false;
}
String vm_type_string = cmd.getSystemVmType();
VirtualMachine.Type vm_type = null;
if (cmd.getIsSystem() && vm_type_string == null){
vm_type = VirtualMachine.Type.DomainRouter;
String vmTypeString = cmd.getSystemVmType();
VirtualMachine.Type vmType = null;
boolean allowNetworkRate = false;
if (cmd.getIsSystem()) {
if (vmTypeString == null || VirtualMachine.Type.DomainRouter.toString().toLowerCase().equals(vmTypeString)){
vmType = VirtualMachine.Type.DomainRouter;
allowNetworkRate = true;
} else if (VirtualMachine.Type.ConsoleProxy.toString().toLowerCase().equals(vmTypeString)){
vmType = VirtualMachine.Type.ConsoleProxy;
} else if (VirtualMachine.Type.SecondaryStorageVm.toString().toLowerCase().equals(vmTypeString)){
vmType = VirtualMachine.Type.SecondaryStorageVm;
} else {
throw new InvalidParameterValueException("Invalid systemVmType. Supported types are: " + VirtualMachine.Type.DomainRouter + ", " + VirtualMachine.Type.ConsoleProxy + ", " + VirtualMachine.Type.SecondaryStorageVm);
}
} else {
allowNetworkRate = true;;
}
else {
if (VirtualMachine.Type.ConsoleProxy.toString().toLowerCase().equals(vm_type_string)){
vm_type = VirtualMachine.Type.ConsoleProxy;
}
else if (VirtualMachine.Type.SecondaryStorageVm.toString().toLowerCase().equals(vm_type_string)){
vm_type = VirtualMachine.Type.SecondaryStorageVm;
}
else if (VirtualMachine.Type.DomainRouter.toString().toLowerCase().equals(vm_type_string)){
vm_type = VirtualMachine.Type.DomainRouter;
}
if (cmd.getNetworkRate() != null && !allowNetworkRate) {
throw new InvalidParameterValueException("Network rate can be specified only for non-System offering and system offerings having \"domainrouter\" systemvmtype");
}
return createServiceOffering(userId, cmd.getIsSystem(), vm_type, cmd.getServiceOfferingName(), cpuNumber.intValue(), memory.intValue(), cpuSpeed.intValue(), cmd.getDisplayText(), localStorageRequired, offerHA,
return createServiceOffering(userId, cmd.getIsSystem(), vmType, cmd.getServiceOfferingName(), cpuNumber.intValue(), memory.intValue(), cpuSpeed.intValue(), cmd.getDisplayText(), localStorageRequired, offerHA,
limitCpuUse, cmd.getTags(), cmd.getDomainId(), cmd.getHostTag(), cmd.getNetworkRate());
}
@ -3202,7 +3200,12 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
if (offering.getRateMbps() != null) {
networkRate = offering.getRateMbps();
} else {
networkRate = Integer.parseInt(_configDao.getValue(Config.VmNetworkThrottlingRate.key()));
//for domain router service offering, get network rate from
if (offering.getSystemVmType() != null && offering.getSystemVmType().equalsIgnoreCase(VirtualMachine.Type.DomainRouter.toString())) {
networkRate = Integer.parseInt(_configDao.getValue(Config.NetworkThrottlingRate.key()));
} else {
networkRate = Integer.parseInt(_configDao.getValue(Config.VmNetworkThrottlingRate.key()));
}
}
// networkRate is unsigned int in serviceOffering table, and can't be set to -1

View File

@ -3097,23 +3097,22 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
Network network = getNetwork(networkId);
NetworkOffering networkOffering = _configMgr.getNetworkOffering(network.getNetworkOfferingId());
// For default vms network offering get rate information from the service offering; for other situations get information
// For default userVm Default network and domR guest/public network, get rate information from the service offering; for other situations get information
// from the network offering
if (vm != null && vm.getType() == Type.User && network.isDefault()) {
boolean isUserVmsDefaultNetwork = false;
boolean isDomRGuestOrPublicNetwork = false;
if (vm != null) {
if (vm.getType() == Type.User && network.isDefault()) {
isUserVmsDefaultNetwork = true;
} else if (vm.getType() == Type.DomainRouter && networkOffering.getTrafficType() == TrafficType.Public && networkOffering.getGuestType() == null) {
isDomRGuestOrPublicNetwork = true;
}
}
if (isUserVmsDefaultNetwork || isDomRGuestOrPublicNetwork) {
return _configMgr.getServiceOfferingNetworkRate(vm.getServiceOfferingId());
} else {
// For router's public network we use networkRate from guestNetworkOffering
if (vm != null && vm.getType() == Type.DomainRouter && networkOffering.getTrafficType() == TrafficType.Public && networkOffering.getGuestType() == null) {
List<? extends NetworkOffering> guestOfferings = _networkOfferingDao.listByTrafficTypeAndGuestType(false, TrafficType.Guest, GuestIpType.Virtual);
if (!guestOfferings.isEmpty()) {
// We have one default guest virtual network offering now
networkOffering = guestOfferings.get(0);
}
}
return _configMgr.getNetworkOfferingNetworkRate(networkOffering.getId());
}
}
Random _rand = new Random(System.currentTimeMillis());