From 47114af94b527f1f0e3a0640209b92b54c0f0904 Mon Sep 17 00:00:00 2001 From: Sheng Yang Date: Wed, 9 Nov 2011 17:08:56 -0800 Subject: [PATCH] NaaS: Add redundant capability for Gateway service --- api/src/com/cloud/network/Network.java | 1 + .../com/cloud/offering/NetworkOffering.java | 2 ++ .../ConfigurationManagerImpl.java | 31 ++++++++++++++++++- .../network/element/VirtualRouterElement.java | 4 +-- .../cloud/offerings/NetworkOfferingVO.java | 16 +++++++++- setup/db/create-schema.sql | 3 +- 6 files changed, 52 insertions(+), 5 deletions(-) diff --git a/api/src/com/cloud/network/Network.java b/api/src/com/cloud/network/Network.java index f96b08b52b0..58b707cb3c7 100644 --- a/api/src/com/cloud/network/Network.java +++ b/api/src/com/cloud/network/Network.java @@ -163,6 +163,7 @@ public interface Network extends ControlledEntity { public static final Capability TrafficStatistics = new Capability("TrafficStatistics"); public static final Capability LoadBalancingSupportedIps = new Capability("LoadBalancingSupportedIps"); public static final Capability AllowDnsSuffixModification = new Capability("AllowDnsSuffixModification"); + public static final Capability RedundantRouter = new Capability("RedundantRouter"); private String name; diff --git a/api/src/com/cloud/offering/NetworkOffering.java b/api/src/com/cloud/offering/NetworkOffering.java index 375b479aa00..fa7cdcac084 100644 --- a/api/src/com/cloud/offering/NetworkOffering.java +++ b/api/src/com/cloud/offering/NetworkOffering.java @@ -100,4 +100,6 @@ public interface NetworkOffering { boolean getDedicatedLB(); boolean getSharedSourceNat(); + + boolean getRedundantRouter(); } diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 320af131285..c8e4a0c6daf 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -2983,9 +2983,17 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } validateFirewallServiceCapablities(fwServiceCapabilityMap); + // verify the Gateway service capabilities specified in the network offering + Map gwServiceCapabilityMap = cmd.getServiceCapabilities(Service.Gateway); + if (!cmd.getGatewayService() && gwServiceCapabilityMap != null && !gwServiceCapabilityMap.isEmpty()) { + throw new InvalidParameterValueException("Capabilities for Gateway service can be specifed only when Gateway service is enabled for network offering."); + } + validateGatewayServiceCapablities(gwServiceCapabilityMap); + Map> serviceCapabilityMap = new HashMap>(); serviceCapabilityMap.put(Service.Lb, lbServiceCapabilityMap); serviceCapabilityMap.put(Service.Firewall, fwServiceCapabilityMap); + serviceCapabilityMap.put(Service.Gateway, gwServiceCapabilityMap); return createNetworkOffering(userId, name, displayText, trafficType, tags, maxConnections, specifyVlan, availability, networkRate, serviceProviderMap, false, guestType, false, serviceOfferingId, serviceCapabilityMap); @@ -3019,6 +3027,20 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } } + void validateGatewayServiceCapablities(Map gwServiceCapabilityMap) { + if (gwServiceCapabilityMap != null) { + if (gwServiceCapabilityMap.keySet().size() > 1 || !gwServiceCapabilityMap.containsKey(Capability.RedundantRouter.getName())) { + throw new InvalidParameterValueException("Only redundant router capability can be sepcified for gateway service"); + } + String param = gwServiceCapabilityMap.get(Capability.RedundantRouter.getName()); + boolean enabled = param.contains("true"); + boolean disabled = param.contains("false"); + if (!enabled && !disabled) { + throw new InvalidParameterValueException("Unknown specified value for " + Capability.RedundantRouter.getName()); + } + } + } + @Override @DB public NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, @@ -3043,7 +3065,14 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura sharedSourceNat = sourceNatType.contains("perzone"); } - NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, networkRate, multicastRate, maxConnections, isDefault, availability, tags, type, dedicatedLb, sharedSourceNat); + Map gwServiceCapabilityMap = serviceCapabilityMap.get(Service.Gateway); + boolean redundantRouter = false; + if ((gwServiceCapabilityMap != null) && (!gwServiceCapabilityMap.isEmpty())) { + String param = gwServiceCapabilityMap.get(Capability.RedundantRouter.getName()); + redundantRouter = param.contains("true"); + } + + NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, networkRate, multicastRate, maxConnections, isDefault, availability, tags, type, dedicatedLb, sharedSourceNat, redundantRouter); if (serviceOfferingId != null) { offering.setServiceOfferingId(serviceOfferingId); diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java index c89ee5329bf..55400201298 100644 --- a/server/src/com/cloud/network/element/VirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VirtualRouterElement.java @@ -125,7 +125,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl Map params = new HashMap(1); params.put(VirtualMachineProfile.Param.ReProgramNetwork, true); - _routerMgr.deployVirtualRouter(network, dest, _accountMgr.getAccount(network.getAccountId()), params, false); + _routerMgr.deployVirtualRouter(network, dest, _accountMgr.getAccount(network.getAccountId()), params, offering.getRedundantRouter()); return true; } @@ -147,7 +147,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl @SuppressWarnings("unchecked") VirtualMachineProfile uservm = (VirtualMachineProfile)vm; - List routers = _routerMgr.deployVirtualRouter(network, dest, _accountMgr.getAccount(network.getAccountId()), uservm.getParameters(), false); + List routers = _routerMgr.deployVirtualRouter(network, dest, _accountMgr.getAccount(network.getAccountId()), uservm.getParameters(), offering.getRedundantRouter()); if ((routers == null) || (routers.size() == 0)) { throw new ResourceUnavailableException("Can't find at least one running router!", this.getClass(), 0); } diff --git a/server/src/com/cloud/offerings/NetworkOfferingVO.java b/server/src/com/cloud/offerings/NetworkOfferingVO.java index 0c244c2628b..79af660c7ea 100644 --- a/server/src/com/cloud/offerings/NetworkOfferingVO.java +++ b/server/src/com/cloud/offerings/NetworkOfferingVO.java @@ -103,6 +103,9 @@ public class NetworkOfferingVO implements NetworkOffering { @Column(name="shared_source_nat_service") boolean sharedSourceNat; + @Column(name="redundant_router_service") + boolean redundantRouter; + @Override public String getDisplayText() { return displayText; @@ -237,6 +240,15 @@ public class NetworkOfferingVO implements NetworkOffering { this.sharedSourceNat = sharedSourceNat; } + @Override + public boolean getRedundantRouter() { + return redundantRouter; + } + + public void setRedundantRouter(boolean redundantRouter) { + this.redundantRouter = redundantRouter; + } + 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; @@ -254,13 +266,15 @@ public class NetworkOfferingVO implements NetworkOffering { this.guestType = guestType; this.dedicatedLB = true; this.sharedSourceNat =false; + this.redundantRouter= false; } 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, boolean dedicatedLb, boolean sharedSourceNat) { + boolean isDefault, Availability availability, String tags, Network.GuestType guestType, boolean dedicatedLb, boolean sharedSourceNat, boolean redundantRouter) { this(name, displayText, trafficType, systemOnly, specifyVlan, rateMbps, multicastRateMbps, concurrentConnections, isDefault, availability, tags, guestType); this.dedicatedLB = dedicatedLb; this.sharedSourceNat = sharedSourceNat; + this.redundantRouter = redundantRouter; } public NetworkOfferingVO() { diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 75706066e1a..5c91ea49a55 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -256,6 +256,7 @@ CREATE TABLE `cloud`.`network_offerings` ( `availability` varchar(255) NOT NULL COMMENT 'availability of the network', `dedicated_lb_service` int(1) unsigned NOT NULL DEFAULT 1 COMMENT 'true if the network offering provides a dedicated load balancer for each network', `shared_source_nat_service` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if the network offering provides the shared source nat service', + `redundant_router_service` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if the network offering provides the redundant router service', `state` char(32) COMMENT 'state of the network offering; has Disabled value by default', `guest_type` char(32) COMMENT 'type of guest network; can be shared or isolated', PRIMARY KEY (`id`), @@ -1863,7 +1864,7 @@ CREATE TABLE `cloud`.`virtual_router_providers` ( `id` bigint unsigned NOT NULL auto_increment COMMENT 'id', `nsp_id` bigint unsigned NOT NULL COMMENT 'Network Service Provider ID', `uuid` varchar(255) UNIQUE, - `type` varchar(255) NOT NULL COMMENT 'DHCP element, or Virtual router, or redundant virtual router', + `type` varchar(255) NOT NULL COMMENT 'Virtual router, or ElbVM', `enabled` int(1) NOT NULL COMMENT 'Enabled or disabled', `removed` datetime COMMENT 'date removed if not null', PRIMARY KEY (`id`),