From 2ebb719aba583e7667bb7293cb955afe0d48f97f Mon Sep 17 00:00:00 2001 From: Sheng Yang Date: Fri, 14 Oct 2011 11:46:05 -0700 Subject: [PATCH] NaaS: Add configuration for virtual router elements --- api/src/com/cloud/api/ApiConstants.java | 3 +- .../api/commands/ConfigureDhcpElementCmd.java | 79 +++++++++-- ...igureRedundantVirtualRouterElementCmd.java | 123 ++++++++++++++++-- .../ConfigureVirtualRouterElementCmd.java | 121 +++++++++++++++-- .../network/element/DhcpElementService.java | 5 +- .../RedundantVirtualRouterElementService.java | 6 +- .../element/VirtualRouterElementService.java | 6 +- client/tomcatconf/components-premium.xml.in | 1 + client/tomcatconf/components.xml.in | 1 + .../DefaultComponentLibrary.java | 2 + .../network/dao/VirtualRouterElementsDao.java | 2 +- .../dao/VirtualRouterElementsDaoImpl.java | 2 +- .../cloud/network/element/DhcpElement.java | 69 +++++++++- .../RedundantVirtualRouterElement.java | 60 ++++++++- .../network/element/VirtualRouterElement.java | 60 ++++++++- .../element/VirtualRouterElementsVO.java | 83 ++++++++++-- .../VirtualNetworkApplianceManager.java | 3 +- .../VirtualNetworkApplianceManagerImpl.java | 8 ++ .../cloud/server/ConfigurationServerImpl.java | 4 +- 19 files changed, 576 insertions(+), 62 deletions(-) diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index d8fb58579c6..e754dfcdac4 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -284,5 +284,6 @@ public class ApiConstants { public static final String DEST_PHYSICAL_NETWORK_ID = "destinationphysicalnetworkid"; public static final String ENABLED = "enabled"; public static final String SERVICE_NAME = "servicename"; - + public static final String DHCP_RANGE = "dhcprange"; + public static final String UUID = "uuid"; } diff --git a/api/src/com/cloud/api/commands/ConfigureDhcpElementCmd.java b/api/src/com/cloud/api/commands/ConfigureDhcpElementCmd.java index 5fd11f733e0..e0bb937553d 100644 --- a/api/src/com/cloud/api/commands/ConfigureDhcpElementCmd.java +++ b/api/src/com/cloud/api/commands/ConfigureDhcpElementCmd.java @@ -49,15 +49,78 @@ public class ConfigureDhcpElementCmd extends BaseAsyncCmd { //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the dhcp element") - private Long id; + @Parameter(name=ApiConstants.UUID, type=CommandType.STRING, required=true, description="the UUID of the virtual router element") + private String uuid; + @Parameter(name=ApiConstants.DHCP_SERVICE, type=CommandType.BOOLEAN, required=true, description="true is dhcp service would be enabled") + private Boolean dhcpService; + + @Parameter(name=ApiConstants.DNS_SERVICE, type=CommandType.BOOLEAN, required=true, description="true is dns service would be enabled") + private Boolean dnsService; + + @Parameter(name=ApiConstants.USERDATA_SERVICE, type=CommandType.BOOLEAN, required=true, description="true is user data service would be enabled") + private Boolean userdataService; + + @Parameter(name=ApiConstants.DHCP_RANGE, type=CommandType.STRING, description="the dhcp range for the DHCP service ") + private String dhcpRange; + + @Parameter(name=ApiConstants.DNS1, type=CommandType.STRING, description="the first DNS") + private String dns1; + + @Parameter(name=ApiConstants.DNS2, type=CommandType.STRING, description="the second DNS") + private String dns2; + + @Parameter(name=ApiConstants.INTERNAL_DNS1, type=CommandType.STRING, description="the first internal DNS") + private String internalDns1; + + @Parameter(name=ApiConstants.INTERNAL_DNS2, type=CommandType.STRING, description="the second internal DNS") + private String internalDns2; + + @Parameter(name=ApiConstants.DOMAIN, type=CommandType.STRING, description="the gateway ip") + private String domainName; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// - public Long getId() { - return id; + public String getUUID() { + return uuid; + } + + public Boolean getDhcpService() { + return dhcpService; + } + + public Boolean getDnsService() { + return dnsService; + } + + public Boolean getUserdataService() { + return userdataService; + } + + public String getDomainName() { + return domainName; + } + + public String getDhcpRange() { + return dhcpRange; + } + + public String getDns1() { + return dns1; + } + + public String getDns2() { + return dns2; + } + + public String getInternalDns1() { + return internalDns1; + } + + public String getInternalDns2() { + return internalDns2; } ///////////////////////////////////////////////////// @@ -85,7 +148,7 @@ public class ConfigureDhcpElementCmd extends BaseAsyncCmd { @Override public String getEventDescription() { - return "configuring dhcp element: " + getId(); + return "configuring dhcp element: " + getUUID(); } public AsyncJob.Type getInstanceType() { @@ -93,13 +156,13 @@ public class ConfigureDhcpElementCmd extends BaseAsyncCmd { } public Long getInstanceId() { - return getId(); + return _service.getIdByUUID(uuid); } @Override public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{ - UserContext.current().setEventDetails("Dhcp element Id: " + getId()); - Boolean result = _service.configure(); + UserContext.current().setEventDetails("Dhcp element: " + getUUID()); + Boolean result = _service.configure(this); if (result){ SuccessResponse response = new SuccessResponse(); response.setResponseName(getCommandName()); diff --git a/api/src/com/cloud/api/commands/ConfigureRedundantVirtualRouterElementCmd.java b/api/src/com/cloud/api/commands/ConfigureRedundantVirtualRouterElementCmd.java index e31acd8705b..405cb7c113b 100644 --- a/api/src/com/cloud/api/commands/ConfigureRedundantVirtualRouterElementCmd.java +++ b/api/src/com/cloud/api/commands/ConfigureRedundantVirtualRouterElementCmd.java @@ -49,17 +49,122 @@ public class ConfigureRedundantVirtualRouterElementCmd extends BaseAsyncCmd { //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the redundant virtual router element") - private Long id; + @Parameter(name=ApiConstants.UUID, type=CommandType.STRING, required=true, description="the UUID of the virtual router element") + private String uuid; - ///////////////////////////////////////////////////// + @Parameter(name=ApiConstants.DHCP_SERVICE, type=CommandType.BOOLEAN, required=true, description="true is dhcp service would be enabled") + private Boolean dhcpService; + + @Parameter(name=ApiConstants.DNS_SERVICE, type=CommandType.BOOLEAN, required=true, description="true is dns service would be enabled") + private Boolean dnsService; + + @Parameter(name=ApiConstants.GATEWAY_SERVICE, type=CommandType.BOOLEAN, required=true, description="true is gateway service would be enabled") + private Boolean gatewayService; + + @Parameter(name=ApiConstants.FIREWALL_SERVICE, type=CommandType.BOOLEAN, required=true, description="true is firewall service would be enabled") + private Boolean firewallService; + + @Parameter(name=ApiConstants.LB_SERVICE, type=CommandType.BOOLEAN, required=true, description="true is lb service would be enabled") + private Boolean lbService; + + @Parameter(name=ApiConstants.USERDATA_SERVICE, type=CommandType.BOOLEAN, required=true, description="true is user data service would be enabled") + private Boolean userdataService; + + @Parameter(name=ApiConstants.SOURCE_NAT_SERVICE, type=CommandType.BOOLEAN, required=true, description="true is source nat service would be enabled") + private Boolean sourceNatService; + + @Parameter(name=ApiConstants.VPN_SERVICE, type=CommandType.BOOLEAN, required=true, description="true is vpn service would be enabled") + private Boolean vpnService; + + @Parameter(name=ApiConstants.DHCP_RANGE, type=CommandType.STRING, description="the dhcp range for the DHCP service ") + private String dhcpRange; + + @Parameter(name=ApiConstants.DNS1, type=CommandType.STRING, description="the first DNS") + private String dns1; + + @Parameter(name=ApiConstants.DNS2, type=CommandType.STRING, description="the second DNS") + private String dns2; + + @Parameter(name=ApiConstants.INTERNAL_DNS1, type=CommandType.STRING, description="the first internal DNS") + private String internalDns1; + + @Parameter(name=ApiConstants.INTERNAL_DNS2, type=CommandType.STRING, description="the second internal DNS") + private String internalDns2; + + @Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, description="the gateway ip") + private String gateway; + + @Parameter(name=ApiConstants.DOMAIN, type=CommandType.STRING, description="the gateway ip") + private String domainName; + /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// - public Long getId() { - return id; + public String getUUID() { + return uuid; } + public Boolean getDhcpService() { + return dhcpService; + } + + public Boolean getDnsService() { + return dnsService; + } + + public Boolean getGatewayService() { + return gatewayService; + } + + public Boolean getFirewallService() { + return firewallService; + } + + public Boolean getLbService() { + return lbService; + } + + public Boolean getUserdataService() { + return userdataService; + } + + public Boolean getSourceNatService() { + return sourceNatService; + } + + public Boolean getVpnService() { + return vpnService; + } + + public String getDomainName() { + return domainName; + } + + public String getDhcpRange() { + return dhcpRange; + } + + public String getDns1() { + return dns1; + } + + public String getDns2() { + return dns2; + } + + public String getInternalDns1() { + return internalDns1; + } + + public String getInternalDns2() { + return internalDns2; + } + + public String getGateway() { + return gateway; + } + + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -85,7 +190,7 @@ public class ConfigureRedundantVirtualRouterElementCmd extends BaseAsyncCmd { @Override public String getEventDescription() { - return "configuring redundant virtual router element: " + getId(); + return "configuring redundant virtual router element: " + getUUID(); } public AsyncJob.Type getInstanceType() { @@ -93,13 +198,13 @@ public class ConfigureRedundantVirtualRouterElementCmd extends BaseAsyncCmd { } public Long getInstanceId() { - return getId(); + return _service.getIdByUUID(uuid); } @Override public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{ - UserContext.current().setEventDetails("Redundant virtual router element Id: " + getId()); - Boolean result = _service.configure(); + UserContext.current().setEventDetails("Redundant virtual router element: " + getUUID()); + Boolean result = _service.configure(this); if (result){ SuccessResponse response = new SuccessResponse(); response.setResponseName(getCommandName()); diff --git a/api/src/com/cloud/api/commands/ConfigureVirtualRouterElementCmd.java b/api/src/com/cloud/api/commands/ConfigureVirtualRouterElementCmd.java index 487a15421ca..af8e3297417 100644 --- a/api/src/com/cloud/api/commands/ConfigureVirtualRouterElementCmd.java +++ b/api/src/com/cloud/api/commands/ConfigureVirtualRouterElementCmd.java @@ -49,15 +49,120 @@ public class ConfigureVirtualRouterElementCmd extends BaseAsyncCmd { //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the virtual router element") - private Long id; + @Parameter(name=ApiConstants.UUID, type=CommandType.STRING, required=true, description="the UUID of the virtual router element") + private String uuid; + @Parameter(name=ApiConstants.DHCP_SERVICE, type=CommandType.BOOLEAN, required=true, description="true is dhcp service would be enabled") + private Boolean dhcpService; + + @Parameter(name=ApiConstants.DNS_SERVICE, type=CommandType.BOOLEAN, required=true, description="true is dns service would be enabled") + private Boolean dnsService; + + @Parameter(name=ApiConstants.GATEWAY_SERVICE, type=CommandType.BOOLEAN, required=true, description="true is gateway service would be enabled") + private Boolean gatewayService; + + @Parameter(name=ApiConstants.FIREWALL_SERVICE, type=CommandType.BOOLEAN, required=true, description="true is firewall service would be enabled") + private Boolean firewallService; + + @Parameter(name=ApiConstants.LB_SERVICE, type=CommandType.BOOLEAN, required=true, description="true is lb service would be enabled") + private Boolean lbService; + + @Parameter(name=ApiConstants.USERDATA_SERVICE, type=CommandType.BOOLEAN, required=true, description="true is user data service would be enabled") + private Boolean userdataService; + + @Parameter(name=ApiConstants.SOURCE_NAT_SERVICE, type=CommandType.BOOLEAN, required=true, description="true is source nat service would be enabled") + private Boolean sourceNatService; + + @Parameter(name=ApiConstants.VPN_SERVICE, type=CommandType.BOOLEAN, required=true, description="true is vpn service would be enabled") + private Boolean vpnService; + + @Parameter(name=ApiConstants.DHCP_RANGE, type=CommandType.STRING, description="the dhcp range for the DHCP service ") + private String dhcpRange; + + @Parameter(name=ApiConstants.DNS1, type=CommandType.STRING, description="the first DNS") + private String dns1; + + @Parameter(name=ApiConstants.DNS2, type=CommandType.STRING, description="the second DNS") + private String dns2; + + @Parameter(name=ApiConstants.INTERNAL_DNS1, type=CommandType.STRING, description="the first internal DNS") + private String internalDns1; + + @Parameter(name=ApiConstants.INTERNAL_DNS2, type=CommandType.STRING, description="the second internal DNS") + private String internalDns2; + + @Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, description="the gateway ip") + private String gateway; + + @Parameter(name=ApiConstants.DOMAIN, type=CommandType.STRING, description="the gateway ip") + private String domainName; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// - public Long getId() { - return id; + public String getUUID() { + return uuid; + } + + public Boolean getDhcpService() { + return dhcpService; + } + + public Boolean getDnsService() { + return dnsService; + } + + public Boolean getGatewayService() { + return gatewayService; + } + + public Boolean getFirewallService() { + return firewallService; + } + + public Boolean getLbService() { + return lbService; + } + + public Boolean getUserdataService() { + return userdataService; + } + + public Boolean getSourceNatService() { + return sourceNatService; + } + + public Boolean getVpnService() { + return vpnService; + } + + public String getDomainName() { + return domainName; + } + + public String getDhcpRange() { + return dhcpRange; + } + + public String getDns1() { + return dns1; + } + + public String getDns2() { + return dns2; + } + + public String getInternalDns1() { + return internalDns1; + } + + public String getInternalDns2() { + return internalDns2; + } + + public String getGateway() { + return gateway; } ///////////////////////////////////////////////////// @@ -85,7 +190,7 @@ public class ConfigureVirtualRouterElementCmd extends BaseAsyncCmd { @Override public String getEventDescription() { - return "configuring virtual router element: " + getId(); + return "configuring virtual router element: " + getUUID(); } public AsyncJob.Type getInstanceType() { @@ -93,13 +198,13 @@ public class ConfigureVirtualRouterElementCmd extends BaseAsyncCmd { } public Long getInstanceId() { - return getId(); + return _service.getIdByUUID(uuid); } @Override public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{ - UserContext.current().setEventDetails("Virtual router element Id: " + getId()); - Boolean result = _service.configure(); + UserContext.current().setEventDetails("Virtual router element: " + getUUID()); + Boolean result = _service.configure(this); if (result){ SuccessResponse response = new SuccessResponse(); response.setResponseName(getCommandName()); diff --git a/api/src/com/cloud/network/element/DhcpElementService.java b/api/src/com/cloud/network/element/DhcpElementService.java index 848c79841b5..4871130feef 100644 --- a/api/src/com/cloud/network/element/DhcpElementService.java +++ b/api/src/com/cloud/network/element/DhcpElementService.java @@ -1,7 +1,10 @@ package com.cloud.network.element; +import com.cloud.api.commands.ConfigureDhcpElementCmd; import com.cloud.utils.component.PluggableService; public interface DhcpElementService extends PluggableService{ - boolean configure(); + boolean configure(ConfigureDhcpElementCmd cmd); + boolean addElement(Long nspId, String uuid); + Long getIdByUUID(String uuid); } diff --git a/api/src/com/cloud/network/element/RedundantVirtualRouterElementService.java b/api/src/com/cloud/network/element/RedundantVirtualRouterElementService.java index ec54099fd35..1b4d8a2cf66 100644 --- a/api/src/com/cloud/network/element/RedundantVirtualRouterElementService.java +++ b/api/src/com/cloud/network/element/RedundantVirtualRouterElementService.java @@ -1,7 +1,7 @@ package com.cloud.network.element; -import com.cloud.utils.component.PluggableService; +import com.cloud.api.commands.ConfigureRedundantVirtualRouterElementCmd; -public interface RedundantVirtualRouterElementService extends PluggableService{ - boolean configure(); +public interface RedundantVirtualRouterElementService extends VirtualRouterElementService { + boolean configure(ConfigureRedundantVirtualRouterElementCmd cmd); } diff --git a/api/src/com/cloud/network/element/VirtualRouterElementService.java b/api/src/com/cloud/network/element/VirtualRouterElementService.java index 705fc8b168c..a5ca60335c0 100644 --- a/api/src/com/cloud/network/element/VirtualRouterElementService.java +++ b/api/src/com/cloud/network/element/VirtualRouterElementService.java @@ -1,7 +1,7 @@ package com.cloud.network.element; -import com.cloud.utils.component.PluggableService; +import com.cloud.api.commands.ConfigureVirtualRouterElementCmd; -public interface VirtualRouterElementService extends PluggableService{ - boolean configure(); +public interface VirtualRouterElementService extends DhcpElementService { + boolean configure(ConfigureVirtualRouterElementCmd cmd); } diff --git a/client/tomcatconf/components-premium.xml.in b/client/tomcatconf/components-premium.xml.in index 9472e76744d..cc032d99ed7 100755 --- a/client/tomcatconf/components-premium.xml.in +++ b/client/tomcatconf/components-premium.xml.in @@ -24,6 +24,7 @@ + diff --git a/client/tomcatconf/components.xml.in b/client/tomcatconf/components.xml.in index b7288f8b5bf..14fea2bc226 100755 --- a/client/tomcatconf/components.xml.in +++ b/client/tomcatconf/components.xml.in @@ -131,5 +131,6 @@ + diff --git a/server/src/com/cloud/configuration/DefaultComponentLibrary.java b/server/src/com/cloud/configuration/DefaultComponentLibrary.java index efc6ba312f1..251c163bdbe 100755 --- a/server/src/com/cloud/configuration/DefaultComponentLibrary.java +++ b/server/src/com/cloud/configuration/DefaultComponentLibrary.java @@ -83,6 +83,7 @@ import com.cloud.network.dao.NetworkRuleConfigDaoImpl; import com.cloud.network.dao.PhysicalNetworkDaoImpl; import com.cloud.network.dao.PhysicalNetworkServiceProviderDaoImpl; import com.cloud.network.dao.RemoteAccessVpnDaoImpl; +import com.cloud.network.dao.VirtualRouterElementsDaoImpl; import com.cloud.network.dao.VpnUserDaoImpl; import com.cloud.network.element.DhcpElement; import com.cloud.network.element.RedundantVirtualRouterElement; @@ -295,6 +296,7 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com info.addParameter("cache.time.to.live", "600"); addDao("PhysicalNetworkDao", PhysicalNetworkDaoImpl.class); addDao("PhysicalNetworkServiceProviderDao", PhysicalNetworkServiceProviderDaoImpl.class); + addDao("VirtualRouterElementsDao", VirtualRouterElementsDaoImpl.class); } @Override diff --git a/server/src/com/cloud/network/dao/VirtualRouterElementsDao.java b/server/src/com/cloud/network/dao/VirtualRouterElementsDao.java index 648ddae1a9f..ff750cdb742 100644 --- a/server/src/com/cloud/network/dao/VirtualRouterElementsDao.java +++ b/server/src/com/cloud/network/dao/VirtualRouterElementsDao.java @@ -23,7 +23,7 @@ import com.cloud.network.element.VirtualRouterElementsVO; import com.cloud.network.element.VirtualRouterElements.VirtualRouterElementsType; import com.cloud.utils.db.GenericDao; -public interface VirtualRouterElementsDao extends GenericDao { +public interface VirtualRouterElementsDao extends GenericDao { public List findByNspIdAndType(long nspId, VirtualRouterElementsType type); public VirtualRouterElementsVO findByUUID(String uuid); } diff --git a/server/src/com/cloud/network/dao/VirtualRouterElementsDaoImpl.java b/server/src/com/cloud/network/dao/VirtualRouterElementsDaoImpl.java index 93972ef4830..2ebda6338ac 100644 --- a/server/src/com/cloud/network/dao/VirtualRouterElementsDaoImpl.java +++ b/server/src/com/cloud/network/dao/VirtualRouterElementsDaoImpl.java @@ -36,7 +36,7 @@ public class VirtualRouterElementsDaoImpl extends GenericDaoBase rules, List routers) throws ResourceUnavailableException; - + + long getDefaultVirtualRouterServiceOfferingId(); } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index f278ed10ac1..cd30210133b 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -2742,4 +2742,12 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian public boolean processTimeout(long agentId, long seq) { return false; } + + @Override + public long getDefaultVirtualRouterServiceOfferingId() { + if (_offering != null) { + return _offering.getId(); + } + return 0; + } } diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index e3d7d57dc77..1bfbcd07017 100644 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -75,6 +75,7 @@ import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.Networks.Mode; import com.cloud.network.Networks.TrafficType; import com.cloud.network.dao.NetworkDao; +import com.cloud.network.dao.VirtualRouterElementsDao; import com.cloud.network.guru.ControlNetworkGuru; import com.cloud.network.guru.DirectPodBasedNetworkGuru; import com.cloud.network.guru.PodBasedNetworkGuru; @@ -120,6 +121,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { private final AccountDao _accountDao; private final ResourceCountDao _resourceCountDao; private final NetworkOfferingServiceMapDao _offeringServiceMapDao; + private final VirtualRouterElementsDao _virtualRouterElementsDao; public ConfigurationServerImpl() { @@ -137,7 +139,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { _accountDao = locator.getDao(AccountDao.class); _resourceCountDao = locator.getDao(ResourceCountDao.class); _offeringServiceMapDao = locator.getDao(NetworkOfferingServiceMapDao.class); - + _virtualRouterElementsDao = locator.getDao(VirtualRouterElementsDao.class); } @Override @DB