Added a new table for inline load balancer deployments, to store mappings between public IPs and NICs.

This commit is contained in:
keshav 2011-08-03 16:10:20 -07:00
parent 66fe12910c
commit 34a0c44f4f
11 changed files with 180 additions and 10 deletions

View File

@ -26,6 +26,7 @@ public abstract class NetworkElementCommand extends Command {
public static final String ACCOUNT_ID = "account.id";
public static final String GUEST_NETWORK_CIDR = "guest.network.cidr";
public static final String GUEST_VLAN_TAG = "guest.vlan.tag";
public static final String ROUTER_NAME = "router.name";
public static final String ROUTER_IP = "router.ip";
public static final String ROUTER_GUEST_IP = "router.guest.ip";

View File

@ -75,6 +75,7 @@ public class ApiConstants {
public static final String HA_ENABLE = "haenable";
public static final String HOST_ID = "hostid";
public static final String HYPERVISOR = "hypervisor";
public static final String INLINE = "inline";
public static final String INSTANCE = "instance";
public static final String ICMP_CODE = "icmpcode";
public static final String ICMP_TYPE = "icmptype";

View File

@ -74,6 +74,7 @@ import com.cloud.network.NetworkManagerImpl;
import com.cloud.network.dao.FirewallRulesCidrsDaoImpl;
import com.cloud.network.dao.FirewallRulesDaoImpl;
import com.cloud.network.dao.IPAddressDaoImpl;
import com.cloud.network.dao.InlineLoadBalancerNicMapDaoImpl;
import com.cloud.network.dao.LoadBalancerDaoImpl;
import com.cloud.network.dao.LoadBalancerVMMapDaoImpl;
import com.cloud.network.dao.NetworkDaoImpl;
@ -268,6 +269,7 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com
addDao("SwiftDao", SwiftDaoImpl.class);
addDao("AgentTransferMapDao", HostTransferMapDaoImpl.class);
addDao("ProjectDao", ProjectDaoImpl.class);
addDao("InlineLoadBalancerNicMapDao", InlineLoadBalancerNicMapDaoImpl.class);
}
@Override

View File

@ -0,0 +1,68 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.network;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name=("inline_load_balancer_nic_map"))
public class InlineLoadBalancerNicMapVO {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private long id;
@Column(name="load_balancer_id")
private long loadBalancerId;
@Column(name="public_ip_address")
private String publicIpAddress;
@Column(name="nic_id")
private long nicId;
public InlineLoadBalancerNicMapVO() { }
public InlineLoadBalancerNicMapVO(long loadBalancerId, String publicIpAddress, long nicId) {
this.loadBalancerId = loadBalancerId;
this.publicIpAddress = publicIpAddress;
this.nicId = nicId;
}
public long getId() {
return id;
}
public long getLoadBalancerId() {
return loadBalancerId;
}
public String getPublicIpAddress() {
return publicIpAddress;
}
public long getNicId() {
return nicId;
}
}

View File

@ -0,0 +1,27 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.network.dao;
import com.cloud.network.InlineLoadBalancerNicMapVO;
import com.cloud.utils.db.GenericDao;
public interface InlineLoadBalancerNicMapDao extends GenericDao<InlineLoadBalancerNicMapVO, Long> {
InlineLoadBalancerNicMapVO findByPublicIpAddress(String publicIpAddress);
InlineLoadBalancerNicMapVO findByNicId(long nicId);
}

View File

@ -0,0 +1,46 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.network.dao;
import javax.ejb.Local;
import com.cloud.network.InlineLoadBalancerNicMapVO;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchCriteria;
@Local(value={InlineLoadBalancerNicMapDao.class})
public class InlineLoadBalancerNicMapDaoImpl extends GenericDaoBase<InlineLoadBalancerNicMapVO, Long> implements InlineLoadBalancerNicMapDao {
@Override
public InlineLoadBalancerNicMapVO findByPublicIpAddress(String publicIpAddress) {
SearchCriteria<InlineLoadBalancerNicMapVO> sc = createSearchCriteria();
sc.addAnd("publicIpAddress", SearchCriteria.Op.EQ, publicIpAddress);
return findOneBy(sc);
}
@Override
public InlineLoadBalancerNicMapVO findByNicId(long nicId) {
SearchCriteria<InlineLoadBalancerNicMapVO> sc = createSearchCriteria();
sc.addAnd("nicId", SearchCriteria.Op.EQ, nicId);
return findOneBy(sc);
}
}

View File

@ -450,10 +450,8 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
for (LoadBalancerVO lb : lbs) {
List<LbDestination> dstList = getExistingDestinations(lb.getId());
if (dstList != null && !dstList.isEmpty()) {
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList);
rules.add(loadBalancing);
}
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList);
rules.add(loadBalancing);
}
if (!_networkMgr.applyRules(rules, false)) {

View File

@ -2048,13 +2048,18 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
List<LoadBalancerVO> lbs = _loadBalancerDao.listByNetworkId(network.getId());
List<LoadBalancingRule> lbRules = new ArrayList<LoadBalancingRule>();
for (LoadBalancerVO lb : lbs) {
List<LbDestination> dstList = _lbMgr.getExistingDestinations(lb.getId());
// load the cidrs,
lb.setSourceCidrList(_firewallCidrsDao.getSourceCidrs(lb.getId()));
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList);
lbRules.add(loadBalancing);
List<LbDestination> dstList = _lbMgr.getExistingDestinations(lb.getId());
if (dstList != null && !dstList.isEmpty()) {
// load the cidrs,
lb.setSourceCidrList(_firewallCidrsDao.getSourceCidrs(lb.getId()));
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList);
lbRules.add(loadBalancing);
}
}
if (!lbRules.isEmpty()) {
result = result && applyLBRules(router, lbRules);
}
result = result && applyLBRules(router, lbRules);
} else if (rules.get(0).getPurpose() == Purpose.PortForwarding) {
result = result && applyPortForwardingRules(router, (List<PortForwardingRule>) rules);
} else if (rules.get(0).getPurpose() == Purpose.StaticNat) {

View File

@ -42,4 +42,6 @@ public interface NicDao extends GenericDao<NicVO, Long> {
void removeNicsForInstance(long instanceId);
NicVO findByNetworkIdAndType(long networkId, VirtualMachine.Type vmType);
NicVO findByIp4Address(String ip4Address);
}

View File

@ -46,6 +46,7 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
AllFieldsSearch.and("instance", AllFieldsSearch.entity().getInstanceId(), Op.EQ);
AllFieldsSearch.and("network", AllFieldsSearch.entity().getNetworkId(), Op.EQ);
AllFieldsSearch.and("vmType", AllFieldsSearch.entity().getVmType(), Op.EQ);
AllFieldsSearch.and("address", AllFieldsSearch.entity().getIp4Address(), Op.EQ);
AllFieldsSearch.done();
IpSearch = createSearchBuilder(String.class);
@ -114,4 +115,11 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
sc.setParameters("vmType", vmType);
return findOneBy(sc);
}
@Override
public NicVO findByIp4Address(String ip4Address) {
SearchCriteria<NicVO> sc = AllFieldsSearch.create();
sc.setParameters("address", ip4Address);
return findOneBy(sc);
}
}

View File

@ -61,6 +61,7 @@ DROP TABLE IF EXISTS `cloud`.`sync_queue`;
DROP TABLE IF EXISTS `cloud`.`sync_queue_item`;
DROP TABLE IF EXISTS `cloud`.`security_group_vm_map`;
DROP TABLE IF EXISTS `cloud`.`load_balancer_vm_map`;
DROP TABLE IF EXISTS `cloud`.`load_balancer_inline_ip_map`;
DROP TABLE IF EXISTS `cloud`.`storage_pool`;
DROP TABLE IF EXISTS `cloud`.`storage_pool_host_ref`;
DROP TABLE IF EXISTS `cloud`.`template_spool_ref`;
@ -626,6 +627,17 @@ CREATE TABLE `cloud`.`load_balancer_vm_map` (
CONSTRAINT `fk_load_balancer_vm_map__instance_id` FOREIGN KEY(`instance_id`) REFERENCES `vm_instance`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`inline_load_balancer_nic_map` (
`id` bigint unsigned NOT NULL auto_increment,
`load_balancer_id` bigint unsigned NOT NULL,
`public_ip_address` char(40) NOT NULL,
`nic_id` bigint unsigned NULL COMMENT 'nic id',
PRIMARY KEY (`id`),
UNIQUE KEY (`nic_id`),
CONSTRAINT `fk_inline_load_balancer_nic_map__load_balancer_id` FOREIGN KEY(`load_balancer_id`) REFERENCES `load_balancing_rules`(`id`) ON DELETE CASCADE,
CONSTRAINT `fk_inline_load_balancer_nic_map__nic_id` FOREIGN KEY(`nic_id`) REFERENCES `nics`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`port_forwarding_rules` (
`id` bigint unsigned NOT NULL COMMENT 'id',
`instance_id` bigint unsigned NOT NULL COMMENT 'vm instance id',