Rules and visitors for Load Balance Rules

Conflicts:
	server/src/com/cloud/network/element/VirtualRouterElement.java
This commit is contained in:
Antonio Fornie 2014-07-03 12:17:26 -05:00 committed by wilderrodrigues
parent 350ac4c4b0
commit 1a85213bbf
25 changed files with 1927 additions and 81 deletions

View File

@ -182,6 +182,10 @@
</bean>
<bean id="vpcVirtualNetworkApplianceManagerImpl"
class="com.cloud.network.router.VpcVirtualNetworkApplianceManagerImpl" />
<bean id="virtualNetworkApplianceFactory"
class="com.cloud.network.rules.VirtualNetworkApplianceFactory" />
<bean id="routerControlHelper"
class="com.cloud.network.router.RouterControlHelper" />
<bean id="ApiAsyncJobDispatcher" class="com.cloud.api.ApiAsyncJobDispatcher">

View File

@ -16,6 +16,23 @@
// under the License.
package com.cloud.network.element;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.cloudstack.api.command.admin.router.ConfigureOvsElementCmd;
import org.apache.cloudstack.api.command.admin.router.ConfigureVirtualRouterElementCmd;
import org.apache.cloudstack.api.command.admin.router.CreateVirtualRouterElementCmd;
import org.apache.cloudstack.api.command.admin.router.ListOvsElementsCmd;
import org.apache.cloudstack.api.command.admin.router.ListVirtualRouterElementsCmd;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.log4j.Logger;
import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.dc.DataCenter;
@ -62,6 +79,7 @@ import com.cloud.network.rules.LoadBalancerContainer;
import com.cloud.network.rules.PortForwardingRule;
import com.cloud.network.rules.RulesManager;
import com.cloud.network.rules.StaticNat;
import com.cloud.network.rules.VirtualNetworkApplianceFactory;
import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.offerings.dao.NetworkOfferingDao;
@ -85,21 +103,6 @@ import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.UserVmDao;
import com.google.gson.Gson;
import org.apache.cloudstack.api.command.admin.router.ConfigureOvsElementCmd;
import org.apache.cloudstack.api.command.admin.router.ConfigureVirtualRouterElementCmd;
import org.apache.cloudstack.api.command.admin.router.CreateVirtualRouterElementCmd;
import org.apache.cloudstack.api.command.admin.router.ListOvsElementsCmd;
import org.apache.cloudstack.api.command.admin.router.ListVirtualRouterElementsCmd;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.log4j.Logger;
import javax.ejb.Local;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Local(value = {NetworkElement.class, FirewallServiceProvider.class,
DhcpServiceProvider.class, UserDataServiceProvider.class,
@ -150,8 +153,10 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
OvsProviderDao _ovsProviderDao;
@Inject
IPAddressDao _ipAddressDao;
@Inject
protected VirtualNetworkApplianceFactory virtualNetworkApplianceFactory;
protected boolean canHandle(Network network, Service service) {
protected boolean canHandle(final Network network, final Service service) {
Long physicalNetworkId = _networkMdl.getPhysicalNetworkId(network);
if (physicalNetworkId == null) {
return false;
@ -181,7 +186,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException,
public boolean implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context) throws ResourceUnavailableException,
ConcurrentOperationException, InsufficientCapacityException {
if (offering.isSystemOnly()) {
@ -198,7 +203,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
if (offering.getRedundantRouter()) {
routerCounts = 2;
}
if ((routers == null) || (routers.size() < routerCounts)) {
if (routers == null || routers.size() < routerCounts) {
throw new ResourceUnavailableException("Can't find all necessary running routers!",
DataCenter.class, network.getDataCenterId());
}
@ -207,7 +212,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
public boolean prepare(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context)
throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
if (vm.getType() != VirtualMachine.Type.User || vm.getHypervisorType() == HypervisorType.BareMetal) {
return false;
@ -230,14 +235,14 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
List<DomainRouterVO> routers =
_routerMgr.deployVirtualRouterInGuestNetwork(network, dest, _accountMgr.getAccount(network.getAccountId()), uservm.getParameters(),
offering.getRedundantRouter());
if ((routers == null) || (routers.size() == 0)) {
if (routers == null || routers.size() == 0) {
throw new ResourceUnavailableException("Can't find at least one running router!", DataCenter.class, network.getDataCenterId());
}
return true;
}
@Override
public boolean applyFWRules(Network config, List<? extends FirewallRule> rules) throws ResourceUnavailableException {
public boolean applyFWRules(final Network config, final List<? extends FirewallRule> rules) throws ResourceUnavailableException {
if (canHandle(config, Service.Firewall)) {
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(config.getId(), Role.VIRTUAL_ROUTER);
if (routers == null || routers.isEmpty()) {
@ -249,8 +254,9 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
if (rules != null && rules.size() == 1) {
// for VR no need to add default egress rule to DENY traffic
if (rules.get(0).getTrafficType() == FirewallRule.TrafficType.Egress && rules.get(0).getType() == FirewallRule.FirewallRuleType.System &&
!_networkMdl.getNetworkEgressDefaultPolicy(config.getId()))
!_networkMdl.getNetworkEgressDefaultPolicy(config.getId())) {
return true;
}
}
if (!_routerMgr.applyFirewallRules(config, rules, routers)) {
@ -268,15 +274,18 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
* number like 12 2) time or tablesize like 12h, 34m, 45k, 54m , here
* last character is non-digit but from known characters .
*/
private static boolean containsOnlyNumbers(String str, String endChar) {
if (str == null)
private static boolean containsOnlyNumbers(final String str, final String endChar) {
if (str == null) {
return false;
}
String number = str;
if (endChar != null) {
boolean matchedEndChar = false;
if (str.length() < 2)
{
return false; // atleast one numeric and one char. example:
}
// 3h
char strEnd = str.toCharArray()[str.length() - 1];
for (char c : endChar.toCharArray()) {
@ -286,8 +295,9 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
break;
}
}
if (!matchedEndChar)
if (!matchedEndChar) {
return false;
}
}
try {
Integer.parseInt(number);
@ -297,7 +307,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
return true;
}
public static boolean validateHAProxyLBRule(LoadBalancingRule rule) {
public static boolean validateHAProxyLBRule(final LoadBalancingRule rule) {
String timeEndChar = "dhms";
if (rule.getSourcePortStart() == NetUtils.HAPROXY_STATS_PORT) {
@ -318,15 +328,17 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
for (Pair<String, String> paramKV : paramsList) {
String key = paramKV.first();
String value = paramKV.second();
if ("tablesize".equalsIgnoreCase(key))
if ("tablesize".equalsIgnoreCase(key)) {
tablesize = value;
if ("expire".equalsIgnoreCase(key))
}
if ("expire".equalsIgnoreCase(key)) {
expire = value;
}
}
if ((expire != null) && !containsOnlyNumbers(expire, timeEndChar)) {
if (expire != null && !containsOnlyNumbers(expire, timeEndChar)) {
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: expire is not in timeformat: " + expire);
}
if ((tablesize != null) && !containsOnlyNumbers(tablesize, "kmg")) {
if (tablesize != null && !containsOnlyNumbers(tablesize, "kmg")) {
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: tablesize is not in size format: " + tablesize);
}
@ -337,16 +349,18 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
for (Pair<String, String> paramKV : paramsList) {
String key = paramKV.first();
String value = paramKV.second();
if ("length".equalsIgnoreCase(key))
if ("length".equalsIgnoreCase(key)) {
length = value;
if ("holdtime".equalsIgnoreCase(key))
}
if ("holdtime".equalsIgnoreCase(key)) {
holdTime = value;
}
}
if ((length != null) && (!containsOnlyNumbers(length, null))) {
if (length != null && !containsOnlyNumbers(length, null)) {
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: length is not a number: " + length);
}
if ((holdTime != null) && (!containsOnlyNumbers(holdTime, timeEndChar) && !containsOnlyNumbers(holdTime, null))) {
if (holdTime != null && !containsOnlyNumbers(holdTime, timeEndChar) && !containsOnlyNumbers(holdTime, null)) {
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: holdtime is not in timeformat: " + holdTime);
}
}
@ -355,7 +369,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean validateLBRule(Network network, LoadBalancingRule rule) {
public boolean validateLBRule(final Network network, final LoadBalancingRule rule) {
List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
rules.add(rule);
if (canHandle(network, Service.Lb) && canHandleLbRules(rules)) {
@ -369,7 +383,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean applyLBRules(Network network, List<LoadBalancingRule> rules) throws ResourceUnavailableException {
public boolean applyLBRules(final Network network, final List<LoadBalancingRule> rules) throws ResourceUnavailableException {
if (canHandle(network, Service.Lb)) {
if (!canHandleLbRules(rules)) {
return false;
@ -392,7 +406,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public String[] applyVpnUsers(RemoteAccessVpn vpn, List<? extends VpnUser> users) throws ResourceUnavailableException {
public String[] applyVpnUsers(final RemoteAccessVpn vpn, final List<? extends VpnUser> users) throws ResourceUnavailableException {
if (vpn.getNetworkId() == null) {
return null;
}
@ -413,7 +427,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean startVpn(RemoteAccessVpn vpn) throws ResourceUnavailableException {
public boolean startVpn(final RemoteAccessVpn vpn) throws ResourceUnavailableException {
if (vpn.getNetworkId() == null) {
return false;
}
@ -433,7 +447,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean stopVpn(RemoteAccessVpn vpn) throws ResourceUnavailableException {
public boolean stopVpn(final RemoteAccessVpn vpn) throws ResourceUnavailableException {
if (vpn.getNetworkId() == null) {
return false;
}
@ -453,7 +467,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress, Set<Service> services) throws ResourceUnavailableException {
public boolean applyIps(final Network network, final List<? extends PublicIpAddress> ipAddress, final Set<Service> services) throws ResourceUnavailableException {
boolean canHandle = true;
for (Service service : services) {
if (!canHandle(network, service)) {
@ -616,7 +630,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean applyStaticNats(Network config, List<? extends StaticNat> rules) throws ResourceUnavailableException {
public boolean applyStaticNats(final Network config, final List<? extends StaticNat> rules) throws ResourceUnavailableException {
if (canHandle(config, Service.StaticNat)) {
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(config.getId(), Role.VIRTUAL_ROUTER);
if (routers == null || routers.isEmpty()) {
@ -632,7 +646,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException {
public boolean shutdown(final Network network, final ReservationContext context, final boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException {
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
if (routers == null || routers.isEmpty()) {
return true;
@ -644,7 +658,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
if (!result) {
s_logger.warn("Failed to stop virtual router element " + router + ", but would try to process clean up anyway.");
}
result = (_routerMgr.destroyRouter(router.getId(), context.getAccount(), context.getCaller().getId()) != null);
result = _routerMgr.destroyRouter(router.getId(), context.getAccount(), context.getCaller().getId()) != null;
if (!result) {
s_logger.warn("Failed to clean up virtual router element " + router);
}
@ -654,7 +668,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean destroy(Network config, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
public boolean destroy(final Network config, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(config.getId(), Role.VIRTUAL_ROUTER);
if (routers == null || routers.isEmpty()) {
return true;
@ -664,13 +678,13 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
// not caller account
Account callerAccount = _accountMgr.getAccount(context.getCaller().getAccountId());
for (DomainRouterVO router : routers) {
result = result && (_routerMgr.destroyRouter(router.getId(), callerAccount, context.getCaller().getId()) != null);
result = result && _routerMgr.destroyRouter(router.getId(), callerAccount, context.getCaller().getId()) != null;
}
return result;
}
@Override
public boolean savePassword(Network network, NicProfile nic, VirtualMachineProfile vm) throws ResourceUnavailableException {
public boolean savePassword(final Network network, final NicProfile nic, final VirtualMachineProfile vm) throws ResourceUnavailableException {
if (!canHandle(network, null)) {
return false;
}
@ -703,7 +717,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean saveSSHKey(Network network, NicProfile nic, VirtualMachineProfile vm, String sshPublicKey) throws ResourceUnavailableException {
public boolean saveSSHKey(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final String sshPublicKey) throws ResourceUnavailableException {
if (!canHandle(network, null)) {
return false;
}
@ -720,7 +734,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean saveUserData(Network network, NicProfile nic, VirtualMachineProfile vm) throws ResourceUnavailableException {
public boolean saveUserData(final Network network, final NicProfile nic, final VirtualMachineProfile vm) throws ResourceUnavailableException {
if (!canHandle(network, null)) {
return false;
}
@ -746,7 +760,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public VirtualRouterProvider configure(ConfigureVirtualRouterElementCmd cmd) {
public VirtualRouterProvider configure(final ConfigureVirtualRouterElementCmd cmd) {
VirtualRouterProviderVO element = _vrProviderDao.findById(cmd.getId());
if (element == null || !(element.getType() == Type.VirtualRouter || element.getType() == Type.VPCVirtualRouter)) {
s_logger.debug("Can't find Virtual Router element with network service provider id " + cmd.getId());
@ -760,7 +774,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public OvsProvider configure(ConfigureOvsElementCmd cmd) {
public OvsProvider configure(final ConfigureOvsElementCmd cmd) {
OvsProviderVO element = _ovsProviderDao.findById(cmd.getId());
if (element == null) {
s_logger.debug("Can't find Ovs element with network service provider id "
@ -775,7 +789,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public VirtualRouterProvider addElement(Long nspId, Type providerType) {
public VirtualRouterProvider addElement(final Long nspId, final Type providerType) {
if (!(providerType == Type.VirtualRouter || providerType == Type.VPCVirtualRouter)) {
throw new InvalidParameterValueException("Element " + getName() + " supports only providerTypes: " + Type.VirtualRouter.toString() + " and " +
Type.VPCVirtualRouter);
@ -791,7 +805,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean applyPFRules(Network network, List<PortForwardingRule> rules) throws ResourceUnavailableException {
public boolean applyPFRules(final Network network, final List<PortForwardingRule> rules) throws ResourceUnavailableException {
if (canHandle(network, Service.PortForwarding)) {
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
if (routers == null || routers.isEmpty()) {
@ -811,7 +825,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean isReady(PhysicalNetworkServiceProvider provider) {
public boolean isReady(final PhysicalNetworkServiceProvider provider) {
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(), getVirtualRouterProvider());
if (element == null) {
return false;
@ -820,7 +834,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) throws ConcurrentOperationException,
public boolean shutdownProviderInstances(final PhysicalNetworkServiceProvider provider, final ReservationContext context) throws ConcurrentOperationException,
ResourceUnavailableException {
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(), getVirtualRouterProvider());
if (element == null) {
@ -831,7 +845,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
List<DomainRouterVO> routers = _routerDao.listByElementId(elementId);
boolean result = true;
for (DomainRouterVO router : routers) {
result = result && (_routerMgr.destroyRouter(router.getId(), context.getAccount(), context.getCaller().getId()) != null);
result = result && _routerMgr.destroyRouter(router.getId(), context.getAccount(), context.getCaller().getId()) != null;
}
_vrProviderDao.remove(elementId);
@ -843,13 +857,13 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
return true;
}
public Long getIdByNspId(Long nspId) {
public Long getIdByNspId(final Long nspId) {
VirtualRouterProviderVO vr = _vrProviderDao.findByNspIdAndType(nspId, Type.VirtualRouter);
return vr.getId();
}
@Override
public VirtualRouterProvider getCreatedElement(long id) {
public VirtualRouterProvider getCreatedElement(final long id) {
VirtualRouterProvider provider = _vrProviderDao.findById(id);
if (!(provider.getType() == Type.VirtualRouter || provider.getType() == Type.VPCVirtualRouter)) {
throw new InvalidParameterValueException("Unable to find provider by id");
@ -858,13 +872,13 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException,
public boolean release(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final ReservationContext context) throws ConcurrentOperationException,
ResourceUnavailableException {
return true;
}
@Override
public boolean configDhcpSupportForSubnet(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
public boolean configDhcpSupportForSubnet(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context)
throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
if (canHandle(network, Service.Dhcp)) {
if (vm.getType() != VirtualMachine.Type.User) {
@ -875,7 +889,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
List<DomainRouterVO> routers = getRouters(network, dest);
if ((routers == null) || (routers.size() == 0)) {
if (routers == null || routers.size() == 0) {
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
}
@ -885,10 +899,10 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean removeDhcpSupportForSubnet(Network network) throws ResourceUnavailableException {
public boolean removeDhcpSupportForSubnet(final Network network) throws ResourceUnavailableException {
if (canHandle(network, Service.Dhcp)) {
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
if ((routers == null) || (routers.size() == 0)) {
if (routers == null || routers.size() == 0) {
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
}
try {
@ -901,7 +915,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
public boolean addDhcpEntry(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context)
throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
if (canHandle(network, Service.Dhcp)) {
if (vm.getType() != VirtualMachine.Type.User) {
@ -913,7 +927,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
List<DomainRouterVO> routers = getRouters(network, dest);
if ((routers == null) || (routers.size() == 0)) {
if (routers == null || routers.size() == 0) {
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
}
@ -923,7 +937,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean addPasswordAndUserdata(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
public boolean addPasswordAndUserdata(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context)
throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
if (canHandle(network, Service.UserData)) {
if (vm.getType() != VirtualMachine.Type.User) {
@ -940,7 +954,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
List<DomainRouterVO> routers = getRouters(network, dest);
if ((routers == null) || (routers.size() == 0)) {
if (routers == null || routers.size() == 0) {
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
}
@ -949,7 +963,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
return false;
}
protected List<DomainRouterVO> getRouters(Network network, DeployDestination dest) {
protected List<DomainRouterVO> getRouters(final Network network, final DeployDestination dest) {
boolean publicNetwork = false;
if (_networkMdl.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, getProvider())) {
publicNetwork = true;
@ -985,7 +999,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public List<? extends VirtualRouterProvider> searchForVirtualRouterElement(ListVirtualRouterElementsCmd cmd) {
public List<? extends VirtualRouterProvider> searchForVirtualRouterElement(final ListVirtualRouterElementsCmd cmd) {
Long id = cmd.getId();
Long nspId = cmd.getNspId();
Boolean enabled = cmd.getEnabled();
@ -1008,7 +1022,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public List<? extends OvsProvider> searchForOvsElement(ListOvsElementsCmd cmd) {
public List<? extends OvsProvider> searchForOvsElement(final ListOvsElementsCmd cmd) {
Long id = cmd.getId();
Long nspId = cmd.getNspId();
Boolean enabled = cmd.getEnabled();
@ -1028,12 +1042,12 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean verifyServicesCombination(Set<Service> services) {
public boolean verifyServicesCombination(final Set<Service> services) {
return true;
}
@Override
public IpDeployer getIpDeployer(Network network) {
public IpDeployer getIpDeployer(final Network network) {
return this;
}
@ -1042,12 +1056,12 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public List<LoadBalancerTO> updateHealthChecks(Network network, List<LoadBalancingRule> lbrules) {
public List<LoadBalancerTO> updateHealthChecks(final Network network, final List<LoadBalancingRule> lbrules) {
// TODO Auto-generated method stub
return null;
}
private boolean canHandleLbRules(List<LoadBalancingRule> rules) {
private boolean canHandleLbRules(final List<LoadBalancingRule> rules) {
Map<Capability, String> lbCaps = getCapabilities().get(Service.Lb);
if (!lbCaps.isEmpty()) {
String schemeCaps = lbCaps.get(Capability.LbSchemes);
@ -1064,7 +1078,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean prepareMigration(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) {
public boolean prepareMigration(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) {
if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) {
return true;
}
@ -1081,7 +1095,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public void rollbackMigration(NicProfile nic, Network network, VirtualMachineProfile vm, ReservationContext src, ReservationContext dst) {
public void rollbackMigration(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final ReservationContext src, final ReservationContext dst) {
if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) {
return;
}
@ -1097,7 +1111,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public void commitMigration(NicProfile nic, Network network, VirtualMachineProfile vm, ReservationContext src, ReservationContext dst) {
public void commitMigration(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final ReservationContext src, final ReservationContext dst) {
if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) {
return;
}
@ -1113,10 +1127,10 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean prepareAggregatedExecution(Network network, DeployDestination dest) throws ResourceUnavailableException {
public boolean prepareAggregatedExecution(final Network network, final DeployDestination dest) throws ResourceUnavailableException {
List<DomainRouterVO> routers = getRouters(network, dest);
if ((routers == null) || (routers.size() == 0)) {
if (routers == null || routers.size() == 0) {
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
}
@ -1124,10 +1138,10 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean completeAggregatedExecution(Network network, DeployDestination dest) throws ResourceUnavailableException {
public boolean completeAggregatedExecution(final Network network, final DeployDestination dest) throws ResourceUnavailableException {
List<DomainRouterVO> routers = getRouters(network, dest);
if ((routers == null) || (routers.size() == 0)) {
if (routers == null || routers.size() == 0) {
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
}
@ -1135,7 +1149,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
public boolean cleanupAggregatedExecution(Network network, DeployDestination dest) throws ResourceUnavailableException {
public boolean cleanupAggregatedExecution(final Network network, final DeployDestination dest) throws ResourceUnavailableException {
// The VR code already cleansup in the Finish routine using finally, lets not waste another command
return true;
}

View File

@ -0,0 +1,54 @@
package com.cloud.network.router;
import java.util.List;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.NetworkVO;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.NicVO;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.NicDao;
public class RouterControlHelper {
private static final Logger logger = Logger.getLogger(RouterControlHelper.class);
@Inject
private DomainRouterDao routerDao = null;
@Inject
private NetworkDao networkDao;
@Inject
private NicDao nicDao;
public String getRouterControlIp(final long routerId) {
String routerControlIpAddress = null;
final List<NicVO> nics = nicDao.listByVmId(routerId);
for (final NicVO n : nics) {
final NetworkVO nc = networkDao.findById(n.getNetworkId());
if (nc != null && nc.getTrafficType() == TrafficType.Control) {
routerControlIpAddress = n.getIp4Address();
// router will have only one control ip
break;
}
}
if (routerControlIpAddress == null) {
logger.warn("Unable to find router's control ip in its attached NICs!. routerId: " + routerId);
final DomainRouterVO router = routerDao.findById(routerId);
return router.getPrivateIpAddress();
}
return routerControlIpAddress;
}
public String getRouterIpInNetwork(final long networkId, final long instanceId) {
return nicDao.getIpAddress(networkId, instanceId);
}
}

View File

@ -0,0 +1,60 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.rules;
import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.topology.NetworkTopologyVisitor;
import com.cloud.vm.NicProfile;
import com.cloud.vm.VirtualMachineProfile;
public class DhcpRules extends RuleApplier {
private final NicProfile nic;
private final VirtualMachineProfile profile;
private final DeployDestination destination;
public DhcpRules(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination destination) {
super(network);
this.nic = nic;
this.profile = profile;
this.destination = destination;
}
@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
this.router = router;
return visitor.visit(this);
}
public NicProfile getNic() {
return nic;
}
public VirtualMachineProfile getProfile() {
return profile;
}
public DeployDestination getDestination() {
return destination;
}
}

View File

@ -0,0 +1,99 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.rules;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.NetworkModel;
import com.cloud.network.dao.LoadBalancerDao;
import com.cloud.network.dao.LoadBalancerVO;
import com.cloud.network.lb.LoadBalancingRule;
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
import com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy;
import com.cloud.network.lb.LoadBalancingRule.LbSslCert;
import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy;
import com.cloud.network.lb.LoadBalancingRulesManager;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.rules.FirewallRule.Purpose;
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
import com.cloud.network.topology.NetworkTopologyVisitor;
import com.cloud.utils.net.Ip;
public class FirewallRules extends RuleApplier {
@Inject
NetworkModel _networkModel;
@Inject
LoadBalancingRulesManager _lbMgr;
@Inject
LoadBalancerDao _loadBalancerDao;
private final List<? extends FirewallRule> rules;
private List<LoadBalancingRule> loadbalancingRules;
private Purpose purpose;
public FirewallRules(final Network network, final List<? extends FirewallRule> rules) {
super(network);
this.rules = rules;
}
@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
this.router = router;
purpose = rules.get(0).getPurpose();
if (purpose == Purpose.LoadBalancing) {
// for load balancer we have to resend all lb rules for the network
final List<LoadBalancerVO> lbs = _loadBalancerDao.listByNetworkIdAndScheme(network.getId(), Scheme.Public);
loadbalancingRules = new ArrayList<LoadBalancingRule>();
for (final LoadBalancerVO lb : lbs) {
final List<LbDestination> dstList = _lbMgr.getExistingDestinations(lb.getId());
final List<LbStickinessPolicy> policyList = _lbMgr.getStickinessPolicies(lb.getId());
final List<LbHealthCheckPolicy> hcPolicyList = _lbMgr.getHealthCheckPolicies(lb.getId());
final LbSslCert sslCert = _lbMgr.getLbSslCert(lb.getId());
final Ip sourceIp = _networkModel.getPublicIpAddress(lb.getSourceIpAddressId()).getAddress();
final LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList, sourceIp, sslCert, lb.getLbProtocol());
loadbalancingRules.add(loadBalancing);
}
}
return visitor.visit(this);
}
public List<? extends FirewallRule> getRules() {
return rules;
}
public List<LoadBalancingRule> getLoadbalancingRules() {
return loadbalancingRules;
}
public Purpose getPurpose() {
return purpose;
}
}

View File

@ -0,0 +1,178 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.rules;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.routing.IpAssocCommand;
import com.cloud.agent.api.routing.NetworkElementCommand;
import com.cloud.agent.api.to.IpAddressTO;
import com.cloud.agent.manager.Commands;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.IpAddress;
import com.cloud.network.Network;
import com.cloud.network.NetworkModel;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PublicIpAddress;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.NetworkVO;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.topology.NetworkTopologyVisitor;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.NicVO;
import com.cloud.vm.dao.NicDao;
public class IpAssociationRules extends RuleApplier {
@Inject
NicDao _nicDao;
@Inject
NetworkDao _networkDao;
@Inject
DataCenterDao _dcDao;
@Inject
NetworkModel _networkModel;
private final List<? extends PublicIpAddress> ipAddresses;
private Commands commands;
public IpAssociationRules(final Network network, final List<? extends PublicIpAddress> ipAddresses) {
super(network);
this.ipAddresses = ipAddresses;
}
@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
this.router = router;
commands = new Commands(Command.OnError.Continue);
//
// Ensure that in multiple vlans case we first send all ip addresses of vlan1, then all ip addresses of vlan2, etc..
final Map<String, ArrayList<PublicIpAddress>> vlanIpMap = new HashMap<String, ArrayList<PublicIpAddress>>();
for (final PublicIpAddress ipAddress : ipAddresses) {
final String vlanTag = ipAddress.getVlanTag();
ArrayList<PublicIpAddress> ipList = vlanIpMap.get(vlanTag);
if (ipList == null) {
ipList = new ArrayList<PublicIpAddress>();
}
//domR doesn't support release for sourceNat IP address; so reset the state
if (ipAddress.isSourceNat() && ipAddress.getState() == IpAddress.State.Releasing) {
ipAddress.setState(IpAddress.State.Allocated);
}
ipList.add(ipAddress);
vlanIpMap.put(vlanTag, ipList);
}
final List<NicVO> nics = _nicDao.listByVmId(router.getId());
String baseMac = null;
for (final NicVO nic : nics) {
final NetworkVO nw = _networkDao.findById(nic.getNetworkId());
if (nw.getTrafficType() == TrafficType.Public) {
baseMac = nic.getMacAddress();
break;
}
}
for (final Map.Entry<String, ArrayList<PublicIpAddress>> vlanAndIp : vlanIpMap.entrySet()) {
final List<PublicIpAddress> ipAddrList = vlanAndIp.getValue();
// Source nat ip address should always be sent first
Collections.sort(ipAddrList, new Comparator<PublicIpAddress>() {
@Override
public int compare(final PublicIpAddress o1, final PublicIpAddress o2) {
final boolean s1 = o1.isSourceNat();
final boolean s2 = o2.isSourceNat();
return (s1 ^ s2) ? ((s1 ^ true) ? 1 : -1) : 0;
}
});
// Get network rate - required for IpAssoc
final Integer networkRate = _networkModel.getNetworkRate(ipAddrList.get(0).getNetworkId(), router.getId());
final Network network = _networkModel.getNetwork(ipAddrList.get(0).getNetworkId());
final IpAddressTO[] ipsToSend = new IpAddressTO[ipAddrList.size()];
int i = 0;
boolean firstIP = true;
for (final PublicIpAddress ipAddr : ipAddrList) {
final boolean add = (ipAddr.getState() == IpAddress.State.Releasing ? false : true);
boolean sourceNat = ipAddr.isSourceNat();
/* enable sourceNAT for the first ip of the public interface */
if (firstIP) {
sourceNat = true;
}
final String vlanId = ipAddr.getVlanTag();
final String vlanGateway = ipAddr.getGateway();
final String vlanNetmask = ipAddr.getNetmask();
String vifMacAddress = null;
// For non-source nat IP, set the mac to be something based on first public nic's MAC
// We cannot depends on first ip because we need to deal with first ip of other nics
if (!ipAddr.isSourceNat() && ipAddr.getVlanId() != 0) {
vifMacAddress = NetUtils.generateMacOnIncrease(baseMac, ipAddr.getVlanId());
} else {
vifMacAddress = ipAddr.getMacAddress();
}
final IpAddressTO ip =
new IpAddressTO(ipAddr.getAccountId(), ipAddr.getAddress().addr(), add, firstIP, sourceNat, vlanId, vlanGateway, vlanNetmask, vifMacAddress,
networkRate, ipAddr.isOneToOneNat());
ip.setTrafficType(network.getTrafficType());
ip.setNetworkName(_networkModel.getNetworkTag(router.getHypervisorType(), network));
ipsToSend[i++] = ip;
/* send the firstIP = true for the first Add, this is to create primary on interface*/
if (!firstIP || add) {
firstIP = false;
}
}
final IpAssocCommand cmd = new IpAssocCommand(ipsToSend);
//cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
//cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(ipAddrList.get(0).getAssociatedWithNetworkId(), router.getId()));
cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
commands.addCommand("IPAssocCommand", cmd);
}
//
return visitor.visit(this);
}
public List<? extends PublicIpAddress> getIpAddresses() {
return ipAddresses;
}
public Commands getCommands() {
return commands;
}
}

View File

@ -0,0 +1,139 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.rules;
import java.util.List;
import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
import com.cloud.agent.api.routing.NetworkElementCommand;
import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.agent.manager.Commands;
import com.cloud.configuration.Config;
import com.cloud.dc.DataCenterVO;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.dao.LoadBalancerVO;
import com.cloud.network.lb.LoadBalancingRule;
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
import com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy;
import com.cloud.network.lb.LoadBalancingRule.LbSslCert;
import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy;
import com.cloud.network.router.RouterControlHelper;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
import com.cloud.network.topology.NetworkTopologyVisitor;
import com.cloud.offering.NetworkOffering;
import com.cloud.utils.net.Ip;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.Nic;
import com.cloud.vm.NicProfile;
public class LoadBalancingRules extends RuleApplier {
private final List<LoadBalancingRule> rules;
protected RouterControlHelper routerControlHelper;
public LoadBalancingRules(final Network network, final List<LoadBalancingRule> rules) {
super(network);
this.rules = rules;
}
@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
this.router = router;
// For load balancer we have to resend all lb rules for the network
final List<LoadBalancerVO> lbs = loadBalancerDao.listByNetworkIdAndScheme(network.getId(), Scheme.Public);
// We are cleaning it before because all the rules have to be sent to the router.
rules.clear();
for (final LoadBalancerVO lb : lbs) {
final List<LbDestination> dstList = lbMgr.getExistingDestinations(lb.getId());
final List<LbStickinessPolicy> policyList = lbMgr.getStickinessPolicies(lb.getId());
final List<LbHealthCheckPolicy> hcPolicyList = lbMgr.getHealthCheckPolicies(lb.getId());
final LbSslCert sslCert = lbMgr.getLbSslCert(lb.getId());
final Ip sourceIp = networkModel.getPublicIpAddress(lb.getSourceIpAddressId()).getAddress();
final LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList, sourceIp, sslCert, lb.getLbProtocol());
rules.add(loadBalancing);
}
return visitor.visit(this);
}
public List<LoadBalancingRule> getRules() {
return rules;
}
public void createApplyLoadBalancingRulesCommands(final List<LoadBalancingRule> rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId) {
final LoadBalancerTO[] lbs = new LoadBalancerTO[rules.size()];
int i = 0;
// We don't support VR to be inline currently
final boolean inline = false;
for (final LoadBalancingRule rule : rules) {
final boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke));
final String protocol = rule.getProtocol();
final String algorithm = rule.getAlgorithm();
final String uuid = rule.getUuid();
final String srcIp = rule.getSourceIp().addr();
final int srcPort = rule.getSourcePortStart();
final List<LbDestination> destinations = rule.getDestinations();
final List<LbStickinessPolicy> stickinessPolicies = rule.getStickinessPolicies();
final LoadBalancerTO lb = new LoadBalancerTO(uuid, srcIp, srcPort, protocol, algorithm, revoked, false, inline, destinations, stickinessPolicies);
lbs[i++] = lb;
}
String routerPublicIp = null;
if (router instanceof DomainRouterVO) {
final DomainRouterVO domr = routerDao.findById(router.getId());
routerPublicIp = domr.getPublicIpAddress();
}
final Network guestNetwork = networkModel.getNetwork(guestNetworkId);
final Nic nic = nicDao.findByNtwkIdAndInstanceId(guestNetwork.getId(), router.getId());
final NicProfile nicProfile =
new NicProfile(nic, guestNetwork, nic.getBroadcastUri(), nic.getIsolationUri(), networkModel.getNetworkRate(guestNetwork.getId(), router.getId()),
networkModel.isSecurityGroupSupportedInNetwork(guestNetwork), networkModel.getNetworkTag(router.getHypervisorType(), guestNetwork));
final NetworkOffering offering = networkOfferingDao.findById(guestNetwork.getNetworkOfferingId());
String maxconn = null;
if (offering.getConcurrentConnections() == null) {
maxconn = configDao.getValue(Config.NetworkLBHaproxyMaxConn.key());
} else {
maxconn = offering.getConcurrentConnections().toString();
}
final LoadBalancerConfigCommand cmd =
new LoadBalancerConfigCommand(lbs, routerPublicIp, this.routerControlHelper.getRouterIpInNetwork(
guestNetworkId, router.getId()), router.getPrivateIpAddress(), itMgr.toNicTO(
nicProfile, router.getHypervisorType()), router.getVpcId(), maxconn, offering.isKeepAliveEnabled());
cmd.lbStatsVisibility = configDao.getValue(Config.NetworkLBHaproxyStatsVisbility.key());
cmd.lbStatsUri = configDao.getValue(Config.NetworkLBHaproxyStatsUri.key());
cmd.lbStatsAuth = configDao.getValue(Config.NetworkLBHaproxyStatsAuth.key());
cmd.lbStatsPort = configDao.getValue(Config.NetworkLBHaproxyStatsPort.key());
cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, this.routerControlHelper.getRouterControlIp(router.getId()));
cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, this.routerControlHelper.getRouterIpInNetwork(guestNetworkId, router.getId()));
cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
final DataCenterVO dcVo = dcDao.findById(router.getDataCenterId());
cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
cmds.addCommand(cmd);
}
}

View File

@ -0,0 +1,47 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.rules;
import java.util.List;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.topology.NetworkTopologyVisitor;
import com.cloud.network.vpc.NetworkACLItem;
public class NetworkAclsRules extends RuleApplier {
private final List<? extends NetworkACLItem> rules;
public NetworkAclsRules(final Network network, final List<? extends NetworkACLItem> rules) {
super(network);
this.rules = rules;
}
@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
this.router = router;
return visitor.visit(this);
}
public List<? extends NetworkACLItem> getRules() {
return rules;
}
}

View File

@ -0,0 +1,53 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.rules;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.topology.NetworkTopologyVisitor;
import com.cloud.vm.NicProfile;
import com.cloud.vm.VirtualMachineProfile;
public class PasswordToRouterRules extends RuleApplier {
private final NicProfile nic;
private final VirtualMachineProfile profile;
public PasswordToRouterRules(final Network network, final NicProfile nic, final VirtualMachineProfile profile) {
super(network);
this.nic = nic;
this.profile = profile;
}
@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
this.router = router;
return visitor.visit(this);
}
public NicProfile getNic() {
return nic;
}
public VirtualMachineProfile getProfile() {
return profile;
}
}

View File

@ -0,0 +1,47 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.rules;
import java.util.List;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.topology.NetworkTopologyVisitor;
import com.cloud.network.vpc.NetworkACLItem;
public class PrivateGatewayRules extends RuleApplier {
private final List<? extends NetworkACLItem> rules;
public PrivateGatewayRules(final Network network, final List<? extends NetworkACLItem> rules) {
super(network);
this.rules = rules;
}
@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
this.router = router;
return visitor.visit(this);
}
public List<? extends NetworkACLItem> getRules() {
return rules;
}
}

View File

@ -0,0 +1,71 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.rules;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.NetworkModel;
import com.cloud.network.dao.LoadBalancerDao;
import com.cloud.network.lb.LoadBalancingRulesManager;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.topology.NetworkTopologyVisitor;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.vm.VirtualMachineManager;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.NicDao;
public abstract class RuleApplier {
protected NetworkModel networkModel;
protected LoadBalancingRulesManager lbMgr;
protected LoadBalancerDao loadBalancerDao;
protected ConfigurationDao configDao;
protected NicDao nicDao;
protected NetworkOfferingDao networkOfferingDao = null;
protected DataCenterDao dcDao = null;
protected DomainRouterDao routerDao = null;
protected VirtualMachineManager itMgr;
protected Network network;
protected VirtualRouter router;
public RuleApplier(final Network network) {
this.network = network;
}
public abstract boolean accept(NetworkTopologyVisitor visitor, VirtualRouter router) throws ResourceUnavailableException;
public Network getNetwork() {
return network;
}
public VirtualRouter getRouter() {
return router;
}
}

View File

@ -0,0 +1,53 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.rules;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.topology.NetworkTopologyVisitor;
import com.cloud.vm.NicProfile;
import com.cloud.vm.VirtualMachineProfile;
public class SshKeyToRouterRules extends RuleApplier {
private final NicProfile nic;
private final VirtualMachineProfile profile;
public SshKeyToRouterRules(final Network network, final NicProfile nic, final VirtualMachineProfile profile) {
super(network);
this.nic = nic;
this.profile = profile;
}
@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
this.router = router;
return visitor.visit(this);
}
public NicProfile getNic() {
return nic;
}
public VirtualMachineProfile getProfile() {
return profile;
}
}

View File

@ -0,0 +1,83 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.rules;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import com.cloud.agent.api.routing.NetworkElementCommand;
import com.cloud.agent.api.routing.SetStaticNatRulesCommand;
import com.cloud.agent.api.to.StaticNatRuleTO;
import com.cloud.agent.manager.Commands;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.IpAddress;
import com.cloud.network.Network;
import com.cloud.network.NetworkModel;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.topology.NetworkTopologyVisitor;
public class StaticNatRules extends RuleApplier {
@Inject
DataCenterDao _dcDao;
@Inject
NetworkModel _networkModel;
private final List<? extends StaticNat> rules;
public StaticNatRules(final Network network, final List<? extends StaticNat> rules) {
super(network);
this.rules = rules;
}
public List<? extends StaticNat> getRules() {
return rules;
}
@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
this.router = router;
return visitor.visit(this);
}
public void createApplyStaticNatCommands(final List<? extends StaticNat> rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId) {
List<StaticNatRuleTO> rulesTO = new ArrayList<StaticNatRuleTO>();
if (rules != null) {
for (final StaticNat rule : rules) {
final IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
final StaticNatRuleTO ruleTO =
new StaticNatRuleTO(0, sourceIp.getAddress().addr(), null, null, rule.getDestIpAddress(), null, null, null, rule.isForRevoke(), false);
rulesTO.add(ruleTO);
}
}
final SetStaticNatRulesCommand cmd = new SetStaticNatRulesCommand(rulesTO, router.getVpcId());
//cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
//cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(guestNetworkId, router.getId()));
cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
cmds.addCommand(cmd);
}
}

View File

@ -0,0 +1,60 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.rules;
import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.topology.NetworkTopologyVisitor;
import com.cloud.vm.NicProfile;
import com.cloud.vm.VirtualMachineProfile;
public class UserdataPwdRules extends RuleApplier {
private final NicProfile nic;
private final VirtualMachineProfile profile;
private final DeployDestination destination;
public UserdataPwdRules(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination destination) {
super(network);
this.nic = nic;
this.profile = profile;
this.destination = destination;
}
@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
this.router = router;
return visitor.visit(this);
}
public NicProfile getNic() {
return nic;
}
public VirtualMachineProfile getProfile() {
return profile;
}
public DeployDestination getDestination() {
return destination;
}
}

View File

@ -0,0 +1,67 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.rules;
import com.cloud.agent.api.Command;
import com.cloud.agent.manager.Commands;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.topology.NetworkTopologyVisitor;
import com.cloud.vm.NicProfile;
import com.cloud.vm.VirtualMachineProfile;
public class UserdataToRouterRules extends RuleApplier {
private final NicProfile nic;
private final VirtualMachineProfile profile;
public UserdataToRouterRules(final Network network, final NicProfile nic, final VirtualMachineProfile profile) {
super(network);
this.nic = nic;
this.profile = profile;
}
@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
this.router = router;
// for basic zone, send vm data/password information only to the router in the same pod
final Commands cmds = new Commands(Command.OnError.Stop);
//final NicVO nicVo = _nicDao.findById(nic.getId());
//final String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId()).getDisplayText();
//final String zoneName = _dcDao.findById(router.getDataCenterId()).getName();
// cmds.addCommand(
// "vmdata",
// generateVmDataCommand(router, nic.getIp4Address(), vm.getUserData(), serviceOffering, zoneName, nic.getIp4Address(), vm.getHostName(), vm.getInstanceName(),
// vm.getId(), vm.getUuid(), null, nic.getNetworkId()));
return visitor.visit(this);
}
public NicProfile getNic() {
return nic;
}
public VirtualMachineProfile getProfile() {
return profile;
}
}

View File

@ -0,0 +1,66 @@
package com.cloud.network.rules;
import java.util.List;
import javax.inject.Inject;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.network.Network;
import com.cloud.network.NetworkModel;
import com.cloud.network.dao.LoadBalancerDao;
import com.cloud.network.lb.LoadBalancingRule;
import com.cloud.network.lb.LoadBalancingRulesManager;
import com.cloud.network.router.RouterControlHelper;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.NicDao;
public class VirtualNetworkApplianceFactory {
@Inject
protected NetworkModel networkModel;
@Inject
protected LoadBalancingRulesManager lbMgr;
@Inject
protected LoadBalancerDao loadBalancerDao;
@Inject
protected ConfigurationDao configDao;
@Inject
protected NicDao nicDao;
@Inject
protected NetworkOfferingDao networkOfferingDao;
@Inject
protected DataCenterDao dcDao;
@Inject
protected DomainRouterDao routerDao;
@Inject
protected RouterControlHelper routerControlHelper;
public LoadBalancingRules createLoadBalancingRules(final Network network,
final List<LoadBalancingRule> rules) {
LoadBalancingRules lbRules = new LoadBalancingRules(network, rules);
lbRules.networkModel = this.networkModel;
lbRules.dcDao = this.dcDao;
lbRules.lbMgr = this.lbMgr;
lbRules.loadBalancerDao = this.loadBalancerDao;
lbRules.configDao = this.configDao;
lbRules.nicDao = this.nicDao;
lbRules.networkOfferingDao = this.networkOfferingDao;
lbRules.routerDao = this.routerDao;
lbRules.routerControlHelper = this.routerControlHelper;
return lbRules;
}
}

View File

@ -0,0 +1,47 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.rules;
import java.util.List;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.PublicIpAddress;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.topology.NetworkTopologyVisitor;
public class VpcIpAssociationRules extends RuleApplier {
private final List<? extends PublicIpAddress> ipAddresses;
public VpcIpAssociationRules(final Network network, final List<? extends PublicIpAddress> ipAddresses) {
super(network);
this.ipAddresses = ipAddresses;
}
@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
this.router = router;
return visitor.visit(this);
}
public List<? extends PublicIpAddress> getIpAddresses() {
return ipAddresses;
}
}

View File

@ -0,0 +1,47 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.rules;
import java.util.List;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.topology.NetworkTopologyVisitor;
import com.cloud.network.vpc.NetworkACLItem;
public class VpnRules extends RuleApplier {
private final List<? extends NetworkACLItem> rules;
public VpnRules(final Network network, final List<? extends NetworkACLItem> rules) {
super(network);
this.rules = rules;
}
@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
this.router = router;
return visitor.visit(this);
}
public List<? extends NetworkACLItem> getRules() {
return rules;
}
}

View File

@ -0,0 +1,107 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.topology;
import java.util.List;
import java.util.Map;
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.lb.LoadBalancingRule;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.rules.RuleApplier;
import com.cloud.user.Account;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.NicProfile;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.VirtualMachineProfile.Param;
public class AdvancedNetworkTopology implements NetworkTopology {
@Override
public List<DomainRouterVO> findOrDeployVirtualRouterInGuestNetwork(
final Network guestNetwork, final DeployDestination dest, final Account owner,
final boolean isRedundant, final Map<Param, Object> params)
throws ConcurrentOperationException, InsufficientCapacityException,
ResourceUnavailableException {
return null;
}
@Override
public StringBuilder createGuestBootLoadArgs(final NicProfile guestNic,
final String defaultDns1, final String defaultDns2, final DomainRouterVO router) {
return null;
}
@Override
public String retrieveGuestDhcpRange(final NicProfile guestNic,
final Network guestNetwork, final DataCenter dc) {
return null;
}
@Override
public NicProfile retrieveControlNic(final VirtualMachineProfile profile) {
return null;
}
@Override
public boolean configDhcpForSubnet(final Network network, final NicProfile nic,
final VirtualMachineProfile profile, final DeployDestination dest,
final List<DomainRouterVO> routers) throws ResourceUnavailableException {
return false;
}
@Override
public boolean applyDhcpEntry(final Network network, final NicProfile nic,
final VirtualMachineProfile profile, final DeployDestination dest,
final List<DomainRouterVO> routers) throws ResourceUnavailableException {
return false;
}
@Override
public boolean applyUserData(final Network network, final NicProfile nic,
final VirtualMachineProfile profile, final DeployDestination dest,
final List<DomainRouterVO> routers) throws ResourceUnavailableException {
return false;
}
@Override
public boolean applyRules(final Network network,
final List<? extends VirtualRouter> routers, final String typeString,
final boolean isPodLevelException, final Long podId,
final boolean failWhenDisconnect, final RuleApplier applier)
throws ResourceUnavailableException {
AdvancedNetworkVisitor visitor = new AdvancedNetworkVisitor(this);
applier.accept(visitor, null);
return false;
}
@Override
public boolean sendCommandsToRouter(VirtualRouter router,
List<LoadBalancingRule> rules, long id) {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -0,0 +1,162 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.topology;
import java.util.List;
import com.cloud.agent.api.Command;
import com.cloud.agent.manager.Commands;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.lb.LoadBalancingRule;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.rules.DhcpRules;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.FirewallRule.Purpose;
import com.cloud.network.rules.FirewallRules;
import com.cloud.network.rules.IpAssociationRules;
import com.cloud.network.rules.LoadBalancingRules;
import com.cloud.network.rules.NetworkAclsRules;
import com.cloud.network.rules.PasswordToRouterRules;
import com.cloud.network.rules.PrivateGatewayRules;
import com.cloud.network.rules.SshKeyToRouterRules;
import com.cloud.network.rules.StaticNat;
import com.cloud.network.rules.StaticNatRules;
import com.cloud.network.rules.UserdataPwdRules;
import com.cloud.network.rules.UserdataToRouterRules;
import com.cloud.network.rules.VpcIpAssociationRules;
import com.cloud.network.rules.VpnRules;
public class AdvancedNetworkVisitor extends NetworkTopologyVisitor {
public AdvancedNetworkVisitor(final NetworkTopology networkTopology) {
super(networkTopology);
}
@Override
public boolean visit(final StaticNatRules nat) throws ResourceUnavailableException {
Network network = nat.getNetwork();
VirtualRouter router = nat.getRouter();
List<? extends StaticNat> rules = nat.getRules();
final Commands cmds = new Commands(Command.OnError.Continue);
nat.createApplyStaticNatCommands(rules, router, cmds, network.getId());
//return sendCommandsToRouter(router, cmds);
return false;
}
@Override
public boolean visit(final LoadBalancingRules loadbalancing) throws ResourceUnavailableException {
Network network = loadbalancing.getNetwork();
VirtualRouter router = loadbalancing.getRouter();
List<LoadBalancingRule> rules = loadbalancing.getRules();
final Commands cmds = new Commands(Command.OnError.Continue);
loadbalancing.createApplyLoadBalancingRulesCommands(rules, router, cmds, network.getId());
return networkTopology.sendCommandsToRouter(router, rules, network.getId());
}
@Override
public boolean visit(final FirewallRules firewall) throws ResourceUnavailableException {
Network network = firewall.getNetwork();
VirtualRouter router = firewall.getRouter();
List<? extends FirewallRule> rules = firewall.getRules();
List<LoadBalancingRule> loadbalancingRules = firewall.getLoadbalancingRules();
Purpose purpose = firewall.getPurpose();
if (purpose == Purpose.LoadBalancing) {
//return sendLBRules(router, loadbalancingRules, network.getId());
} else if (purpose == Purpose.PortForwarding) {
//return sendPortForwardingRules(router, (List<PortForwardingRule>)rules, network.getId());
} else if (purpose == Purpose.StaticNat) {
//return sendStaticNatRules(router, (List<StaticNatRule>)rules, network.getId());
} else if (purpose == Purpose.Firewall) {
//return sendFirewallRules(router, (List<FirewallRule>)rules, network.getId());
}
//s_logger.warn("Unable to apply rules of purpose: " + rules.get(0).getPurpose());
return false;
}
@Override
public boolean visit(final IpAssociationRules ipRules) throws ResourceUnavailableException {
VirtualRouter router = ipRules.getRouter();
Commands commands = ipRules.getCommands();
//return sendCommandsToRouter(router, commands);
return false;
}
@Override
public boolean visit(final UserdataPwdRules nat) throws ResourceUnavailableException {
return false;
}
@Override
public boolean visit(final DhcpRules nat) throws ResourceUnavailableException {
return false;
}
@Override
public boolean visit(final SshKeyToRouterRules nat) throws ResourceUnavailableException {
return false;
}
@Override
public boolean visit(final PasswordToRouterRules nat) throws ResourceUnavailableException {
return false;
}
@Override
public boolean visit(final NetworkAclsRules nat) throws ResourceUnavailableException {
return false;
}
@Override
public boolean visit(final VpcIpAssociationRules nat) throws ResourceUnavailableException {
return false;
}
@Override
public boolean visit(final UserdataToRouterRules userdata) throws ResourceUnavailableException {
return false;
}
@Override
public boolean visit(PrivateGatewayRules userdata) throws ResourceUnavailableException {
return false;
}
@Override
public boolean visit(VpnRules userdata) throws ResourceUnavailableException {
return false;
}
}

View File

@ -0,0 +1,102 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.topology;
import java.util.List;
import java.util.Map;
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.lb.LoadBalancingRule;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.rules.RuleApplier;
import com.cloud.user.Account;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.NicProfile;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.VirtualMachineProfile.Param;
public class BasicNetworkTopology implements NetworkTopology {
@Override
public List<DomainRouterVO> findOrDeployVirtualRouterInGuestNetwork(
final Network guestNetwork, final DeployDestination dest, final Account owner,
final boolean isRedundant, final Map<Param, Object> params)
throws ConcurrentOperationException, InsufficientCapacityException,
ResourceUnavailableException {
return null;
}
@Override
public StringBuilder createGuestBootLoadArgs(final NicProfile guestNic,
final String defaultDns1, final String defaultDns2, final DomainRouterVO router) {
return null;
}
@Override
public String retrieveGuestDhcpRange(final NicProfile guestNic,
final Network guestNetwork, final DataCenter dc) {
return null;
}
@Override
public NicProfile retrieveControlNic(final VirtualMachineProfile profile) {
return null;
}
@Override
public boolean configDhcpForSubnet(final Network network, final NicProfile nic,
final VirtualMachineProfile profile, final DeployDestination dest,
final List<DomainRouterVO> routers) throws ResourceUnavailableException {
return false;
}
@Override
public boolean applyDhcpEntry(final Network network, final NicProfile nic,
final VirtualMachineProfile profile, final DeployDestination dest,
final List<DomainRouterVO> routers) throws ResourceUnavailableException {
return false;
}
@Override
public boolean applyUserData(final Network network, final NicProfile nic,
final VirtualMachineProfile profile, final DeployDestination dest,
final List<DomainRouterVO> routers) throws ResourceUnavailableException {
return false;
}
@Override
public boolean applyRules(final Network network,
final List<? extends VirtualRouter> routers, final String typeString,
final boolean isPodLevelException, final Long podId,
final boolean failWhenDisconnect, final RuleApplier applier)
throws ResourceUnavailableException {
return false;
}
@Override
public boolean sendCommandsToRouter(VirtualRouter router,
List<LoadBalancingRule> rules, long id) {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -0,0 +1,111 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.topology;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.rules.DhcpRules;
import com.cloud.network.rules.FirewallRules;
import com.cloud.network.rules.IpAssociationRules;
import com.cloud.network.rules.LoadBalancingRules;
import com.cloud.network.rules.NetworkAclsRules;
import com.cloud.network.rules.PasswordToRouterRules;
import com.cloud.network.rules.PrivateGatewayRules;
import com.cloud.network.rules.SshKeyToRouterRules;
import com.cloud.network.rules.StaticNatRules;
import com.cloud.network.rules.UserdataPwdRules;
import com.cloud.network.rules.UserdataToRouterRules;
import com.cloud.network.rules.VpcIpAssociationRules;
import com.cloud.network.rules.VpnRules;
public class BasicNetworkVisitor extends NetworkTopologyVisitor {
public BasicNetworkVisitor(final NetworkTopology networkTopology) {
super(networkTopology);
}
@Override
public boolean visit(final StaticNatRules nat) throws ResourceUnavailableException {
return false;
}
@Override
public boolean visit(final LoadBalancingRules nat) throws ResourceUnavailableException {
return false;
}
@Override
public boolean visit(final FirewallRules nat) throws ResourceUnavailableException {
return false;
}
@Override
public boolean visit(final IpAssociationRules nat) throws ResourceUnavailableException {
return false;
}
@Override
public boolean visit(final UserdataPwdRules nat) throws ResourceUnavailableException {
return false;
}
@Override
public boolean visit(final DhcpRules nat) throws ResourceUnavailableException {
return false;
}
@Override
public boolean visit(final SshKeyToRouterRules nat) throws ResourceUnavailableException {
return false;
}
@Override
public boolean visit(final PasswordToRouterRules nat) throws ResourceUnavailableException {
return false;
}
@Override
public boolean visit(final NetworkAclsRules nat) throws ResourceUnavailableException {
return false;
}
@Override
public boolean visit(final VpcIpAssociationRules nat) throws ResourceUnavailableException {
return false;
}
@Override
public boolean visit(final UserdataToRouterRules userdata) throws ResourceUnavailableException {
Network network = userdata.getNetwork();
VirtualRouter router = userdata.getRouter();
//return sendCommandsToRouter(router, cmds);
return false;
}
@Override
public boolean visit(PrivateGatewayRules userdata) throws ResourceUnavailableException {
return false;
}
@Override
public boolean visit(VpnRules userdata) throws ResourceUnavailableException {
return false;
}
}

View File

@ -0,0 +1,63 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.topology;
import java.util.List;
import java.util.Map;
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.lb.LoadBalancingRule;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.rules.RuleApplier;
import com.cloud.user.Account;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.NicProfile;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.VirtualMachineProfile.Param;
public interface NetworkTopology {
List<DomainRouterVO> findOrDeployVirtualRouterInGuestNetwork(final Network guestNetwork, final DeployDestination dest, Account owner, final boolean isRedundant,
final Map<Param, Object> params) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException;
StringBuilder createGuestBootLoadArgs(final NicProfile guestNic, final String defaultDns1, final String defaultDns2, DomainRouterVO router);
String retrieveGuestDhcpRange(final NicProfile guestNic, final Network guestNetwork, final DataCenter dc);
NicProfile retrieveControlNic(final VirtualMachineProfile profile);
boolean configDhcpForSubnet(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination dest, final List<DomainRouterVO> routers)
throws ResourceUnavailableException;
boolean applyDhcpEntry(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination dest, final List<DomainRouterVO> routers)
throws ResourceUnavailableException;
boolean applyUserData(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination dest, final List<DomainRouterVO> routers)
throws ResourceUnavailableException;
boolean applyRules(final Network network, final List<? extends VirtualRouter> routers, final String typeString, final boolean isPodLevelException, final Long podId,
final boolean failWhenDisconnect, final RuleApplier applier) throws ResourceUnavailableException;
boolean sendCommandsToRouter(VirtualRouter router,
List<LoadBalancingRule> rules, long id);
}

View File

@ -0,0 +1,52 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.topology;
import java.util.Hashtable;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.NetworkType;
public final class NetworkTopologyContext {
private static NetworkTopologyContext instance;
static {
instance = new NetworkTopologyContext();
}
private final Hashtable<NetworkType, NetworkTopology> flyweight;
private NetworkTopologyContext() {
flyweight = new Hashtable<DataCenter.NetworkType, NetworkTopology>();
flyweight.put(NetworkType.Basic, new BasicNetworkTopology());
flyweight.put(NetworkType.Advanced, new AdvancedNetworkTopology());
}
public static NetworkTopologyContext getInstance() {
return instance;
}
public NetworkTopology retrieveNetworkTopology(final DataCenter dc) {
if (!flyweight.containsKey(dc.getNetworkType())) {
throw new IllegalArgumentException("The type given cannot be related to a NetworkTopology implementation. "
+ "Please, give a correct type.");
}
return flyweight.get(dc.getNetworkType());
}
}

View File

@ -0,0 +1,60 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.topology;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.rules.DhcpRules;
import com.cloud.network.rules.FirewallRules;
import com.cloud.network.rules.IpAssociationRules;
import com.cloud.network.rules.LoadBalancingRules;
import com.cloud.network.rules.NetworkAclsRules;
import com.cloud.network.rules.PasswordToRouterRules;
import com.cloud.network.rules.PrivateGatewayRules;
import com.cloud.network.rules.SshKeyToRouterRules;
import com.cloud.network.rules.StaticNatRules;
import com.cloud.network.rules.UserdataPwdRules;
import com.cloud.network.rules.UserdataToRouterRules;
import com.cloud.network.rules.VpcIpAssociationRules;
import com.cloud.network.rules.VpnRules;
public abstract class NetworkTopologyVisitor {
protected final NetworkTopology networkTopology;
public NetworkTopologyVisitor(final NetworkTopology networkTopology) {
this.networkTopology = networkTopology;
}
public abstract boolean visit(StaticNatRules nat) throws ResourceUnavailableException;
public abstract boolean visit(LoadBalancingRules loadbalancing) throws ResourceUnavailableException;
public abstract boolean visit(FirewallRules firewall) throws ResourceUnavailableException;
public abstract boolean visit(IpAssociationRules ipAddresses) throws ResourceUnavailableException;
public abstract boolean visit(UserdataPwdRules userdata) throws ResourceUnavailableException;
public abstract boolean visit(DhcpRules dhcp) throws ResourceUnavailableException;
public abstract boolean visit(SshKeyToRouterRules ssh) throws ResourceUnavailableException;
public abstract boolean visit(PasswordToRouterRules pwd) throws ResourceUnavailableException;
public abstract boolean visit(NetworkAclsRules acl) throws ResourceUnavailableException;
public abstract boolean visit(VpcIpAssociationRules vpcIp) throws ResourceUnavailableException;
public abstract boolean visit(UserdataToRouterRules userdata) throws ResourceUnavailableException;
public abstract boolean visit(VpnRules userdata) throws ResourceUnavailableException;
public abstract boolean visit(PrivateGatewayRules userdata) throws ResourceUnavailableException;
public NetworkTopology getNetworkTopology() {
return networkTopology;
}
}