diff --git a/api/src/com/cloud/deploy/DataCenterDeployment.java b/api/src/com/cloud/deploy/DataCenterDeployment.java index 7e3be074503..e882102c959 100644 --- a/api/src/com/cloud/deploy/DataCenterDeployment.java +++ b/api/src/com/cloud/deploy/DataCenterDeployment.java @@ -19,7 +19,9 @@ package com.cloud.deploy; public class DataCenterDeployment implements DeploymentPlan { long _dcId; - public DataCenterDeployment(long dataCenterId) { + int _count; + + public DataCenterDeployment(long dataCenterId, int count) { _dcId = dataCenterId; } @@ -27,4 +29,9 @@ public class DataCenterDeployment implements DeploymentPlan { public long getDataCenterId() { return _dcId; } + + @Override + public int getCount() { + return _count; + } } diff --git a/api/src/com/cloud/deploy/DeploymentPlan.java b/api/src/com/cloud/deploy/DeploymentPlan.java index e619fc6a1e2..a36d7b35154 100644 --- a/api/src/com/cloud/deploy/DeploymentPlan.java +++ b/api/src/com/cloud/deploy/DeploymentPlan.java @@ -23,5 +23,5 @@ package com.cloud.deploy; */ public interface DeploymentPlan { public long getDataCenterId(); - + public int getCount(); } diff --git a/api/src/com/cloud/network/NetworkProfile.java b/api/src/com/cloud/network/NetworkConfiguration.java similarity index 88% rename from api/src/com/cloud/network/NetworkProfile.java rename to api/src/com/cloud/network/NetworkConfiguration.java index 9f4efee9e8b..f0193b6c25d 100644 --- a/api/src/com/cloud/network/NetworkProfile.java +++ b/api/src/com/cloud/network/NetworkConfiguration.java @@ -6,13 +6,12 @@ package com.cloud.network; import com.cloud.network.Network.BroadcastDomainType; import com.cloud.network.Network.Mode; import com.cloud.network.Network.TrafficType; -import com.cloud.user.OwnedBy; /** * A NetworkProfile defines the specifics of a network * owned by an account. */ -public interface NetworkProfile extends OwnedBy { +public interface NetworkConfiguration { /** * @return id of the network profile. Null means the network profile is not from the database. diff --git a/api/src/com/cloud/network/NetworkProfiler.java b/api/src/com/cloud/network/NetworkProfiler.java index 04e8eaf2347..6a3621a6856 100644 --- a/api/src/com/cloud/network/NetworkProfiler.java +++ b/api/src/com/cloud/network/NetworkProfiler.java @@ -7,6 +7,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; +import com.cloud.deploy.DeploymentPlan; import com.cloud.exception.ConflictingNetworkSettingsException; import com.cloud.offering.NetworkOffering; import com.cloud.offering.ServiceOffering; @@ -21,8 +22,8 @@ import com.cloud.vm.VirtualMachine; * */ public interface NetworkProfiler extends Adapter { - NetworkProfile convert(NetworkOffering offering, Map params, Account owner); + NetworkConfiguration convert(NetworkOffering offering, DeploymentPlan plan, Map params, Account owner); - List convert(Collection networkOfferings, Account owner); - boolean check(VirtualMachine vm, ServiceOffering serviceOffering, Collection networkProfiles) throws ConflictingNetworkSettingsException; + List convert(Collection networkOfferings, Account owner); + boolean check(VirtualMachine vm, ServiceOffering serviceOffering, Collection networkProfiles) throws ConflictingNetworkSettingsException; } diff --git a/api/src/com/cloud/vm/NetworkConcierge.java b/api/src/com/cloud/vm/NetworkConcierge.java index 12a266a8669..665103ccfad 100644 --- a/api/src/com/cloud/vm/NetworkConcierge.java +++ b/api/src/com/cloud/vm/NetworkConcierge.java @@ -5,7 +5,7 @@ package com.cloud.vm; import com.cloud.exception.InsufficientAddressCapacityException; import com.cloud.exception.InsufficientVirtualNetworkCapcityException; -import com.cloud.network.NetworkProfile; +import com.cloud.network.NetworkConfiguration; import com.cloud.utils.Pair; import com.cloud.utils.component.Adapter; @@ -19,7 +19,7 @@ import com.cloud.utils.component.Adapter; public interface NetworkConcierge extends Adapter { String getUniqueName(); - Nic allocate(VirtualMachine vm, NetworkProfile profile, Nic nic); + Nic allocate(VirtualMachine vm, NetworkConfiguration profile, Nic nic); Pair reserve(long vmId, NetworkCharacteristics ch) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException; diff --git a/server/src/com/cloud/alert/AlertManagerImpl.java b/server/src/com/cloud/alert/AlertManagerImpl.java index 9250bb86557..e7b4222777d 100644 --- a/server/src/com/cloud/alert/AlertManagerImpl.java +++ b/server/src/com/cloud/alert/AlertManagerImpl.java @@ -333,7 +333,7 @@ public class AlertManagerImpl implements AlertManager { List newCapacities = new ArrayList(); // get all hosts.. - SearchCriteria sc = _hostDao.createSearchCriteria(); + SearchCriteria sc = _hostDao.createSearchCriteria(); sc.addAnd("status", SearchCriteria.Op.EQ, Status.Up.toString()); List hosts = _hostDao.search(sc, null); diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 48864b50dcc..1c72bdd2905 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.net.InetSocketAddress; import java.nio.channels.SocketChannel; import java.nio.charset.Charset; +import java.util.ArrayList; import java.util.Date; import java.util.Enumeration; import java.util.HashMap; @@ -83,8 +84,8 @@ import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.StorageUnavailableException; import com.cloud.ha.HighAvailabilityManager; import com.cloud.host.Host; -import com.cloud.host.HostVO; import com.cloud.host.Host.Type; +import com.cloud.host.HostVO; import com.cloud.host.dao.HostDao; import com.cloud.info.ConsoleProxyConnectionInfo; import com.cloud.info.ConsoleProxyInfo; @@ -96,8 +97,8 @@ import com.cloud.info.RunningHostInfoAgregator.ZoneHostInfo; import com.cloud.maid.StackMaid; import com.cloud.network.IpAddrAllocator; import com.cloud.network.IpAddrAllocator.networkInfo; +import com.cloud.network.NetworkConfigurationVO; import com.cloud.network.NetworkManager; -import com.cloud.network.NetworkProfileVO; import com.cloud.network.dao.IPAddressDao; import com.cloud.offering.NetworkOffering; import com.cloud.offerings.NetworkOfferingVO; @@ -1016,7 +1017,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach ConsoleProxyVO proxy = new ConsoleProxyVO(id, name, _template.getId(), _template.getGuestOSId(), dataCenterId, 0); proxy = _consoleProxyDao.persist(proxy); - List profiles = _networkMgr.getSystemAccountNetworkProfiles(NetworkOfferingVO.SystemVmControlNetwork, NetworkOfferingVO.SystemVmManagementNetwork, NetworkOfferingVO.SystemVmPublicNetwork); + List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemVmControlNetwork, NetworkOfferingVO.SystemVmManagementNetwork, NetworkOfferingVO.SystemVmPublicNetwork); + List profiles = new ArrayList(offerings.size()); try { proxy = _vmMgr.allocate(proxy, _template, _serviceOffering, profiles, dc, _accountMgr.getSystemAccount()); proxy = _vmMgr.create(proxy); diff --git a/server/src/com/cloud/network/NetworkProfileVO.java b/server/src/com/cloud/network/NetworkConfigurationVO.java similarity index 83% rename from server/src/com/cloud/network/NetworkProfileVO.java rename to server/src/com/cloud/network/NetworkConfigurationVO.java index a7083a11f0c..5f3326ad6e8 100644 --- a/server/src/com/cloud/network/NetworkProfileVO.java +++ b/server/src/com/cloud/network/NetworkConfigurationVO.java @@ -36,8 +36,8 @@ import com.cloud.vm.NetworkCharacteristics; * */ @Entity -@Table(name="network_profiles") -public class NetworkProfileVO implements NetworkProfile { +@Table(name="network_configurations") +public class NetworkConfigurationVO implements NetworkConfiguration { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) Long id; @@ -46,9 +46,6 @@ public class NetworkProfileVO implements NetworkProfile { @Enumerated(value=EnumType.STRING) Mode mode; - @Column(name="account_id") - long accountId; - @Column(name="broadcast_domain_type") @Enumerated(value=EnumType.STRING) BroadcastDomainType broadcastDomainType; @@ -69,15 +66,17 @@ public class NetworkProfileVO implements NetworkProfile { @Column(name="network_offering_id") long networkOfferingId; - public NetworkProfileVO() { + @Column(name="data_center_id") + long dataCenterId; + + public NetworkConfigurationVO() { } - public NetworkProfileVO(NetworkProfile that, long accountId, long offeringId) { - this(accountId, that.getTrafficType(), that.getMode(), that.getBroadcastDomainType(), offeringId); + public NetworkConfigurationVO(NetworkConfiguration that, long accountId, long offeringId) { + this(that.getTrafficType(), that.getMode(), that.getBroadcastDomainType(), offeringId); } - public NetworkProfileVO(long accountId, TrafficType trafficType, Mode mode, BroadcastDomainType broadcastDomainType, long networkOfferingId) { - this.accountId = accountId; + public NetworkConfigurationVO(TrafficType trafficType, Mode mode, BroadcastDomainType broadcastDomainType, long networkOfferingId) { this.trafficType = trafficType; this.mode = mode; this.broadcastDomainType = broadcastDomainType; @@ -103,15 +102,6 @@ public class NetworkProfileVO implements NetworkProfile { this.mode = mode; } - @Override - public long getAccountId() { - return accountId; - } - - public void setAccountId(long accountId) { - this.accountId = accountId; - } - @Override public BroadcastDomainType getBroadcastDomainType() { return broadcastDomainType; diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 368131f6d94..4aec20e783a 100644 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -213,13 +213,13 @@ public interface NetworkManager extends Manager { */ List listPublicIpAddressesInVirtualNetwork(long accountId, long dcId, Boolean sourceNat); - NetworkProfileVO setupNetworkProfile(AccountVO account, NetworkOfferingVO offering); - NetworkProfileVO setupNetworkProfile(AccountVO account, NetworkOfferingVO offering, Map params); - List setupNetworkProfiles(AccountVO account, List offerings); + NetworkConfigurationVO setupNetworkProfile(AccountVO account, NetworkOfferingVO offering); + NetworkConfigurationVO setupNetworkProfile(AccountVO account, NetworkOfferingVO offering, Map params); + List setupNetworkProfiles(AccountVO account, List offerings); - List getSystemAccountNetworkProfiles(String... offeringNames); + List getSystemAccountNetworkOfferings(String... offeringNames); - List allocate(K vm, List> networks) throws InsufficientCapacityException; + List allocate(K vm, List> networks) throws InsufficientCapacityException; List prepare(K vm); diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 40f5e74a7e2..fe898df0985 100644 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -79,6 +79,7 @@ import com.cloud.dc.VlanVO; import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.HostPodDao; import com.cloud.dc.dao.VlanDao; +import com.cloud.deploy.DeploymentPlan; import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; import com.cloud.event.EventState; @@ -104,7 +105,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.NetworkConfigurationDao; import com.cloud.network.dao.SecurityGroupVMMapDao; import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering.GuestIpType; @@ -201,7 +202,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager @Inject ServiceOfferingDao _serviceOfferingDao = null; @Inject UserStatisticsDao _statsDao = null; @Inject NetworkOfferingDao _networkOfferingDao = null; - @Inject NetworkProfileDao _networkProfileDao = null; + @Inject NetworkConfigurationDao _networkProfileDao = null; @Inject NicDao _nicDao; Adapters _networkProfilers; @@ -216,7 +217,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager int _routerCleanupInterval = 3600; int _routerStatsInterval = 300; private ServiceOfferingVO _offering; - private HashMap> _systemNetworks = new HashMap>(5); + private HashMap _systemNetworks = new HashMap(5); private VMTemplateVO _template; @@ -1846,19 +1847,19 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager NetworkOfferingVO publicNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmPublicNetwork, TrafficType.Public, null); publicNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(publicNetworkOffering); - _systemNetworks.put(NetworkOfferingVO.SystemVmPublicNetwork, new Pair(publicNetworkOffering, null)); + _systemNetworks.put(NetworkOfferingVO.SystemVmPublicNetwork, publicNetworkOffering); NetworkOfferingVO managementNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmManagementNetwork, TrafficType.Management, null); managementNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(managementNetworkOffering); - _systemNetworks.put(NetworkOfferingVO.SystemVmManagementNetwork, new Pair(managementNetworkOffering, null)); + _systemNetworks.put(NetworkOfferingVO.SystemVmManagementNetwork, managementNetworkOffering); NetworkOfferingVO controlNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmControlNetwork, TrafficType.Control, null); controlNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(controlNetworkOffering); - _systemNetworks.put(NetworkOfferingVO.SystemVmControlNetwork, new Pair(controlNetworkOffering, null)); + _systemNetworks.put(NetworkOfferingVO.SystemVmControlNetwork, controlNetworkOffering); NetworkOfferingVO guestNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmGuestNetwork, TrafficType.Guest, GuestIpType.Virtualized); guestNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(guestNetworkOffering); - _systemNetworks.put(NetworkOfferingVO.SystemVmGuestNetwork, new Pair(guestNetworkOffering, null)); + _systemNetworks.put(NetworkOfferingVO.SystemVmGuestNetwork, guestNetworkOffering); NetworkOfferingVO storageNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmStorageNetwork, TrafficType.Storage, null); storageNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(storageNetworkOffering); - _systemNetworks.put(NetworkOfferingVO.SystemVmGuestNetwork, new Pair(storageNetworkOffering, null)); + _systemNetworks.put(NetworkOfferingVO.SystemVmGuestNetwork, storageNetworkOffering); s_logger.info("Network Manager is configured."); @@ -1872,17 +1873,6 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager @Override public boolean start() { - AccountVO systemAccount = _accountMgr.getSystemAccount(); - /* - for (Pair network : _systemNetworks.values()) { - network.second(setupNetworkProfile(systemAccount, network.first())); - if (network.second() == null) { - s_logger.warn("Unable to setup system account's network profile for " + network.first().getName()); - return false; - } - } - */ - _executor.scheduleAtFixedRate(new RouterCleanupTask(), _routerCleanupInterval, _routerCleanupInterval, TimeUnit.SECONDS); _executor.scheduleAtFixedRate(new NetworkUsageTask(), _routerStatsInterval, _routerStatsInterval, TimeUnit.SECONDS); return true; @@ -2352,27 +2342,27 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager } @Override - public NetworkProfileVO setupNetworkProfile(AccountVO owner, NetworkOfferingVO offering) { + public NetworkConfigurationVO setupNetworkProfile(AccountVO owner, NetworkOfferingVO offering) { return setupNetworkProfile(owner, offering, new HashMap()); } @Override - public NetworkProfileVO setupNetworkProfile(AccountVO owner, NetworkOfferingVO offering, Map params) { + public NetworkConfigurationVO setupNetworkProfile(AccountVO owner, NetworkOfferingVO offering, Map params) { for (NetworkProfiler profiler : _networkProfilers) { - NetworkProfile profile = profiler.convert(offering, params, owner); + NetworkConfiguration profile = profiler.convert(offering, null, params, owner); if (profile == null) { continue; } if (profile.getId() != null) { - if (profile instanceof NetworkProfileVO) { - return (NetworkProfileVO)profile; + if (profile instanceof NetworkConfigurationVO) { + return (NetworkConfigurationVO)profile; } else { return _networkProfileDao.findById(profile.getId()); } } - NetworkProfileVO vo = new NetworkProfileVO(profile, owner.getId(), offering.getId()); + NetworkConfigurationVO vo = new NetworkConfigurationVO(profile, owner.getId(), offering.getId()); return _networkProfileDao.persist(vo); } @@ -2380,8 +2370,8 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager } @Override - public List setupNetworkProfiles(AccountVO owner, List offerings) { - List profiles = new ArrayList(offerings.size()); + public List setupNetworkProfiles(AccountVO owner, List offerings) { + List profiles = new ArrayList(offerings.size()); for (NetworkOfferingVO offering : offerings) { profiles.add(setupNetworkProfile(owner, offering)); } @@ -2389,27 +2379,31 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager } @Override - public List getSystemAccountNetworkProfiles(String... offeringNames) { - List profiles = new ArrayList(offeringNames.length); + public List getSystemAccountNetworkOfferings(String... offeringNames) { + List offerings = new ArrayList(offeringNames.length); for (String offeringName : offeringNames) { - Pair network = _systemNetworks.get(offeringName); + NetworkOfferingVO network = _systemNetworks.get(offeringName); if (network == null) { throw new CloudRuntimeException("Unable to find system network profile for " + offeringName); } - profiles.add(network.second()); + offerings.add(network); } - return profiles; + return offerings; + } + + public NetworkConfigurationVO createNetworkConfiguration(NetworkOfferingVO offering, DeploymentPlan plan, AccountVO owner) { + return null; } @Override @DB - public List allocate(K vm, List> networks) throws InsufficientCapacityException { + public List allocate(K vm, List> networks) throws InsufficientCapacityException { List nics = new ArrayList(networks.size()); Transaction txn = Transaction.currentTxn(); txn.start(); - for (Pair network : networks) { + for (Pair network : networks) { for (NetworkConcierge concierge : _networkConcierges) { Nic nic = concierge.allocate(vm, network.first(), network.second()); if (nic == null) { diff --git a/server/src/com/cloud/network/NetworkProfilerImpl.java b/server/src/com/cloud/network/NetworkProfilerImpl.java index 173fd62d9e8..ff346a5d778 100644 --- a/server/src/com/cloud/network/NetworkProfilerImpl.java +++ b/server/src/com/cloud/network/NetworkProfilerImpl.java @@ -9,32 +9,35 @@ import java.util.Map; import javax.ejb.Local; +import com.cloud.dc.DataCenterVO; +import com.cloud.dc.dao.DataCenterDao; +import com.cloud.deploy.DeploymentPlan; import com.cloud.exception.ConflictingNetworkSettingsException; import com.cloud.network.Network.BroadcastDomainType; import com.cloud.network.Network.Mode; -import com.cloud.network.dao.NetworkProfileDao; +import com.cloud.network.dao.NetworkConfigurationDao; import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering.GuestIpType; import com.cloud.offering.ServiceOffering; import com.cloud.user.Account; import com.cloud.utils.component.AdapterBase; import com.cloud.utils.component.Inject; -import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.VirtualMachine; @Local(value=NetworkProfiler.class) public class NetworkProfilerImpl extends AdapterBase implements NetworkProfiler { - @Inject protected NetworkProfileDao _profileDao; + @Inject protected NetworkConfigurationDao _profileDao; + @Inject protected DataCenterDao _dcDao; protected NetworkProfilerImpl() { super(); } @Override - public NetworkProfile convert(NetworkOffering offering, Map params, Account owner) { - List profiles = _profileDao.listBy(owner.getId(), offering.getId()); + public NetworkConfiguration convert(NetworkOffering offering, DeploymentPlan plan, Map params, Account owner) { + List profiles = _profileDao.listBy(owner.getId(), offering.getId()); - for (NetworkProfileVO profile : profiles) { + for (NetworkConfigurationVO profile : profiles) { // FIXME: We should do more comparisons such as if the specific cidr matches. return profile; } @@ -46,22 +49,25 @@ public class NetworkProfilerImpl extends AdapterBase implements NetworkProfiler mode = Mode.Dhcp; broadcastType = BroadcastDomainType.Vlan; } else { - throw new CloudRuntimeException("Unable to convert " + ipType); + broadcastType = BroadcastDomainType.Native; + mode = Mode.Dhcp; } - return new NetworkProfileVO(owner.getId(), offering.getTrafficType(), mode, broadcastType, offering.getId()); + NetworkConfigurationVO profile = new NetworkConfigurationVO(offering.getTrafficType(), mode, broadcastType, offering.getId()); + DataCenterVO dc = _dcDao.findById(plan.getDataCenterId()); + return profile; } @Override - public List convert(Collection networkOfferings, Account owner) { - List profiles = _profileDao.listBy(owner.getId()); + public List convert(Collection networkOfferings, Account owner) { + List profiles = _profileDao.listBy(owner.getId()); for (NetworkOffering offering : networkOfferings) { } return null; } @Override - public boolean check(VirtualMachine vm, ServiceOffering serviceOffering, Collection networkProfiles) throws ConflictingNetworkSettingsException { + public boolean check(VirtualMachine vm, ServiceOffering serviceOffering, Collection networkProfiles) throws ConflictingNetworkSettingsException { return false; } diff --git a/server/src/com/cloud/network/dao/NetworkProfileDao.java b/server/src/com/cloud/network/dao/NetworkConfigurationDao.java similarity index 76% rename from server/src/com/cloud/network/dao/NetworkProfileDao.java rename to server/src/com/cloud/network/dao/NetworkConfigurationDao.java index 34e6c71410f..f5f3b0cd640 100644 --- a/server/src/com/cloud/network/dao/NetworkProfileDao.java +++ b/server/src/com/cloud/network/dao/NetworkConfigurationDao.java @@ -19,10 +19,10 @@ package com.cloud.network.dao; import java.util.List; -import com.cloud.network.NetworkProfileVO; +import com.cloud.network.NetworkConfigurationVO; import com.cloud.utils.db.GenericDao; -public interface NetworkProfileDao extends GenericDao { - List listBy(long accountId); - List listBy(long accountId, long offeringId); +public interface NetworkConfigurationDao extends GenericDao { + List listBy(long accountId); + List listBy(long accountId, long offeringId); } diff --git a/server/src/com/cloud/network/dao/NetworkProfileDaoImpl.java b/server/src/com/cloud/network/dao/NetworkConfigurationDaoImpl.java similarity index 54% rename from server/src/com/cloud/network/dao/NetworkProfileDaoImpl.java rename to server/src/com/cloud/network/dao/NetworkConfigurationDaoImpl.java index e5ced555c69..3bfee58ef6c 100644 --- a/server/src/com/cloud/network/dao/NetworkProfileDaoImpl.java +++ b/server/src/com/cloud/network/dao/NetworkConfigurationDaoImpl.java @@ -24,57 +24,65 @@ 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; +import com.cloud.network.NetworkAccountDaoImpl; +import com.cloud.network.NetworkAccountVO; +import com.cloud.network.NetworkConfigurationVO; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; -@Local(value=NetworkProfileDao.class) -public class NetworkProfileDaoImpl extends GenericDaoBase implements NetworkProfileDao { - final SearchBuilder ProfileSearch; - final SearchBuilder AccountSearch; +@Local(value=NetworkConfigurationDao.class) +public class NetworkConfigurationDaoImpl extends GenericDaoBase implements NetworkConfigurationDao { + final SearchBuilder ProfileSearch; + final SearchBuilder AccountSearch; + NetworkAccountDaoImpl _accountsDao = new NetworkAccountDaoImpl(); - protected NetworkProfileDaoImpl() { + protected NetworkConfigurationDaoImpl() { super(); ProfileSearch = createSearchBuilder(); - ProfileSearch.and("account", ProfileSearch.entity().getAccountId(), SearchCriteria.Op.EQ); ProfileSearch.and("trafficType", ProfileSearch.entity().getTrafficType(), SearchCriteria.Op.EQ); ProfileSearch.and("cidr", ProfileSearch.entity().getCidr(), SearchCriteria.Op.EQ); ProfileSearch.and("broadcastType", ProfileSearch.entity().getBroadcastDomainType(), SearchCriteria.Op.EQ); + SearchBuilder join = _accountsDao.createSearchBuilder(); + join.and("account", join.entity().getAccountId(), SearchCriteria.Op.EQ); + ProfileSearch.join("accounts", join, ProfileSearch.entity().getId(), join.entity().getNetworkConfigurationId()); ProfileSearch.done(); AccountSearch = createSearchBuilder(); - AccountSearch.and("account", AccountSearch.entity().getAccountId(), SearchCriteria.Op.EQ); AccountSearch.and("offering", AccountSearch.entity().getNetworkOfferingId(), SearchCriteria.Op.EQ); + join = _accountsDao.createSearchBuilder(); + join.and("account", join.entity().getAccountId(), SearchCriteria.Op.EQ); + AccountSearch.join("accounts", join, AccountSearch.entity().getId(), join.entity().getNetworkConfigurationId()); AccountSearch.done(); } - public NetworkProfileVO findBy(TrafficType trafficType, Mode mode, BroadcastDomainType broadcastType, long accountId) { - SearchCriteria sc = ProfileSearch.create(); - sc.setParameters("account", accountId); + public NetworkConfigurationVO findBy(TrafficType trafficType, Mode mode, BroadcastDomainType broadcastType, long accountId) { + SearchCriteria sc = ProfileSearch.create(); sc.setParameters("trafficType", trafficType); sc.setParameters("broadcastType", broadcastType); + sc.setJoinParameters("accounts", "account", accountId); return null; } @Override - public List listBy(long accountId) { - SearchCriteria sc = AccountSearch.create(); + public List listBy(long accountId) { + SearchCriteria sc = AccountSearch.create(); sc.setParameters("account", accountId); + sc.setJoinParameters("accounts", "account", accountId); return listActiveBy(sc); } @Override - public List listBy(long accountId, long offeringId) { - SearchCriteria sc = AccountSearch.create(); + public List listBy(long accountId, long offeringId) { + SearchCriteria sc = AccountSearch.create(); sc.setParameters("offering", offeringId); - sc.setParameters("account", accountId); + sc.setJoinParameters("accounts", "account", accountId); return listActiveBy(sc); } diff --git a/server/src/com/cloud/vm/MauriceMoss.java b/server/src/com/cloud/vm/MauriceMoss.java index f06293f06aa..63fcc2dae55 100644 --- a/server/src/com/cloud/vm/MauriceMoss.java +++ b/server/src/com/cloud/vm/MauriceMoss.java @@ -33,7 +33,7 @@ import com.cloud.dc.DataCenterVO; import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.network.NetworkManager; -import com.cloud.network.NetworkProfileVO; +import com.cloud.network.NetworkConfigurationVO; import com.cloud.service.ServiceOfferingVO; import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.Storage.ImageFormat; @@ -68,7 +68,7 @@ public class MauriceMoss implements VmManager { ServiceOfferingVO serviceOffering, Pair rootDiskOffering, List> dataDiskOfferings, - List> networks, + List> networks, DataCenterVO dc, AccountVO owner) throws InsufficientCapacityException { if (s_logger.isDebugEnabled()) { @@ -96,7 +96,7 @@ public class MauriceMoss implements VmManager { ServiceOfferingVO serviceOffering, Long rootSize, Pair dataDiskOffering, - List> networks, + List> networks, DataCenterVO dc, AccountVO owner) throws InsufficientCapacityException { List> diskOfferings = new ArrayList>(1); @@ -110,11 +110,11 @@ public class MauriceMoss implements VmManager { public T allocate(T vm, VMTemplateVO template, ServiceOfferingVO serviceOffering, - List networkProfiles, + List networkProfiles, DataCenterVO dc, AccountVO owner) throws InsufficientCapacityException { - List> networks = new ArrayList>(networkProfiles.size()); - for (NetworkProfileVO profile : networkProfiles) { - networks.add(new Pair(profile, null)); + List> networks = new ArrayList>(networkProfiles.size()); + for (NetworkConfigurationVO profile : networkProfiles) { + networks.add(new Pair(profile, null)); } return allocate(vm, template, serviceOffering, new Pair(serviceOffering, null), null, networks, dc, owner); } diff --git a/server/src/com/cloud/vm/VmManager.java b/server/src/com/cloud/vm/VmManager.java index 4f29fb50e00..53de68f9522 100644 --- a/server/src/com/cloud/vm/VmManager.java +++ b/server/src/com/cloud/vm/VmManager.java @@ -24,7 +24,7 @@ import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.StorageUnavailableException; -import com.cloud.network.NetworkProfileVO; +import com.cloud.network.NetworkConfigurationVO; import com.cloud.service.ServiceOfferingVO; import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.VMTemplateVO; @@ -42,7 +42,7 @@ public interface VmManager extends Manager { ServiceOfferingVO serviceOffering, Pair rootDiskOffering, List> dataDiskOfferings, - List> networks, + List> networks, DataCenterVO dc, AccountVO owner) throws InsufficientCapacityException; @@ -51,14 +51,14 @@ public interface VmManager extends Manager { ServiceOfferingVO serviceOffering, Long rootSize, Pair dataDiskOffering, - List> networks, + List> networks, DataCenterVO dc, AccountVO owner) throws InsufficientCapacityException; T allocate(T vm, VMTemplateVO template, ServiceOfferingVO serviceOffering, - List networkProfiles, + List networkProfiles, DataCenterVO dc, AccountVO owner) throws InsufficientCapacityException; diff --git a/setup/db/create-index-fk.sql b/setup/db/create-index-fk.sql index 7de4c557c54..666aae7ad3d 100644 --- a/setup/db/create-index-fk.sql +++ b/setup/db/create-index-fk.sql @@ -26,10 +26,11 @@ ALTER TABLE `cloud`.`op_ha_work` ADD INDEX `i_op_ha_work__step`(`step`); ALTER TABLE `cloud`.`op_ha_work` ADD INDEX `i_op_ha_work__type`(`type`); ALTER TABLE `cloud`.`op_ha_work` ADD INDEX `i_op_ha_work__mgmt_server_id`(`mgmt_server_id`); -ALTER TABLE `cloud`.`network_profiles` ADD CONSTRAINT `fk_network_profiles__account_id` FOREIGN KEY `fk_network_profiles__account_id`(`account_id`) REFERENCES `account`(`id`) ON DELETE CASCADE; +ALTER TABLE `cloud`.`account_network_ref` ADD CONSTRAINT `fk_account_network_ref__account_id` FOREIGN KEY `fk_account_network_ref__account_id`(`account_id`) REFERENCES `account`(`id`) ON DELETE CASCADE; +ALTER TABLE `cloud`.`account_network_ref` ADD CONSTRAINT `fk_account_network_ref__network_configuration_id` FOREIGN KEY `fk_account_network_ref__network_configuration_id`(`network_configuration_id`) REFERENCES `network_configurations`(`id`) ON DELETE CASCADE; ALTER TABLE `cloud`.`nics` ADD CONSTRAINT `fk_nics__instance_id` FOREIGN KEY `fk_nics__instance_id`(`instance_id`) REFERENCES `vm_instance`(`id`) ON DELETE CASCADE; -ALTER TABLE `cloud`.`nics` ADD CONSTRAINT `fk_nics__network_profile_id` FOREIGN KEY `fk_nics__network_profile_id`(`network_profile_id`) REFERENCES `network_profiles`(`id`); +ALTER TABLE `cloud`.`nics` ADD CONSTRAINT `fk_nics__network_configuration_id` FOREIGN KEY `fk_nics__network_configuration_id`(`network_configuration_id`) REFERENCES `network_configurations`(`id`); ALTER TABLE `cloud`.`op_dc_ip_address_alloc` ADD INDEX `i_op_dc_ip_address_alloc__pod_id__data_center_id__taken` (`pod_id`, `data_center_id`, `taken`, `instance_id`); ALTER TABLE `cloud`.`op_dc_ip_address_alloc` ADD UNIQUE `i_op_dc_ip_address_alloc__ip_address__data_center_id`(`ip_address`, `data_center_id`); diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 88d26deda2d..d636a34afb2 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -74,7 +74,7 @@ DROP TABLE IF EXISTS `cloud`.`storage_pool_details`; DROP TABLE IF EXISTS `cloud`.`ext_lun_details`; DROP TABLE IF EXISTS `cloud`.`cluster`; DROP TABLE IF EXISTS `cloud`.`nics`; -DROP TABLE IF EXISTS `cloud`.`network_profiles`; +DROP TABLE IF EXISTS `cloud`.`network_configurations`; DROP TABLE IF EXISTS `cloud`.`network_offerings`; DROP TABLE IF EXISTS `cloud`.`host_master`; DROP TABLE IF EXISTS `cloud`.`hypervisor_properties`; @@ -87,24 +87,24 @@ CREATE TABLE `cloud`.`hypervsior_properties` ( `max_network_devices` int(10) NOT NULL COMMENT 'maximum number of network devices' ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -CREATE TABLE `cloud`.`network_profiles` ( +CREATE TABLE `cloud`.`network_configurations` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', `name` varchar(255) COMMENT 'name for this network', - `account_id` bigint unsigned NOT NULL COMMENT 'Owner of this network configuration', `traffic_type` varchar(32) NOT NULL COMMENT 'type of traffic going through this network', `broadcast_domain_type` varchar(32) NOT NULL COMMENT 'type of broadcast domain used', - `gateway` varchar(15) NOT NULL COMMENT 'gateway for this network profile', + `gateway` varchar(15) NOT NULL COMMENT 'gateway for this network configuration', `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', - `network_offering_id` bigint unsigned NOT NULL COMMENT 'network offering id that this profile is created from', + `network_offering_id` bigint unsigned NOT NULL COMMENT 'network offering id that this configuration is created from', + `data_center_id` bigint unsigned NOT NULL COMMENT 'data center id that this configuration is used in', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `cloud`.`account_network_ref` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', `account_id` bigint unsigned NOT NULL COMMENT 'account id', - `network_profile_id` bigint unsigned NOT NULL COMMENT 'network profile_id', + `network_configuration_id` bigint unsigned NOT NULL COMMENT 'network configuration id', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -113,7 +113,7 @@ CREATE TABLE `cloud`.`nics` ( `instance_id` bigint unsigned NOT NULL COMMENT 'vm instance id', `ip4_address` varchar(15) COMMENT 'ip4 address', `mac_address` varchar(17) COMMENT 'mac address', - `network_profile_id` bigint unsigned NOT NULL COMMENT 'network id', + `network_configuration_id` bigint unsigned NOT NULL COMMENT 'network configuration id', `vlan` varchar(64) COMMENT 'Virtualized network identifier', `state` varchar(32) NOT NULL COMMENT 'state of the creation', `name` varchar(64) COMMENT 'Name of the component that reserved the ip address', @@ -125,13 +125,13 @@ CREATE TABLE `cloud`.`nics` ( CREATE TABLE `cloud`.`network_offerings` ( `id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT COMMENT 'id', `name` varchar(64) NOT NULL unique COMMENT 'network offering', - `type` varchar(32) NOT NULL COMMENT 'type of network', + `type` varchar(32) COMMENT 'type of network', `display_text` varchar(255) NOT NULL COMMENT 'text to display to users', `nw_rate` smallint unsigned COMMENT 'network rate throttle mbits/s', `mc_rate` smallint unsigned COMMENT 'mcast rate throttle mbits/s', `concurrent_connections` int(10) unsigned COMMENT 'concurrent connections supported on this network', `traffic_type` varchar(32) NOT NULL COMMENT 'traffic type carried on this network', - `tags` varchar(4096) NOT NULL COMMENT 'tags supported by this offering', + `tags` varchar(4096) COMMENT 'tags supported by this offering', `system_only` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'Is this network offering for system use only', `created` datetime NOT NULL COMMENT 'time the entry was created', `removed` datetime DEFAULT NULL COMMENT 'time the entry was removed',