mirror of https://github.com/apache/cloudstack.git
bug 9154: Add redundancy capability to VirtualRouterElement
Also move redundancy checking to VirtualRouterElement
This commit is contained in:
parent
470c80a2c6
commit
be216bf975
|
|
@ -48,7 +48,7 @@ public interface Network extends ControlledEntity {
|
|||
public static final Service Vpn = new Service("Vpn", Capability.SupportedVpnTypes);
|
||||
public static final Service Dhcp = new Service("Dhcp");
|
||||
public static final Service Dns = new Service("Dns", Capability.AllowDnsSuffixModification);
|
||||
public static final Service Gateway = new Service("Gateway");
|
||||
public static final Service Gateway = new Service("Gateway", Capability.Redundancy);
|
||||
public static final Service Firewall = new Service("Firewall", Capability.PortForwarding, Capability.StaticNat, Capability.SupportedProtocols, Capability.MultipleIps, Capability.SupportedSourceNatTypes, Capability.TrafficStatistics);
|
||||
public static final Service Lb = new Service("Lb", Capability.SupportedLBAlgorithms, Capability.SupportedProtocols, Capability.TrafficStatistics, Capability.LoadBalancingSupportedIps);
|
||||
public static final Service UserData = new Service("UserData");
|
||||
|
|
@ -118,6 +118,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 Redundancy = new Capability("Redundancy");
|
||||
|
||||
private String name;
|
||||
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ import com.cloud.exception.AccountLimitException;
|
|||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InsufficientNetworkCapacityException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
|
|
@ -1134,6 +1135,16 @@ 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);
|
||||
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement,
|
|||
|
||||
Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
|
||||
params.put(VirtualMachineProfile.Param.RestartNetwork, true);
|
||||
_routerMgr.deployVirtualRouter(guestConfig, dest, context.getAccount(), params);
|
||||
_routerMgr.deployVirtualRouter(guestConfig, dest, context.getAccount(), params, offering.getRedundantRouter());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -115,7 +115,8 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement,
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
VirtualMachineProfile<UserVm> uservm = (VirtualMachineProfile<UserVm>)vm;
|
||||
List<DomainRouterVO> routers = _routerMgr.deployVirtualRouter(network, dest, uservm.getOwner(), uservm.getParameters());
|
||||
NetworkOffering offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
|
||||
List<DomainRouterVO> routers = _routerMgr.deployVirtualRouter(network, dest, uservm.getOwner(), uservm.getParameters(), offering.getRedundantRouter());
|
||||
List<VirtualRouter> rets = _routerMgr.addVirtualMachineIntoNetwork(network, nic, uservm, dest, context, routers);
|
||||
return (rets != null) && (!rets.isEmpty());
|
||||
} else {
|
||||
|
|
@ -266,7 +267,10 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement,
|
|||
|
||||
capabilities.put(Service.UserData, null);
|
||||
capabilities.put(Service.Dhcp, null);
|
||||
capabilities.put(Service.Gateway, null);
|
||||
|
||||
Map<Capability, String> gatewayCapabilities = new HashMap<Capability, String>();
|
||||
gatewayCapabilities.put(Capability.Redundancy, "true");
|
||||
capabilities.put(Service.Gateway, gatewayCapabilities);
|
||||
|
||||
return capabilities;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA
|
|||
|
||||
List<DomainRouterVO> getRouters(long accountId, long zoneId);
|
||||
|
||||
List<DomainRouterVO> deployVirtualRouter(Network guestNetwork, DeployDestination dest, Account owner, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException;
|
||||
List<DomainRouterVO> deployVirtualRouter(Network guestNetwork, DeployDestination dest, Account owner, Map<VirtualMachineProfile.Param, Object> params, boolean isRedundant) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException;
|
||||
|
||||
List<DomainRouterVO> deployDhcp(Network guestNetwork, DeployDestination dest, Account owner, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException;
|
||||
|
||||
|
|
|
|||
|
|
@ -792,7 +792,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
}
|
||||
|
||||
@DB
|
||||
protected List<DomainRouterVO> findOrCreateVirtualRouters(Network guestNetwork, DeployDestination dest, Account owner) throws ConcurrentOperationException, InsufficientCapacityException {
|
||||
protected List<DomainRouterVO> findOrCreateVirtualRouters(Network guestNetwork, DeployDestination dest, Account owner, boolean isRedundant) throws ConcurrentOperationException, InsufficientCapacityException {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
|
|
@ -807,8 +807,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
List<DomainRouterVO> routers = _routerDao.findByNetwork(guestNetwork.getId());
|
||||
|
||||
int routerCount = 1;
|
||||
NetworkOffering offering = _networkOfferingDao.findById(guestNetwork.getNetworkOfferingId());
|
||||
if (offering.getRedundantRouter()) {
|
||||
if (isRedundant) {
|
||||
routerCount = 2;
|
||||
}
|
||||
|
||||
|
|
@ -846,8 +845,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
List<NetworkVO> publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false, false);
|
||||
networks.add(new Pair<NetworkVO, NicProfile>(publicNetworks.get(0), defaultNic));
|
||||
NicProfile gatewayNic = new NicProfile();
|
||||
/* For redundant router */
|
||||
if (offering.getRedundantRouter()) {
|
||||
if (isRedundant) {
|
||||
gatewayNic.setIp4Address(_networkMgr.acquireGuestIpAddress(guestNetwork));
|
||||
gatewayNic.setMacAddress(_networkMgr.getNextAvailableMacAddressInNetwork(guestNetwork.getId()));
|
||||
} else {
|
||||
|
|
@ -869,11 +867,11 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
s_logger.error("Too much redundant routers!");
|
||||
}
|
||||
int priority = 0;
|
||||
if (offering.getRedundantRouter()) {
|
||||
if (isRedundant) {
|
||||
priority = 100 - routers.size() * 20;
|
||||
}
|
||||
router = new DomainRouterVO(id, _offering.getId(), VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(), template.getGuestOSId(),
|
||||
owner.getDomainId(), owner.getId(), guestNetwork.getId(), offering.getRedundantRouter(), priority, RedundantState.UNKNOWN, _offering.getOfferHA());
|
||||
owner.getDomainId(), owner.getId(), guestNetwork.getId(), isRedundant, priority, RedundantState.UNKNOWN, _offering.getOfferHA());
|
||||
router = _itMgr.allocate(router, template, _offering, networks, plan, null, owner);
|
||||
// Creating stats entry for router
|
||||
UserStatisticsVO stats = _userStatsDao.findBy(owner.getId(), dcId, router.getNetworkId(), null, router.getId(), router.getType().toString());
|
||||
|
|
@ -892,7 +890,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<DomainRouterVO> deployVirtualRouter(Network guestNetwork, DeployDestination dest, Account owner, Map<Param, Object> params) throws InsufficientCapacityException,
|
||||
public List<DomainRouterVO> deployVirtualRouter(Network guestNetwork, DeployDestination dest, Account owner, Map<Param, Object> params, boolean isRedundant) throws InsufficientCapacityException,
|
||||
ConcurrentOperationException, ResourceUnavailableException {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Starting a router for " + guestNetwork + " in " + dest);
|
||||
|
|
@ -902,7 +900,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
+ guestNetwork;
|
||||
assert guestNetwork.getTrafficType() == TrafficType.Guest;
|
||||
|
||||
List<DomainRouterVO> routers = findOrCreateVirtualRouters(guestNetwork, dest, owner);
|
||||
List<DomainRouterVO> routers = findOrCreateVirtualRouters(guestNetwork, dest, owner, isRedundant);
|
||||
|
||||
for (DomainRouterVO router : routers) {
|
||||
State state = router.getState();
|
||||
|
|
|
|||
Loading…
Reference in New Issue