diff --git a/api/src/com/cloud/network/NetworkConfiguration.java b/api/src/com/cloud/network/NetworkConfiguration.java index 9f9078e619b..bed8dcae9ea 100644 --- a/api/src/com/cloud/network/NetworkConfiguration.java +++ b/api/src/com/cloud/network/NetworkConfiguration.java @@ -90,4 +90,6 @@ public interface NetworkConfiguration extends OwnedBy, PartOf { long getNetworkOfferingId(); State getState(); + + long getRelated(); } diff --git a/core/src/com/cloud/vm/DomainRouterVO.java b/core/src/com/cloud/vm/DomainRouterVO.java index 66f94d7a70d..752b0fc0610 100755 --- a/core/src/com/cloud/vm/DomainRouterVO.java +++ b/core/src/com/cloud/vm/DomainRouterVO.java @@ -83,6 +83,9 @@ public class DomainRouterVO extends VMInstanceVO implements DomainRouter { @Column(name="guest_dc_mac_address") private String guestZoneMacAddress; + @Column(name="network_configuration_id") + long networkConfigurationId; + @Column(name="role") @Enumerated(EnumType.STRING) private Role role = Role.DHCP_FIREWALL_LB_PASSWD_USERDATA; @@ -138,8 +141,10 @@ 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); + this.networkConfigurationId = networkConfigurationId; } public void setGateway(String gateway) { @@ -162,6 +167,10 @@ public class DomainRouterVO extends VMInstanceVO implements DomainRouter { this.guestMacAddress = routerMacAddress; } + public long getNetworkConfigurationId() { + return networkConfigurationId; + } + @Override public String getGuestNetmask() { return guestNetmask; diff --git a/core/src/com/cloud/vm/dao/DomainRouterDao.java b/core/src/com/cloud/vm/dao/DomainRouterDao.java index 837e580cfe0..0e29b029458 100755 --- a/core/src/com/cloud/vm/dao/DomainRouterDao.java +++ b/core/src/com/cloud/vm/dao/DomainRouterDao.java @@ -20,9 +20,9 @@ package com.cloud.vm.dao; import java.util.List; import com.cloud.utils.db.GenericDao; +import com.cloud.vm.DomainRouter.Role; import com.cloud.vm.DomainRouterVO; import com.cloud.vm.VirtualMachine; -import com.cloud.vm.DomainRouter.Role; /** * @@ -114,4 +114,6 @@ public interface DomainRouterDao extends GenericDao { public List listByVlanDbId(Long vlanId); DomainRouterVO findBy(long accountId, long dcId, Role role); + + DomainRouterVO findByNetworkConfiguration(long networkConfigurationId); } diff --git a/core/src/com/cloud/vm/dao/DomainRouterDaoImpl.java b/core/src/com/cloud/vm/dao/DomainRouterDaoImpl.java index dbe113e118f..218dcdd515a 100755 --- a/core/src/com/cloud/vm/dao/DomainRouterDaoImpl.java +++ b/core/src/com/cloud/vm/dao/DomainRouterDaoImpl.java @@ -60,6 +60,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase im protected final SearchBuilder DomainIdSearch; protected final SearchBuilder VlanDbIdSearch; protected final SearchBuilder StateChangeSearch; + protected final SearchBuilder NetworkConfigSearch; protected final Attribute _updateTimeAttr; protected DomainRouterDaoImpl() { @@ -114,6 +115,9 @@ public class DomainRouterDaoImpl extends GenericDaoBase im StateChangeSearch.and("host", StateChangeSearch.entity().getHostId(), SearchCriteria.Op.EQ); StateChangeSearch.and("update", StateChangeSearch.entity().getUpdated(), SearchCriteria.Op.EQ); StateChangeSearch.done(); + + NetworkConfigSearch = createSearchBuilder(); + NetworkConfigSearch.and("network", NetworkConfigSearch.entity().getNetworkConfigurationId(), SearchCriteria.Op.EQ); _updateTimeAttr = _allAttributes.get("updateTime"); assert _updateTimeAttr != null : "Couldn't get this updateTime attribute"; @@ -296,4 +300,11 @@ public class DomainRouterDaoImpl extends GenericDaoBase im sc.setParameters("vlanDbId", vlanDbId); return listBy(sc); } + + @Override + public DomainRouterVO findByNetworkConfiguration(long networkConfigurationId) { + SearchCriteria sc = NetworkConfigSearch.create(); + sc.setParameters("network", networkConfigurationId); + return findOneBy(sc); + } } diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 2e57cb80a5f..4e5aec0a88f 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -1062,9 +1062,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach NicProfile defaultNic = new NicProfile(); defaultNic.setDefaultNic(true); defaultNic.setDeviceId(2); - networks.add(new Pair(_networkMgr.setupNetworkConfiguration(systemAcct, defaultOffering.get(0), plan), defaultNic)); + networks.add(new Pair(_networkMgr.setupNetworkConfiguration(systemAcct, defaultOffering.get(0), plan).get(0), defaultNic)); for (NetworkOfferingVO offering : offerings) { - networks.add(new Pair(_networkMgr.setupNetworkConfiguration(systemAcct, offering, plan), null)); + networks.add(new Pair(_networkMgr.setupNetworkConfiguration(systemAcct, offering, plan).get(0), null)); } ConsoleProxyVO proxy = new ConsoleProxyVO(id, _serviceOffering.getId(), name, _template.getId(), _template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId(), 0); proxy = _consoleProxyDao.persist(proxy); @@ -2375,7 +2375,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach } @Override - public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest) { + public boolean finalizeDeployment(Commands cmds, ConsoleProxyVO proxy, VirtualMachineProfile profile, DeployDestination dest) { Start2Command cmd = cmds.getCommand(Start2Command.class); VirtualMachineTO vm = cmd.getVirtualMachine(); @@ -2428,7 +2428,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach } @Override - public boolean checkDeploymentResult(Commands cmds, VirtualMachineProfile profile, DeployDestination dest) { + public boolean checkDeploymentResult(Commands cmds, ConsoleProxyVO proxy, VirtualMachineProfile profile, DeployDestination dest) { return true; } } diff --git a/server/src/com/cloud/network/NetworkConfigurationVO.java b/server/src/com/cloud/network/NetworkConfigurationVO.java index 402c05b1ccc..13c32de495e 100644 --- a/server/src/com/cloud/network/NetworkConfigurationVO.java +++ b/server/src/com/cloud/network/NetworkConfigurationVO.java @@ -21,8 +21,6 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; import javax.persistence.TableGenerator; @@ -42,7 +40,6 @@ import com.cloud.utils.net.NetUtils; public class NetworkConfigurationVO implements NetworkConfiguration { @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; @@ -148,6 +145,7 @@ public class NetworkConfigurationVO implements NetworkConfiguration { this.state = state; } + @Override public long getRelated() { return related; } diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 6e162fe99b5..0c1016b04ea 100644 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -298,9 +298,8 @@ public interface NetworkManager extends Manager { public boolean deleteIpForwardingRule(DeleteIPForwardingRuleCmd cmd) throws PermissionDeniedException, InvalidParameterValueException; - 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 setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, DeploymentPlan plan); + List setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, NetworkConfiguration predefined, DeploymentPlan plan); List getSystemAccountNetworkOfferings(String... offeringNames); diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 636162040cb..75d3cca01dd 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -1576,22 +1576,23 @@ public class NetworkManagerImpl implements NetworkManager { } @Override - public NetworkConfigurationVO setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, DeploymentPlan plan) { + public List setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, DeploymentPlan plan) { return setupNetworkConfiguration(owner, offering, null, plan); } @Override - public NetworkConfigurationVO setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, NetworkConfiguration predefined, DeploymentPlan plan) { + public List 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)); } - return configs.get(0); + return configs; } - long id = _networkConfigDao.getNextInSequence(Long.class, "id"); - long related = id; + configs = new ArrayList(); + + long related = -1; for (NetworkGuru guru : _networkGurus) { NetworkConfiguration config = guru.design(offering, plan, predefined, owner); @@ -1601,28 +1602,29 @@ public class NetworkManagerImpl implements NetworkManager { if (config.getId() != null) { if (config instanceof NetworkConfigurationVO) { - return (NetworkConfigurationVO)config; + configs.add((NetworkConfigurationVO)config); } else { - return _networkConfigDao.findById(config.getId()); + configs.add(_networkConfigDao.findById(config.getId())); } + continue; + } + + long id = _networkConfigDao.getNextInSequence(Long.class, "id"); + if (related == -1) { + related = id; } NetworkConfigurationVO vo = new NetworkConfigurationVO(id, config, offering.getId(), plan.getDataCenterId(), guru.getName(), owner.getDomainId(), owner.getId(), related); - return _networkConfigDao.persist(vo); + configs.add(_networkConfigDao.persist(vo)); } - throw new CloudRuntimeException("Unable to convert network offering to network profile: " + offering.getId()); + if (configs.size() < 1) { + throw new CloudRuntimeException("Unable to convert network offering to network profile: " + offering.getId()); + } + + return configs; } - @Override - 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)); - } - return profiles; - } - @Override public List getSystemAccountNetworkOfferings(String... offeringNames) { List offerings = new ArrayList(offeringNames.length); @@ -1636,11 +1638,6 @@ public class NetworkManagerImpl implements NetworkManager { return offerings; } - public NetworkConfigurationVO createNetworkConfiguration(NetworkOfferingVO offering, DeploymentPlan plan, Account owner) { - return null; - } - - @Override @DB public List allocate(VirtualMachineProfile vm, List> networks) throws InsufficientCapacityException { List nicProfiles = new ArrayList(networks.size()); diff --git a/server/src/com/cloud/network/dao/NetworkConfigurationDao.java b/server/src/com/cloud/network/dao/NetworkConfigurationDao.java index 97fb92ad7bf..dc98d7529c1 100644 --- a/server/src/com/cloud/network/dao/NetworkConfigurationDao.java +++ b/server/src/com/cloud/network/dao/NetworkConfigurationDao.java @@ -32,4 +32,5 @@ public interface NetworkConfigurationDao extends GenericDao createSearchBuilderForAccount(); List getNetworkConfigurationsForOffering(long offeringId, long dataCenterId, long accountId); + List getRelatedNetworkConfigurations(long related); } diff --git a/server/src/com/cloud/network/dao/NetworkConfigurationDaoImpl.java b/server/src/com/cloud/network/dao/NetworkConfigurationDaoImpl.java index 483af6feb8f..4df669c1e04 100644 --- a/server/src/com/cloud/network/dao/NetworkConfigurationDaoImpl.java +++ b/server/src/com/cloud/network/dao/NetworkConfigurationDaoImpl.java @@ -41,6 +41,7 @@ public class NetworkConfigurationDaoImpl extends GenericDaoBase AccountSearch; final SearchBuilder OfferingSearch; final SearchBuilder RelatedConfigSearch; + final SearchBuilder RelatedConfigsSearch; NetworkAccountDaoImpl _accountsDao = new NetworkAccountDaoImpl(); @@ -74,6 +75,10 @@ public class NetworkConfigurationDaoImpl extends GenericDaoBase findBy(TrafficType trafficType, Mode mode, BroadcastDomainType broadcastType, long networkOfferingId, long dataCenterId) { @@ -138,4 +143,11 @@ public class NetworkConfigurationDaoImpl extends GenericDaoBase getRelatedNetworkConfigurations(long related) { + SearchCriteria sc = RelatedConfigsSearch.create(); + sc.setParameters("related", related); + 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 869089730fe..09a005d9f50 100644 --- a/server/src/com/cloud/network/element/DomainRouterElement.java +++ b/server/src/com/cloud/network/element/DomainRouterElement.java @@ -23,10 +23,13 @@ import javax.ejb.Local; import org.apache.log4j.Logger; +import com.cloud.network.Network.TrafficType; import com.cloud.network.NetworkConfiguration; import com.cloud.network.NetworkConfiguration.State; import com.cloud.network.NetworkConfigurationVO; import com.cloud.network.NetworkManager; +import com.cloud.network.dao.NetworkConfigurationDao; +import com.cloud.network.router.DomainRouterManager; import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering.GuestIpType; import com.cloud.user.Account; @@ -40,7 +43,9 @@ import com.cloud.vm.VirtualMachineProfile; public class DomainRouterElement extends AdapterBase implements NetworkElement { private static final Logger s_logger = Logger.getLogger(DomainRouterElement.class); + @Inject NetworkConfigurationDao _networkConfigDao; @Inject NetworkManager _networkMgr; + @Inject DomainRouterManager _routerMgr; @Override public Boolean implement(NetworkConfiguration config, NetworkOffering offering, Account user) { @@ -49,14 +54,30 @@ public class DomainRouterElement extends AdapterBase implements NetworkElement { return null; } - List configs = _networkMgr.getNetworkConfigurationsforOffering(offering.getId(), config.getDataCenterId(), user.getId()); + List configs = _networkConfigDao.getRelatedNetworkConfigurations(config.getRelated()); + NetworkConfigurationVO publicConfig = null; + NetworkConfigurationVO guestConfig = null; 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; } + if (c.getTrafficType() == TrafficType.Public) { + publicConfig = c; + } else if (c.getTrafficType() == TrafficType.Guest) { + guestConfig = c; + } else { + if (s_logger.isDebugEnabled()) { + s_logger.debug("The network configurations are different than what I expected: " + c); + } + return null; + } } + if (publicConfig == null || guestConfig == null) { + s_logger.debug("Expected to find the network configuration for " + (publicConfig == null ? "public" : "") + (guestConfig == null ? " guest" : "")); + return null; + } return true; } diff --git a/server/src/com/cloud/network/router/DomainRouterManager.java b/server/src/com/cloud/network/router/DomainRouterManager.java index a2610adc559..8392ad0df77 100644 --- a/server/src/com/cloud/network/router/DomainRouterManager.java +++ b/server/src/com/cloud/network/router/DomainRouterManager.java @@ -28,9 +28,14 @@ import com.cloud.dc.DataCenterVO; import com.cloud.dc.HostPodVO; import com.cloud.dc.VlanVO; import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.PermissionDeniedException; +import com.cloud.exception.StorageUnavailableException; +import com.cloud.network.NetworkConfiguration; +import com.cloud.offering.NetworkOffering; import com.cloud.service.ServiceOfferingVO; +import com.cloud.user.Account; import com.cloud.utils.component.Manager; import com.cloud.vm.DomainRouter; import com.cloud.vm.DomainRouterVO; @@ -161,4 +166,6 @@ public interface DomainRouterManager extends Manager { DomainRouterVO getRouter(long accountId, long zoneId); DomainRouterVO getRouter(String publicIpAddress); + + DomainRouterVO deploy(NetworkConfiguration publicConfig, NetworkConfiguration virtualConfig, NetworkOffering offering, Account owner) throws InsufficientCapacityException, StorageUnavailableException, ConcurrentOperationException; } diff --git a/server/src/com/cloud/network/router/DomainRouterManagerImpl.java b/server/src/com/cloud/network/router/DomainRouterManagerImpl.java index 559f54858e7..3e5be664705 100644 --- a/server/src/com/cloud/network/router/DomainRouterManagerImpl.java +++ b/server/src/com/cloud/network/router/DomainRouterManagerImpl.java @@ -1957,42 +1957,59 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach (accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN)); } + @Override @DB 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); + s_logger.debug("Starting 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); + DataCenterDeployment plan = new DataCenterDeployment(dcId, 1); - NetworkOfferingVO controlOffering = offerings.get(0); - NetworkConfigurationVO controlConfig = _networkMgr.setupNetworkConfiguration(_systemAcct, controlOffering, plan); + Transaction txn = Transaction.currentTxn(); + txn.start(); - 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; + virtualConfig = _networkProfileDao.lock(virtualConfig.getId(), true); + if (virtualConfig == null) { + throw new ConcurrentOperationException("Unable to get the lock on " + virtualConfig); + } + + DomainRouterVO router = _routerDao.findByNetworkConfiguration(virtualConfig.getId()); + if (router == null) { + long id = _routerDao.getNextInSequence(Long.class, "id"); + if (s_logger.isDebugEnabled()) { + s_logger.debug("Creating the router " + id); + } + + List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemVmControlNetwork); + + NetworkOfferingVO controlOffering = offerings.get(0); + NetworkConfigurationVO controlConfig = _networkMgr.setupNetworkConfiguration(_systemAcct, controlOffering, plan).get(0); + + router = new DomainRouterVO(id, _offering.getId(), VirtualMachineName.getRouterName(id, _instance), _template.getId(), _template.getGuestOSId(), owner.getDomainId(), owner.getId(), virtualConfig.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); + } + txn.commit(); + + return _vmMgr.start(router, plan, owner, this); } @Override - public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest) { + public boolean finalizeDeployment(Commands cmds, DomainRouterVO router, VirtualMachineProfile profile, DeployDestination dest) { Start2Command cmd = cmds.getCommand(Start2Command.class); VirtualMachineTO vm = cmd.getVirtualMachine(); @@ -2035,176 +2052,8 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach } @Override - public boolean checkDeploymentResult(Commands cmds, VirtualMachineProfile profile, DeployDestination dest) { + public boolean checkDeploymentResult(Commands cmds, DomainRouterVO router, 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/vm/MauriceMoss.java b/server/src/com/cloud/vm/MauriceMoss.java index e99ff0b392d..c883b6dabb9 100644 --- a/server/src/com/cloud/vm/MauriceMoss.java +++ b/server/src/com/cloud/vm/MauriceMoss.java @@ -212,6 +212,17 @@ public class MauriceMoss implements VmManager { @Override public T start(T vm, DeploymentPlan plan, Account acct, VirtualMachineGuru guru) throws InsufficientCapacityException, ConcurrentOperationException { + State state = vm.getState(); + if (state == State.Starting || state == State.Running) { + s_logger.debug("VM is already started: " + vm); + return vm; + } + + if (state != State.Stopped) { + s_logger.debug("VM " + vm + " is not in a state to be started: " + state); + return null; + } + if (s_logger.isDebugEnabled()) { s_logger.debug("Creating actual resources for VM " + vm); } @@ -275,7 +286,7 @@ public class MauriceMoss implements VmManager { Commands cmds = new Commands(OnError.Revert); cmds.addCommand(new Start2Command(vmTO)); if (guru != null) { - guru.finalizeDeployment(cmds, vmProfile, dest); + guru.finalizeDeployment(cmds, vm, vmProfile, dest); } try { Answer[] answers = _agentMgr.send(dest.getHost().getId(), cmds); diff --git a/server/src/com/cloud/vm/VirtualMachineGuru.java b/server/src/com/cloud/vm/VirtualMachineGuru.java index 2e2f096186d..ead31b4fd8d 100644 --- a/server/src/com/cloud/vm/VirtualMachineGuru.java +++ b/server/src/com/cloud/vm/VirtualMachineGuru.java @@ -32,7 +32,7 @@ public interface VirtualMachineGuru { * @param dest destination to send the command. * @return true if everything checks out. false if not and we should try again. */ - boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest); + boolean finalizeDeployment(Commands cmds, T vm, VirtualMachineProfile profile, DeployDestination dest); /** @@ -42,5 +42,5 @@ public interface VirtualMachineGuru { * @param dest destination it was sent to. * @return true if deployment was fine; false if it didn't go well. */ - boolean checkDeploymentResult(Commands cmds, VirtualMachineProfile profile, DeployDestination dest); + boolean checkDeploymentResult(Commands cmds, T vm, VirtualMachineProfile profile, DeployDestination dest); } diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 7306c09d48d..e83a29a4da7 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -623,6 +623,7 @@ CREATE TABLE `cloud`.`domain_router` ( `vlan_db_id` bigint unsigned COMMENT 'Foreign key into vlan id table', `vlan_id` varchar(255) COMMENT 'optional VLAN ID for DomainRouter that can be used in rundomr.sh', `dhcp_ip_address` bigint unsigned NOT NULL DEFAULT 2 COMMENT 'next ip address for dhcp for this domR', + `network_configuration_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT 'network configuration that this domain router belongs to', `role` varchar(64) NOT NULL COMMENT 'type of role played by this router', PRIMARY KEY (`id`) ) ENGINE = InnoDB DEFAULT CHARSET=utf8 COMMENT = 'information about the domR instance';