mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
In hostAllocator, input clusterId instead of storagepool
This commit is contained in:
parent
d4828debba
commit
7f991f7e25
@ -404,7 +404,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory {
|
||||
Enumeration<HostAllocator> en = _hostAllocators.enumeration();
|
||||
while (en.hasMoreElements()) {
|
||||
final HostAllocator allocator = en.nextElement();
|
||||
final Host host = allocator.allocateTo(vmc, offering, type, dc, pod, sp, template, avoid);
|
||||
final Host host = allocator.allocateTo(vmc, offering, type, dc, pod, sp.getClusterId(), template, avoid);
|
||||
if (host == null) {
|
||||
continue;
|
||||
} else {
|
||||
|
||||
@ -22,15 +22,15 @@ import java.util.Set;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.HostPodVO;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.Host.Type;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
import com.cloud.storage.StoragePoolVO;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.component.Adapter;
|
||||
import com.cloud.vm.VmCharacteristics;
|
||||
|
||||
public interface HostAllocator extends Adapter {
|
||||
Host allocateTo(VmCharacteristics vm, ServiceOffering offering, Host.Type type, DataCenterVO dc, HostPodVO pod, StoragePoolVO sp, VMTemplateVO template, Set<Host> avoid);
|
||||
boolean isVirtualMachineUpgradable(final UserVm vm, final ServiceOffering offering);
|
||||
Host allocateTo(VmCharacteristics vm, ServiceOffering offering, Type type, DataCenterVO dc, HostPodVO pod, Long clusterId, VMTemplateVO template, Set<Host> avoid);
|
||||
|
||||
}
|
||||
|
||||
@ -51,6 +51,7 @@ import com.cloud.storage.dao.StoragePoolHostDao;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.vm.ConsoleProxyVO;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.SecondaryStorageVmVO;
|
||||
@ -68,23 +69,22 @@ import com.cloud.vm.dao.UserVmDao;
|
||||
public class FirstFitAllocator implements HostAllocator {
|
||||
private static final Logger s_logger = Logger.getLogger(FirstFitAllocator.class);
|
||||
private String _name;
|
||||
protected HostDao _hostDao;
|
||||
protected DetailsDao _hostDetailsDao;
|
||||
protected UserVmDao _vmDao;
|
||||
protected ServiceOfferingDao _offeringDao;
|
||||
protected DomainRouterDao _routerDao;
|
||||
protected ConsoleProxyDao _consoleProxyDao;
|
||||
protected SecondaryStorageVmDao _secStorgaeVmDao;
|
||||
protected StoragePoolHostDao _storagePoolHostDao;
|
||||
protected ConfigurationDao _configDao;
|
||||
protected GuestOSDao _guestOSDao;
|
||||
protected GuestOSCategoryDao _guestOSCategoryDao;
|
||||
@Inject HostDao _hostDao = null;
|
||||
@Inject DetailsDao _hostDetailsDao = null;
|
||||
@Inject UserVmDao _vmDao = null;
|
||||
@Inject ServiceOfferingDao _offeringDao = null;
|
||||
@Inject DomainRouterDao _routerDao = null;
|
||||
@Inject ConsoleProxyDao _consoleProxyDao = null;
|
||||
@Inject SecondaryStorageVmDao _secStorgaeVmDao = null;
|
||||
@Inject ConfigurationDao _configDao = null;
|
||||
@Inject GuestOSDao _guestOSDao = null;
|
||||
@Inject GuestOSCategoryDao _guestOSCategoryDao = null;
|
||||
float _factor = 1;
|
||||
protected String _allocationAlgorithm = "random";
|
||||
|
||||
@Override
|
||||
public Host allocateTo(VmCharacteristics vm, ServiceOffering offering, Type type, DataCenterVO dc,
|
||||
HostPodVO pod, StoragePoolVO sp, VMTemplateVO template,
|
||||
HostPodVO pod, Long clusterId, VMTemplateVO template,
|
||||
Set<Host> avoid) {
|
||||
|
||||
if (type == Host.Type.Storage) {
|
||||
@ -92,28 +92,21 @@ public class FirstFitAllocator implements HostAllocator {
|
||||
return null;
|
||||
}
|
||||
|
||||
s_logger.debug("Looking for hosts associated with storage pool " + sp.getId());
|
||||
s_logger.debug("Looking for hosts in dc: " + dc.getId() + " pod:" + pod.getId() + " cluster:" + clusterId);
|
||||
|
||||
List<StoragePoolHostVO> poolhosts = _storagePoolHostDao.listByPoolId(sp.getId());
|
||||
List<HostVO> hosts = new ArrayList<HostVO>();
|
||||
for( StoragePoolHostVO poolhost : poolhosts ){
|
||||
hosts.add(_hostDao.findById(poolhost.getHostId()));
|
||||
}
|
||||
|
||||
long podId = pod.getId();
|
||||
List<HostVO> podHosts = new ArrayList<HostVO>(hosts.size());
|
||||
Iterator<HostVO> it = hosts.iterator();
|
||||
List<HostVO> clusterHosts = _hostDao.listBy(type, clusterId, pod.getId(), dc.getId());
|
||||
Iterator<HostVO> it = clusterHosts.iterator();
|
||||
while (it.hasNext()) {
|
||||
HostVO host = it.next();
|
||||
if (host.getPodId() == podId && !avoid.contains(host)) {
|
||||
if (avoid.contains(host)) {
|
||||
clusterHosts.remove(host);
|
||||
} else {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Adding host " + host + " as possible pod host");
|
||||
}
|
||||
podHosts.add(host);
|
||||
}
|
||||
}
|
||||
|
||||
return allocateTo(offering, template, avoid, podHosts);
|
||||
}
|
||||
return allocateTo(offering, template, avoid, clusterHosts);
|
||||
}
|
||||
|
||||
protected Host allocateTo(ServiceOffering offering, VMTemplateVO template, Set<Host> avoid, List<HostVO> hosts) {
|
||||
@ -335,17 +328,6 @@ public class FirstFitAllocator implements HostAllocator {
|
||||
public boolean configure(String name, Map<String, Object> params) {
|
||||
_name = name;
|
||||
ComponentLocator locator = ComponentLocator.getCurrentLocator();
|
||||
_hostDao = locator.getDao(HostDao.class);
|
||||
_hostDetailsDao = locator.getDao(DetailsDao.class);
|
||||
_vmDao = locator.getDao(UserVmDao.class);
|
||||
_offeringDao = locator.getDao(ServiceOfferingDao.class);
|
||||
_routerDao = locator.getDao(DomainRouterDao.class);
|
||||
_consoleProxyDao = locator.getDao(ConsoleProxyDao.class);
|
||||
_secStorgaeVmDao = locator.getDao(SecondaryStorageVmDao.class);
|
||||
_storagePoolHostDao = locator.getDao(StoragePoolHostDao.class);
|
||||
_configDao = locator.getDao(ConfigurationDao.class);
|
||||
_guestOSDao = locator.getDao(GuestOSDao.class);
|
||||
_guestOSCategoryDao = locator.getDao(GuestOSCategoryDao.class);
|
||||
if (_configDao != null) {
|
||||
Map<String, String> configs = _configDao.getConfiguration(params);
|
||||
String opFactor = configs.get("cpu.overprovisioning.factor");
|
||||
|
||||
@ -37,7 +37,7 @@ import com.cloud.vm.VmCharacteristics;
|
||||
public class FirstFitRoutingAllocator extends FirstFitAllocator {
|
||||
@Override
|
||||
public Host allocateTo(VmCharacteristics vm, ServiceOffering offering, Host.Type type, DataCenterVO dc, HostPodVO pod,
|
||||
StoragePoolVO sp, VMTemplateVO template, Set<Host> avoid) {
|
||||
Long clusterId, VMTemplateVO template, Set<Host> avoid) {
|
||||
try {
|
||||
NDC.push("FirstFitRoutingAllocator");
|
||||
if (type != Host.Type.Routing) {
|
||||
@ -45,7 +45,7 @@ public class FirstFitRoutingAllocator extends FirstFitAllocator {
|
||||
return null;
|
||||
}
|
||||
//all hosts should be of type routing anyway.
|
||||
return super.allocateTo(vm, offering, type, dc, pod, sp, template, avoid);
|
||||
return super.allocateTo(vm, offering, type, dc, pod, clusterId, template, avoid);
|
||||
} finally {
|
||||
NDC.pop();
|
||||
}
|
||||
|
||||
@ -46,13 +46,13 @@ public class RandomAllocator implements HostAllocator {
|
||||
|
||||
@Override
|
||||
public Host allocateTo(VmCharacteristics vm, ServiceOffering offering, Host.Type type, DataCenterVO dc, HostPodVO pod,
|
||||
StoragePoolVO sp, VMTemplateVO template, Set<Host> avoid) {
|
||||
Long clusterId, VMTemplateVO template, Set<Host> avoid) {
|
||||
if (type == Host.Type.Storage) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// list all computing hosts, regardless of whether they support routing...it's random after all
|
||||
List<? extends Host> hosts = _hostDao.listBy(type, sp.getClusterId(), sp.getPodId(), sp.getDataCenterId());
|
||||
List<? extends Host> hosts = _hostDao.listBy(type, clusterId, pod.getId(), dc.getId());
|
||||
if (hosts.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -54,8 +54,8 @@ public class RecreateHostAllocator extends FirstFitRoutingAllocator {
|
||||
|
||||
@Override
|
||||
public Host allocateTo(VmCharacteristics vm, ServiceOffering offering, Host.Type type, DataCenterVO dc, HostPodVO pod,
|
||||
StoragePoolVO sp, VMTemplateVO template, Set<Host> avoid) {
|
||||
Host host = super.allocateTo(vm, offering, type, dc, pod, sp, template, avoid);
|
||||
Long clusterId, VMTemplateVO template, Set<Host> avoid) {
|
||||
Host host = super.allocateTo(vm, offering, type, dc, pod, clusterId, template, avoid);
|
||||
if (host != null) {
|
||||
return host;
|
||||
}
|
||||
@ -77,16 +77,15 @@ public class RecreateHostAllocator extends FirstFitRoutingAllocator {
|
||||
s_logger.debug("Removing " + pcId + " from the list of available pods");
|
||||
pcs.remove(new PodCluster(new HostPodVO(pcId.first()), pcId.second() != null ? new ClusterVO(pcId.second()) : null));
|
||||
}
|
||||
|
||||
for (PodCluster p : pcs) {
|
||||
List<StoragePoolVO> pools = _poolDao.listBy(dc.getId(), p.getPod().getId(), p.getCluster() == null ? null : p.getCluster().getId());
|
||||
for (StoragePoolVO pool : pools) {
|
||||
host = super.allocateTo(vm, offering, type, dc, p.getPod(), pool, template, avoid);
|
||||
if (host != null) {
|
||||
return host;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (PodCluster p : pcs) {
|
||||
clusterId = p.getCluster() == null ? null : p.getCluster().getId();
|
||||
host = super.allocateTo(vm, offering, type, dc, p.getPod(),
|
||||
clusterId, template, avoid);
|
||||
if (host != null) {
|
||||
return host;
|
||||
}
|
||||
}
|
||||
|
||||
s_logger.debug("Unable to find any available pods at all!");
|
||||
return null;
|
||||
|
||||
@ -48,7 +48,7 @@ public class TestingAllocator implements HostAllocator {
|
||||
|
||||
@Override
|
||||
public Host allocateTo(VmCharacteristics vm, ServiceOffering offering, Host.Type type, DataCenterVO dc, HostPodVO pod,
|
||||
StoragePoolVO sp, VMTemplateVO template, Set<Host> avoid) {
|
||||
Long clusterId, VMTemplateVO template, Set<Host> avoid) {
|
||||
if (type == Host.Type.Routing && _routingHost != null) {
|
||||
return _hostDao.findById(_routingHost);
|
||||
} else if (type == Host.Type.Storage && _storageHost != null) {
|
||||
|
||||
@ -694,6 +694,7 @@ public class UserVmManagerImpl implements UserVmManager {
|
||||
_eventDao.persist(event);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if (!_vmDao.updateIf(vm, Event.StartRequested, host.getId())) {
|
||||
String description = "Unable to start VM " + vm.toString() + " because the state is not correct.";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user