From b646f07f9c95b66bb660c33501c24022c5738f54 Mon Sep 17 00:00:00 2001 From: Sheng Yang Date: Wed, 2 Nov 2011 18:42:19 -0700 Subject: [PATCH] NaaS: Add back service offering ID for network offering It would be used to adjust service offering of virtual router --- .../commands/CreateNetworkOfferingCmd.java | 7 ++++++ .../com/cloud/offering/NetworkOffering.java | 2 ++ .../configuration/ConfigurationManager.java | 3 ++- .../ConfigurationManagerImpl.java | 20 +++++++++++++++-- .../com/cloud/network/NetworkManagerImpl.java | 6 ++--- .../VirtualNetworkApplianceManagerImpl.java | 22 ++++++++++++++----- .../cloud/offerings/NetworkOfferingVO.java | 12 ++++++++++ setup/db/create-schema.sql | 1 + 8 files changed, 61 insertions(+), 12 deletions(-) diff --git a/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java b/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java index b99deb62c42..6510a30f784 100644 --- a/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java +++ b/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java @@ -70,6 +70,9 @@ public class CreateNetworkOfferingCmd extends BaseCmd { @Parameter(name=ApiConstants.NETWORKRATE, type=CommandType.INTEGER, description="data transfer rate in megabits per second allowed.") private Integer networkRate; + @Parameter(name=ApiConstants.SERVICE_OFFERING_ID, type=CommandType.LONG, description="the service offering ID used by virtual router provider") + private Long serviceOfferingId; + @Parameter(name=ApiConstants.DHCP_SERVICE, type=CommandType.BOOLEAN, description="true if network offering supports dhcp service") private Boolean dhcpService; @@ -153,6 +156,10 @@ public class CreateNetworkOfferingCmd extends BaseCmd { return maxConnections; } + public Long getServiceOfferingId() { + return serviceOfferingId; + } + public Boolean getDhcpService() { return dhcpService == null ? false : dhcpService; } diff --git a/api/src/com/cloud/offering/NetworkOffering.java b/api/src/com/cloud/offering/NetworkOffering.java index 09902b227cd..0ae8c4a1a6e 100644 --- a/api/src/com/cloud/offering/NetworkOffering.java +++ b/api/src/com/cloud/offering/NetworkOffering.java @@ -93,4 +93,6 @@ public interface NetworkOffering { State getState(); GuestType getGuestType(); + + Long getServiceOfferingId(); } diff --git a/server/src/com/cloud/configuration/ConfigurationManager.java b/server/src/com/cloud/configuration/ConfigurationManager.java index 6519f766fe7..757116516c4 100644 --- a/server/src/com/cloud/configuration/ConfigurationManager.java +++ b/server/src/com/cloud/configuration/ConfigurationManager.java @@ -182,10 +182,11 @@ public interface ConfigurationManager extends ConfigurationService, Manager { * @param systemOnly TODO * @param id * @param specifyVlan; + * @param serviceOfferingId * @return network offering object */ - NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, Availability availability, Integer networkRate, Map> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly); + NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, Availability availability, Integer networkRate, Map> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId); Vlan createVlanAndPublicIpRange(Long userId, Long zoneId, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, boolean forVirtualNetwork, String vlanId, Account account, Long networkId, Long physicalNetworkId) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException; diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index ac5aa961905..763c2acbbd0 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -2845,6 +2845,18 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura Integer maxConnections = cmd.getMaxconnections(); + Long serviceOfferingId = cmd.getServiceOfferingId(); + + if (serviceOfferingId != null) { + ServiceOfferingVO offering = _serviceOfferingDao.findById(serviceOfferingId); + if (offering == null) { + throw new InvalidParameterValueException("Cannot find specified service offering: " + serviceOfferingId); + } + if (!VirtualMachine.Type.DomainRouter.toString().equalsIgnoreCase(offering.getSystemVmType())) { + throw new InvalidParameterValueException("The specified service offering " + serviceOfferingId + " cannot be used by virtual router!"); + } + } + // configure service provider map Map> serviceProviderMap = new HashMap>(); Set defaultProviders = new HashSet(); @@ -2927,19 +2939,23 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } } - return createNetworkOffering(userId, name, displayText, trafficType, tags, maxConnections, specifyVlan, availability, networkRate, serviceProviderMap, false, guestType, false); + return createNetworkOffering(userId, name, displayText, trafficType, tags, maxConnections, specifyVlan, availability, networkRate, serviceProviderMap, false, guestType, false, serviceOfferingId); } @Override @DB public NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, - Availability availability, Integer networkRate, Map> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly) { + Availability availability, Integer networkRate, Map> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId) { String multicastRateStr = _configDao.getValue("multicast.throttling.rate"); int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); tags = cleanupTags(tags); NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, networkRate, multicastRate, maxConnections, isDefault, availability, tags, type); + + if (serviceOfferingId != null) { + offering.setServiceOfferingId(serviceOfferingId); + } Transaction txn = Transaction.currentTxn(); txn.start(); diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index e415f6b715d..16d86dd6591 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -890,18 +890,18 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag NetworkOfferingVO defaultGuestOffering = _networkOfferingDao.findByUniqueName(NetworkOffering.SystemGuestNetwork); if (defaultGuestOffering == null) { - defaultGuestOffering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.SystemGuestNetwork, "System Offering for System-Guest-Network", TrafficType.Guest, null, null, false, Availability.Optional, null, defaultDirectNetworkOfferingProviders, true, Network.GuestType.Shared, false); + defaultGuestOffering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.SystemGuestNetwork, "System Offering for System-Guest-Network", TrafficType.Guest, null, null, false, Availability.Optional, null, defaultDirectNetworkOfferingProviders, true, Network.GuestType.Shared, false, null); _networkOfferingDao.update(defaultGuestOffering.getId(), defaultGuestOffering); } NetworkOfferingVO offering = null; if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultVirtualizedNetworkOffering) == null) { - offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM,NetworkOffering.DefaultVirtualizedNetworkOffering, "Virtual Vlan", TrafficType.Guest, null, null, false, Availability.Required, null, defaultVirtualNetworkOfferingProviders, true, Network.GuestType.Isolated, false); + offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM,NetworkOffering.DefaultVirtualizedNetworkOffering, "Virtual Vlan", TrafficType.Guest, null, null, false, Availability.Required, null, defaultVirtualNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null); _networkOfferingDao.update(offering.getId(), offering); } if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultDirectNetworkOffering) == null) { - offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.DefaultDirectNetworkOffering, "Direct", TrafficType.Guest, null, null, true, Availability.Optional, null, defaultDirectNetworkOfferingProviders, true, Network.GuestType.Shared, false); + offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.DefaultDirectNetworkOffering, "Direct", TrafficType.Guest, null, null, true, Availability.Optional, null, defaultDirectNetworkOfferingProviders, true, Network.GuestType.Shared, false, null); _networkOfferingDao.update(offering.getId(), offering); } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 151e508ab5d..0c5dddfd303 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1099,15 +1099,20 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian //Router is the network element, we don't know the hypervisor type yet. //Try to allocate the domR twice using diff hypervisors, and when failed both times, throw the exception up List supportedHypervisors = _resourceMgr.getSupportedHypervisorTypes(dest.getDataCenter().getId()); + Long offering_id = _networkOfferingDao.findById(guestNetwork.getNetworkOfferingId()).getServiceOfferingId(); + if (offering_id == null) { + offering_id = _offering.getId(); + } + ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(offering_id); int retry = 0; for (HypervisorType hType : supportedHypervisors) { try { s_logger.debug("Allocating the domR with the hypervisor type " + hType); VMTemplateVO template = _templateDao.findRoutingTemplate(hType); - router = new DomainRouterVO(id, _offering.getId(), 0, VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(), - template.getGuestOSId(), owner.getDomainId(), owner.getId(), guestNetwork.getId(), isRedundant, 0, false, RedundantState.UNKNOWN, _offering.getOfferHA(), false); - router = _itMgr.allocate(router, template, _offering, networks, plan, null, owner); + router = new DomainRouterVO(id, routerOffering.getId(), 0, VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(), + template.getGuestOSId(), owner.getDomainId(), owner.getId(), guestNetwork.getId(), isRedundant, 0, false, RedundantState.UNKNOWN, routerOffering.getOfferHA(), false); + router = _itMgr.allocate(router, template, routerOffering, networks, plan, null, owner); break; } catch (InsufficientCapacityException ex) { if (retry < 2) { @@ -1303,6 +1308,11 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian //Router is the network element, we don't know the hypervisor type yet. //Try to allocate the domR twice using diff hypervisors, and when failed both times, throw the exception up List supportedHypervisors = _resourceMgr.getSupportedHypervisorTypes(dest.getDataCenter().getId()); + Long offering_id = _networkOfferingDao.findById(guestNetwork.getNetworkOfferingId()).getServiceOfferingId(); + if (offering_id == null) { + offering_id = _offering.getId(); + } + ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(offering_id); int retry = 0; for (HypervisorType hType : supportedHypervisors) { try { @@ -1310,10 +1320,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian /* Before starting router, already know the hypervisor type */ VMTemplateVO template = _templateDao.findRoutingTemplate(hType); - router = new DomainRouterVO(id, _offering.getId(), 0, VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(), - template.getGuestOSId(), owner.getDomainId(), owner.getId(), guestNetwork.getId(), false, 0, false, RedundantState.UNKNOWN, _offering.getOfferHA(), false); + router = new DomainRouterVO(id, routerOffering.getId(), 0, VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(), + template.getGuestOSId(), owner.getDomainId(), owner.getId(), guestNetwork.getId(), false, 0, false, RedundantState.UNKNOWN, routerOffering.getOfferHA(), false); router.setRole(Role.DHCP_USERDATA); - router = _itMgr.allocate(router, template, _offering, networks, plan, null, owner); + router = _itMgr.allocate(router, template, routerOffering, networks, plan, null, owner); break; } catch (InsufficientCapacityException ex) { if (retry < 2) { diff --git a/server/src/com/cloud/offerings/NetworkOfferingVO.java b/server/src/com/cloud/offerings/NetworkOfferingVO.java index 791169000b0..26e0f8c4f27 100644 --- a/server/src/com/cloud/offerings/NetworkOfferingVO.java +++ b/server/src/com/cloud/offerings/NetworkOfferingVO.java @@ -70,6 +70,9 @@ public class NetworkOfferingVO implements NetworkOffering { @Column(name="system_only") boolean systemOnly; + @Column(name="service_offering_id") + Long serviceOfferingId; + @Column(name="tags", length=4096) String tags; @@ -201,6 +204,15 @@ public class NetworkOfferingVO implements NetworkOffering { return guestType; } + public void setServiceOfferingId(Long serviceOfferingId) { + this.serviceOfferingId = serviceOfferingId; + } + + @Override + public Long getServiceOfferingId() { + return serviceOfferingId; + } + public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, Integer concurrentConnections, boolean isDefault, Availability availability, String tags, Network.GuestType guestType) { this.name = name; this.displayText = displayText; diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index dd03cce8331..fecc3308339 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -249,6 +249,7 @@ CREATE TABLE `cloud`.`network_offerings` ( `tags` varchar(4096) COMMENT 'tags supported by this offering', `system_only` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'Is this network offering for system use only', `specify_vlan` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'Should the user specify vlan', + `service_offering_id` bigint unsigned COMMENT 'service offering id that virtual router is tied to', `created` datetime NOT NULL COMMENT 'time the entry was created', `removed` datetime DEFAULT NULL COMMENT 'time the entry was removed', `default` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if network offering is default',