NaaS: Add VirtualRouterElements table

It would cover the configuration of DHCPElement, VirtualRouterElement and
RedundantVirtualRouterElement.

Also add foreign key in domain_router table to reflect the domain_router is
created from which element and use what configuration.
This commit is contained in:
Sheng Yang 2011-10-20 13:48:21 -07:00
parent 04f106a595
commit fdc354adb5
8 changed files with 393 additions and 10 deletions

View File

@ -36,6 +36,9 @@ import com.cloud.network.router.VirtualRouter;
@PrimaryKeyJoinColumn(name="id")
@DiscriminatorValue(value="DomainRouter")
public class DomainRouterVO extends VMInstanceVO implements VirtualRouter {
@Column(name="element_id")
private long elementId;
@Column(name="public_ip_address")
private String publicIpAddress;
@ -79,6 +82,7 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter {
public DomainRouterVO(long id,
long serviceOfferingId,
long elementId,
String name,
long templateId,
HypervisorType hypervisorType,
@ -90,9 +94,9 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter {
int priority,
boolean isPriorityBumpUp,
RedundantState redundantState,
boolean haEnabled,
boolean stopPending) {
boolean haEnabled, boolean stopPending) {
super(id, serviceOfferingId, name, name, Type.DomainRouter, templateId, hypervisorType, guestOSId, domainId, accountId, haEnabled);
this.elementId = elementId;
this.networkId = networkId;
this.isRedundantRouter = isRedundantRouter;
this.priority = priority;
@ -103,6 +107,7 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter {
public DomainRouterVO(long id,
long serviceOfferingId,
long elementId,
String name,
long templateId,
HypervisorType hypervisorType,
@ -115,9 +120,9 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter {
boolean isPriorityBumpUp,
RedundantState redundantState,
boolean haEnabled,
boolean stopPending,
VirtualMachine.Type vmType) {
boolean stopPending, VirtualMachine.Type vmType) {
super(id, serviceOfferingId, name, name, vmType, templateId, hypervisorType, guestOSId, domainId, accountId, haEnabled);
this.elementId = elementId;
this.networkId = networkId;
this.isRedundantRouter = isRedundantRouter;
this.priority = priority;
@ -126,6 +131,10 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter {
this.stopPending = stopPending;
}
public long getElementId() {
return elementId;
}
public void setPublicIpAddress(String publicIpAddress) {
this.publicIpAddress = publicIpAddress;
}

View File

@ -0,0 +1,29 @@
/**
* Copyright (C) 2011 Citrix Systems, 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 java.util.List;
import com.cloud.network.element.VirtualRouterElementsVO;
import com.cloud.network.element.VirtualRouterElements.VirtualRouterElementsType;
import com.cloud.utils.db.GenericDao;
public interface VirtualRouterElementsDao extends GenericDao<VirtualRouterElementsVO, Long> {
public List<VirtualRouterElementsVO> findByNspIdAndType(long nspId, VirtualRouterElementsType type);
public VirtualRouterElementsVO findByUUID(String uuid);
}

View File

@ -0,0 +1,58 @@
/**
* Copyright (C) 2011 Citrix Systems, 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 java.util.List;
import javax.ejb.Local;
import com.cloud.network.element.VirtualRouterElementsVO;
import com.cloud.network.element.VirtualRouterElements.VirtualRouterElementsType;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
@Local(value=VirtualRouterElementsDao.class) @DB(txn=false)
public class VirtualRouterElementsDaoImpl extends GenericDaoBase<VirtualRouterElementsVO, Long> implements VirtualRouterElementsDao {
final SearchBuilder<VirtualRouterElementsVO> AllFieldsSearch;
public VirtualRouterElementsDaoImpl() {
super();
AllFieldsSearch = createSearchBuilder();
AllFieldsSearch.and("nsp_id", AllFieldsSearch.entity().getNspId(), SearchCriteria.Op.EQ);
AllFieldsSearch.and("uuid", AllFieldsSearch.entity().getUUID(), SearchCriteria.Op.EQ);
AllFieldsSearch.and("type", AllFieldsSearch.entity().getType(), SearchCriteria.Op.EQ);
AllFieldsSearch.done();
}
@Override
public List<VirtualRouterElementsVO> findByNspIdAndType(long nspId, VirtualRouterElementsType type) {
SearchCriteria<VirtualRouterElementsVO> sc = AllFieldsSearch.create();
sc.setParameters("nsp_id", nspId);
sc.setParameters("type", type);
return listBy(sc);
}
@Override
public VirtualRouterElementsVO findByUUID(String uuid) {
SearchCriteria<VirtualRouterElementsVO> sc = AllFieldsSearch.create();
sc.setParameters("uuid", uuid);
return findOneBy(sc);
}
}

View File

@ -0,0 +1,28 @@
/**
* Copyright (C) 2011 Citrix Systems, 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.element;
public interface VirtualRouterElements {
public enum VirtualRouterElementsType {
DhcpElement,
VirtualRouterElement,
RedundantVirtualRouterElement,
}
public VirtualRouterElementsType getType();
}

View File

@ -0,0 +1,230 @@
/**
* Copyright (C) 2011 Citrix Systems, 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.element;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import com.cloud.utils.db.GenericDao;
@Entity
@Table(name=("virtual_router_elements"))
public class VirtualRouterElementsVO implements VirtualRouterElements {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
long id;
@Column(name="type")
@Enumerated(EnumType.STRING)
private VirtualRouterElementsType type;
@Column(name="ready")
private boolean isReady;
@Column(name="nsp_id")
private long nspId;
@Column(name="uuid")
private String uuid;
@Column(name="dhcp_provided")
private boolean isDhcpProvided;
@Column(name="dns_provided")
private boolean isDnsProvided;
@Column(name="gateway_provided")
private boolean isGatewayProvided;
@Column(name="firewall_provided")
private boolean isFirewallProvided;
@Column(name="source_nat_provided")
private boolean isSourceNatProvided;
@Column(name="load_balance_provided")
private boolean isLoadBalanceProvided;
@Column(name="vpn_provided")
private boolean isVpnProvided;
@Column(name="dhcp_range")
private String dhcpRange;
@Column(name="default_domain_name")
private String defaultDomainName;
@Column(name="dns1")
private String dns1;
@Column(name="dns2")
private String dns2;
@Column(name="internal_dns1")
private String internalDns1;
@Column(name="internal_dns2")
private String internalDns2;
@Column(name="gateway_ip")
private String gatewayIp;
@Column(name=GenericDao.REMOVED_COLUMN)
Date removed;
public VirtualRouterElementsVO(long nspId, String uuid, boolean isReady, VirtualRouterElementsType type, boolean isDhcpProvided, boolean isDnsProvided,
boolean isGatewayProvided, boolean isFirewallProvided, boolean isSourceNatProvided, boolean isLoadBalanceProvided, boolean isVpnProvided) {
this.nspId = nspId;
this.uuid = uuid;
this.isReady = isReady;
this.type = type;
this.isDhcpProvided = isDhcpProvided;
this.isDnsProvided = isDnsProvided;
this.isGatewayProvided = isGatewayProvided;
this.isFirewallProvided = isFirewallProvided;
this.isSourceNatProvided = isSourceNatProvided;
this.isLoadBalanceProvided = isLoadBalanceProvided;
this.isVpnProvided = isVpnProvided;
}
public long getNspId() {
return nspId;
}
public String getUUID() {
return uuid;
}
public long getId() {
return id;
}
public String getDhcpRange() {
return dhcpRange;
}
public void setDhcpRange(String dhcpRange) {
this.dhcpRange = dhcpRange;
}
public String getDefaultDomainName() {
return defaultDomainName;
}
public void setDefaultDomainName(String defaultDomainName) {
this.defaultDomainName = defaultDomainName;
}
public String getDns1() {
return dns1;
}
public void setDns1(String dns1) {
this.dns1 = dns1;
}
public String getDns2() {
return dns2;
}
public void setDns2(String dns2) {
this.dns2 = dns2;
}
public String getInternalDns1() {
return internalDns1;
}
public void setInternalDns1(String internalDns1) {
this.internalDns1 = internalDns1;
}
public String getInternalDns2() {
return internalDns2;
}
public void setInternalDns2(String internalDns2) {
this.internalDns2 = internalDns2;
}
public boolean isDhcpProvided() {
return isDhcpProvided;
}
public boolean isDnsProvided() {
return isDnsProvided;
}
public boolean isGatewayProvided() {
return isGatewayProvided;
}
public boolean isFirewallProvided() {
return isFirewallProvided;
}
public boolean isSourceNatProvided() {
return isSourceNatProvided;
}
public boolean isLoadBalanceProvided() {
return isLoadBalanceProvided;
}
public boolean isVpnProvided() {
return isVpnProvided;
}
@Override
public VirtualRouterElementsType getType() {
return this.type;
}
public String getGatewayIp() {
return gatewayIp;
}
public void setGatewayIp(String gatewayIp) {
this.gatewayIp = gatewayIp;
}
public Date getRemoved() {
return removed;
}
public void setRemoved(Date removed) {
this.removed = removed;
}
public void setReady(boolean isReady) {
this.isReady = isReady;
}
public boolean isReady() {
return isReady;
}
}

View File

@ -497,8 +497,8 @@ public class ElasticLoadBalancerManagerImpl implements
VMTemplateVO template = _templateDao.findSystemVMTemplate(dcId);
elbVm = new DomainRouterVO(id, _elasticLbVmOffering.getId(), VirtualMachineName.getSystemVmName(id, _instance, _elbVmNamePrefix), template.getId(), template.getHypervisorType(), template.getGuestOSId(),
owner.getDomainId(), owner.getId(), guestNetwork.getId(), false, 0, false, RedundantState.UNKNOWN, _elasticLbVmOffering.getOfferHA(), false, VirtualMachine.Type.ElasticLoadBalancerVm);
elbVm = new DomainRouterVO(id, _elasticLbVmOffering.getId(), 0, VirtualMachineName.getSystemVmName(id, _instance, _elbVmNamePrefix), template.getId(), template.getHypervisorType(),
template.getGuestOSId(), owner.getDomainId(), owner.getId(), guestNetwork.getId(), false, 0, false, RedundantState.UNKNOWN, _elasticLbVmOffering.getOfferHA(), false, VirtualMachine.Type.ElasticLoadBalancerVm);
elbVm.setRole(Role.LB);
elbVm = _itMgr.allocate(elbVm, template, _elasticLbVmOffering, networks, plan, null, owner);
//TODO: create usage stats

View File

@ -1090,8 +1090,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
if (routers.size() >= 5) {
s_logger.error("Too much redundant routers!");
}
router = new DomainRouterVO(id, _offering.getId(), VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(), template.getGuestOSId(),
owner.getDomainId(), owner.getId(), guestNetwork.getId(), isRedundant, 0, false, RedundantState.UNKNOWN, _offering.getOfferHA(), false);
router = new DomainRouterVO(id, _offering.getId(), 0, VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(),
template.getGuestOSId(), owner.getDomainId(), owner.getId(), guestNetwork.getId(), isRedundant, 0, false, RedundantState.UNKNOWN, _offering.getOfferHA(), false);
router = _itMgr.allocate(router, template, _offering, networks, plan, null, owner);
// Creating stats entry for router
UserStatisticsVO stats = _userStatsDao.findBy(owner.getId(), dcId, router.getNetworkId(), null, router.getId(), router.getType().toString());
@ -1275,8 +1275,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
/* Before starting router, already know the hypervisor type */
VMTemplateVO template = _templateDao.findRoutingTemplate(dest.getCluster().getHypervisorType());
router = new DomainRouterVO(id, _offering.getId(), VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(), template.getGuestOSId(),
owner.getDomainId(), owner.getId(), guestNetwork.getId(), false, 0, false, RedundantState.UNKNOWN, _offering.getOfferHA(), false);
router = new DomainRouterVO(id, _offering.getId(), 0, VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(),
template.getGuestOSId(), owner.getDomainId(), owner.getId(), guestNetwork.getId(), false, 0, false, RedundantState.UNKNOWN, _offering.getOfferHA(), false);
router.setRole(Role.DHCP_USERDATA);
router = _itMgr.allocate(router, template, _offering, networks, plan, null, owner);
routers.add(router);

View File

@ -118,6 +118,7 @@ DROP TABLE IF EXISTS `cloud`.`network_tags`;
DROP TABLE IF EXISTS `cloud`.`op_host_transfer`;
DROP TABLE IF EXISTS `cloud`.`projects`;
DROP TABLE IF EXISTS `cloud`.`physical_network`;
DROP TABLE IF EXISTS `cloud`.`virtual_router_elements`;
CREATE TABLE `cloud`.`version` (
`id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT COMMENT 'id',
@ -929,6 +930,7 @@ CREATE TABLE `cloud`.`user_vm_details` (
CREATE TABLE `cloud`.`domain_router` (
`id` bigint unsigned UNIQUE NOT NULL COMMENT 'Primary Key',
`element_id` bigint unsigned NOT NULL COMMENT 'correlated virtual router element ID',
`public_mac_address` varchar(17) COMMENT 'mac address of the public facing network card',
`public_ip_address` char(40) COMMENT 'public ip address used for source net',
`public_netmask` varchar(15) COMMENT 'netmask used for the domR',
@ -945,6 +947,7 @@ CREATE TABLE `cloud`.`domain_router` (
`scripts_version` varchar(100) COMMENT 'scripts version',
PRIMARY KEY (`id`),
CONSTRAINT `fk_domain_router__id` FOREIGN KEY `fk_domain_router__id` (`id`) REFERENCES `vm_instance`(`id`) ON DELETE CASCADE
#CONSTRAINT `fk_domain_router__element_id` FOREIGN KEY `fk_domain_router__element_id` (`element_id`) REFERENCES `virtual_router_elements`(`id`)
) ENGINE = InnoDB DEFAULT CHARSET=utf8 COMMENT = 'information about the domR instance';
CREATE TABLE `cloud`.`upload` (
@ -1724,6 +1727,32 @@ CREATE TABLE `cloud`.`elastic_lb_vm_map` (
CONSTRAINT `fk_elastic_lb_vm_map__lb_id` FOREIGN KEY `fk_elastic_lb_vm_map__lb_id` (`lb_id`) REFERENCES `load_balancing_rules` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`virtual_router_elements` (
`id` bigint unsigned NOT NULL auto_increment,
`nsp_id` bigint unsigned NOT NULL,
`uuid` varchar(255) UNIQUE,
`ready` int(1) NOT NULL,
`type` varchar(255) NOT NULL,
`dhcp_provided` int(1) NOT NULL,
`dns_provided` int(1) NOT NULL,
`gateway_provided` int(1) NOT NULL,
`firewall_provided` int(1) NOT NULL,
`source_nat_provided` int(1) NOT NULL,
`load_balance_provided` int(1) NOT NULL,
`vpn_provided` int(1) NOT NULL,
`service_offering_id` bigint unsigned NOT NULL,
`dhcp_range` varchar(255),
`default_domain_name` varchar(255),
`dns1` varchar(255),
`dns2` varchar(255),
`internal_dns1` varchar(255),
`internal_dns2` varchar(255),
`gateway_ip` varchar(255),
`removed` datetime COMMENT 'date removed if not null',
PRIMARY KEY (`id`),
CONSTRAINT `fk_virtual_router_elements__service_offering_id` FOREIGN KEY `fk_virtual_router_elements__service_offering_id` (`service_offering_id`) REFERENCES `service_offering`(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `ntwk_offering_service_map` (
`id` bigint unsigned NOT NULL auto_increment,