Merge branch 'master' of ssh://git.cloud.com/var/lib/git/cloudstack-oss

This commit is contained in:
Kelven Yang 2010-08-23 14:17:18 -07:00
commit 7a46156d09
4 changed files with 198 additions and 180 deletions

View File

@ -1683,7 +1683,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory {
// If this command is from a KVM agent, or from an agent that has a
// null hypervisor type, don't do the CIDR check
if (hypervisorType == null || hypervisorType == Hypervisor.Type.KVM || hypervisorType == Hypervisor.Type.VMware)
if (hypervisorType == null || hypervisorType == Hypervisor.Type.KVM || hypervisorType == Hypervisor.Type.VmWare)
doCidrCheck = false;
if (doCidrCheck)

View File

@ -154,38 +154,14 @@ public class UserConcentratedAllocator implements PodAllocator {
}
private boolean dataCenterAndPodHasEnoughCapacity(long dataCenterId, long podId, long capacityNeeded, short capacityType, long[] hostCandidate) {
List<CapacityVO> capacities = null;
if (m_capacityCheckLock.lock(120)) { // 2 minutes
try {
SearchCriteria<CapacityVO> sc = _capacityDao.createSearchCriteria();
sc.addAnd("capacityType", SearchCriteria.Op.EQ, capacityType);
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, dataCenterId);
sc.addAnd("podId", SearchCriteria.Op.EQ, podId);
List<CapacityVO> capacities = _capacityDao.search(sc, null);
boolean enoughCapacity = false;
if (capacities != null) {
for (CapacityVO capacity : capacities) {
if(capacityType == CapacityVO.CAPACITY_TYPE_CPU || capacityType == CapacityVO.CAPACITY_TYPE_MEMORY) {
//
// for CPU/Memory, we now switch to static allocation
//
if ((capacity.getTotalCapacity() -
calcHostAllocatedCpuMemoryCapacity(capacity.getHostOrPoolId(), capacityType)) >= capacityNeeded) {
hostCandidate[0] = capacity.getHostOrPoolId();
enoughCapacity = true;
break;
}
} else {
if ((capacity.getTotalCapacity() - capacity.getUsedCapacity()) >= capacityNeeded) {
hostCandidate[0] = capacity.getHostOrPoolId();
enoughCapacity = true;
break;
}
}
}
}
return enoughCapacity;
capacities = _capacityDao.search(sc, null);
} finally {
m_capacityCheckLock.unlock();
}
@ -203,6 +179,31 @@ public class UserConcentratedAllocator implements PodAllocator {
return true;
*/
}
boolean enoughCapacity = false;
if (capacities != null) {
for (CapacityVO capacity : capacities) {
if(capacityType == CapacityVO.CAPACITY_TYPE_CPU || capacityType == CapacityVO.CAPACITY_TYPE_MEMORY) {
//
// for CPU/Memory, we now switch to static allocation
//
if ((capacity.getTotalCapacity() -
calcHostAllocatedCpuMemoryCapacity(capacity.getHostOrPoolId(), capacityType)) >= capacityNeeded) {
hostCandidate[0] = capacity.getHostOrPoolId();
enoughCapacity = true;
break;
}
} else {
if ((capacity.getTotalCapacity() - capacity.getUsedCapacity()) >= capacityNeeded) {
hostCandidate[0] = capacity.getHostOrPoolId();
enoughCapacity = true;
break;
}
}
}
}
return enoughCapacity;
}
private boolean skipCalculation(VMInstanceVO vm) {

View File

@ -327,16 +327,13 @@ public class AlertManagerImpl implements AlertManager {
// the amount allocated. Hopefully it's limited to 3 entry points and will keep the amount allocated
// per host accurate.
if (m_capacityCheckLock.lock(5)) { // 5 second timeout
if (s_logger.isTraceEnabled()) {
s_logger.trace("recalculating system capacity");
}
try {
// delete the old records
_capacityDao.clearNonStorageCapacities();
List<CapacityVO> newCapacities = new ArrayList<CapacityVO>();
// get all hosts..
SearchCriteria<HostVO> sc = _hostDao.createSearchCriteria();
SearchCriteria sc = _hostDao.createSearchCriteria();
sc.addAnd("status", SearchCriteria.Op.EQ, Status.Up.toString());
List<HostVO> hosts = _hostDao.search(sc, null);
@ -350,6 +347,7 @@ public class AlertManagerImpl implements AlertManager {
if (host.getType() != Host.Type.Routing) {
continue;
}
long cpu = 0;
long usedMemory = 0;
List<DomainRouterVO> domainRouters = _routerDao.listUpByHostId(host.getId());
@ -391,8 +389,8 @@ public class AlertManagerImpl implements AlertManager {
CapacityVO newMemoryCapacity = new CapacityVO(host.getId(), host.getDataCenterId(), host.getPodId(), usedMemory, totalMemory, CapacityVO.CAPACITY_TYPE_MEMORY);
CapacityVO newCPUCapacity = new CapacityVO(host.getId(), host.getDataCenterId(), host.getPodId(), cpu, (long)(host.getCpus()*host.getSpeed()* _cpuOverProvisioningFactor), CapacityVO.CAPACITY_TYPE_CPU);
_capacityDao.persist(newMemoryCapacity);
_capacityDao.persist(newCPUCapacity);
newCapacities.add(newMemoryCapacity);
newCapacities.add(newCPUCapacity);
}
// Calculate storage pool capacity
@ -406,7 +404,7 @@ public class AlertManagerImpl implements AlertManager {
provFactor = _overProvisioningFactor;
}
CapacityVO newStorageCapacity = new CapacityVO(pool.getId(), pool.getDataCenterId(), pool.getPodId(), disk, pool.getCapacityBytes() * provFactor, CapacityVO.CAPACITY_TYPE_STORAGE_ALLOCATED);
_capacityDao.persist(newStorageCapacity);
newCapacities.add(newStorageCapacity);
continue;
}
@ -420,7 +418,7 @@ public class AlertManagerImpl implements AlertManager {
int allocatedPublicIPs = _publicIPAddressDao.countIPs(dcId, -1, true);
CapacityVO newPublicIPCapacity = new CapacityVO(null, dcId, null, allocatedPublicIPs, totalPublicIPs, CapacityVO.CAPACITY_TYPE_PUBLIC_IP);
_capacityDao.persist(newPublicIPCapacity);
newCapacities.add(newPublicIPCapacity);
}
// Calculate new Private IP capacity
@ -433,7 +431,16 @@ public class AlertManagerImpl implements AlertManager {
int allocatedPrivateIPs = _privateIPAddressDao.countIPs(podId, dcId, true);
CapacityVO newPrivateIPCapacity = new CapacityVO(null, dcId, podId, allocatedPrivateIPs, totalPrivateIPs, CapacityVO.CAPACITY_TYPE_PRIVATE_IP);
_capacityDao.persist(newPrivateIPCapacity);
newCapacities.add(newPrivateIPCapacity);
}
if (m_capacityCheckLock.lock(5)) { // 5 second timeout
try {
// delete the old records
_capacityDao.clearNonStorageCapacities();
for (CapacityVO newCapacity : newCapacities) {
_capacityDao.persist(newCapacity);
}
} finally {
m_capacityCheckLock.unlock();

View File

@ -293,18 +293,8 @@ public class StatsCollector {
}
_storagePoolStats = storagePoolStats;
if (m_capacityCheckLock.lock(5)) { // 5 second timeout
if (s_logger.isTraceEnabled()) {
s_logger.trace("recalculating system storage capacity");
}
try {
// now update the capacity table with the new stats
// FIXME: the right way to do this is to register a listener (see RouterStatsListener)
// for the host stats, send the Watch<something>Command at a regular interval
// to collect the stats from an agent and update the database as needed. The
// listener model has connects/disconnects to keep things in sync much better
// than this model right now
_capacityDao.clearStorageCapacities();
// a list to store the new capacity entries that will be committed once everything is calculated
List<CapacityVO> newCapacities = new ArrayList<CapacityVO>();
// create new entries
for (Long hostId : storageStats.keySet()) {
@ -315,10 +305,12 @@ public class StatsCollector {
if (Host.Type.SecondaryStorage.equals(host.getType())) {
CapacityVO capacity = new CapacityVO(host.getId(), host.getDataCenterId(), host.getPodId(), stats.getByteUsed(), stats.getCapacityBytes(), CapacityVO.CAPACITY_TYPE_SECONDARY_STORAGE);
_capacityDao.persist(capacity);
newCapacities.add(capacity);
// _capacityDao.persist(capacity);
} else if (Host.Type.Storage.equals(host.getType())) {
CapacityVO capacity = new CapacityVO(host.getId(), host.getDataCenterId(), host.getPodId(), stats.getByteUsed(), stats.getCapacityBytes(), CapacityVO.CAPACITY_TYPE_STORAGE);
_capacityDao.persist(capacity);
newCapacities.add(capacity);
// _capacityDao.persist(capacity);
}
}
@ -339,7 +331,25 @@ public class StatsCollector {
_storagePoolDao.update(pool.getId(), pool);
CapacityVO capacity = new CapacityVO(poolId, pool.getDataCenterId(), pool.getPodId(), stats.getByteUsed(), stats.getCapacityBytes(), CapacityVO.CAPACITY_TYPE_STORAGE);
_capacityDao.persist(capacity);
newCapacities.add(capacity);
// _capacityDao.persist(capacity);
}
if (m_capacityCheckLock.lock(5)) { // 5 second timeout
if (s_logger.isTraceEnabled()) {
s_logger.trace("recalculating system storage capacity");
}
try {
// now update the capacity table with the new stats
// FIXME: the right way to do this is to register a listener (see RouterStatsListener)
// for the host stats, send the Watch<something>Command at a regular interval
// to collect the stats from an agent and update the database as needed. The
// listener model has connects/disconnects to keep things in sync much better
// than this model right now
_capacityDao.clearStorageCapacities();
for (CapacityVO newCapacity : newCapacities) {
_capacityDao.persist(newCapacity);
}
} finally {
m_capacityCheckLock.unlock();