From 794ca16a655ea914ebf02c4619a6e995abfecea0 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Tue, 19 Oct 2010 10:26:39 -0700 Subject: [PATCH] Added code to start domR --- .../cloud/network/NetworkConfiguration.java | 4 +- .../network/configuration/NetworkGuru.java | 2 - .../cloud/network/element/NetworkElement.java | 11 +- .../com/cloud/offering/ServiceOffering.java | 1 + core/src/com/cloud/vm/DomainRouterVO.java | 69 ++--- .../consoleproxy/ConsoleProxyManagerImpl.java | 5 +- .../com/cloud/network/NetworkAccountVO.java | 10 +- .../cloud/network/NetworkConfigurationVO.java | 68 ++++- .../src/com/cloud/network/NetworkManager.java | 18 +- .../com/cloud/network/NetworkManagerImpl.java | 77 +++-- .../network/dao/NetworkConfigurationDao.java | 7 +- .../dao/NetworkConfigurationDaoImpl.java | 39 ++- .../network/element/DomainRouterElement.java | 44 ++- .../router/DomainRouterManagerImpl.java | 272 +++++++++++++++++- .../src/com/cloud/storage/StorageManager.java | 7 +- .../com/cloud/storage/StorageManagerImpl.java | 15 +- server/src/com/cloud/user/AccountManager.java | 2 +- .../com/cloud/user/AccountManagerImpl.java | 2 +- server/src/com/cloud/vm/MauriceMoss.java | 12 +- .../src/com/cloud/vm/VirtualMachineGuru.java | 2 +- server/src/com/cloud/vm/VmManager.java | 10 +- setup/db/create-schema.sql | 1 + 22 files changed, 531 insertions(+), 147 deletions(-) diff --git a/api/src/com/cloud/network/NetworkConfiguration.java b/api/src/com/cloud/network/NetworkConfiguration.java index 760e7ce2e13..9f9078e619b 100644 --- a/api/src/com/cloud/network/NetworkConfiguration.java +++ b/api/src/com/cloud/network/NetworkConfiguration.java @@ -6,9 +6,11 @@ package com.cloud.network; import java.util.List; import java.util.Set; +import com.cloud.domain.PartOf; import com.cloud.network.Network.BroadcastDomainType; import com.cloud.network.Network.Mode; import com.cloud.network.Network.TrafficType; +import com.cloud.user.OwnedBy; import com.cloud.utils.fsm.FiniteState; import com.cloud.utils.fsm.StateMachine; @@ -16,7 +18,7 @@ import com.cloud.utils.fsm.StateMachine; * A NetworkProfile defines the specifics of a network * owned by an account. */ -public interface NetworkConfiguration { +public interface NetworkConfiguration extends OwnedBy, PartOf { enum Event { ImplementNetwork, DestroyNetwork; diff --git a/api/src/com/cloud/network/configuration/NetworkGuru.java b/api/src/com/cloud/network/configuration/NetworkGuru.java index 2cb0a5a1764..d2ba488602c 100644 --- a/api/src/com/cloud/network/configuration/NetworkGuru.java +++ b/api/src/com/cloud/network/configuration/NetworkGuru.java @@ -27,8 +27,6 @@ public interface NetworkGuru extends Adapter { NicProfile allocate(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException; -// NicProfile create(NicProfile nic, NetworkConfiguration config, VirtualMachineProfile vm, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException; - String reserve(NicProfile nic, NetworkConfiguration config, VirtualMachineProfile vm, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException; boolean release(String uniqueId); diff --git a/api/src/com/cloud/network/element/NetworkElement.java b/api/src/com/cloud/network/element/NetworkElement.java index 4296fe36010..0597c467233 100644 --- a/api/src/com/cloud/network/element/NetworkElement.java +++ b/api/src/com/cloud/network/element/NetworkElement.java @@ -5,6 +5,7 @@ package com.cloud.network.element; import com.cloud.network.NetworkConfiguration; import com.cloud.offering.NetworkOffering; +import com.cloud.user.Account; import com.cloud.utils.component.Adapter; import com.cloud.vm.NicProfile; import com.cloud.vm.VirtualMachineProfile; @@ -17,9 +18,9 @@ public interface NetworkElement extends Adapter { * Implement the network configuration as specified. * @param config fully specified network configuration. * @param offering network offering that originated the network configuration. - * @return true if network configuration is now usable; false if not. + * @return true if network configuration is now usable; false if not; null if not handled by this element. */ - boolean implement(NetworkConfiguration config, NetworkOffering offering); + Boolean implement(NetworkConfiguration config, NetworkOffering offering, Account user); /** * Prepare the nic profile to be used within the network. @@ -28,9 +29,9 @@ public interface NetworkElement extends Adapter { * @param offering * @return */ - boolean prepare(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering); + Boolean prepare(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering, Account user); - boolean release(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering); + Boolean release(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering, Account user); - boolean shutdown(NetworkConfiguration config, NetworkOffering offering); + Boolean shutdown(NetworkConfiguration config, NetworkOffering offering, Account user); } diff --git a/api/src/com/cloud/offering/ServiceOffering.java b/api/src/com/cloud/offering/ServiceOffering.java index 333b6f1bbcf..1d675ec57f8 100755 --- a/api/src/com/cloud/offering/ServiceOffering.java +++ b/api/src/com/cloud/offering/ServiceOffering.java @@ -66,4 +66,5 @@ public interface ServiceOffering { * @return whether or not the service offering requires local storage */ boolean getUseLocalStorage(); + } diff --git a/core/src/com/cloud/vm/DomainRouterVO.java b/core/src/com/cloud/vm/DomainRouterVO.java index 300df2ad318..66f94d7a70d 100755 --- a/core/src/com/cloud/vm/DomainRouterVO.java +++ b/core/src/com/cloud/vm/DomainRouterVO.java @@ -87,55 +87,6 @@ public class DomainRouterVO extends VMInstanceVO implements DomainRouter { @Enumerated(EnumType.STRING) private Role role = Role.DHCP_FIREWALL_LB_PASSWD_USERDATA; - public DomainRouterVO(long id, - long serviceOfferingId, - String name, - String instanceName, - String privateMacAddress, - String privateIpAddress, - String privateNetmask, - long templateId, - long guestOSId, - String guestMacAddress, - String guestIpAddress, - String guestNetmask, - String vnet, - long accountId, - long domainId, - String publicMacAddress, - String publicIpAddress, - String publicNetMask, - Long vlanDbId, - String vlanId, - long podId, - long dataCenterId, - int ramSize, - String gateway, - String domain, - Long hostId, - String dns1, - String dns2) { - super(id, serviceOfferingId, name, instanceName, Type.DomainRouter, templateId, guestOSId, privateMacAddress, privateIpAddress, privateNetmask, dataCenterId, podId, domainId, accountId, true, hostId); - this.privateMacAddress = privateMacAddress; - this.guestMacAddress = guestMacAddress; - this.guestIpAddress = guestIpAddress; - this.publicIpAddress = publicIpAddress; - this.publicMacAddress = publicMacAddress; - this.publicNetmask = publicNetMask; - this.vlanDbId = vlanDbId; - this.vlanId = vlanId; - this.ramSize = ramSize; - this.gateway = gateway; - this.domain = domain; - this.dns1 = dns1; - this.dns2 = dns2; - this.dataCenterId = dataCenterId; - this.vnet = vnet; - this.accountId = accountId; - this.domainId = domainId; - this.guestNetmask = guestNetmask; - } - public DomainRouterVO(long id, long serviceOfferingId, String name, @@ -160,7 +111,24 @@ public class DomainRouterVO extends VMInstanceVO implements DomainRouter { String domain, String dns1, String dns2) { - this(id, serviceOfferingId, name, name, privateMacAddress, privateIpAddress, privateNetmask, templateId, guestOSId, guestMacAddress, guestIpAddress, guestNetmask, null, accountId, domainId, publicMacAddress, publicIpAddress, publicNetMask, vlanDbId, vlanId, podId, dataCenterId, ramSize, gateway, domain, null, dns1, dns2); + super(id, serviceOfferingId, name, name, Type.DomainRouter, templateId, guestOSId, privateMacAddress, privateIpAddress, privateNetmask, dataCenterId, podId, domainId, accountId, true, null); + this.privateMacAddress = privateMacAddress; + this.guestMacAddress = guestMacAddress; + this.guestIpAddress = guestIpAddress; + this.publicIpAddress = publicIpAddress; + this.publicMacAddress = publicMacAddress; + this.publicNetmask = publicNetMask; + this.vlanDbId = vlanDbId; + this.vlanId = vlanId; + this.ramSize = ramSize; + this.gateway = gateway; + this.domain = domain; + this.dns1 = dns1; + this.dns2 = dns2; + this.dataCenterId = dataCenterId; + this.accountId = accountId; + this.domainId = domainId; + this.guestNetmask = guestNetmask; } public DomainRouterVO(long id, @@ -170,7 +138,6 @@ public class DomainRouterVO extends VMInstanceVO implements DomainRouter { long guestOSId, long domainId, long accountId, - long networkConfigurationId, boolean haEnabled) { super(id, serviceOfferingId, name, name, Type.DomainRouter, templateId, guestOSId, domainId, accountId, haEnabled); } diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 5b02d5e6c96..2e57cb80a5f 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -184,7 +184,7 @@ import com.google.gson.GsonBuilder; // because sooner or later, it will be driven into Running state // @Local(value = { ConsoleProxyManager.class }) -public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMachineManager, AgentHook, VirtualMachineGuru { +public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMachineManager, AgentHook, VirtualMachineGuru { private static final Logger s_logger = Logger.getLogger(ConsoleProxyManagerImpl.class); private static final int DEFAULT_FIND_HOST_RETRY_COUNT = 2; @@ -540,7 +540,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach public ConsoleProxyVO start2(long proxyVmId, long startEventId) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException { ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyVmId); DeploymentPlan plan = new DataCenterDeployment(proxy.getDataCenterId(), 1); - return _vmMgr.start(proxy, plan, this); + AccountVO systemAcct = _accountMgr.getSystemAccount(); + return _vmMgr.start(proxy, plan, systemAcct, this); } @Override diff --git a/server/src/com/cloud/network/NetworkAccountVO.java b/server/src/com/cloud/network/NetworkAccountVO.java index 665b03c9691..4c900567603 100644 --- a/server/src/com/cloud/network/NetworkAccountVO.java +++ b/server/src/com/cloud/network/NetworkAccountVO.java @@ -24,13 +24,17 @@ public class NetworkAccountVO implements OwnedBy { @Column(name="network_configuration_id") long networkConfigurationId; + + @Column(name="is_owner") + boolean owner; protected NetworkAccountVO() { } - public NetworkAccountVO(long networkConfigurationId, long accountId) { + public NetworkAccountVO(long networkConfigurationId, long accountId, boolean owner) { this.networkConfigurationId = networkConfigurationId; this.accountId = accountId; + this.owner = owner; } @Override @@ -41,5 +45,9 @@ public class NetworkAccountVO implements OwnedBy { public long getNetworkConfigurationId() { return networkConfigurationId; } + + public boolean isOwner() { + return owner; + } } diff --git a/server/src/com/cloud/network/NetworkConfigurationVO.java b/server/src/com/cloud/network/NetworkConfigurationVO.java index 57d0e66bb20..402c05b1ccc 100644 --- a/server/src/com/cloud/network/NetworkConfigurationVO.java +++ b/server/src/com/cloud/network/NetworkConfigurationVO.java @@ -34,15 +34,17 @@ import com.cloud.utils.NumbersUtil; import com.cloud.utils.net.NetUtils; /** - * NetworkProfileVO contains information about a specific network. + * NetworkConfigurationVO contains information about a specific network. * */ @Entity @Table(name="network_configurations") public class NetworkConfigurationVO implements NetworkConfiguration { @Id - @GeneratedValue(strategy=GenerationType.IDENTITY) - Long id; + @TableGenerator(name="network_configuration_sq", table="sequence", pkColumnName="name", valueColumnName="value", pkColumnValue="network_configuration_seq", allocationSize=1) + @GeneratedValue(strategy=GenerationType.SEQUENCE) + @Column(name="id") + long id; @Column(name="mode") @Enumerated(value=EnumType.STRING) @@ -71,6 +73,9 @@ public class NetworkConfigurationVO implements NetworkConfiguration { @Column(name="data_center_id") long dataCenterId; + @Column(name="related") + long related; + @Column(name="guru_name") String guruName; @@ -81,6 +86,12 @@ public class NetworkConfigurationVO implements NetworkConfiguration { @Column(name="dns") String dns; + @Column(name="domain_id") + long domainId; + + @Column(name="account_id") + long accountId; + @Column(name="mac_address_seq", updatable=false, nullable=false) @TableGenerator(name="mac_address_seq", table="network_configuration", pkColumnName="id", valueColumnName="mac_address_seq", allocationSize=1) long macAddress = 1; @@ -88,12 +99,14 @@ public class NetworkConfigurationVO implements NetworkConfiguration { public NetworkConfigurationVO() { } - public NetworkConfigurationVO(NetworkConfiguration that, long offeringId, long dataCenterId, String guruName) { - this(that.getTrafficType(), that.getMode(), that.getBroadcastDomainType(), offeringId, dataCenterId); - this.guruName = guruName; - this.state = that.getState(); - } - + /** + * Constructor to be used for the adapters because it only initializes what's needed. + * @param trafficType + * @param mode + * @param broadcastDomainType + * @param networkOfferingId + * @param dataCenterId + */ public NetworkConfigurationVO(TrafficType trafficType, Mode mode, BroadcastDomainType broadcastDomainType, long networkOfferingId, long dataCenterId) { this.trafficType = trafficType; this.mode = mode; @@ -103,6 +116,29 @@ public class NetworkConfigurationVO implements NetworkConfiguration { this.state = State.Allocated; } + public NetworkConfigurationVO(long id, NetworkConfiguration that, long offeringId, long dataCenterId, String guruName, long domainId, long accountId, long related) { + this(id, that.getTrafficType(), that.getMode(), that.getBroadcastDomainType(), offeringId, dataCenterId, domainId, accountId, related); + this.guruName = guruName; + this.state = that.getState(); + } + + /** + * Constructor for the actual DAO object. + * @param trafficType + * @param mode + * @param broadcastDomainType + * @param networkOfferingId + * @param dataCenterId + * @param domainId + * @param accountId + */ + public NetworkConfigurationVO(long id, TrafficType trafficType, Mode mode, BroadcastDomainType broadcastDomainType, long networkOfferingId, long dataCenterId, long domainId, long accountId, long related) { + this(trafficType, mode, broadcastDomainType, networkOfferingId, dataCenterId); + this.domainId = domainId; + this.accountId = accountId; + this.related = related; + } + @Override public State getState() { return state; @@ -111,6 +147,10 @@ public class NetworkConfigurationVO implements NetworkConfiguration { public void setState(State state) { this.state = state; } + + public long getRelated() { + return related; + } @Override public Long getId() { @@ -122,6 +162,16 @@ public class NetworkConfigurationVO implements NetworkConfiguration { return mode; } + @Override + public long getAccountId() { + return accountId; + } + + @Override + public long getDomainId() { + return domainId; + } + @Override public long getNetworkOfferingId() { return networkOfferingId; diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 22940f012c3..6e162fe99b5 100644 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -53,6 +53,7 @@ import com.cloud.exception.ResourceAllocationException; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.offerings.NetworkOfferingVO; import com.cloud.service.ServiceOfferingVO; +import com.cloud.user.Account; import com.cloud.user.AccountVO; import com.cloud.utils.Pair; import com.cloud.utils.component.Manager; @@ -177,7 +178,7 @@ public interface NetworkManager extends Manager { * @param so service offering associated with this request * @return public ip address. */ - public String assignSourceNatIpAddress(AccountVO account, DataCenterVO dc, String domain, ServiceOfferingVO so, long startEventId, HypervisorType hyperType) throws ResourceAllocationException; + public String assignSourceNatIpAddress(Account account, DataCenterVO dc, String domain, ServiceOfferingVO so, long startEventId, HypervisorType hyperType) throws ResourceAllocationException; /** * @param fwRules list of rules to be updated @@ -297,19 +298,22 @@ public interface NetworkManager extends Manager { public boolean deleteIpForwardingRule(DeleteIPForwardingRuleCmd cmd) throws PermissionDeniedException, InvalidParameterValueException; - NetworkConfigurationVO setupNetworkConfiguration(AccountVO owner, NetworkOfferingVO offering, DeploymentPlan plan); - NetworkConfigurationVO setupNetworkConfiguration(AccountVO owner, NetworkOfferingVO offering, NetworkConfiguration predefined, DeploymentPlan plan); - List setupNetworkConfigurations(AccountVO owner, List offerings, DeploymentPlan plan); + NetworkConfigurationVO setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, DeploymentPlan plan); + NetworkConfigurationVO setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, NetworkConfiguration predefined, DeploymentPlan plan); + List setupNetworkConfigurations(Account owner, List offerings, DeploymentPlan plan); List getSystemAccountNetworkOfferings(String... offeringNames); List allocate(VirtualMachineProfile vm, List> networks) throws InsufficientCapacityException; - NicTO[] prepare(VirtualMachineProfile profile, DeployDestination dest) throws InsufficientAddressCapacityException, InsufficientVirtualNetworkCapcityException; + NicTO[] prepare(VirtualMachineProfile profile, DeployDestination dest, Account user) throws InsufficientAddressCapacityException, InsufficientVirtualNetworkCapcityException; void release(VirtualMachineProfile vmProfile); - void create(K vm); - List getNics(K vm); boolean upgradeRouter(UpgradeRouterCmd cmd) throws InvalidParameterValueException, PermissionDeniedException; + + List getAccountsUsingNetworkConfiguration(long configurationId); + AccountVO getNetworkConfigurationOwner(long configurationId); + + List getNetworkConfigurationsforOffering(long offeringId, long dataCenterId, long accountId); } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index e4fa01fd4f5..636162040cb 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -136,6 +136,7 @@ import com.cloud.utils.component.Adapters; import com.cloud.utils.component.Inject; import com.cloud.utils.db.DB; import com.cloud.utils.db.JoinBuilder; +import com.cloud.utils.db.JoinBuilder.JoinType; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.Transaction; @@ -197,7 +198,7 @@ public class NetworkManagerImpl implements NetworkManager { @Inject AccountVlanMapDao _accountVlanMapDao; @Inject UserStatisticsDao _statsDao = null; @Inject NetworkOfferingDao _networkOfferingDao = null; - @Inject NetworkConfigurationDao _networkProfileDao = null; + @Inject NetworkConfigurationDao _networkConfigDao = null; @Inject NicDao _nicDao; @Inject GuestOSDao _guestOSDao = null; @Inject DomainRouterManager _routerMgr; @@ -210,6 +211,8 @@ public class NetworkManagerImpl implements NetworkManager { private HashMap _systemNetworks = new HashMap(5); ScheduledExecutorService _executor; + + SearchBuilder AccountsUsingNetworkConfigurationSearch; @Override public boolean sendSshKeysToHost(Long hostId, String pubKey, String prvKey) { @@ -217,7 +220,7 @@ public class NetworkManagerImpl implements NetworkManager { } @Override @DB - public String assignSourceNatIpAddress(AccountVO account, final DataCenterVO dc, final String domain, final ServiceOfferingVO serviceOffering, long startEventId, HypervisorType hyperType) throws ResourceAllocationException { + public String assignSourceNatIpAddress(Account account, final DataCenterVO dc, final String domain, final ServiceOfferingVO serviceOffering, long startEventId, HypervisorType hyperType) throws ResourceAllocationException { if (serviceOffering.getGuestIpType() == NetworkOffering.GuestIpType.DirectDual || serviceOffering.getGuestIpType() == NetworkOffering.GuestIpType.DirectSingle) { return null; } @@ -525,7 +528,7 @@ public class NetworkManagerImpl implements NetworkManager { Transaction txn = Transaction.currentTxn(); - AccountVO accountToLock = null; + Account accountToLock = null; try { if (s_logger.isDebugEnabled()) { s_logger.debug("Associate IP address called for user " + userId + " account " + accountId); @@ -1496,6 +1499,13 @@ public class NetworkManagerImpl implements NetworkManager { storageNetworkOffering = _networkOfferingDao.persistSystemNetworkOffering(storageNetworkOffering); _systemNetworks.put(NetworkOfferingVO.SystemVmGuestNetwork, storageNetworkOffering); + AccountsUsingNetworkConfigurationSearch = _accountDao.createSearchBuilder(); + SearchBuilder networkAccountSearch = _networkConfigDao.createSearchBuilderForAccount(); + AccountsUsingNetworkConfigurationSearch.join("nc", networkAccountSearch, AccountsUsingNetworkConfigurationSearch.entity().getId(), networkAccountSearch.entity().getAccountId(), JoinType.INNER); + networkAccountSearch.and("config", networkAccountSearch.entity().getNetworkConfigurationId(), SearchCriteria.Op.EQ); + networkAccountSearch.and("owner", networkAccountSearch.entity().isOwner(), SearchCriteria.Op.EQ); + AccountsUsingNetworkConfigurationSearch.done(); + s_logger.info("Network Manager is configured."); return true; @@ -1566,13 +1576,13 @@ public class NetworkManagerImpl implements NetworkManager { } @Override - public NetworkConfigurationVO setupNetworkConfiguration(AccountVO owner, NetworkOfferingVO offering, DeploymentPlan plan) { + public NetworkConfigurationVO setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, DeploymentPlan plan) { return setupNetworkConfiguration(owner, offering, null, plan); } @Override - public NetworkConfigurationVO setupNetworkConfiguration(AccountVO owner, NetworkOfferingVO offering, NetworkConfiguration predefined, DeploymentPlan plan) { - List configs = _networkProfileDao.listBy(owner.getId(), offering.getId(), plan.getDataCenterId()); + public NetworkConfigurationVO setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, NetworkConfiguration predefined, DeploymentPlan plan) { + List configs = _networkConfigDao.listBy(owner.getId(), offering.getId(), plan.getDataCenterId()); if (configs.size() > 0) { if (s_logger.isDebugEnabled()) { s_logger.debug("Found existing network configuration for offering " + offering + ": " + configs.get(0)); @@ -1580,6 +1590,9 @@ public class NetworkManagerImpl implements NetworkManager { return configs.get(0); } + long id = _networkConfigDao.getNextInSequence(Long.class, "id"); + long related = id; + for (NetworkGuru guru : _networkGurus) { NetworkConfiguration config = guru.design(offering, plan, predefined, owner); if (config == null) { @@ -1590,19 +1603,19 @@ public class NetworkManagerImpl implements NetworkManager { if (config instanceof NetworkConfigurationVO) { return (NetworkConfigurationVO)config; } else { - return _networkProfileDao.findById(config.getId()); + return _networkConfigDao.findById(config.getId()); } } - NetworkConfigurationVO vo = new NetworkConfigurationVO(config, offering.getId(), plan.getDataCenterId(), guru.getName()); - return _networkProfileDao.persist(vo, owner.getId()); + NetworkConfigurationVO vo = new NetworkConfigurationVO(id, config, offering.getId(), plan.getDataCenterId(), guru.getName(), owner.getDomainId(), owner.getId(), related); + return _networkConfigDao.persist(vo); } throw new CloudRuntimeException("Unable to convert network offering to network profile: " + offering.getId()); } @Override - public List setupNetworkConfigurations(AccountVO owner, List offerings, DeploymentPlan plan) { + public List setupNetworkConfigurations(Account owner, List offerings, DeploymentPlan plan) { List profiles = new ArrayList(offerings.size()); for (NetworkOfferingVO offering : offerings) { profiles.add(setupNetworkConfiguration(owner, offering, plan)); @@ -1623,7 +1636,7 @@ public class NetworkManagerImpl implements NetworkManager { return offerings; } - public NetworkConfigurationVO createNetworkConfiguration(NetworkOfferingVO offering, DeploymentPlan plan, AccountVO owner) { + public NetworkConfigurationVO createNetworkConfiguration(NetworkOfferingVO offering, DeploymentPlan plan, Account owner) { return null; } @@ -1750,12 +1763,12 @@ public class NetworkManagerImpl implements NetworkManager { } @Override - public NicTO[] prepare(VirtualMachineProfile vmProfile, DeployDestination dest) throws InsufficientAddressCapacityException, InsufficientVirtualNetworkCapcityException { + public NicTO[] prepare(VirtualMachineProfile vmProfile, DeployDestination dest, Account user) throws InsufficientAddressCapacityException, InsufficientVirtualNetworkCapcityException { List nics = _nicDao.listBy(vmProfile.getId()); NicTO[] nicTos = new NicTO[nics.size()]; int i = 0; for (NicVO nic : nics) { - NetworkConfigurationVO config = _networkProfileDao.findById(nic.getNetworkConfigurationId()); + NetworkConfigurationVO config = _networkConfigDao.findById(nic.getNetworkConfigurationId()); NicProfile profile = null; if (nic.getReservationStrategy() == ReservationStrategy.Start) { NetworkGuru concierge = _networkGurus.get(config.getGuruName()); @@ -1776,7 +1789,7 @@ public class NetworkManagerImpl implements NetworkManager { nic.setAddressFormat(profile.getFormat()); _nicDao.update(nic.getId(), nic); for (NetworkElement element : _networkElements) { - if (!element.prepare(config, profile, vmProfile, null)) { + if (!element.prepare(config, profile, vmProfile, null, user)) { s_logger.warn("Unable to prepare " + nic + " for element " + element.getName()); return null; } @@ -1793,7 +1806,7 @@ public class NetworkManagerImpl implements NetworkManager { public void release(VirtualMachineProfile vmProfile) { List nics = _nicDao.listBy(vmProfile.getId()); for (NicVO nic : nics) { - NetworkConfigurationVO config = _networkProfileDao.findById(nic.getNetworkConfigurationId()); + NetworkConfigurationVO config = _networkConfigDao.findById(nic.getNetworkConfigurationId()); if (nic.getReservationStrategy() == ReservationStrategy.Start) { NetworkGuru concierge = _networkGurus.get(config.getGuruName()); nic.setState(Resource.State.Releasing); @@ -1804,7 +1817,7 @@ public class NetworkManagerImpl implements NetworkManager { } NicProfile toNicProfile(NicVO nic) { - NetworkConfiguration config = _networkProfileDao.findById(nic.getNetworkConfigurationId()); + NetworkConfiguration config = _networkConfigDao.findById(nic.getNetworkConfigurationId()); NicProfile profile = new NicProfile(nic, config, nic.getBroadcastUri(), nic.getIsolationUri()); return profile; } @@ -1824,10 +1837,6 @@ public class NetworkManagerImpl implements NetworkManager { } } - @Override - public void create(K vm) { - } - @Override public List getNics(K vm) { return _nicDao.listBy(vm.getId()); @@ -2275,14 +2284,14 @@ public class NetworkManagerImpl implements NetworkManager { return true; } - AccountVO accountVO = _accountDao.findById(accountId); - if (accountVO == null) { + Account Account = _accountDao.findById(accountId); + if (Account == null) { return false; } if ((ipVO.getAccountId() == null) || (ipVO.getAccountId().longValue() != accountId)) { // FIXME: is the user visible in the admin account's domain???? - if (!BaseCmd.isAdmin(accountVO.getType())) { + if (!BaseCmd.isAdmin(Account.getType())) { if (s_logger.isDebugEnabled()) { s_logger.debug("permission denied disassociating IP address " + ipAddress + "; acct: " + accountId + "; ip (acct / dc / dom / alloc): " + ipVO.getAccountId() + " / " + ipVO.getDataCenterId() + " / " + ipVO.getDomainId() + " / " + ipVO.getAllocated()); @@ -2433,5 +2442,25 @@ public class NetworkManagerImpl implements NetworkManager { } return success; } - + + @Override + public List getAccountsUsingNetworkConfiguration(long configurationId) { + SearchCriteria sc = AccountsUsingNetworkConfigurationSearch.create(); + sc.setJoinParameters("nc", "config", configurationId); + return _accountDao.search(sc, null); + } + + @Override + public AccountVO getNetworkConfigurationOwner(long configurationId) { + SearchCriteria sc = AccountsUsingNetworkConfigurationSearch.create(); + sc.setJoinParameters("nc", "config", configurationId); + sc.setJoinParameters("nc", "owner", true); + List accounts = _accountDao.search(sc, null); + return accounts.size() != 0 ? accounts.get(0) : null; + } + + @Override + public List getNetworkConfigurationsforOffering(long offeringId, long dataCenterId, long accountId) { + return _networkConfigDao.getNetworkConfigurationsForOffering(offeringId, dataCenterId, accountId); + } } diff --git a/server/src/com/cloud/network/dao/NetworkConfigurationDao.java b/server/src/com/cloud/network/dao/NetworkConfigurationDao.java index a842a38d4f2..97fb92ad7bf 100644 --- a/server/src/com/cloud/network/dao/NetworkConfigurationDao.java +++ b/server/src/com/cloud/network/dao/NetworkConfigurationDao.java @@ -19,12 +19,17 @@ package com.cloud.network.dao; import java.util.List; +import com.cloud.network.NetworkAccountVO; import com.cloud.network.NetworkConfigurationVO; import com.cloud.utils.db.GenericDao; +import com.cloud.utils.db.SearchBuilder; public interface NetworkConfigurationDao extends GenericDao { List listBy(long accountId); List listBy(long accountId, long offeringId, long dataCenterId); - NetworkConfigurationVO persist(NetworkConfigurationVO config, long accountId); + @Override + NetworkConfigurationVO persist(NetworkConfigurationVO config); void addAccountToNetworkConfiguration(long configId, long accountId); + SearchBuilder createSearchBuilderForAccount(); + List getNetworkConfigurationsForOffering(long offeringId, long dataCenterId, long accountId); } diff --git a/server/src/com/cloud/network/dao/NetworkConfigurationDaoImpl.java b/server/src/com/cloud/network/dao/NetworkConfigurationDaoImpl.java index 8a5c0a03cfa..483af6feb8f 100644 --- a/server/src/com/cloud/network/dao/NetworkConfigurationDaoImpl.java +++ b/server/src/com/cloud/network/dao/NetworkConfigurationDaoImpl.java @@ -30,6 +30,7 @@ import com.cloud.network.NetworkConfigurationVO; import com.cloud.utils.db.DB; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.JoinBuilder; +import com.cloud.utils.db.JoinBuilder.JoinType; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.Transaction; @@ -39,6 +40,7 @@ public class NetworkConfigurationDaoImpl extends GenericDaoBase ProfileSearch; final SearchBuilder AccountSearch; final SearchBuilder OfferingSearch; + final SearchBuilder RelatedConfigSearch; NetworkAccountDaoImpl _accountsDao = new NetworkAccountDaoImpl(); @@ -64,6 +66,14 @@ public class NetworkConfigurationDaoImpl extends GenericDaoBase join2 = _accountsDao.createSearchBuilder(); + join2.and("account", join2.entity().getAccountId(), SearchCriteria.Op.EQ); + RelatedConfigSearch.join("account", join2, join2.entity().getNetworkConfigurationId(), RelatedConfigSearch.entity().getId(), JoinType.INNER); + RelatedConfigSearch.done(); } public List findBy(TrafficType trafficType, Mode mode, BroadcastDomainType broadcastType, long networkOfferingId, long dataCenterId) { @@ -95,24 +105,37 @@ public class NetworkConfigurationDaoImpl extends GenericDaoBase createSearchBuilderForAccount() { + return _accountsDao.createSearchBuilder(); + } + + @Override + public List getNetworkConfigurationsForOffering(long offeringId, long dataCenterId, long accountId) { + SearchCriteria sc = RelatedConfigSearch.create(); + sc.setParameters("offering", offeringId); + sc.setParameters("dc", dataCenterId); + sc.setJoinParameters("account", "account", accountId); + return search(sc, null); + } } diff --git a/server/src/com/cloud/network/element/DomainRouterElement.java b/server/src/com/cloud/network/element/DomainRouterElement.java index 7f039c13b62..869089730fe 100644 --- a/server/src/com/cloud/network/element/DomainRouterElement.java +++ b/server/src/com/cloud/network/element/DomainRouterElement.java @@ -17,38 +17,64 @@ */ package com.cloud.network.element; +import java.util.List; + import javax.ejb.Local; +import org.apache.log4j.Logger; + import com.cloud.network.NetworkConfiguration; +import com.cloud.network.NetworkConfiguration.State; +import com.cloud.network.NetworkConfigurationVO; +import com.cloud.network.NetworkManager; import com.cloud.offering.NetworkOffering; +import com.cloud.offering.NetworkOffering.GuestIpType; +import com.cloud.user.Account; import com.cloud.utils.component.AdapterBase; +import com.cloud.utils.component.Inject; import com.cloud.vm.NicProfile; import com.cloud.vm.VirtualMachineProfile; @Local(value=NetworkElement.class) public class DomainRouterElement extends AdapterBase implements NetworkElement { + private static final Logger s_logger = Logger.getLogger(DomainRouterElement.class); + + @Inject NetworkManager _networkMgr; @Override - public boolean implement(NetworkConfiguration config, NetworkOffering offering) { + public Boolean implement(NetworkConfiguration config, NetworkOffering offering, Account user) { + if (offering.getGuestIpType() != GuestIpType.Virtualized) { + s_logger.trace("Not handling guest ip type = " + offering.getGuestIpType()); + return null; + } + + List configs = _networkMgr.getNetworkConfigurationsforOffering(offering.getId(), config.getDataCenterId(), user.getId()); + for (NetworkConfigurationVO c : configs) { + if (c.getState() != State.Implemented && c.getState() != State.Setup) { + s_logger.debug("Not all network is ready to be implemented yet."); + return true; + } + } + + + return true; + } + + @Override + public Boolean prepare(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering, Account user) { // TODO Auto-generated method stub return false; } @Override - public boolean prepare(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering) { + public Boolean release(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering, Account user) { // TODO Auto-generated method stub return false; } @Override - public boolean release(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean shutdown(NetworkConfiguration config, NetworkOffering offering) { + public Boolean shutdown(NetworkConfiguration config, NetworkOffering offering, Account user) { // TODO Auto-generated method stub return false; } diff --git a/server/src/com/cloud/network/router/DomainRouterManagerImpl.java b/server/src/com/cloud/network/router/DomainRouterManagerImpl.java index 6a6a68a400b..559f54858e7 100644 --- a/server/src/com/cloud/network/router/DomainRouterManagerImpl.java +++ b/server/src/com/cloud/network/router/DomainRouterManagerImpl.java @@ -46,12 +46,16 @@ import com.cloud.agent.api.NetworkUsageCommand; import com.cloud.agent.api.PrepareForMigrationCommand; import com.cloud.agent.api.RebootAnswer; import com.cloud.agent.api.RebootRouterCommand; +import com.cloud.agent.api.Start2Command; import com.cloud.agent.api.StartRouterAnswer; import com.cloud.agent.api.StartRouterCommand; import com.cloud.agent.api.StopCommand; import com.cloud.agent.api.routing.DhcpEntryCommand; import com.cloud.agent.api.routing.SavePasswordCommand; import com.cloud.agent.api.routing.VmDataCommand; +import com.cloud.agent.api.to.NicTO; +import com.cloud.agent.api.to.VirtualMachineTO; +import com.cloud.agent.api.to.VirtualMachineTO.SshMonitor; import com.cloud.agent.manager.Commands; import com.cloud.alert.AlertManager; import com.cloud.api.commands.RebootRouterCmd; @@ -76,6 +80,8 @@ import com.cloud.dc.dao.AccountVlanMapDao; import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.HostPodDao; import com.cloud.dc.dao.VlanDao; +import com.cloud.deploy.DataCenterDeployment; +import com.cloud.deploy.DeployDestination; import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; import com.cloud.event.EventState; @@ -85,6 +91,7 @@ import com.cloud.event.EventVO; import com.cloud.event.dao.EventDao; import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.PermissionDeniedException; @@ -96,6 +103,9 @@ import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.FirewallRuleVO; import com.cloud.network.IPAddressVO; +import com.cloud.network.Network.TrafficType; +import com.cloud.network.NetworkConfiguration; +import com.cloud.network.NetworkConfigurationVO; import com.cloud.network.NetworkManager; import com.cloud.network.SshKeysDistriMonitor; import com.cloud.network.dao.FirewallRulesDao; @@ -107,6 +117,7 @@ import com.cloud.network.dao.NetworkRuleConfigDao; import com.cloud.network.dao.SecurityGroupDao; import com.cloud.network.dao.SecurityGroupVMMapDao; import com.cloud.offering.NetworkOffering; +import com.cloud.offerings.NetworkOfferingVO; import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; @@ -143,12 +154,16 @@ import com.cloud.utils.net.NetUtils; import com.cloud.vm.DomainRouter; import com.cloud.vm.DomainRouter.Role; import com.cloud.vm.DomainRouterVO; +import com.cloud.vm.NicProfile; import com.cloud.vm.State; import com.cloud.vm.UserVmVO; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.Event; +import com.cloud.vm.VirtualMachineGuru; import com.cloud.vm.VirtualMachineManager; import com.cloud.vm.VirtualMachineName; +import com.cloud.vm.VirtualMachineProfile; +import com.cloud.vm.VmManager; import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.NicDao; import com.cloud.vm.dao.UserVmDao; @@ -157,7 +172,7 @@ import com.cloud.vm.dao.UserVmDao; * NetworkManagerImpl implements NetworkManager. */ @Local(value={DomainRouterManager.class}) -public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMachineManager { +public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMachineManager, VirtualMachineGuru { private static final Logger s_logger = Logger.getLogger(DomainRouterManagerImpl.class); String _name; @@ -204,6 +219,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach @Inject NicDao _nicDao; @Inject GuestOSDao _guestOSDao = null; @Inject NetworkManager _networkMgr; + @Inject VmManager _vmMgr; long _routerTemplateId = -1; int _routerRamSize; @@ -220,6 +236,8 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach private VMTemplateVO _template; ScheduledExecutorService _executor; + + AccountVO _systemAcct; @Override public DomainRouterVO getRouter(long accountId, long dataCenterId) { @@ -1414,6 +1432,8 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach _routerTemplateId = _template.getId(); } + _systemAcct = _accountMgr.getSystemAccount(); + s_logger.info("DomainRouterManager is configured."); return true; @@ -1936,5 +1956,255 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach (accountType == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || (accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN)); } + + public DomainRouterVO deploy(NetworkConfiguration publicConfig, NetworkConfiguration virtualConfig, NetworkOffering offering, Account owner) throws InsufficientCapacityException, StorageUnavailableException, ConcurrentOperationException { + long dcId = publicConfig.getDataCenterId(); + + if (s_logger.isDebugEnabled()) { + s_logger.debug("Creating a router for network configurations: public=" + publicConfig + "; virtual=" + virtualConfig); + } + assert dcId == virtualConfig.getDataCenterId() : "Domain router cannot span networks in two data centers"; + assert publicConfig.getState() == NetworkConfiguration.State.Implemented : "Network is not yet fully implemented: " + publicConfig; + assert virtualConfig.getState() == NetworkConfiguration.State.Implemented : "Network is not yet fully implemented: " + virtualConfig; + + DataCenterDeployment plan = new DataCenterDeployment(dcId, 1); + List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemVmControlNetwork); + + NetworkOfferingVO controlOffering = offerings.get(0); + NetworkConfigurationVO controlConfig = _networkMgr.setupNetworkConfiguration(_systemAcct, controlOffering, plan); + + long id = _routerDao.getNextInSequence(Long.class, "id"); + DomainRouterVO router = new DomainRouterVO(id, _offering.getId(), VirtualMachineName.getRouterName(id, _instance), _template.getId(), _template.getGuestOSId(), owner.getDomainId(), owner.getId(), _offering.getOfferHA()); + _routerDao.persist(router); + + List> networks = new ArrayList>(3); + NicProfile defaultNic = new NicProfile(); + defaultNic.setDefaultNic(true); + defaultNic.setDeviceId(2); + networks.add(new Pair((NetworkConfigurationVO)publicConfig, defaultNic)); + networks.add(new Pair((NetworkConfigurationVO)virtualConfig, null)); + networks.add(new Pair(controlConfig, null)); + + _vmMgr.allocate(router, _template, _offering, networks, plan, owner); + router = _vmMgr.start(router, plan, owner, this); + + return router; + } + + @Override + public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest) { + Start2Command cmd = cmds.getCommand(Start2Command.class); + VirtualMachineTO vm = cmd.getVirtualMachine(); + + StringBuilder buf = new StringBuilder(); + buf.append(" template=domP type=router"); + buf.append(" name=").append(vm.getName()); + NicTO controlNic = null; + for (NicTO nic : vm.getNics()) { + int deviceId = nic.getDeviceId(); + buf.append(" eth").append(deviceId).append("ip=").append(nic.getIp()); + buf.append(" eth").append(deviceId).append("mask=").append(nic.getNetmask()); + if (nic.isDefaultNic()) { + buf.append(" gateway=").append(nic.getGateway()); + buf.append(" dns1=").append(nic.getDns1()); + if (nic.getDns2() != null) { + buf.append(" dns2=").append(nic.getDns2()); + } + } + if (nic.getType() == TrafficType.Management) { + buf.append(" localgw=").append(dest.getPod().getGateway()); + } else if (nic.getType() == TrafficType.Control) { + controlNic = nic; + } + } + + String bootArgs = buf.toString(); + if (s_logger.isDebugEnabled()) { + s_logger.debug("Boot Args for " + vm + ": " + bootArgs); + } + vm.setBootArgs(bootArgs); + + if (controlNic == null) { + throw new CloudRuntimeException("Didn't start a control port"); + } + + SshMonitor monitor = new SshMonitor(controlNic.getIp(), 3922); + vm.setMonitor(monitor); + + return true; + } + + @Override + public boolean checkDeploymentResult(Commands cmds, VirtualMachineProfile profile, DeployDestination dest) { + return true; + } + +// if (s_logger.isDebugEnabled()) { +// s_logger.debug("Creating a router for account=" + accountId + "; publicIpAddress=" + publicIpAddress + "; dc=" + dataCenterId + "domain=" + domain); +// } +// +// final AccountVO account = _accountDao.acquire(accountId); +// if (account == null) { +// throw new ConcurrentOperationException("Unable to acquire account " + accountId); +// } +// +// if(s_logger.isDebugEnabled()) +// s_logger.debug("lock on account " + accountId + " for createRouter is acquired"); +// +// final Transaction txn = Transaction.currentTxn(); +// DomainRouterVO router = null; +// boolean success = false; +// try { +// router = _routerDao.findBy(accountId, dataCenterId); +// if (router != null && router.getState() != State.Creating) { +// if (s_logger.isDebugEnabled()) { +// s_logger.debug("Router " + router.toString() + " found for account " + accountId + " in data center " + dataCenterId); +// } +// success = true; +// return router; +// } +// EventVO event = new EventVO(); +// event.setUserId(1L); +// event.setAccountId(accountId); +// event.setType(EventTypes.EVENT_ROUTER_CREATE); +// event.setState(EventState.Started); +// event.setStartId(startEventId); +// event.setDescription("Creating Router for account with Id: "+accountId); +// event = _eventDao.persist(event); +// +// final DataCenterVO dc = _dcDao.findById(dataCenterId); +// final VMTemplateVO template = _templateDao.findRoutingTemplate(); +// +// String[] macAddresses = getMacAddressPair(dataCenterId); +// String privateMacAddress = macAddresses[0]; +// String publicMacAddress = macAddresses[1]; +// +// final long id = _routerDao.getNextInSequence(Long.class, "id"); +// +// if (domain == null) { +// domain = "v" + Long.toHexString(accountId) + "." + _domain; +// } +// +// final String name = VirtualMachineName.getRouterName(id, _instance).intern(); +// long routerMacAddress = NetUtils.mac2Long(dc.getRouterMacAddress()) | ((dc.getId() & 0xff) << 32); +// +// //set the guestNetworkCidr from the dc obj +// String guestNetworkCidr = dc.getGuestNetworkCidr(); +// String[] cidrTuple = guestNetworkCidr.split("\\/"); +// String guestIpAddress = NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1])); +// String guestNetmask = NetUtils.getCidrNetmask(Long.parseLong(cidrTuple[1])); +// +//// String path = null; +//// final int numVolumes = offering.isMirroredVolumes()?2:1; +//// long routerId = 0; +// +// // Find the VLAN ID, VLAN gateway, and VLAN netmask for publicIpAddress +// IPAddressVO ipVO = _ipAddressDao.findById(publicIpAddress); +// VlanVO vlan = _vlanDao.findById(ipVO.getVlanDbId()); +// String vlanId = vlan.getVlanId(); +// String vlanGateway = vlan.getVlanGateway(); +// String vlanNetmask = vlan.getVlanNetmask(); +// +// Pair pod = null; +// Set avoids = new HashSet(); +// boolean found = false; +// while ((pod = _agentMgr.findPod(template, offering, dc, accountId, avoids)) != null) { +// +// if (s_logger.isDebugEnabled()) { +// s_logger.debug("Attempting to create in pod " + pod.first().getName()); +// } +// +// router = new DomainRouterVO(id, +// _offering.getId(), +// name, +// privateMacAddress, +// null, +// null, +// _routerTemplateId, +// template.getGuestOSId(), +// NetUtils.long2Mac(routerMacAddress), +// guestIpAddress, +// guestNetmask, +// accountId, +// account.getDomainId(), +// publicMacAddress, +// publicIpAddress, +// vlanNetmask, +// vlan.getId(), +// vlanId, +// pod.first().getId(), +// dataCenterId, +// _routerRamSize, +// vlanGateway, +// domain, +// dc.getDns1(), +// dc.getDns2()); +// router.setMirroredVols(offering.isMirrored()); +// +// router.setLastHostId(pod.second()); +// router = _routerDao.persist(router); +// +// List vols = _storageMgr.create(account, router, template, dc, pod.first(), _offering, null,0); +// if(vols != null) { +// found = true; +// break; +// } +// +// _routerDao.expunge(router.getId()); +// if (s_logger.isDebugEnabled()) { +// s_logger.debug("Unable to find storage host or pool in pod " + pod.first().getName() + " (id:" + pod.first().getId() + "), checking other pods"); +// } +// avoids.add(pod.first().getId()); +// } +// +// if (!found) { +// event.setDescription("failed to create Domain Router : " + name); +// event.setLevel(EventVO.LEVEL_ERROR); +// _eventDao.persist(event); +// throw new ExecutionException("Unable to create DomainRouter"); +// } +// _routerDao.updateIf(router, Event.OperationSucceeded, null); +// +// s_logger.debug("Router created: id=" + router.getId() + "; name=" + router.getName()); +// +// event = new EventVO(); +// event.setUserId(1L); // system user performed the action +// event.setAccountId(accountId); +// event.setType(EventTypes.EVENT_ROUTER_CREATE); +// event.setStartId(startEventId); +// event.setDescription("successfully created Domain Router : " + router.getName() + " with ip : " + publicIpAddress); +// _eventDao.persist(event); +// success = true; +// return router; +// } catch (final Throwable th) { +// if (th instanceof ExecutionException) { +// s_logger.error("Error while starting router due to " + th.getMessage()); +// } else { +// s_logger.error("Unable to create router", th); +// } +// txn.rollback(); +// +// if (router != null && router.getState() == State.Creating) { +// _routerDao.expunge(router.getId()); +// } +// return null; +// } finally { +// if (account != null) { +// if(s_logger.isDebugEnabled()) +// s_logger.debug("Releasing lock on account " + account.getId() + " for createRouter"); +// _accountDao.release(account.getId()); +// } +// if(!success){ +// EventVO event = new EventVO(); +// event.setUserId(1L); // system user performed the action +// event.setAccountId(accountId); +// event.setType(EventTypes.EVENT_ROUTER_CREATE); +// event.setStartId(startEventId); +// event.setLevel(EventVO.LEVEL_ERROR); +// event.setDescription("Failed to create router for account " + accountId + " in data center " + dataCenterId); +// _eventDao.persist(event); +// } +// } + } diff --git a/server/src/com/cloud/storage/StorageManager.java b/server/src/com/cloud/storage/StorageManager.java index 0c382ebcc27..2f9692b3079 100755 --- a/server/src/com/cloud/storage/StorageManager.java +++ b/server/src/com/cloud/storage/StorageManager.java @@ -48,7 +48,6 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.service.ServiceOfferingVO; import com.cloud.storage.Volume.VolumeType; import com.cloud.user.Account; -import com.cloud.user.AccountVO; import com.cloud.utils.Pair; import com.cloud.utils.component.Manager; import com.cloud.utils.exception.ExecutionException; @@ -59,7 +58,7 @@ import com.cloud.vm.VirtualMachineProfile; public interface StorageManager extends Manager { - VolumeVO allocateIsoInstalledVm(VMInstanceVO vm, VMTemplateVO template, DiskOfferingVO rootOffering, Long size, DataCenterVO dc, AccountVO account); + VolumeVO allocateIsoInstalledVm(VMInstanceVO vm, VMTemplateVO template, DiskOfferingVO rootOffering, Long size, DataCenterVO dc, Account account); /** * Calls the storage agent and makes the volumes sharable with this host. @@ -339,8 +338,8 @@ public interface StorageManager extends Manager { * @param account * @return VolumeVO a persisted volume. */ - DiskProfile allocateRawVolume(VolumeType type, String name, DiskOfferingVO offering, Long size, T vm, AccountVO owner); - DiskProfile allocateTemplatedVolume(VolumeType type, String name, DiskOfferingVO offering, VMTemplateVO template, T vm, AccountVO owner); + DiskProfile allocateRawVolume(VolumeType type, String name, DiskOfferingVO offering, Long size, T vm, Account owner); + DiskProfile allocateTemplatedVolume(VolumeType type, String name, DiskOfferingVO offering, VMTemplateVO template, T vm, Account owner); Long findHostIdForStoragePool(StoragePool pool); void createCapacityEntry(StoragePoolVO storagePool, long allocated); diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index 4c01a108444..9d625bfcae8 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -136,7 +136,6 @@ import com.cloud.storage.snapshot.SnapshotScheduler; import com.cloud.template.TemplateManager; import com.cloud.user.Account; import com.cloud.user.AccountManager; -import com.cloud.user.AccountVO; import com.cloud.user.User; import com.cloud.user.UserContext; import com.cloud.user.dao.AccountDao; @@ -253,14 +252,14 @@ public class StorageManagerImpl implements StorageManager { } @DB - public List allocate(DiskProfile rootDisk, List dataDisks, VMInstanceVO vm, DataCenterVO dc, AccountVO account) { + public List allocate(DiskProfile rootDisk, List dataDisks, VMInstanceVO vm, DataCenterVO dc, Account owner) { ArrayList vols = new ArrayList(dataDisks.size() + 1); VolumeVO dataVol = null; VolumeVO rootVol = null; long deviceId = 0; Transaction txn = Transaction.currentTxn(); txn.start(); - rootVol = new VolumeVO(VolumeType.ROOT, rootDisk.getName(), dc.getId(), account.getDomainId(), account.getId(), rootDisk.getDiskOfferingId(), rootDisk.getSize()); + rootVol = new VolumeVO(VolumeType.ROOT, rootDisk.getName(), dc.getId(), owner.getDomainId(), owner.getId(), rootDisk.getDiskOfferingId(), rootDisk.getSize()); if (rootDisk.getTemplateId() != null) { rootVol.setTemplateId(rootDisk.getTemplateId()); } @@ -269,7 +268,7 @@ public class StorageManagerImpl implements StorageManager { rootVol = _volsDao.persist(rootVol); vols.add(rootVol); for (DiskProfile dataDisk : dataDisks) { - dataVol = new VolumeVO(VolumeType.DATADISK, dataDisk.getName(), dc.getId(), account.getDomainId(), account.getId(), dataDisk.getDiskOfferingId(), dataDisk.getSize()); + dataVol = new VolumeVO(VolumeType.DATADISK, dataDisk.getName(), dc.getId(), owner.getDomainId(), owner.getId(), dataDisk.getDiskOfferingId(), dataDisk.getSize()); dataVol.setDeviceId(deviceId++); dataVol.setInstanceId(vm.getId()); dataVol = _volsDao.persist(dataVol); @@ -281,7 +280,7 @@ public class StorageManagerImpl implements StorageManager { } @Override - public VolumeVO allocateIsoInstalledVm(VMInstanceVO vm, VMTemplateVO template, DiskOfferingVO rootOffering, Long size, DataCenterVO dc, AccountVO account) { + public VolumeVO allocateIsoInstalledVm(VMInstanceVO vm, VMTemplateVO template, DiskOfferingVO rootOffering, Long size, DataCenterVO dc, Account account) { assert (template.getFormat() == ImageFormat.ISO) : "The template has to be ISO"; long rootId = _volsDao.getNextInSequence(Long.class, "volume_seq"); @@ -1662,7 +1661,7 @@ public class StorageManagerImpl implements StorageManager { // check if the volume can be created for the user // Check that the resource limit for volumes won't be exceeded - if (_accountMgr.resourceLimitExceeded((AccountVO)targetAccount, ResourceType.volume)) { + if (_accountMgr.resourceLimitExceeded((Account)targetAccount, ResourceType.volume)) { ResourceAllocationException rae = new ResourceAllocationException("Maximum number of volumes for account: " + targetAccount.getAccountName() + " has been exceeded."); rae.setResourceType("volume"); throw rae; @@ -2509,7 +2508,7 @@ public class StorageManagerImpl implements StorageManager { } @Override - public DiskProfile allocateRawVolume(VolumeType type, String name, DiskOfferingVO offering, Long size, T vm, AccountVO owner) { + public DiskProfile allocateRawVolume(VolumeType type, String name, DiskOfferingVO offering, Long size, T vm, Account owner) { if (size == null) { size = offering.getDiskSizeInBytes(); } @@ -2524,7 +2523,7 @@ public class StorageManagerImpl implements StorageManager { } @Override - public DiskProfile allocateTemplatedVolume(VolumeType type, String name, DiskOfferingVO offering, VMTemplateVO template, T vm, AccountVO owner) { + public DiskProfile allocateTemplatedVolume(VolumeType type, String name, DiskOfferingVO offering, VMTemplateVO template, T vm, Account owner) { assert (template.getFormat() != ImageFormat.ISO) : "ISO is not a template really...."; SearchCriteria sc = HostTemplateStatesSearch.create(); diff --git a/server/src/com/cloud/user/AccountManager.java b/server/src/com/cloud/user/AccountManager.java index 71a570a0ebf..210f1ebdca7 100644 --- a/server/src/com/cloud/user/AccountManager.java +++ b/server/src/com/cloud/user/AccountManager.java @@ -85,7 +85,7 @@ public interface AccountManager extends Manager { * @param count the number of resources being allocated, count will be added to current allocation and compared against maximum allowed allocation * @return true if the limit has been exceeded */ - public boolean resourceLimitExceeded(AccountVO account, ResourceCount.ResourceType type, long...count); + public boolean resourceLimitExceeded(Account account, ResourceCount.ResourceType type, long...count); /** * Gets the count of resources for a resource type and account diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index 19b95442d03..b01621bf242 100644 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -185,7 +185,7 @@ public class AccountManagerImpl implements AccountManager { } @Override - public boolean resourceLimitExceeded(AccountVO account, ResourceType type, long...count) { + public boolean resourceLimitExceeded(Account account, ResourceType type, long...count) { long numResources = ((count.length == 0) ? 1 : count[0]); // Don't place any limits on system or admin accounts diff --git a/server/src/com/cloud/vm/MauriceMoss.java b/server/src/com/cloud/vm/MauriceMoss.java index 7484c90a787..e99ff0b392d 100644 --- a/server/src/com/cloud/vm/MauriceMoss.java +++ b/server/src/com/cloud/vm/MauriceMoss.java @@ -61,7 +61,7 @@ import com.cloud.storage.Volume.VolumeType; import com.cloud.storage.dao.GuestOSDao; import com.cloud.storage.dao.VMTemplateDao; import com.cloud.template.VirtualMachineTemplate.BootloaderType; -import com.cloud.user.AccountVO; +import com.cloud.user.Account; import com.cloud.utils.Journal; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; @@ -100,7 +100,7 @@ public class MauriceMoss implements VmManager { List> dataDiskOfferings, List> networks, DeploymentPlan plan, - AccountVO owner) throws InsufficientCapacityException { + Account owner) throws InsufficientCapacityException { if (s_logger.isDebugEnabled()) { s_logger.debug("Allocating entries for VM: " + vm); } @@ -154,7 +154,7 @@ public class MauriceMoss implements VmManager { Pair dataDiskOffering, List> networks, DeploymentPlan plan, - AccountVO owner) throws InsufficientCapacityException { + Account owner) throws InsufficientCapacityException { List> diskOfferings = new ArrayList>(1); if (dataDiskOffering != null) { diskOfferings.add(dataDiskOffering); @@ -168,7 +168,7 @@ public class MauriceMoss implements VmManager { ServiceOfferingVO serviceOffering, List> networks, DeploymentPlan plan, - AccountVO owner) throws InsufficientCapacityException { + Account owner) throws InsufficientCapacityException { return allocate(vm, template, serviceOffering, new Pair(serviceOffering, null), null, networks, plan, owner); } @@ -211,7 +211,7 @@ public class MauriceMoss implements VmManager { } @Override - public T start(T vm, DeploymentPlan plan, VirtualMachineGuru guru) throws InsufficientCapacityException, ConcurrentOperationException { + public T start(T vm, DeploymentPlan plan, Account acct, VirtualMachineGuru guru) throws InsufficientCapacityException, ConcurrentOperationException { if (s_logger.isDebugEnabled()) { s_logger.debug("Creating actual resources for VM " + vm); } @@ -267,7 +267,7 @@ public class MauriceMoss implements VmManager { s_logger.warn("Unable to contact storage.", e); continue; } - NicTO[] nics = _networkMgr.prepare(vmProfile, dest); + NicTO[] nics = _networkMgr.prepare(vmProfile, dest, acct); vmTO.setNics(nics); vmTO.setDisks(volumes); diff --git a/server/src/com/cloud/vm/VirtualMachineGuru.java b/server/src/com/cloud/vm/VirtualMachineGuru.java index 0c1a68034a5..2e2f096186d 100644 --- a/server/src/com/cloud/vm/VirtualMachineGuru.java +++ b/server/src/com/cloud/vm/VirtualMachineGuru.java @@ -24,7 +24,7 @@ import com.cloud.deploy.DeployDestination; * A VirtualMachineGuru knows how to process a certain type of virtual machine. * */ -public interface VirtualMachineGuru { +public interface VirtualMachineGuru { /** * finalize the virtual machine deployment. * @param cmds commands that were created. diff --git a/server/src/com/cloud/vm/VmManager.java b/server/src/com/cloud/vm/VmManager.java index 0849ec3e859..9e27dcf7393 100644 --- a/server/src/com/cloud/vm/VmManager.java +++ b/server/src/com/cloud/vm/VmManager.java @@ -28,7 +28,7 @@ import com.cloud.network.NetworkConfigurationVO; import com.cloud.service.ServiceOfferingVO; import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.VMTemplateVO; -import com.cloud.user.AccountVO; +import com.cloud.user.Account; import com.cloud.utils.Pair; import com.cloud.utils.component.Manager; @@ -44,7 +44,7 @@ public interface VmManager extends Manager { List> dataDiskOfferings, List> networks, DeploymentPlan plan, - AccountVO owner) throws InsufficientCapacityException, StorageUnavailableException; + Account owner) throws InsufficientCapacityException, StorageUnavailableException; VirtualMachineProfile allocate(T vm, VMTemplateVO template, @@ -53,16 +53,16 @@ public interface VmManager extends Manager { Pair dataDiskOffering, List> networks, DeploymentPlan plan, - AccountVO owner) throws InsufficientCapacityException, StorageUnavailableException; + Account owner) throws InsufficientCapacityException, StorageUnavailableException; VirtualMachineProfile allocate(T vm, VMTemplateVO template, ServiceOfferingVO serviceOffering, List> networkProfiles, DeploymentPlan plan, - AccountVO owner) throws InsufficientCapacityException, StorageUnavailableException; + Account owner) throws InsufficientCapacityException, StorageUnavailableException; - T start(T vm, DeploymentPlan plan, VirtualMachineGuru checker) throws InsufficientCapacityException, StorageUnavailableException, ConcurrentOperationException; + T start(T vm, DeploymentPlan plan, Account user, VirtualMachineGuru checker) throws InsufficientCapacityException, StorageUnavailableException, ConcurrentOperationException; T stop(T vm) throws AgentUnavailableException, ConcurrentOperationException; diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 0019f016315..7306c09d48d 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -244,6 +244,7 @@ INSERT INTO `cloud`.`sequence` (name, value) VALUES ('public_mac_address_seq', 1 INSERT INTO `cloud`.`sequence` (name, value) VALUES ('private_mac_address_seq', 1); INSERT INTO `cloud`.`sequence` (name, value) VALUES ('storage_pool_seq', 200); INSERT INTO `cloud`.`sequence` (name, value) VALUES ('volume_seq', 1); +INSERT INTO `cloud`.`sequence` (name, value) VALUES ('network_configuration_seq', 1); CREATE TABLE `cloud`.`disk_template_ref` ( `id` bigint unsigned NOT NULL auto_increment,