Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
// under the License.
package com.cloud.capacity;

import java.util.Map;

import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;

import com.cloud.host.Host;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.storage.VMTemplateVO;
import com.cloud.vm.VirtualMachine;

Expand Down Expand Up @@ -99,6 +102,8 @@ boolean checkIfHostHasCapacity(long hostId, Integer cpu, long ram, boolean check

void updateCapacityForHost(Host host);

void updateCapacityForHost(Host host, Map<Long, ServiceOfferingVO> offeringsMap);

/**
* @param pool storage pool
* @param templateForVmCreation template that will be used for vm creation
Expand Down
12 changes: 11 additions & 1 deletion server/src/main/java/com/cloud/alert/AlertManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
import com.cloud.network.dao.IPAddressDao;
import com.cloud.org.Grouping.AllocationState;
import com.cloud.resource.ResourceManager;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.StorageManager;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.component.ManagerBase;
Expand Down Expand Up @@ -121,6 +123,8 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi
private ConfigurationManager _configMgr;
@Inject
protected ConfigDepot _configDepot;
@Inject
ServiceOfferingDao _offeringsDao;

private Timer _timer = null;
private long _capacityCheckPeriod = 60L * 60L * 1000L; // One hour by default.
Expand Down Expand Up @@ -275,8 +279,14 @@ public void recalculateCapacity() {
// get all hosts...even if they are not in 'UP' state
List<HostVO> hosts = _resourceMgr.listAllNotInMaintenanceHostsInOneZone(Host.Type.Routing, null);
if (hosts != null) {
// prepare 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);
}
for (HostVO host : hosts) {
_capacityMgr.updateCapacityForHost(host);
_capacityMgr.updateCapacityForHost(host, offeringsMap);
}
}
if (s_logger.isDebugEnabled()) {
Expand Down
11 changes: 11 additions & 0 deletions server/src/main/java/com/cloud/capacity/CapacityManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,12 @@ public void updateCapacityForHost(final Host host) {
for (ServiceOfferingVO offering : offerings) {
offeringsMap.put(offering.getId(), offering);
}
updateCapacityForHost(host, offeringsMap);
}

@DB
@Override
public void updateCapacityForHost(final Host host, final Map<Long, ServiceOfferingVO> offeringsMap) {
long usedCpuCore = 0;
long reservedCpuCore = 0;
long usedCpu = 0;
Expand Down Expand Up @@ -664,6 +669,9 @@ public void updateCapacityForHost(final Host host) {
ramOvercommitRatio = Float.parseFloat(vmDetailRam);
}
ServiceOffering so = offeringsMap.get(vm.getServiceOfferingId());
if (so == null) {
so = _offeringsDao.findByIdIncludingRemoved(vm.getServiceOfferingId());
}
if (so.isDynamic()) {
usedMemory +=
((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.memory.name())) * 1024L * 1024L) / ramOvercommitRatio) *
Expand Down Expand Up @@ -703,6 +711,9 @@ public void updateCapacityForHost(final Host host) {
}
ServiceOffering so = offeringsMap.get(vm.getServiceOfferingId());
Map<String, String> vmDetails = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
if (so == null) {
so = _offeringsDao.findByIdIncludingRemoved(vm.getServiceOfferingId());
}
if (so.isDynamic()) {
reservedMemory +=
((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.memory.name())) * 1024L * 1024L) / ramOvercommitRatio) *
Expand Down