mirror of https://github.com/apache/cloudstack.git
bug 10422: accidentally removed the code for sourceTemplate id when the the volume is created out of template. Checking it in.
status 10422: resolved fixed
This commit is contained in:
parent
7d060d3388
commit
a2bdcf5159
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package com.cloud.capacity;
|
||||
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
|
||||
|
|
@ -32,4 +33,6 @@ public interface CapacityManager extends Manager {
|
|||
void allocateVmCapacity(VirtualMachine vm, boolean fromLastHost);
|
||||
|
||||
boolean checkIfHostHasCapacity(long hostId, Integer cpu, long ram, boolean checkFromReservedCapacity, float cpuOverprovisioningFactor);
|
||||
|
||||
void updateCapacityForHost(HostVO host);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ public class CapacityManagerImpl implements CapacityManager, StateListener<State
|
|||
_executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("HostCapacity-Checker"));
|
||||
VirtualMachine.State.getStateMachine().registerListener(this);
|
||||
_agentManager.registerForHostEvents(new StorageCapacityListener(_capacityDao, _storageOverProvisioningFactor), true, false, false);
|
||||
_agentManager.registerForHostEvents(new ComputeCapacityListener(_capacityDao, _cpuOverProvisioningFactor), true, false, false);
|
||||
_agentManager.registerForHostEvents(new ComputeCapacityListener(_capacityDao, this, _cpuOverProvisioningFactor), true, false, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -498,6 +498,110 @@ public class CapacityManagerImpl implements CapacityManager, StateListener<State
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCapacityForHost(HostVO host){
|
||||
// prep the service offerings
|
||||
List<ServiceOfferingVO> offerings = _offeringsDao.listAllIncludingRemoved();
|
||||
Map<Long, ServiceOfferingVO> offeringsMap = new HashMap<Long, ServiceOfferingVO>();
|
||||
for (ServiceOfferingVO offering : offerings) {
|
||||
offeringsMap.put(offering.getId(), offering);
|
||||
}
|
||||
|
||||
long usedCpu = 0;
|
||||
long usedMemory = 0;
|
||||
long reservedMemory = 0;
|
||||
long reservedCpu = 0;
|
||||
|
||||
List<VMInstanceVO> vms = _vmDao.listUpByHostId(host.getId());
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Found " + vms.size() + " VMs on host " + host.getId());
|
||||
}
|
||||
|
||||
for (VMInstanceVO vm : vms) {
|
||||
ServiceOffering so = offeringsMap.get(vm.getServiceOfferingId());
|
||||
usedMemory += so.getRamSize() * 1024L * 1024L;
|
||||
usedCpu += so.getCpu() * so.getSpeed();
|
||||
}
|
||||
|
||||
List<VMInstanceVO> vmsByLastHostId = _vmDao.listByLastHostId(host.getId());
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Found " + vmsByLastHostId.size() + " VM, not running on host " + host.getId());
|
||||
}
|
||||
for (VMInstanceVO vm : vmsByLastHostId) {
|
||||
long secondsSinceLastUpdate = (DateUtil.currentGMTTime().getTime() - vm.getUpdateTime().getTime()) / 1000;
|
||||
if (secondsSinceLastUpdate < _vmCapacityReleaseInterval) {
|
||||
ServiceOffering so = offeringsMap.get(vm.getServiceOfferingId());
|
||||
reservedMemory += so.getRamSize() * 1024L * 1024L;
|
||||
reservedCpu += so.getCpu() * so.getSpeed();
|
||||
}
|
||||
}
|
||||
|
||||
CapacityVO cpuCap = _capacityDao.findByHostIdType(host.getId(), CapacityVO.CAPACITY_TYPE_CPU);
|
||||
CapacityVO memCap = _capacityDao.findByHostIdType(host.getId(), CapacityVO.CAPACITY_TYPE_MEMORY);
|
||||
|
||||
if (cpuCap != null && memCap != null){
|
||||
if (cpuCap.getUsedCapacity() == usedCpu && cpuCap.getReservedCapacity() == reservedCpu) {
|
||||
s_logger.debug("No need to calibrate cpu capacity, host:" + host.getId() + " usedCpu: " + cpuCap.getUsedCapacity()
|
||||
+ " reservedCpu: " + cpuCap.getReservedCapacity());
|
||||
} else if (cpuCap.getReservedCapacity() != reservedCpu) {
|
||||
s_logger.debug("Calibrate reserved cpu for host: " + host.getId() + " old reservedCpu:" + cpuCap.getReservedCapacity()
|
||||
+ " new reservedCpu:" + reservedCpu);
|
||||
cpuCap.setReservedCapacity(reservedCpu);
|
||||
} else if (cpuCap.getUsedCapacity() != usedCpu) {
|
||||
s_logger.debug("Calibrate used cpu for host: " + host.getId() + " old usedCpu:" + cpuCap.getUsedCapacity() + " new usedCpu:"
|
||||
+ usedCpu);
|
||||
cpuCap.setUsedCapacity(usedCpu);
|
||||
}
|
||||
|
||||
if (memCap.getUsedCapacity() == usedMemory && memCap.getReservedCapacity() == reservedMemory) {
|
||||
s_logger.debug("No need to calibrate memory capacity, host:" + host.getId() + " usedMem: " + memCap.getUsedCapacity()
|
||||
+ " reservedMem: " + memCap.getReservedCapacity());
|
||||
} else if (memCap.getReservedCapacity() != reservedMemory) {
|
||||
s_logger.debug("Calibrate reserved memory for host: " + host.getId() + " old reservedMem:" + memCap.getReservedCapacity()
|
||||
+ " new reservedMem:" + reservedMemory);
|
||||
memCap.setReservedCapacity(reservedMemory);
|
||||
} else if (memCap.getUsedCapacity() != usedMemory) {
|
||||
/*
|
||||
* Didn't calibrate for used memory, because VMs can be in state(starting/migrating) that I don't know on which host they are
|
||||
* allocated
|
||||
*/
|
||||
s_logger.debug("Calibrate used memory for host: " + host.getId() + " old usedMem: " + memCap.getUsedCapacity()
|
||||
+ " new usedMem: " + usedMemory);
|
||||
memCap.setUsedCapacity(usedMemory);
|
||||
}
|
||||
|
||||
try {
|
||||
_capacityDao.update(cpuCap.getId(), cpuCap);
|
||||
_capacityDao.update(memCap.getId(), memCap);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}else {
|
||||
|
||||
CapacityVO capacity = new CapacityVO(host.getId(),
|
||||
host.getDataCenterId(), host.getPodId(), host.getClusterId(), usedMemory,
|
||||
host.getTotalMemory(),
|
||||
CapacityVO.CAPACITY_TYPE_MEMORY);
|
||||
capacity.setReservedCapacity(reservedMemory);
|
||||
_capacityDao.persist(capacity);
|
||||
|
||||
capacity = new CapacityVO(
|
||||
host.getId(),
|
||||
host.getDataCenterId(),
|
||||
host.getPodId(),
|
||||
host.getClusterId(),
|
||||
usedCpu,
|
||||
(long)(host.getCpus().longValue()
|
||||
* host.getSpeed().longValue()
|
||||
* _cpuOverProvisioningFactor),
|
||||
CapacityVO.CAPACITY_TYPE_CPU);
|
||||
capacity.setReservedCapacity(reservedCpu);
|
||||
_capacityDao.persist(capacity);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preStateTransitionEvent(State oldState, Event event, State newState, VirtualMachine vm, boolean transitionStatus, Long id) {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -33,19 +33,23 @@ import com.cloud.capacity.dao.CapacityDao;
|
|||
import com.cloud.exception.ConnectionException;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
|
||||
|
||||
public class ComputeCapacityListener implements Listener {
|
||||
private static final Logger s_logger = Logger.getLogger(ComputeCapacityListener.class);
|
||||
CapacityDao _capacityDao;
|
||||
CapacityDao _capacityDao;
|
||||
CapacityManager _capacityMgr;
|
||||
float _cpuOverProvisioningFactor = 1.0f;
|
||||
|
||||
|
||||
public ComputeCapacityListener(CapacityDao _capacityDao,
|
||||
CapacityManager _capacityMgr,
|
||||
float _overProvisioningFactor) {
|
||||
super();
|
||||
this._capacityDao = _capacityDao;
|
||||
this._capacityMgr = _capacityMgr;
|
||||
this._cpuOverProvisioningFactor = _overProvisioningFactor;
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +80,7 @@ public class ComputeCapacityListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
_capacityMgr.updateCapacityForHost(server);
|
||||
SearchCriteria<CapacityVO> capacityCPU = _capacityDao
|
||||
.createSearchCriteria();
|
||||
capacityCPU.addAnd("hostOrPoolId", SearchCriteria.Op.EQ,
|
||||
|
|
|
|||
Loading…
Reference in New Issue