Skip to content

Commit ba127da

Browse files
Merge remote-tracking branch 'origin/4.15'
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2 parents ff376d8 + 6bde138 commit ba127da

File tree

7 files changed

+67
-35
lines changed

7 files changed

+67
-35
lines changed

engine/components-api/src/main/java/com/cloud/capacity/CapacityManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616
// under the License.
1717
package com.cloud.capacity;
1818

19+
import java.util.Map;
20+
1921
import org.apache.cloudstack.framework.config.ConfigKey;
2022
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
2123

2224
import com.cloud.host.Host;
25+
import com.cloud.service.ServiceOfferingVO;
2326
import com.cloud.storage.VMTemplateVO;
2427
import com.cloud.vm.VirtualMachine;
2528

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

100103
void updateCapacityForHost(Host host);
101104

105+
void updateCapacityForHost(Host host, Map<Long, ServiceOfferingVO> offeringsMap);
106+
102107
/**
103108
* @param pool storage pool
104109
* @param templateForVmCreation template that will be used for vm creation

server/src/main/java/com/cloud/alert/AlertManagerImpl.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
import com.cloud.network.dao.IPAddressDao;
7676
import com.cloud.org.Grouping.AllocationState;
7777
import com.cloud.resource.ResourceManager;
78+
import com.cloud.service.ServiceOfferingVO;
79+
import com.cloud.service.dao.ServiceOfferingDao;
7880
import com.cloud.storage.StorageManager;
7981
import com.cloud.utils.NumbersUtil;
8082
import com.cloud.utils.component.ManagerBase;
@@ -121,6 +123,8 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi
121123
private ConfigurationManager _configMgr;
122124
@Inject
123125
protected ConfigDepot _configDepot;
126+
@Inject
127+
ServiceOfferingDao _offeringsDao;
124128

125129
private Timer _timer = null;
126130
private long _capacityCheckPeriod = 60L * 60L * 1000L; // One hour by default.
@@ -275,8 +279,14 @@ public void recalculateCapacity() {
275279
// get all hosts...even if they are not in 'UP' state
276280
List<HostVO> hosts = _resourceMgr.listAllNotInMaintenanceHostsInOneZone(Host.Type.Routing, null);
277281
if (hosts != null) {
282+
// prepare the service offerings
283+
List<ServiceOfferingVO> offerings = _offeringsDao.listAllIncludingRemoved();
284+
Map<Long, ServiceOfferingVO> offeringsMap = new HashMap<Long, ServiceOfferingVO>();
285+
for (ServiceOfferingVO offering : offerings) {
286+
offeringsMap.put(offering.getId(), offering);
287+
}
278288
for (HostVO host : hosts) {
279-
_capacityMgr.updateCapacityForHost(host);
289+
_capacityMgr.updateCapacityForHost(host, offeringsMap);
280290
}
281291
}
282292
if (s_logger.isDebugEnabled()) {

server/src/main/java/com/cloud/capacity/CapacityManagerImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,12 @@ public void updateCapacityForHost(final Host host) {
629629
for (ServiceOfferingVO offering : offerings) {
630630
offeringsMap.put(offering.getId(), offering);
631631
}
632+
updateCapacityForHost(host, offeringsMap);
633+
}
632634

635+
@DB
636+
@Override
637+
public void updateCapacityForHost(final Host host, final Map<Long, ServiceOfferingVO> offeringsMap) {
633638
long usedCpuCore = 0;
634639
long reservedCpuCore = 0;
635640
long usedCpu = 0;
@@ -666,6 +671,9 @@ public void updateCapacityForHost(final Host host) {
666671
ramOvercommitRatio = Float.parseFloat(vmDetailRam);
667672
}
668673
ServiceOffering so = offeringsMap.get(vm.getServiceOfferingId());
674+
if (so == null) {
675+
so = _offeringsDao.findByIdIncludingRemoved(vm.getServiceOfferingId());
676+
}
669677
if (so.isDynamic()) {
670678
usedMemory +=
671679
((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.memory.name())) * 1024L * 1024L) / ramOvercommitRatio) *
@@ -705,6 +713,9 @@ public void updateCapacityForHost(final Host host) {
705713
}
706714
ServiceOffering so = offeringsMap.get(vm.getServiceOfferingId());
707715
Map<String, String> vmDetails = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
716+
if (so == null) {
717+
so = _offeringsDao.findByIdIncludingRemoved(vm.getServiceOfferingId());
718+
}
708719
if (so.isDynamic()) {
709720
reservedMemory +=
710721
((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.memory.name())) * 1024L * 1024L) / ramOvercommitRatio) *

server/src/main/java/com/cloud/server/StatsCollector.java

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -687,18 +687,17 @@ protected void runInContext() {
687687
return;
688688
}
689689
// collect the vm disk statistics(total) from hypervisor. added by weizhou, 2013.03.
690-
s_logger.trace("Running VM disk stats ...");
691-
try {
692-
Transaction.execute(new TransactionCallbackNoReturn() {
693-
@Override
694-
public void doInTransactionWithoutResult(TransactionStatus status) {
695-
s_logger.debug("VmDiskStatsTask is running...");
690+
s_logger.debug("VmDiskStatsTask is running...");
696691

697-
SearchCriteria<HostVO> sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance();
698-
sc.addAnd("hypervisorType", SearchCriteria.Op.IN, HypervisorType.KVM, HypervisorType.VMware);
699-
List<HostVO> hosts = _hostDao.search(sc, null);
692+
SearchCriteria<HostVO> sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance();
693+
sc.addAnd("hypervisorType", SearchCriteria.Op.IN, HypervisorType.KVM, HypervisorType.VMware);
694+
List<HostVO> hosts = _hostDao.search(sc, null);
700695

701-
for (HostVO host : hosts) {
696+
for (HostVO host : hosts) {
697+
try {
698+
Transaction.execute(new TransactionCallbackNoReturn() {
699+
@Override
700+
public void doInTransactionWithoutResult(TransactionStatus status) {
702701
List<UserVmVO> vms = _userVmDao.listRunningByHostId(host.getId());
703702
List<Long> vmIds = new ArrayList<Long>();
704703

@@ -709,7 +708,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
709708

710709
HashMap<Long, List<VmDiskStatsEntry>> vmDiskStatsById = _userVmMgr.getVmDiskStatistics(host.getId(), host.getName(), vmIds);
711710
if (vmDiskStatsById == null)
712-
continue;
711+
return;
713712

714713
Set<Long> vmIdSet = vmDiskStatsById.keySet();
715714
for (Long vmId : vmIdSet) {
@@ -796,10 +795,10 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
796795
}
797796
}
798797
}
799-
}
800-
});
801-
} catch (Exception e) {
802-
s_logger.warn("Error while collecting vm disk stats from hosts", e);
798+
});
799+
} catch (Exception e) {
800+
s_logger.warn(String.format("Error while collecting vm disk stats from host %s : ", host.getName()), e);
801+
}
803802
}
804803
}
805804
}
@@ -815,16 +814,16 @@ protected void runInContext() {
815814
return;
816815
}
817816
// collect the vm network statistics(total) from hypervisor
818-
try {
819-
Transaction.execute(new TransactionCallbackNoReturn() {
820-
@Override
821-
public void doInTransactionWithoutResult(TransactionStatus status) {
822-
s_logger.debug("VmNetworkStatsTask is running...");
817+
s_logger.debug("VmNetworkStatsTask is running...");
823818

824-
SearchCriteria<HostVO> sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance();
825-
List<HostVO> hosts = _hostDao.search(sc, null);
819+
SearchCriteria<HostVO> sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance();
820+
List<HostVO> hosts = _hostDao.search(sc, null);
826821

827-
for (HostVO host : hosts) {
822+
for (HostVO host : hosts) {
823+
try {
824+
Transaction.execute(new TransactionCallbackNoReturn() {
825+
@Override
826+
public void doInTransactionWithoutResult(TransactionStatus status) {
828827
List<UserVmVO> vms = _userVmDao.listRunningByHostId(host.getId());
829828
List<Long> vmIds = new ArrayList<Long>();
830829

@@ -835,7 +834,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
835834

836835
HashMap<Long, List<VmNetworkStatsEntry>> vmNetworkStatsById = _userVmMgr.getVmNetworkStatistics(host.getId(), host.getName(), vmIds);
837836
if (vmNetworkStatsById == null)
838-
continue;
837+
return;
839838

840839
Set<Long> vmIdSet = vmNetworkStatsById.keySet();
841840
for (Long vmId : vmIdSet) {
@@ -915,10 +914,10 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
915914
}
916915
}
917916
}
918-
}
919-
});
920-
} catch (Exception e) {
921-
s_logger.warn("Error while collecting vm network stats from hosts", e);
917+
});
918+
} catch (Exception e) {
919+
s_logger.warn(String.format("Error while collecting vm network stats from host %s : ", host.getName()), e);
920+
}
922921
}
923922
}
924923
}

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,12 +2529,16 @@ public UserVm updateVirtualMachine(UpdateVMCmd cmd) throws ResourceUnavailableEx
25292529
final List<String> userBlacklistedSettings = Stream.of(QueryService.UserVMBlacklistedDetails.value().split(","))
25302530
.map(item -> (item).trim())
25312531
.collect(Collectors.toList());
2532+
final List<String> userReadOnlySettings = Stream.of(QueryService.UserVMReadOnlyUIDetails.value().split(","))
2533+
.map(item -> (item).trim())
2534+
.collect(Collectors.toList());
25322535
if (cleanupDetails){
25332536
if (caller != null && caller.getType() == Account.ACCOUNT_TYPE_ADMIN) {
25342537
userVmDetailsDao.removeDetails(id);
25352538
} else {
25362539
for (final UserVmDetailVO detail : userVmDetailsDao.listDetails(id)) {
2537-
if (detail != null && !userBlacklistedSettings.contains(detail.getName())) {
2540+
if (detail != null && !userBlacklistedSettings.contains(detail.getName())
2541+
&& !userReadOnlySettings.contains(detail.getName())) {
25382542
userVmDetailsDao.removeDetail(id, detail.getName());
25392543
}
25402544
}
@@ -2546,15 +2550,18 @@ public UserVm updateVirtualMachine(UpdateVMCmd cmd) throws ResourceUnavailableEx
25462550
}
25472551

25482552
if (caller != null && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
2549-
// Ensure blacklisted detail is not passed by non-root-admin user
2553+
// Ensure blacklisted or read-only detail is not passed by non-root-admin user
25502554
for (final String detailName : details.keySet()) {
25512555
if (userBlacklistedSettings.contains(detailName)) {
25522556
throw new InvalidParameterValueException("You're not allowed to add or edit the restricted setting: " + detailName);
25532557
}
2558+
if (userReadOnlySettings.contains(detailName)) {
2559+
throw new InvalidParameterValueException("You're not allowed to add or edit the read-only setting: " + detailName);
2560+
}
25542561
}
2555-
// Add any hidden/blacklisted detail
2562+
// Add any hidden/blacklisted or read-only detail
25562563
for (final UserVmDetailVO detail : userVmDetailsDao.listDetails(id)) {
2557-
if (userBlacklistedSettings.contains(detail.getName())) {
2564+
if (userBlacklistedSettings.contains(detail.getName()) || userReadOnlySettings.contains(detail.getName())) {
25582565
details.put(detail.getName(), detail.getValue());
25592566
}
25602567
}

setup/bindir/cloud-setup-databases.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ Sql parameters:
179179
***************************************************************
180180
Please run:
181181
182-
cloud-setup-database -h
182+
cloudstack-setup-databases -h
183183
184184
for full help
185185
''' % msg

test/integration/component/test_mm_domain_limits.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def setupAccounts(self):
210210
domainid=self.child_do_admin_2.domainid)
211211
return
212212

213-
@attr(tags=["advanced", "advancedns","simulator"], required_hardware="false")
213+
@attr(tags=["advanced", "advancedns","simulator"], required_hardware="true")
214214
def test_01_change_service_offering(self):
215215
"""Test Deploy VM with specified RAM & verify the usage"""
216216

0 commit comments

Comments
 (0)