mirror of https://github.com/apache/cloudstack.git
Simplify the components that VirtualMachineManager uses
This commit is contained in:
parent
1ca4f66306
commit
861be3063c
|
|
@ -729,7 +729,6 @@
|
|||
|
||||
<bean id="clusteredVirtualMachineManagerImpl" class="com.cloud.vm.ClusteredVirtualMachineManagerImpl" >
|
||||
<property name="HostAllocators" value="#{hostAllocators.Adapters}" />
|
||||
<property name="Planners" value="#{deploymentPlanners.Adapters}" />
|
||||
</bean>
|
||||
|
||||
<bean id="networkManagerImpl" class="com.cloud.network.NetworkManagerImpl" >
|
||||
|
|
|
|||
|
|
@ -20,17 +20,19 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.cluster.ClusterManager;
|
||||
import com.cloud.cluster.ClusterManagerListener;
|
||||
import com.cloud.cluster.ManagementServerHostVO;
|
||||
|
||||
@Local(value=VirtualMachineManager.class)
|
||||
public class ClusteredVirtualMachineManagerImpl extends VirtualMachineManagerImpl implements ClusterManagerListener {
|
||||
|
||||
@Inject
|
||||
ClusterManager _clusterMgr;
|
||||
|
||||
protected ClusteredVirtualMachineManagerImpl() {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,12 +17,10 @@
|
|||
package com.cloud.vm;
|
||||
|
||||
import com.cloud.domain.Domain;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
import com.cloud.user.dao.UserDao;
|
||||
import com.cloud.utils.Journal;
|
||||
import com.cloud.utils.db.EntityManager;
|
||||
|
||||
public class ReservationContextImpl implements ReservationContext {
|
||||
User _caller;
|
||||
|
|
@ -66,16 +64,16 @@ public class ReservationContextImpl implements ReservationContext {
|
|||
@Override
|
||||
public Account getAccount() {
|
||||
if (_account == null) {
|
||||
_account = s_accountDao.findByIdIncludingRemoved(_caller.getId());
|
||||
_account = s_entityMgr.findById(Account.class, _caller.getId());
|
||||
}
|
||||
return _account;
|
||||
return _account;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Domain getDomain() {
|
||||
if (_domain == null) {
|
||||
getAccount();
|
||||
_domain = s_domainDao.findByIdIncludingRemoved(_account.getDomainId());
|
||||
_domain = s_entityMgr.findById(Domain.class, _account.getDomainId());
|
||||
}
|
||||
return _domain;
|
||||
}
|
||||
|
|
@ -90,13 +88,9 @@ public class ReservationContextImpl implements ReservationContext {
|
|||
return _reservationId;
|
||||
}
|
||||
|
||||
static UserDao s_userDao;
|
||||
static DomainDao s_domainDao;
|
||||
static AccountDao s_accountDao;
|
||||
static EntityManager s_entityMgr;
|
||||
|
||||
static public void setComponents(UserDao userDao, DomainDao domainDao, AccountDao accountDao) {
|
||||
s_userDao = userDao;
|
||||
s_domainDao = domainDao;
|
||||
s_accountDao = accountDao;
|
||||
static public void init(EntityManager entityMgr) {
|
||||
s_entityMgr = entityMgr;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
|
|||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
import org.apache.cloudstack.utils.identity.ManagementServerNode;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.AgentManager.OnError;
|
||||
|
|
@ -81,7 +82,6 @@ import com.cloud.agent.manager.Commands;
|
|||
import com.cloud.agent.manager.allocator.HostAllocator;
|
||||
import com.cloud.alert.AlertManager;
|
||||
import com.cloud.capacity.CapacityManager;
|
||||
import com.cloud.cluster.ClusterManager;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.ConfigurationManager;
|
||||
import com.cloud.configuration.Resource.ResourceType;
|
||||
|
|
@ -94,11 +94,9 @@ import com.cloud.dc.HostPodVO;
|
|||
import com.cloud.dc.dao.ClusterDao;
|
||||
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.deploy.DeploymentPlan;
|
||||
import com.cloud.deploy.DeploymentPlanner;
|
||||
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
|
||||
import com.cloud.deploy.DeploymentPlanningManager;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
|
|
@ -145,7 +143,6 @@ import com.cloud.service.ServiceOfferingVO;
|
|||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import com.cloud.storage.DiskOfferingVO;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.storage.StorageManager;
|
||||
import com.cloud.storage.StoragePool;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.Volume;
|
||||
|
|
@ -164,7 +161,6 @@ import com.cloud.user.AccountManager;
|
|||
import com.cloud.user.ResourceLimitService;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
import com.cloud.user.dao.UserDao;
|
||||
import com.cloud.utils.Journal;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.Pair;
|
||||
|
|
@ -197,8 +193,6 @@ import com.cloud.vm.snapshot.dao.VMSnapshotDao;
|
|||
public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMachineManager, Listener {
|
||||
private static final Logger s_logger = Logger.getLogger(VirtualMachineManagerImpl.class);
|
||||
|
||||
@Inject
|
||||
protected StorageManager _storageMgr;
|
||||
@Inject
|
||||
DataStoreManager dataStoreMgr;
|
||||
@Inject
|
||||
|
|
@ -216,14 +210,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
@Inject
|
||||
protected VMTemplateDao _templateDao;
|
||||
@Inject
|
||||
protected UserDao _userDao;
|
||||
@Inject
|
||||
protected AccountDao _accountDao;
|
||||
@Inject
|
||||
protected DomainDao _domainDao;
|
||||
@Inject
|
||||
protected ClusterManager _clusterMgr;
|
||||
@Inject
|
||||
protected ItWorkDao _workDao;
|
||||
@Inject
|
||||
protected UserVmDao _userVmDao;
|
||||
|
|
@ -278,20 +268,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
@Inject
|
||||
protected IPAddressDao _publicIpAddressDao;
|
||||
@Inject
|
||||
protected VlanDao _vlanDao;
|
||||
@Inject
|
||||
protected NicIpAliasDao _nicIpAliasDao;
|
||||
@Inject
|
||||
protected EntityManager _entityMgr;
|
||||
|
||||
protected List<DeploymentPlanner> _planners;
|
||||
public List<DeploymentPlanner> getPlanners() {
|
||||
return _planners;
|
||||
}
|
||||
public void setPlanners(List<DeploymentPlanner> _planners) {
|
||||
this._planners = _planners;
|
||||
}
|
||||
|
||||
protected List<HostAllocator> _hostAllocators;
|
||||
public List<HostAllocator> getHostAllocators() {
|
||||
return _hostAllocators;
|
||||
|
|
@ -574,8 +554,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
|
||||
_retry = NumbersUtil.parseInt(params.get(Config.StartRetry.key()), 10);
|
||||
|
||||
ReservationContextImpl.setComponents(_userDao, _domainDao, _accountDao);
|
||||
VirtualMachineProfileImpl.setComponents(_offeringDao, _templateDao, _accountDao);
|
||||
ReservationContextImpl.init(_entityMgr);
|
||||
VirtualMachineProfileImpl.init(_entityMgr);
|
||||
|
||||
_cancelWait = NumbersUtil.parseLong(params.get(Config.VmOpCancelInterval.key()), 3600);
|
||||
_cleanupWait = NumbersUtil.parseLong(params.get(Config.VmOpCleanupWait.key()), 3600);
|
||||
|
|
@ -586,7 +566,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
_forceStop = Boolean.parseBoolean(params.get(Config.VmDestroyForcestop.key()));
|
||||
|
||||
_executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("Vm-Operations-Cleanup"));
|
||||
_nodeId = _clusterMgr.getManagementNodeId();
|
||||
_nodeId = ManagementServerNode.getManagementServerId();
|
||||
|
||||
_agentMgr.registerForHostEvents(this, true, true, true);
|
||||
|
||||
|
|
@ -2854,17 +2834,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
ResourceUnavailableException, InsufficientCapacityException {
|
||||
|
||||
s_logger.debug("Adding vm " + vm + " to network " + network + "; requested nic profile " + requested);
|
||||
VMInstanceVO vmVO;
|
||||
if (vm.getType() == VirtualMachine.Type.User) {
|
||||
vmVO = _userVmDao.findById(vm.getId());
|
||||
} else {
|
||||
vmVO = _vmDao.findById(vm.getId());
|
||||
}
|
||||
VMInstanceVO vmVO = _vmDao.findById(vm.getId());
|
||||
ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM),
|
||||
_accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM));
|
||||
|
||||
VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null,
|
||||
null, null, null);
|
||||
VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, null, null, null);
|
||||
|
||||
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
|
||||
Host host = _hostDao.findById(vm.getHostId());
|
||||
|
|
|
|||
|
|
@ -25,13 +25,11 @@ import com.cloud.agent.api.to.DiskTO;
|
|||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
import com.cloud.template.VirtualMachineTemplate.BootloaderType;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
import com.cloud.utils.db.EntityManager;
|
||||
|
||||
/**
|
||||
* Implementation of VirtualMachineProfile.
|
||||
|
|
@ -40,8 +38,8 @@ import com.cloud.user.dao.AccountDao;
|
|||
public class VirtualMachineProfileImpl implements VirtualMachineProfile {
|
||||
|
||||
VirtualMachine _vm;
|
||||
ServiceOfferingVO _offering;
|
||||
VMTemplateVO _template;
|
||||
ServiceOffering _offering;
|
||||
VirtualMachineTemplate _template;
|
||||
UserVmDetailVO _userVmDetails;
|
||||
Map<Param, Object> _params;
|
||||
List<NicProfile> _nics = new ArrayList<NicProfile>();
|
||||
|
|
@ -88,7 +86,7 @@ public class VirtualMachineProfileImpl implements VirtualMachineProfile {
|
|||
@Override
|
||||
public ServiceOffering getServiceOffering() {
|
||||
if (_offering == null) {
|
||||
_offering = s_offeringDao.findByIdIncludingRemoved(_vm.getServiceOfferingId());
|
||||
_offering = s_entityMgr.findById(ServiceOffering.class, _vm.getServiceOfferingId());
|
||||
}
|
||||
return _offering;
|
||||
}
|
||||
|
|
@ -106,7 +104,7 @@ public class VirtualMachineProfileImpl implements VirtualMachineProfile {
|
|||
@Override
|
||||
public VirtualMachineTemplate getTemplate() {
|
||||
if (_template == null && _vm != null) {
|
||||
_template = s_templateDao.findByIdIncludingRemoved(_vm.getTemplateId());
|
||||
_template = s_entityMgr.findById(VirtualMachineTemplate.class, _vm.getTemplateId());
|
||||
}
|
||||
return _template;
|
||||
}
|
||||
|
|
@ -184,7 +182,7 @@ public class VirtualMachineProfileImpl implements VirtualMachineProfile {
|
|||
@Override
|
||||
public Account getOwner() {
|
||||
if (_owner == null) {
|
||||
_owner = s_accountDao.findByIdIncludingRemoved(_vm.getAccountId());
|
||||
_owner = s_entityMgr.findById(Account.class, _vm.getAccountId());
|
||||
}
|
||||
return _owner;
|
||||
}
|
||||
|
|
@ -194,13 +192,10 @@ public class VirtualMachineProfileImpl implements VirtualMachineProfile {
|
|||
return _bootArgs.toString();
|
||||
}
|
||||
|
||||
static ServiceOfferingDao s_offeringDao;
|
||||
static VMTemplateDao s_templateDao;
|
||||
static AccountDao s_accountDao;
|
||||
static void setComponents(ServiceOfferingDao offeringDao, VMTemplateDao templateDao, AccountDao accountDao) {
|
||||
s_offeringDao = offeringDao;
|
||||
s_templateDao = templateDao;
|
||||
s_accountDao = accountDao;
|
||||
static EntityManager s_entityMgr;
|
||||
|
||||
static void init(EntityManager entityMgr) {
|
||||
s_entityMgr = entityMgr;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -189,7 +189,6 @@ public class VirtualMachineManagerImplTest {
|
|||
_vmMgr._volsDao = _volsDao;
|
||||
_vmMgr.volumeMgr = _storageMgr;
|
||||
_vmMgr._accountDao = _accountDao;
|
||||
_vmMgr._userDao = _userDao;
|
||||
_vmMgr._accountMgr = _accountMgr;
|
||||
_vmMgr._configMgr = _configMgr;
|
||||
_vmMgr._capacityMgr = _capacityMgr;
|
||||
|
|
|
|||
Loading…
Reference in New Issue