From 415bc8ae20f708b9d8d964ba5bb0d5a4ee92962d Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Tue, 24 Aug 2010 14:40:29 -0700 Subject: [PATCH] bug 5764: checkin before I switch to work on 2.1.x --- api/src/com/cloud/network/Network.java | 3 +- .../xen/resource/CitrixResourceBase.java | 2 +- .../consoleproxy/ConsoleProxyManagerImpl.java | 2 +- .../xen/discoverer/XcpServerDiscoverer.java | 9 +++-- .../com/cloud/network/NetworkManagerImpl.java | 36 ++++++++++++++++--- .../com/cloud/network/NetworkProfileVO.java | 15 ++++++-- .../cloud/network/NetworkProfilerImpl.java | 1 + .../cloud/network/dao/NetworkProfileDao.java | 4 ++- .../network/dao/NetworkProfileDaoImpl.java | 24 ++++++++++++- setup/db/create-schema.sql | 1 + 10 files changed, 81 insertions(+), 16 deletions(-) diff --git a/api/src/com/cloud/network/Network.java b/api/src/com/cloud/network/Network.java index c5c35b0d13b..25d77faa11d 100644 --- a/api/src/com/cloud/network/Network.java +++ b/api/src/com/cloud/network/Network.java @@ -44,6 +44,7 @@ public class Network { Native, Vlan, Vswitch, + LinkLocal, Vnet; }; @@ -54,7 +55,7 @@ public class Network { Public, Guest, Storage, - LinkLocal, + Control, Vpn, Management }; diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 8b16dec93c9..d88b50528cd 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -700,7 +700,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR Pair getNetworkForTraffic(Connection conn, TrafficType type) throws XenAPIException, XmlRpcException { if (type == TrafficType.Guest) { return new Pair(Network.getByUuid(conn, _host.guestNetwork), _host.guestPif); - } else if (type == TrafficType.LinkLocal) { + } else if (type == TrafficType.Control) { return new Pair(Network.getByUuid(conn, _host.linkLocalNetwork), null); } else if (type == TrafficType.Management) { return new Pair(Network.getByUuid(conn, _host.privateNetwork), _host.privatePif); diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 8402256a5eb..73cf5e94e49 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -2357,7 +2357,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach _publicNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(_publicNetworkOffering); _managementNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmManagementNetwork, TrafficType.Management, null); _managementNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(_managementNetworkOffering); - _linkLocalNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmLinkLocalNetwork, TrafficType.LinkLocal, null); + _linkLocalNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmLinkLocalNetwork, TrafficType.Control, null); _linkLocalNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(_linkLocalNetworkOffering); _capacityScanScheduler.scheduleAtFixedRate(getCapacityScanTask(), STARTUP_DELAY, _capacityScanInterval, TimeUnit.MILLISECONDS); diff --git a/server/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java b/server/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java index cc1fb72b343..049d9a70923 100644 --- a/server/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java +++ b/server/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java @@ -53,15 +53,14 @@ import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.xen.resource.CitrixResourceBase; import com.cloud.hypervisor.xen.resource.XcpServerResource; import com.cloud.hypervisor.xen.resource.XenServerConnectionPool; -import com.cloud.hypervisor.xen.resource.XenServerResource; import com.cloud.resource.Discoverer; import com.cloud.resource.DiscovererBase; import com.cloud.resource.ServerResource; +import com.cloud.storage.Storage.FileSystem; +import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.VMTemplateHostVO; import com.cloud.storage.VMTemplateStorageResourceAssoc; import com.cloud.storage.VMTemplateVO; -import com.cloud.storage.Storage.FileSystem; -import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.dao.VMTemplateDao; import com.cloud.storage.dao.VMTemplateHostDao; import com.cloud.storage.template.TemplateInfo; @@ -383,8 +382,8 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L if(prodBrand.equals("XenCloudPlatform") && prodVersion.equals("0.1.1")) return new XcpServerResource(); - if(prodBrand.equals("XenServer") && prodVersion.equals("5.6.0")) - return new XenServerResource(); +// if(prodBrand.equals("XenServer") && prodVersion.equals("5.6.0")) +// return new XenServerResource(); String msg = "Only support XCP 0.1.1 and Xerver 5.6.0, but this one is " + prodBrand + " " + prodVersion; _alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId, podId, msg, msg); diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index e88e1344776..60f7ba6e21a 100644 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -102,6 +102,7 @@ import com.cloud.network.Network.TrafficType; import com.cloud.network.dao.FirewallRulesDao; import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.LoadBalancerDao; +import com.cloud.network.dao.NetworkProfileDao; import com.cloud.network.dao.SecurityGroupVMMapDao; import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering.GuestIpType; @@ -193,6 +194,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager @Inject ServiceOfferingDao _serviceOfferingDao = null; @Inject UserStatisticsDao _statsDao = null; @Inject NetworkOfferingDao _networkOfferingDao = null; + @Inject NetworkProfileDao _networkProfileDao = null; Adapters _networkProfilers; @@ -1835,7 +1837,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager _publicNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(_publicNetworkOffering); _managementNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmManagementNetwork, TrafficType.Management, null); _managementNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(_managementNetworkOffering); - _linkLocalNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmLinkLocalNetwork, TrafficType.LinkLocal, null); + _linkLocalNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmLinkLocalNetwork, TrafficType.Control, null); _linkLocalNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(_linkLocalNetworkOffering); _guestNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmGuestNetwork, TrafficType.Guest, GuestIpType.Virtualized); _guestNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(_guestNetworkOffering); @@ -1848,6 +1850,29 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager return true; } + + public void setupNetworkProfiles(List offerings, AccountVO account) { + List profiles = null; + for (NetworkProfiler profiler : _networkProfilers) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Sending network profiles to " + profiler.getName()); + } + profiles = profiler.convert(offerings, account); + if (profiles != null) { + break; + } + } + + if (profiles == null) { + s_logger.debug("Unable to resolve the network profiles"); + throw new CloudRuntimeException("Uanble to convert network offerings to network profiles for that account"); + } + + for (NetworkProfile profile : profiles) { + NetworkProfileVO vo = new NetworkProfileVO(profile, account.getId()); + vo = _networkProfileDao.persist(vo); + } + } @Override public String getName() { @@ -1861,9 +1886,12 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager offerings.add(_guestNetworkOffering); offerings.add(_linkLocalNetworkOffering); offerings.add(_managementNetworkOffering); - - for (NetworkProfiler profiler : _networkProfilers) { - List profiles = profiler.convert(offerings, _accountMgr.getSystemAccount()); + + try { + setupNetworkProfiles(offerings, _accountMgr.getSystemAccount()); + } catch (Exception e) { + s_logger.warn("Unable to setup the system network profiles"); + return false; } _executor.scheduleAtFixedRate(new RouterCleanupTask(), _routerCleanupInterval, _routerCleanupInterval, TimeUnit.SECONDS); _executor.scheduleAtFixedRate(new NetworkUsageTask(), _routerStatsInterval, _routerStatsInterval, TimeUnit.SECONDS); diff --git a/server/src/com/cloud/network/NetworkProfileVO.java b/server/src/com/cloud/network/NetworkProfileVO.java index cd9099147ac..05531fd8f5a 100644 --- a/server/src/com/cloud/network/NetworkProfileVO.java +++ b/server/src/com/cloud/network/NetworkProfileVO.java @@ -57,8 +57,8 @@ public class NetworkProfileVO implements OwnedBy { @Enumerated(value=EnumType.STRING) TrafficType trafficType; - @Column(name="vlanIds") - String vlanIds; + @Column(name="vlan_id") + Long vlanId; @Column(name="gateway") String gateway; @@ -69,6 +69,10 @@ public class NetworkProfileVO implements OwnedBy { public NetworkProfileVO() { } + public NetworkProfileVO(NetworkProfile that, long accountId) { + this(accountId, that.getTrafficType(), that.getMode(), that.getBroadcastDomainType()); + } + public NetworkProfileVO(long accountId, TrafficType trafficType, Mode mode, BroadcastDomainType broadcastDomainType) { this.accountId = accountId; this.trafficType = trafficType; @@ -129,4 +133,11 @@ public class NetworkProfileVO implements OwnedBy { this.cidr = cidr; } + public Long getVlanId() { + return vlanId; + } + + public void setVlanId(Long vlanId) { + this.vlanId = vlanId; + } } diff --git a/server/src/com/cloud/network/NetworkProfilerImpl.java b/server/src/com/cloud/network/NetworkProfilerImpl.java index 22ac017126a..a6ce246242a 100644 --- a/server/src/com/cloud/network/NetworkProfilerImpl.java +++ b/server/src/com/cloud/network/NetworkProfilerImpl.java @@ -27,6 +27,7 @@ public class NetworkProfilerImpl extends AdapterBase implements NetworkProfiler @Override public List convert(Collection networkOfferings, Account owner) { + List profiles = _profileDao.listBy(owner.getId()); for (NetworkOffering offering : networkOfferings) { } return null; diff --git a/server/src/com/cloud/network/dao/NetworkProfileDao.java b/server/src/com/cloud/network/dao/NetworkProfileDao.java index 2938d5de2f3..e2e6c713388 100644 --- a/server/src/com/cloud/network/dao/NetworkProfileDao.java +++ b/server/src/com/cloud/network/dao/NetworkProfileDao.java @@ -17,9 +17,11 @@ */ package com.cloud.network.dao; +import java.util.List; + import com.cloud.network.NetworkProfileVO; import com.cloud.utils.db.GenericDao; public interface NetworkProfileDao extends GenericDao { - + List listBy(long accountId); } diff --git a/server/src/com/cloud/network/dao/NetworkProfileDaoImpl.java b/server/src/com/cloud/network/dao/NetworkProfileDaoImpl.java index 09da5628ccb..d41967c5c13 100644 --- a/server/src/com/cloud/network/dao/NetworkProfileDaoImpl.java +++ b/server/src/com/cloud/network/dao/NetworkProfileDaoImpl.java @@ -17,8 +17,11 @@ */ package com.cloud.network.dao; +import java.util.List; + import javax.ejb.Local; +import com.cloud.network.Network.BroadcastDomainType; import com.cloud.network.Network.Mode; import com.cloud.network.Network.TrafficType; import com.cloud.network.NetworkProfileVO; @@ -29,6 +32,7 @@ import com.cloud.utils.db.SearchCriteria; @Local(value=NetworkProfileDao.class) public class NetworkProfileDaoImpl extends GenericDaoBase implements NetworkProfileDao { final SearchBuilder ProfileSearch; + final SearchBuilder AccountSearch; protected NetworkProfileDaoImpl() { super(); @@ -38,10 +42,28 @@ public class NetworkProfileDaoImpl extends GenericDaoBase sc = ProfileSearch.create(); + sc.setParameters("account", accountId); + sc.setParameters("trafficType", trafficType); + sc.setParameters("broadcastType", broadcastType); + return null; } + + @Override + public List listBy(long accountId) { + SearchCriteria sc = AccountSearch.create(); + sc.setParameters("account", accountId); + + return listActiveBy(sc); + } } diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index c4c28ecb2aa..e9dd4fecdb7 100644 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -95,6 +95,7 @@ CREATE TABLE `cloud`.`network_profiles` ( `gateway` varchar(15) NOT NULL COMMENT 'gateway for this network profile', `cidr` varchar(32) NOT NULL COMMENT 'network cidr', `mode` varchar(32) NOT NULL COMMENT 'How to retrieve ip address in this network', + `vlan_id` bigint unsigned NULL COMMENT 'vlan id if the broadcast_domain_type is the vlan', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;