mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
more changes for the rewrite
This commit is contained in:
parent
794ca16a65
commit
2da8035bd1
@ -90,4 +90,6 @@ public interface NetworkConfiguration extends OwnedBy, PartOf {
|
||||
long getNetworkOfferingId();
|
||||
|
||||
State getState();
|
||||
|
||||
long getRelated();
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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<DomainRouterVO, Long> {
|
||||
public List<DomainRouterVO> listByVlanDbId(Long vlanId);
|
||||
|
||||
DomainRouterVO findBy(long accountId, long dcId, Role role);
|
||||
|
||||
DomainRouterVO findByNetworkConfiguration(long networkConfigurationId);
|
||||
}
|
||||
|
||||
@ -60,6 +60,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
|
||||
protected final SearchBuilder<DomainRouterVO> DomainIdSearch;
|
||||
protected final SearchBuilder<DomainRouterVO> VlanDbIdSearch;
|
||||
protected final SearchBuilder<DomainRouterVO> StateChangeSearch;
|
||||
protected final SearchBuilder<DomainRouterVO> NetworkConfigSearch;
|
||||
protected final Attribute _updateTimeAttr;
|
||||
|
||||
protected DomainRouterDaoImpl() {
|
||||
@ -114,6 +115,9 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> 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<DomainRouterVO, Long> im
|
||||
sc.setParameters("vlanDbId", vlanDbId);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DomainRouterVO findByNetworkConfiguration(long networkConfigurationId) {
|
||||
SearchCriteria<DomainRouterVO> sc = NetworkConfigSearch.create();
|
||||
sc.setParameters("network", networkConfigurationId);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1062,9 +1062,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
|
||||
NicProfile defaultNic = new NicProfile();
|
||||
defaultNic.setDefaultNic(true);
|
||||
defaultNic.setDeviceId(2);
|
||||
networks.add(new Pair<NetworkConfigurationVO, NicProfile>(_networkMgr.setupNetworkConfiguration(systemAcct, defaultOffering.get(0), plan), defaultNic));
|
||||
networks.add(new Pair<NetworkConfigurationVO, NicProfile>(_networkMgr.setupNetworkConfiguration(systemAcct, defaultOffering.get(0), plan).get(0), defaultNic));
|
||||
for (NetworkOfferingVO offering : offerings) {
|
||||
networks.add(new Pair<NetworkConfigurationVO, NicProfile>(_networkMgr.setupNetworkConfiguration(systemAcct, offering, plan), null));
|
||||
networks.add(new Pair<NetworkConfigurationVO, NicProfile>(_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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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<NetworkConfigurationVO> setupNetworkConfigurations(Account owner, List<NetworkOfferingVO> offerings, DeploymentPlan plan);
|
||||
List<NetworkConfigurationVO> setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, DeploymentPlan plan);
|
||||
List<NetworkConfigurationVO> setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, NetworkConfiguration predefined, DeploymentPlan plan);
|
||||
|
||||
List<NetworkOfferingVO> getSystemAccountNetworkOfferings(String... offeringNames);
|
||||
|
||||
|
||||
@ -1576,22 +1576,23 @@ public class NetworkManagerImpl implements NetworkManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkConfigurationVO setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, DeploymentPlan plan) {
|
||||
public List<NetworkConfigurationVO> 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<NetworkConfigurationVO> setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, NetworkConfiguration predefined, DeploymentPlan plan) {
|
||||
List<NetworkConfigurationVO> 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<NetworkConfigurationVO>();
|
||||
|
||||
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<NetworkConfigurationVO> setupNetworkConfigurations(Account owner, List<NetworkOfferingVO> offerings, DeploymentPlan plan) {
|
||||
List<NetworkConfigurationVO> profiles = new ArrayList<NetworkConfigurationVO>(offerings.size());
|
||||
for (NetworkOfferingVO offering : offerings) {
|
||||
profiles.add(setupNetworkConfiguration(owner, offering, plan));
|
||||
}
|
||||
return profiles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NetworkOfferingVO> getSystemAccountNetworkOfferings(String... offeringNames) {
|
||||
List<NetworkOfferingVO> offerings = new ArrayList<NetworkOfferingVO>(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<NicProfile> allocate(VirtualMachineProfile vm, List<Pair<NetworkConfigurationVO, NicProfile>> networks) throws InsufficientCapacityException {
|
||||
List<NicProfile> nicProfiles = new ArrayList<NicProfile>(networks.size());
|
||||
|
||||
@ -32,4 +32,5 @@ public interface NetworkConfigurationDao extends GenericDao<NetworkConfiguration
|
||||
void addAccountToNetworkConfiguration(long configId, long accountId);
|
||||
SearchBuilder<NetworkAccountVO> createSearchBuilderForAccount();
|
||||
List<NetworkConfigurationVO> getNetworkConfigurationsForOffering(long offeringId, long dataCenterId, long accountId);
|
||||
List<NetworkConfigurationVO> getRelatedNetworkConfigurations(long related);
|
||||
}
|
||||
|
||||
@ -41,6 +41,7 @@ public class NetworkConfigurationDaoImpl extends GenericDaoBase<NetworkConfigura
|
||||
final SearchBuilder<NetworkConfigurationVO> AccountSearch;
|
||||
final SearchBuilder<NetworkConfigurationVO> OfferingSearch;
|
||||
final SearchBuilder<NetworkConfigurationVO> RelatedConfigSearch;
|
||||
final SearchBuilder<NetworkConfigurationVO> RelatedConfigsSearch;
|
||||
|
||||
NetworkAccountDaoImpl _accountsDao = new NetworkAccountDaoImpl();
|
||||
|
||||
@ -74,6 +75,10 @@ public class NetworkConfigurationDaoImpl extends GenericDaoBase<NetworkConfigura
|
||||
join2.and("account", join2.entity().getAccountId(), SearchCriteria.Op.EQ);
|
||||
RelatedConfigSearch.join("account", join2, join2.entity().getNetworkConfigurationId(), RelatedConfigSearch.entity().getId(), JoinType.INNER);
|
||||
RelatedConfigSearch.done();
|
||||
|
||||
RelatedConfigsSearch = createSearchBuilder();
|
||||
RelatedConfigsSearch.and("related", RelatedConfigsSearch.entity().getRelated(), SearchCriteria.Op.EQ);
|
||||
RelatedConfigsSearch.done();
|
||||
}
|
||||
|
||||
public List<NetworkConfigurationVO> findBy(TrafficType trafficType, Mode mode, BroadcastDomainType broadcastType, long networkOfferingId, long dataCenterId) {
|
||||
@ -138,4 +143,11 @@ public class NetworkConfigurationDaoImpl extends GenericDaoBase<NetworkConfigura
|
||||
sc.setJoinParameters("account", "account", accountId);
|
||||
return search(sc, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NetworkConfigurationVO> getRelatedNetworkConfigurations(long related) {
|
||||
SearchCriteria<NetworkConfigurationVO> sc = RelatedConfigsSearch.create();
|
||||
sc.setParameters("related", related);
|
||||
return search(sc, null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<NetworkConfigurationVO> configs = _networkMgr.getNetworkConfigurationsforOffering(offering.getId(), config.getDataCenterId(), user.getId());
|
||||
List<NetworkConfigurationVO> 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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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<NetworkOfferingVO> 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<Pair<NetworkConfigurationVO, NicProfile>> networks = new ArrayList<Pair<NetworkConfigurationVO, NicProfile>>(3);
|
||||
NicProfile defaultNic = new NicProfile();
|
||||
defaultNic.setDefaultNic(true);
|
||||
defaultNic.setDeviceId(2);
|
||||
networks.add(new Pair<NetworkConfigurationVO, NicProfile>((NetworkConfigurationVO)publicConfig, defaultNic));
|
||||
networks.add(new Pair<NetworkConfigurationVO, NicProfile>((NetworkConfigurationVO)virtualConfig, null));
|
||||
networks.add(new Pair<NetworkConfigurationVO, NicProfile>(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<NetworkOfferingVO> 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<Pair<NetworkConfigurationVO, NicProfile>> networks = new ArrayList<Pair<NetworkConfigurationVO, NicProfile>>(3);
|
||||
NicProfile defaultNic = new NicProfile();
|
||||
defaultNic.setDefaultNic(true);
|
||||
defaultNic.setDeviceId(2);
|
||||
networks.add(new Pair<NetworkConfigurationVO, NicProfile>((NetworkConfigurationVO)publicConfig, defaultNic));
|
||||
networks.add(new Pair<NetworkConfigurationVO, NicProfile>((NetworkConfigurationVO)virtualConfig, null));
|
||||
networks.add(new Pair<NetworkConfigurationVO, NicProfile>(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<HostPodVO, Long> pod = null;
|
||||
// Set<Long> avoids = new HashSet<Long>();
|
||||
// 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<VolumeVO> 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);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -212,6 +212,17 @@ public class MauriceMoss implements VmManager {
|
||||
|
||||
@Override
|
||||
public <T extends VMInstanceVO> T start(T vm, DeploymentPlan plan, Account acct, VirtualMachineGuru<T> 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);
|
||||
|
||||
@ -32,7 +32,7 @@ public interface VirtualMachineGuru<T extends VMInstanceVO> {
|
||||
* @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<T extends VMInstanceVO> {
|
||||
* @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);
|
||||
}
|
||||
|
||||
@ -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';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user