mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Merge remote-tracking branch 'origin/4.14' into 4.15
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
commit
6bde1384ff
@ -16,10 +16,13 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package com.cloud.capacity;
|
package com.cloud.capacity;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||||
|
|
||||||
import com.cloud.host.Host;
|
import com.cloud.host.Host;
|
||||||
|
import com.cloud.service.ServiceOfferingVO;
|
||||||
import com.cloud.storage.VMTemplateVO;
|
import com.cloud.storage.VMTemplateVO;
|
||||||
import com.cloud.vm.VirtualMachine;
|
import com.cloud.vm.VirtualMachine;
|
||||||
|
|
||||||
@ -99,6 +102,8 @@ public interface CapacityManager {
|
|||||||
|
|
||||||
void updateCapacityForHost(Host host);
|
void updateCapacityForHost(Host host);
|
||||||
|
|
||||||
|
void updateCapacityForHost(Host host, Map<Long, ServiceOfferingVO> offeringsMap);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param pool storage pool
|
* @param pool storage pool
|
||||||
* @param templateForVmCreation template that will be used for vm creation
|
* @param templateForVmCreation template that will be used for vm creation
|
||||||
|
|||||||
@ -75,6 +75,8 @@ import com.cloud.host.HostVO;
|
|||||||
import com.cloud.network.dao.IPAddressDao;
|
import com.cloud.network.dao.IPAddressDao;
|
||||||
import com.cloud.org.Grouping.AllocationState;
|
import com.cloud.org.Grouping.AllocationState;
|
||||||
import com.cloud.resource.ResourceManager;
|
import com.cloud.resource.ResourceManager;
|
||||||
|
import com.cloud.service.ServiceOfferingVO;
|
||||||
|
import com.cloud.service.dao.ServiceOfferingDao;
|
||||||
import com.cloud.storage.StorageManager;
|
import com.cloud.storage.StorageManager;
|
||||||
import com.cloud.utils.NumbersUtil;
|
import com.cloud.utils.NumbersUtil;
|
||||||
import com.cloud.utils.component.ManagerBase;
|
import com.cloud.utils.component.ManagerBase;
|
||||||
@ -121,6 +123,8 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi
|
|||||||
private ConfigurationManager _configMgr;
|
private ConfigurationManager _configMgr;
|
||||||
@Inject
|
@Inject
|
||||||
protected ConfigDepot _configDepot;
|
protected ConfigDepot _configDepot;
|
||||||
|
@Inject
|
||||||
|
ServiceOfferingDao _offeringsDao;
|
||||||
|
|
||||||
private Timer _timer = null;
|
private Timer _timer = null;
|
||||||
private long _capacityCheckPeriod = 60L * 60L * 1000L; // One hour by default.
|
private long _capacityCheckPeriod = 60L * 60L * 1000L; // One hour by default.
|
||||||
@ -275,8 +279,14 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi
|
|||||||
// get all hosts...even if they are not in 'UP' state
|
// get all hosts...even if they are not in 'UP' state
|
||||||
List<HostVO> hosts = _resourceMgr.listAllNotInMaintenanceHostsInOneZone(Host.Type.Routing, null);
|
List<HostVO> hosts = _resourceMgr.listAllNotInMaintenanceHostsInOneZone(Host.Type.Routing, null);
|
||||||
if (hosts != 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) {
|
for (HostVO host : hosts) {
|
||||||
_capacityMgr.updateCapacityForHost(host);
|
_capacityMgr.updateCapacityForHost(host, offeringsMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
|
|||||||
@ -629,7 +629,12 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
|
|||||||
for (ServiceOfferingVO offering : offerings) {
|
for (ServiceOfferingVO offering : offerings) {
|
||||||
offeringsMap.put(offering.getId(), offering);
|
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 usedCpuCore = 0;
|
||||||
long reservedCpuCore = 0;
|
long reservedCpuCore = 0;
|
||||||
long usedCpu = 0;
|
long usedCpu = 0;
|
||||||
@ -666,6 +671,9 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
|
|||||||
ramOvercommitRatio = Float.parseFloat(vmDetailRam);
|
ramOvercommitRatio = Float.parseFloat(vmDetailRam);
|
||||||
}
|
}
|
||||||
ServiceOffering so = offeringsMap.get(vm.getServiceOfferingId());
|
ServiceOffering so = offeringsMap.get(vm.getServiceOfferingId());
|
||||||
|
if (so == null) {
|
||||||
|
so = _offeringsDao.findByIdIncludingRemoved(vm.getServiceOfferingId());
|
||||||
|
}
|
||||||
if (so.isDynamic()) {
|
if (so.isDynamic()) {
|
||||||
usedMemory +=
|
usedMemory +=
|
||||||
((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.memory.name())) * 1024L * 1024L) / ramOvercommitRatio) *
|
((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.memory.name())) * 1024L * 1024L) / ramOvercommitRatio) *
|
||||||
@ -705,6 +713,9 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
|
|||||||
}
|
}
|
||||||
ServiceOffering so = offeringsMap.get(vm.getServiceOfferingId());
|
ServiceOffering so = offeringsMap.get(vm.getServiceOfferingId());
|
||||||
Map<String, String> vmDetails = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
|
Map<String, String> vmDetails = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
|
||||||
|
if (so == null) {
|
||||||
|
so = _offeringsDao.findByIdIncludingRemoved(vm.getServiceOfferingId());
|
||||||
|
}
|
||||||
if (so.isDynamic()) {
|
if (so.isDynamic()) {
|
||||||
reservedMemory +=
|
reservedMemory +=
|
||||||
((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.memory.name())) * 1024L * 1024L) / ramOvercommitRatio) *
|
((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.memory.name())) * 1024L * 1024L) / ramOvercommitRatio) *
|
||||||
|
|||||||
@ -687,18 +687,17 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// collect the vm disk statistics(total) from hypervisor. added by weizhou, 2013.03.
|
// collect the vm disk statistics(total) from hypervisor. added by weizhou, 2013.03.
|
||||||
s_logger.trace("Running VM disk stats ...");
|
s_logger.debug("VmDiskStatsTask is running...");
|
||||||
try {
|
|
||||||
Transaction.execute(new TransactionCallbackNoReturn() {
|
|
||||||
@Override
|
|
||||||
public void doInTransactionWithoutResult(TransactionStatus status) {
|
|
||||||
s_logger.debug("VmDiskStatsTask is running...");
|
|
||||||
|
|
||||||
SearchCriteria<HostVO> sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance();
|
SearchCriteria<HostVO> sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance();
|
||||||
sc.addAnd("hypervisorType", SearchCriteria.Op.IN, HypervisorType.KVM, HypervisorType.VMware);
|
sc.addAnd("hypervisorType", SearchCriteria.Op.IN, HypervisorType.KVM, HypervisorType.VMware);
|
||||||
List<HostVO> hosts = _hostDao.search(sc, null);
|
List<HostVO> hosts = _hostDao.search(sc, null);
|
||||||
|
|
||||||
for (HostVO host : hosts) {
|
for (HostVO host : hosts) {
|
||||||
|
try {
|
||||||
|
Transaction.execute(new TransactionCallbackNoReturn() {
|
||||||
|
@Override
|
||||||
|
public void doInTransactionWithoutResult(TransactionStatus status) {
|
||||||
List<UserVmVO> vms = _userVmDao.listRunningByHostId(host.getId());
|
List<UserVmVO> vms = _userVmDao.listRunningByHostId(host.getId());
|
||||||
List<Long> vmIds = new ArrayList<Long>();
|
List<Long> vmIds = new ArrayList<Long>();
|
||||||
|
|
||||||
@ -709,7 +708,7 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
|
|||||||
|
|
||||||
HashMap<Long, List<VmDiskStatsEntry>> vmDiskStatsById = _userVmMgr.getVmDiskStatistics(host.getId(), host.getName(), vmIds);
|
HashMap<Long, List<VmDiskStatsEntry>> vmDiskStatsById = _userVmMgr.getVmDiskStatistics(host.getId(), host.getName(), vmIds);
|
||||||
if (vmDiskStatsById == null)
|
if (vmDiskStatsById == null)
|
||||||
continue;
|
return;
|
||||||
|
|
||||||
Set<Long> vmIdSet = vmDiskStatsById.keySet();
|
Set<Long> vmIdSet = vmDiskStatsById.keySet();
|
||||||
for (Long vmId : vmIdSet) {
|
for (Long vmId : vmIdSet) {
|
||||||
@ -796,10 +795,10 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
s_logger.warn(String.format("Error while collecting vm disk stats from host %s : ", host.getName()), e);
|
||||||
s_logger.warn("Error while collecting vm disk stats from hosts", e);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -815,16 +814,16 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// collect the vm network statistics(total) from hypervisor
|
// collect the vm network statistics(total) from hypervisor
|
||||||
try {
|
s_logger.debug("VmNetworkStatsTask is running...");
|
||||||
Transaction.execute(new TransactionCallbackNoReturn() {
|
|
||||||
@Override
|
|
||||||
public void doInTransactionWithoutResult(TransactionStatus status) {
|
|
||||||
s_logger.debug("VmNetworkStatsTask is running...");
|
|
||||||
|
|
||||||
SearchCriteria<HostVO> sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance();
|
SearchCriteria<HostVO> sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance();
|
||||||
List<HostVO> hosts = _hostDao.search(sc, null);
|
List<HostVO> hosts = _hostDao.search(sc, null);
|
||||||
|
|
||||||
for (HostVO host : hosts) {
|
for (HostVO host : hosts) {
|
||||||
|
try {
|
||||||
|
Transaction.execute(new TransactionCallbackNoReturn() {
|
||||||
|
@Override
|
||||||
|
public void doInTransactionWithoutResult(TransactionStatus status) {
|
||||||
List<UserVmVO> vms = _userVmDao.listRunningByHostId(host.getId());
|
List<UserVmVO> vms = _userVmDao.listRunningByHostId(host.getId());
|
||||||
List<Long> vmIds = new ArrayList<Long>();
|
List<Long> vmIds = new ArrayList<Long>();
|
||||||
|
|
||||||
@ -835,7 +834,7 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
|
|||||||
|
|
||||||
HashMap<Long, List<VmNetworkStatsEntry>> vmNetworkStatsById = _userVmMgr.getVmNetworkStatistics(host.getId(), host.getName(), vmIds);
|
HashMap<Long, List<VmNetworkStatsEntry>> vmNetworkStatsById = _userVmMgr.getVmNetworkStatistics(host.getId(), host.getName(), vmIds);
|
||||||
if (vmNetworkStatsById == null)
|
if (vmNetworkStatsById == null)
|
||||||
continue;
|
return;
|
||||||
|
|
||||||
Set<Long> vmIdSet = vmNetworkStatsById.keySet();
|
Set<Long> vmIdSet = vmNetworkStatsById.keySet();
|
||||||
for (Long vmId : vmIdSet) {
|
for (Long vmId : vmIdSet) {
|
||||||
@ -915,10 +914,10 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
s_logger.warn(String.format("Error while collecting vm network stats from host %s : ", host.getName()), e);
|
||||||
s_logger.warn("Error while collecting vm network stats from hosts", e);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -179,7 +179,7 @@ Sql parameters:
|
|||||||
***************************************************************
|
***************************************************************
|
||||||
Please run:
|
Please run:
|
||||||
|
|
||||||
cloud-setup-database -h
|
cloudstack-setup-databases -h
|
||||||
|
|
||||||
for full help
|
for full help
|
||||||
''' % msg
|
''' % msg
|
||||||
|
|||||||
@ -210,7 +210,7 @@ class TestDomainMemoryLimits(cloudstackTestCase):
|
|||||||
domainid=self.child_do_admin_2.domainid)
|
domainid=self.child_do_admin_2.domainid)
|
||||||
return
|
return
|
||||||
|
|
||||||
@attr(tags=["advanced", "advancedns","simulator"], required_hardware="false")
|
@attr(tags=["advanced", "advancedns","simulator"], required_hardware="true")
|
||||||
def test_01_change_service_offering(self):
|
def test_01_change_service_offering(self):
|
||||||
"""Test Deploy VM with specified RAM & verify the usage"""
|
"""Test Deploy VM with specified RAM & verify the usage"""
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user