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.
This commit is contained in:
Sheng Yang 2011-10-10 15:26:21 -07:00
parent 0121c0516d
commit 30d48c40b3
9 changed files with 88 additions and 39 deletions

View File

@ -101,6 +101,4 @@ public interface NetworkOffering {
GuestIpType getGuestType();
String getUniqueName();
boolean getRedundantRouter();
}

View File

@ -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());

View File

@ -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);

View File

@ -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<Service, Map<Capability, String>> capabilities = getZoneCapabilities(dc.getId());
Map<Capability, String> 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);

View File

@ -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<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(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<? extends VirtualMachine> 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> uservm = (VirtualMachineProfile<UserVm>)vm;
List<DomainRouterVO> 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<VirtualRouter> rets = _routerMgr.addVirtualMachineIntoNetwork(network, nic, uservm, dest, context, routers);
return (rets != null) && (!rets.isEmpty());
} else {
return false;
}
}
}

View File

@ -107,7 +107,7 @@ public class VirtualRouterElement extends DhcpElement implements SourceNATServic
Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(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> uservm = (VirtualMachineProfile<UserVm>)vm;
NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
boolean isRedundant = offering.getRedundantRouter();
List<DomainRouterVO> routers = _routerMgr.deployVirtualRouter(network, dest, _accountMgr.getAccount(network.getAccountId()), uservm.getParameters(), isRedundant);
List<DomainRouterVO> 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);
}

View File

@ -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

View File

@ -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);
}

View File

@ -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`)