Merge remote-tracking branch 'origin/4.15'

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Rohit Yadav 2021-02-05 16:02:26 +05:30
commit ba127dab3e
7 changed files with 67 additions and 35 deletions

View File

@ -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;
@ -99,6 +102,8 @@ public interface CapacityManager {
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

View File

@ -75,6 +75,8 @@ import com.cloud.host.HostVO;
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;
@ -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.
@ -275,8 +279,14 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi
// 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()) {

View File

@ -629,7 +629,12 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
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;
@ -666,6 +671,9 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
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) *
@ -705,6 +713,9 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
}
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) *

View File

@ -687,18 +687,17 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
return;
}
// collect the vm disk statistics(total) from hypervisor. added by weizhou, 2013.03.
s_logger.trace("Running VM disk stats ...");
try {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
s_logger.debug("VmDiskStatsTask is running...");
s_logger.debug("VmDiskStatsTask is running...");
SearchCriteria<HostVO> sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance();
sc.addAnd("hypervisorType", SearchCriteria.Op.IN, HypervisorType.KVM, HypervisorType.VMware);
List<HostVO> hosts = _hostDao.search(sc, null);
SearchCriteria<HostVO> sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance();
sc.addAnd("hypervisorType", SearchCriteria.Op.IN, HypervisorType.KVM, HypervisorType.VMware);
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<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);
if (vmDiskStatsById == null)
continue;
return;
Set<Long> vmIdSet = vmDiskStatsById.keySet();
for (Long vmId : vmIdSet) {
@ -796,10 +795,10 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
}
}
}
}
});
} catch (Exception e) {
s_logger.warn("Error while collecting vm disk stats from hosts", e);
});
} catch (Exception e) {
s_logger.warn(String.format("Error while collecting vm disk stats from host %s : ", host.getName()), e);
}
}
}
}
@ -815,16 +814,16 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
return;
}
// collect the vm network statistics(total) from hypervisor
try {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
s_logger.debug("VmNetworkStatsTask is running...");
s_logger.debug("VmNetworkStatsTask is running...");
SearchCriteria<HostVO> sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance();
List<HostVO> hosts = _hostDao.search(sc, null);
SearchCriteria<HostVO> sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance();
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<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);
if (vmNetworkStatsById == null)
continue;
return;
Set<Long> vmIdSet = vmNetworkStatsById.keySet();
for (Long vmId : vmIdSet) {
@ -915,10 +914,10 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
}
}
}
}
});
} catch (Exception e) {
s_logger.warn("Error while collecting vm network stats from hosts", e);
});
} catch (Exception e) {
s_logger.warn(String.format("Error while collecting vm network stats from host %s : ", host.getName()), e);
}
}
}
}

View File

@ -2529,12 +2529,16 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
final List<String> userBlacklistedSettings = Stream.of(QueryService.UserVMBlacklistedDetails.value().split(","))
.map(item -> (item).trim())
.collect(Collectors.toList());
final List<String> userReadOnlySettings = Stream.of(QueryService.UserVMReadOnlyUIDetails.value().split(","))
.map(item -> (item).trim())
.collect(Collectors.toList());
if (cleanupDetails){
if (caller != null && caller.getType() == Account.ACCOUNT_TYPE_ADMIN) {
userVmDetailsDao.removeDetails(id);
} else {
for (final UserVmDetailVO detail : userVmDetailsDao.listDetails(id)) {
if (detail != null && !userBlacklistedSettings.contains(detail.getName())) {
if (detail != null && !userBlacklistedSettings.contains(detail.getName())
&& !userReadOnlySettings.contains(detail.getName())) {
userVmDetailsDao.removeDetail(id, detail.getName());
}
}
@ -2546,15 +2550,18 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
}
if (caller != null && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
// Ensure blacklisted detail is not passed by non-root-admin user
// Ensure blacklisted or read-only detail is not passed by non-root-admin user
for (final String detailName : details.keySet()) {
if (userBlacklistedSettings.contains(detailName)) {
throw new InvalidParameterValueException("You're not allowed to add or edit the restricted setting: " + detailName);
}
if (userReadOnlySettings.contains(detailName)) {
throw new InvalidParameterValueException("You're not allowed to add or edit the read-only setting: " + detailName);
}
}
// Add any hidden/blacklisted detail
// Add any hidden/blacklisted or read-only detail
for (final UserVmDetailVO detail : userVmDetailsDao.listDetails(id)) {
if (userBlacklistedSettings.contains(detail.getName())) {
if (userBlacklistedSettings.contains(detail.getName()) || userReadOnlySettings.contains(detail.getName())) {
details.put(detail.getName(), detail.getValue());
}
}

View File

@ -179,7 +179,7 @@ Sql parameters:
***************************************************************
Please run:
cloud-setup-database -h
cloudstack-setup-databases -h
for full help
''' % msg

View File

@ -210,7 +210,7 @@ class TestDomainMemoryLimits(cloudstackTestCase):
domainid=self.child_do_admin_2.domainid)
return
@attr(tags=["advanced", "advancedns","simulator"], required_hardware="false")
@attr(tags=["advanced", "advancedns","simulator"], required_hardware="true")
def test_01_change_service_offering(self):
"""Test Deploy VM with specified RAM & verify the usage"""