From 30d48c40b349eb8081f991fd5ae9680163034995 Mon Sep 17 00:00:00 2001 From: Sheng Yang Date: Mon, 10 Oct 2011 15:26:21 -0700 Subject: [PATCH] Network as a service(NaaS): Separate redundant virtual router as a standalone element Since we would introduce a way to specify each service provider in the network offering, it's better for redundant virtual router as a separate service provider. Also isRedundant() flag in the network offering would be removed. Redundant virtual router temporality won't work from now. Until we're able to add different network elements/service providers in network_offering. --- .../com/cloud/offering/NetworkOffering.java | 2 - .../src/com/cloud/api/ApiResponseHelper.java | 2 +- .../ConfigurationManagerImpl.java | 2 +- .../com/cloud/network/NetworkManagerImpl.java | 15 +--- .../RedundantVirtualRouterElement.java | 76 +++++++++++++++++++ .../network/element/VirtualRouterElement.java | 6 +- .../cloud/offerings/NetworkOfferingVO.java | 17 +---- .../cloud/server/ConfigurationServerImpl.java | 6 +- setup/db/create-schema.sql | 1 - 9 files changed, 88 insertions(+), 39 deletions(-) create mode 100644 server/src/com/cloud/network/element/RedundantVirtualRouterElement.java diff --git a/api/src/com/cloud/offering/NetworkOffering.java b/api/src/com/cloud/offering/NetworkOffering.java index f43b9943297..394e1d9ce37 100644 --- a/api/src/com/cloud/offering/NetworkOffering.java +++ b/api/src/com/cloud/offering/NetworkOffering.java @@ -101,6 +101,4 @@ public interface NetworkOffering { GuestIpType getGuestType(); String getUniqueName(); - - boolean getRedundantRouter(); } diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 25f9aae5d4c..24d0c8fc032 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -2110,7 +2110,7 @@ public class ApiResponseHelper implements ResponseGenerator { response.setSpecifyVlan(offering.getSpecifyVlan()); response.setAvailability(offering.getAvailability().toString()); response.setNetworkRate(ApiDBUtils.getNetworkRate(offering.getId())); - response.setRedundantRouter(offering.getRedundantRouter()); + response.setRedundantRouter(false); if (offering.getGuestType() != null) { response.setGuestIpType(offering.getGuestType().toString()); diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 226054359e2..6475d72d78a 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -2909,7 +2909,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, false, specifyVlan, networkRate, multicastRate, maxConnections, false, availability, true, true, true, - gatewayService, firewallService, lbService, vpnService, guestIpType, redundantRouter); + gatewayService, firewallService, lbService, vpnService, guestIpType); if ((offering = _networkOfferingDao.persist(offering)) != null) { UserContext.current().setEventDetails(" Id: "+offering.getId()+" Name: "+name); diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index acc8a091de0..a3b56e463b2 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -783,20 +783,20 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag NetworkOfferingVO guestNetworkOffering = new NetworkOfferingVO(NetworkOffering.SystemGuestNetwork, "System Offering for System-Guest-Network", TrafficType.Guest, true, false, null, null, null, true, Availability.Required, // services - all true except for firewall/lb/vpn and gateway services - true, true, true, false, false, false, false, GuestIpType.Direct, false); + true, true, true, false, false, false, false, GuestIpType.Direct); guestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(guestNetworkOffering); _systemNetworks.put(NetworkOfferingVO.SystemGuestNetwork, guestNetworkOffering); NetworkOfferingVO defaultGuestNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultVirtualizedNetworkOffering, "Virtual Vlan", TrafficType.Guest, false, false, null, null, null, true, Availability.Required, // services - true, true, true, true, true, true, true, GuestIpType.Virtual, false); + true, true, true, true, true, true, true, GuestIpType.Virtual); defaultGuestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestNetworkOffering); NetworkOfferingVO defaultGuestDirectNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultDirectNetworkOffering, "Direct", TrafficType.Guest, false, true, null, null, null, true, Availability.Optional, // services - all true except for firewall/lb/vpn and gateway services - true, true, true, false, false, false, false, GuestIpType.Direct, false); + true, true, true, false, false, false, false, GuestIpType.Direct); defaultGuestDirectNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestDirectNetworkOffering); AccountsUsingNetworkSearch = _accountDao.createSearchBuilder(); @@ -1185,15 +1185,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId()); - // Check if we can provide the required capability - if (offering.getRedundantRouter()) { - DataCenter dc = dest.getDataCenter(); - Map> capabilities = getZoneCapabilities(dc.getId()); - Map gatewayCap = capabilities.get(Service.Gateway); - if (!gatewayCap.get(Capability.Redundancy).equalsIgnoreCase("true")) { - throw new InsufficientNetworkCapacityException("Zone lacks the feature that required by NetworkOffering: Redundant Virtual Router", dc.getClass(), dc.getId()); - } - } network.setReservationId(context.getReservationId()); network.setState(Network.State.Implementing); diff --git a/server/src/com/cloud/network/element/RedundantVirtualRouterElement.java b/server/src/com/cloud/network/element/RedundantVirtualRouterElement.java new file mode 100644 index 00000000000..21ca386da72 --- /dev/null +++ b/server/src/com/cloud/network/element/RedundantVirtualRouterElement.java @@ -0,0 +1,76 @@ +package com.cloud.network.element; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.ejb.Local; + +import org.apache.log4j.Logger; + +import com.cloud.dc.DataCenter; +import com.cloud.deploy.DeployDestination; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.Network; +import com.cloud.network.Network.GuestIpType; +import com.cloud.network.Network.Provider; +import com.cloud.network.router.VirtualRouter; +import com.cloud.offering.NetworkOffering; +import com.cloud.uservm.UserVm; +import com.cloud.vm.DomainRouterVO; +import com.cloud.vm.NicProfile; +import com.cloud.vm.ReservationContext; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachineProfile; + +@Local(value=NetworkElement.class) +public class RedundantVirtualRouterElement extends VirtualRouterElement { + private static final Logger s_logger = Logger.getLogger(RedundantVirtualRouterElement.class); + + private boolean canHandle(GuestIpType ipType, DataCenter dc) { + String provider = dc.getGatewayProvider(); + boolean result = (provider != null && ipType == GuestIpType.Virtual && provider.equals(Provider.VirtualRouter.getName())); + if (!result) { + s_logger.trace("Virtual router element only takes care of guest ip type " + GuestIpType.Virtual + " for provider " + Provider.VirtualRouter.getName()); + } + return result; + } + + + @Override + public boolean implement(Network guestConfig, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException { + if (!canHandle(guestConfig.getGuestType(), dest.getDataCenter())) { + return false; + } + + Map params = new HashMap(1); + params.put(VirtualMachineProfile.Param.RestartNetwork, true); + + _routerMgr.deployVirtualRouter(guestConfig, dest, _accountMgr.getAccount(guestConfig.getAccountId()), params, true); + + return true; + } + + + @Override + public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { + if (canHandle(network.getGuestType(), dest.getDataCenter())) { + if (vm.getType() != VirtualMachine.Type.User) { + return false; + } + + @SuppressWarnings("unchecked") + VirtualMachineProfile uservm = (VirtualMachineProfile)vm; + List routers = _routerMgr.deployVirtualRouter(network, dest, _accountMgr.getAccount(network.getAccountId()), uservm.getParameters(), true); + if ((routers == null) || (routers.size() == 0)) { + throw new ResourceUnavailableException("Can't find at least one running router!", this.getClass(), 0); + } + List rets = _routerMgr.addVirtualMachineIntoNetwork(network, nic, uservm, dest, context, routers); + return (rets != null) && (!rets.isEmpty()); + } else { + return false; + } + } +} diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java index ef73c1bd5b8..963757a7b7e 100644 --- a/server/src/com/cloud/network/element/VirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VirtualRouterElement.java @@ -107,7 +107,7 @@ public class VirtualRouterElement extends DhcpElement implements SourceNATServic Map params = new HashMap(1); params.put(VirtualMachineProfile.Param.RestartNetwork, true); - _routerMgr.deployVirtualRouter(guestConfig, dest, _accountMgr.getAccount(guestConfig.getAccountId()), params, offering.getRedundantRouter()); + _routerMgr.deployVirtualRouter(guestConfig, dest, _accountMgr.getAccount(guestConfig.getAccountId()), params, false); return true; } @@ -122,9 +122,7 @@ public class VirtualRouterElement extends DhcpElement implements SourceNATServic @SuppressWarnings("unchecked") VirtualMachineProfile uservm = (VirtualMachineProfile)vm; - NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId()); - boolean isRedundant = offering.getRedundantRouter(); - List routers = _routerMgr.deployVirtualRouter(network, dest, _accountMgr.getAccount(network.getAccountId()), uservm.getParameters(), isRedundant); + List routers = _routerMgr.deployVirtualRouter(network, dest, _accountMgr.getAccount(network.getAccountId()), uservm.getParameters(), false); 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 da6c2a8a696..dacef41abb0 100644 --- a/server/src/com/cloud/offerings/NetworkOfferingVO.java +++ b/server/src/com/cloud/offerings/NetworkOfferingVO.java @@ -116,9 +116,6 @@ public class NetworkOfferingVO implements NetworkOffering { @Column(name="guest_type") GuestIpType guestType; - @Column(name="redundant_router") - boolean redundantRouter; - @Override public String getDisplayText() { return displayText; @@ -332,16 +329,7 @@ public class NetworkOfferingVO implements NetworkOffering { this.uniqueName = uniqueName; } - @Override - public boolean getRedundantRouter() { - return this.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, boolean dhcpService, boolean dnsService, boolean userDataService, boolean gatewayService, boolean firewallService, boolean lbService, boolean vpnService, GuestIpType guestIpType, boolean isRedundantRouterEnabled) { + public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, Integer concurrentConnections, boolean isDefault, Availability availability, boolean dhcpService, boolean dnsService, boolean userDataService, boolean gatewayService, boolean firewallService, boolean lbService, boolean vpnService, GuestIpType guestIpType) { this.name = name; this.displayText = displayText; this.rateMbps = rateMbps; @@ -360,7 +348,6 @@ public class NetworkOfferingVO implements NetworkOffering { this.lbService = lbService; this.vpnService = vpnService; this.guestType = guestIpType; - this.redundantRouter = isRedundantRouterEnabled; this.uniqueName = name; } @@ -370,7 +357,7 @@ public class NetworkOfferingVO implements NetworkOffering { * @param trafficType */ public NetworkOfferingVO(String name, TrafficType trafficType) { - this(name, "System Offering for " + name, trafficType, true, false, 0, 0, null, true, Availability.Required, false, false, false, false, false, false, false, null, false); + this(name, "System Offering for " + name, trafficType, true, false, 0, 0, null, true, Availability.Required, false, false, false, false, false, false, false, null); } @Override diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index 257fcf8bb75..a7aaaea3fec 100644 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -829,7 +829,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { true, false, null, null, null, true, Availability.Required, true, true, true, //services - all true except for lb/vpn and gateway - false, true, false, false, GuestIpType.Direct, false); + false, true, false, false, GuestIpType.Direct); guestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(guestNetworkOffering); @@ -840,7 +840,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { false, false, null, null, null, true, Availability.Required, true, true, true, //services - true, true, true, true, GuestIpType.Virtual, false); + true, true, true, true, GuestIpType.Virtual); defaultGuestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestNetworkOffering); NetworkOfferingVO defaultGuestDirectNetworkOffering = new NetworkOfferingVO( NetworkOffering.DefaultDirectNetworkOffering, @@ -849,7 +849,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { false, true, null, null, null, true, Availability.Optional, true, true, true, //services - all true except for firewall/lb/vpn and gateway - false, false, false, false, GuestIpType.Direct, false); + false, false, false, false, GuestIpType.Direct); defaultGuestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestDirectNetworkOffering); } diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 1ae24aa8a68..9214a322b35 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -270,7 +270,6 @@ CREATE TABLE `cloud`.`network_offerings` ( `dhcp_service` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if network offering provides dhcp service', `shared_source_nat_service` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if the network offering provides the shared source nat service', `guest_type` char(32) COMMENT 'guest ip type of network offering', - `redundant_router` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if network offering provides redundant routers', PRIMARY KEY (`id`), INDEX `i_network_offerings__system_only`(`system_only`), INDEX `i_network_offerings__removed`(`removed`)