Skip to content

Commit 3d8ea4f

Browse files
committed
Merge remote-tracking branch 'origin/4.17'
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2 parents 4abb8b9 + cf32f77 commit 3d8ea4f

File tree

14 files changed

+539
-72
lines changed

14 files changed

+539
-72
lines changed

api/src/main/java/com/cloud/server/ManagementService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ public interface ManagementService {
436436
*/
437437
Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolume(Long volumeId);
438438

439-
Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolumeInternal(Long volumeId, Long newDiskOfferingId, Long newSize, Long newMinIops, Long newMaxIops, boolean keepSourceStoragePool, boolean bypassStorageTypeCheck);
439+
Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForSystemMigrationOfVolume(Long volumeId, Long newDiskOfferingId, Long newSize, Long newMinIops, Long newMaxIops, boolean keepSourceStoragePool, boolean bypassStorageTypeCheck);
440440

441441
String[] listEventTypes();
442442

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) throws
524524
@Override
525525
public void allocate(final String vmInstanceName, final VirtualMachineTemplate template, final ServiceOffering serviceOffering,
526526
final LinkedHashMap<? extends Network, List<? extends NicProfile>> networks, final DeploymentPlan plan, final HypervisorType hyperType) throws InsufficientCapacityException {
527-
DiskOffering diskOffering = _diskOfferingDao.findById(serviceOffering.getId());
527+
DiskOffering diskOffering = _diskOfferingDao.findById(serviceOffering.getDiskOfferingId());
528528
allocate(vmInstanceName, template, serviceOffering, new DiskOfferingInfo(diskOffering), new ArrayList<>(), networks, plan, hyperType, null, null);
529529
}
530530

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3526,7 +3526,7 @@ public HashMap<String, VmStatsEntry> getVmStats(final Connection conn, final Get
35263526
} else if (param.matches("vbd_.*_write")) {
35273527
vmStatsAnswer.setDiskWriteKBs(vmStatsAnswer.getDiskWriteKBs() + getDataAverage(dataNode, col, numRows) / BASE_TO_CONVERT_BYTES_INTO_KILOBYTES);
35283528
} else if (param.contains("memory_internal_free")) {
3529-
vmStatsAnswer.setIntFreeMemoryKBs(vmStatsAnswer.getIntFreeMemoryKBs() + getDataAverage(dataNode, col, numRows) / BASE_TO_CONVERT_BYTES_INTO_KILOBYTES);
3529+
vmStatsAnswer.setIntFreeMemoryKBs(vmStatsAnswer.getIntFreeMemoryKBs() + getDataAverage(dataNode, col, numRows));
35303530
} else if (param.contains("memory_target")) {
35313531
vmStatsAnswer.setTargetMemoryKBs(vmStatsAnswer.getTargetMemoryKBs() + getDataAverage(dataNode, col, numRows) / BASE_TO_CONVERT_BYTES_INTO_KILOBYTES);
35323532
} else if (param.contains("memory")) {

server/src/main/java/com/cloud/acl/DomainChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected DomainChecker() {
120120
*/
121121

122122
private void checkPublicTemplateAccess(VirtualMachineTemplate template, Account owner, Account caller){
123-
if (!QueryService.SharePublicTemplatesWithOtherDomains.valueIn(owner.getDomainId()) ||
123+
if (QueryService.SharePublicTemplatesWithOtherDomains.valueIn(owner.getDomainId()) ||
124124
caller.getDomainId() == owner.getDomainId() ||
125125
_domainDao.isChildDomain(owner.getDomainId(), caller.getDomainId())) {
126126
return;

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,7 @@ private boolean hasSuitablePoolsForVolume(final VolumeVO volume, final Host host
15521552
@Override
15531553
public Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolume(final Long volumeId) {
15541554

1555-
Pair<List<? extends StoragePool>, List<? extends StoragePool>> allPoolsAndSuitablePoolsPair = listStoragePoolsForMigrationOfVolumeInternal(volumeId, null, null, null, null, false, true);
1555+
Pair<List<? extends StoragePool>, List<? extends StoragePool>> allPoolsAndSuitablePoolsPair = listStoragePoolsForMigrationOfVolumeInternal(volumeId, null, null, null, null, false, true, false);
15561556
List<? extends StoragePool> allPools = allPoolsAndSuitablePoolsPair.first();
15571557
List<? extends StoragePool> suitablePools = allPoolsAndSuitablePoolsPair.second();
15581558
List<StoragePool> avoidPools = new ArrayList<>();
@@ -1568,13 +1568,20 @@ public Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStorag
15681568
return new Pair<List<? extends StoragePool>, List<? extends StoragePool>>(allPools, suitablePools);
15691569
}
15701570

1571-
public Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolumeInternal(final Long volumeId, Long newDiskOfferingId, Long newSize, Long newMinIops, Long newMaxIops, boolean keepSourceStoragePool, boolean bypassStorageTypeCheck) {
1572-
final Account caller = getCaller();
1573-
if (!_accountMgr.isRootAdmin(caller.getId())) {
1574-
if (s_logger.isDebugEnabled()) {
1575-
s_logger.debug("Caller is not a root admin, permission denied to migrate the volume");
1571+
@Override
1572+
public Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForSystemMigrationOfVolume(final Long volumeId, Long newDiskOfferingId, Long newSize, Long newMinIops, Long newMaxIops, boolean keepSourceStoragePool, boolean bypassStorageTypeCheck) {
1573+
return listStoragePoolsForMigrationOfVolumeInternal(volumeId, newDiskOfferingId, newSize, newMinIops, newMaxIops, keepSourceStoragePool, bypassStorageTypeCheck, true);
1574+
}
1575+
1576+
public Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolumeInternal(final Long volumeId, Long newDiskOfferingId, Long newSize, Long newMinIops, Long newMaxIops, boolean keepSourceStoragePool, boolean bypassStorageTypeCheck, boolean bypassAccountCheck) {
1577+
if (!bypassAccountCheck) {
1578+
final Account caller = getCaller();
1579+
if (!_accountMgr.isRootAdmin(caller.getId())) {
1580+
if (s_logger.isDebugEnabled()) {
1581+
s_logger.debug("Caller is not a root admin, permission denied to migrate the volume");
1582+
}
1583+
throw new PermissionDeniedException("No permission to migrate volume, only root admin can migrate a volume");
15761584
}
1577-
throw new PermissionDeniedException("No permission to migrate volume, only root admin can migrate a volume");
15781585
}
15791586

15801587
final VolumeVO volume = _volumeDao.findById(volumeId);

server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
import org.apache.cloudstack.utils.volume.VirtualMachineDiskInfo;
9797
import org.apache.commons.collections.CollectionUtils;
9898
import org.apache.commons.collections.MapUtils;
99+
import org.apache.commons.lang3.ObjectUtils;
99100
import org.apache.commons.lang3.StringUtils;
100101
import org.apache.commons.lang3.builder.ToStringBuilder;
101102
import org.apache.commons.lang3.builder.ToStringStyle;
@@ -1803,14 +1804,14 @@ private Volume changeDiskOfferingForVolumeInternal(VolumeVO volume, Long newDisk
18031804
return volume;
18041805
}
18051806

1806-
if (currentSize != newSize || newMaxIops != volume.getMaxIops() || newMinIops != volume.getMinIops()) {
1807+
if (currentSize != newSize || !compareEqualsIncludingNullOrZero(newMaxIops, volume.getMaxIops()) || !compareEqualsIncludingNullOrZero(newMinIops, volume.getMinIops())) {
18071808
volumeResizeRequired = true;
18081809
validateVolumeReadyStateAndHypervisorChecks(volume, currentSize, newSize);
18091810
}
18101811

18111812
StoragePoolVO existingStoragePool = _storagePoolDao.findById(volume.getPoolId());
18121813

1813-
Pair<List<? extends StoragePool>, List<? extends StoragePool>> poolsPair = managementService.listStoragePoolsForMigrationOfVolumeInternal(volume.getId(), newDiskOffering.getId(), newSize, newMinIops, newMaxIops, true, false);
1814+
Pair<List<? extends StoragePool>, List<? extends StoragePool>> poolsPair = managementService.listStoragePoolsForSystemMigrationOfVolume(volume.getId(), newDiskOffering.getId(), newSize, newMinIops, newMaxIops, true, false);
18141815
List<? extends StoragePool> suitableStoragePools = poolsPair.second();
18151816

18161817
if (!suitableStoragePools.stream().anyMatch(p -> (p.getId() == existingStoragePool.getId()))) {
@@ -1859,6 +1860,21 @@ private Volume changeDiskOfferingForVolumeInternal(VolumeVO volume, Long newDisk
18591860
return volume;
18601861
}
18611862

1863+
/**
1864+
* This method is to compare long values, in miniops and maxiops a or b can be null or 0.
1865+
* Use this method to treat 0 and null as same
1866+
*
1867+
* @param a
1868+
* @param b
1869+
* @return true if a and b are equal excluding 0 and null values.
1870+
*/
1871+
private boolean compareEqualsIncludingNullOrZero(Long a, Long b) {
1872+
a = ObjectUtils.defaultIfNull(a, 0L);
1873+
b = ObjectUtils.defaultIfNull(b, 0L);
1874+
1875+
return a.equals(b);
1876+
}
1877+
18621878
/**
18631879
* Returns true if the new disk offering is the same than current offering, and the respective Service offering is a custom (constraint or unconstraint) offering.
18641880
*/

server/src/main/java/com/cloud/tags/TaggedResourceManagerImpl.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,10 @@ public Map<String, String> getTagsFromResource(ResourceObjectType type, long res
318318
private void informStoragePoolForVmTags(long vmId, String key, String value) {
319319
List<VolumeVO> volumeVos = volumeDao.findByInstance(vmId);
320320
for (VolumeVO volume : volumeVos) {
321-
DataStore dataStore = dataStoreMgr.getDataStore(volume.getPoolId(), DataStoreRole.Primary);
321+
Long poolId = volume.getPoolId();
322+
DataStore dataStore = retrieveDatastore(poolId);
322323
if (dataStore == null || !(dataStore.getDriver() instanceof PrimaryDataStoreDriver)) {
324+
s_logger.info(String.format("No data store found for VM %d with pool ID %d.", vmId, poolId));
323325
continue;
324326
}
325327
PrimaryDataStoreDriver dataStoreDriver = (PrimaryDataStoreDriver) dataStore.getDriver();
@@ -328,4 +330,11 @@ private void informStoragePoolForVmTags(long vmId, String key, String value) {
328330
}
329331
}
330332
}
333+
334+
protected DataStore retrieveDatastore(Long poolId) {
335+
if (poolId == null) {
336+
return null;
337+
}
338+
return dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
339+
}
331340
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@
4747
*/
4848
public interface UserVmManager extends UserVmService {
4949
String EnableDynamicallyScaleVmCK = "enable.dynamic.scale.vm";
50+
String AllowDiskOfferingChangeDuringScaleVmCK = "allow.diskoffering.change.during.scale.vm";
5051
String AllowUserExpungeRecoverVmCK ="allow.user.expunge.recover.vm";
5152
ConfigKey<Boolean> EnableDynamicallyScaleVm = new ConfigKey<Boolean>("Advanced", Boolean.class, EnableDynamicallyScaleVmCK, "false",
5253
"Enables/Disables dynamically scaling a vm", true, ConfigKey.Scope.Zone);
54+
ConfigKey<Boolean> AllowDiskOfferingChangeDuringScaleVm = new ConfigKey<Boolean>("Advanced", Boolean.class, AllowDiskOfferingChangeDuringScaleVmCK, "false",
55+
"Determines whether to allow or disallow disk offering change for root volume during scaling of a stopped or running vm", true, ConfigKey.Scope.Zone);
5356
ConfigKey<Boolean> AllowUserExpungeRecoverVm = new ConfigKey<Boolean>("Advanced", Boolean.class, AllowUserExpungeRecoverVmCK, "false",
5457
"Determines whether users can expunge or recover their vm", true, ConfigKey.Scope.Account);
5558
ConfigKey<Boolean> DisplayVMOVFProperties = new ConfigKey<Boolean>("Advanced", Boolean.class, "vm.display.ovf.properties", "false",

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ private UserVm upgradeStoppedVirtualMachine(Long vmId, Long svcOffId, Map<String
12961296

12971297
// resize and migrate the root volume if required
12981298
DiskOfferingVO newDiskOffering = _diskOfferingDao.findById(newServiceOffering.getDiskOfferingId());
1299-
changeDiskOfferingForRootVolume(vmId, newDiskOffering, customParameters);
1299+
changeDiskOfferingForRootVolume(vmId, newDiskOffering, customParameters, vmInstance.getDataCenterId());
13001300

13011301
_itMgr.upgradeVmDb(vmId, newServiceOffering, currentServiceOffering);
13021302

@@ -2066,7 +2066,7 @@ private boolean upgradeRunningVirtualMachine(Long vmId, Long newServiceOfferingI
20662066

20672067
// #3 resize or migrate the root volume if required
20682068
DiskOfferingVO newDiskOffering = _diskOfferingDao.findById(newServiceOffering.getDiskOfferingId());
2069-
changeDiskOfferingForRootVolume(vmId, newDiskOffering, customParameters);
2069+
changeDiskOfferingForRootVolume(vmId, newDiskOffering, customParameters, vmInstance.getDataCenterId());
20702070

20712071
// #4 scale the vm now
20722072
vmInstance = _vmInstanceDao.findById(vmId);
@@ -2109,7 +2109,14 @@ protected void validateDiskOfferingChecks(ServiceOfferingVO currentServiceOfferi
21092109
}
21102110
}
21112111

2112-
private void changeDiskOfferingForRootVolume(Long vmId, DiskOfferingVO newDiskOffering, Map<String, String> customParameters) throws ResourceAllocationException {
2112+
private void changeDiskOfferingForRootVolume(Long vmId, DiskOfferingVO newDiskOffering, Map<String, String> customParameters, Long zoneId) throws ResourceAllocationException {
2113+
2114+
if (!AllowDiskOfferingChangeDuringScaleVm.valueIn(zoneId)) {
2115+
if (s_logger.isDebugEnabled()) {
2116+
s_logger.debug(String.format("Changing the disk offering of the root volume during the compute offering change operation is disabled. Please check the setting [%s].", AllowDiskOfferingChangeDuringScaleVm.key()));
2117+
}
2118+
return;
2119+
}
21132120

21142121
List<VolumeVO> vols = _volsDao.findReadyAndAllocatedRootVolumesByInstance(vmId);
21152122

@@ -7985,7 +7992,7 @@ public String getConfigComponentName() {
79857992

79867993
@Override
79877994
public ConfigKey<?>[] getConfigKeys() {
7988-
return new ConfigKey<?>[] {EnableDynamicallyScaleVm, AllowUserExpungeRecoverVm, VmIpFetchWaitInterval, VmIpFetchTrialMax,
7995+
return new ConfigKey<?>[] {EnableDynamicallyScaleVm, AllowDiskOfferingChangeDuringScaleVm, AllowUserExpungeRecoverVm, VmIpFetchWaitInterval, VmIpFetchTrialMax,
79897996
VmIpFetchThreadPoolMax, VmIpFetchTaskWorkers, AllowDeployVmIfGivenHostFails, EnableAdditionalVmConfig, DisplayVMOVFProperties,
79907997
KvmAdditionalConfigAllowList, XenServerAdditionalConfigAllowList, VmwareAdditionalConfigAllowList};
79917998
}

server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ private UserVm migrateImportedVM(HostVO sourceHost, VirtualMachineTemplate templ
794794
continue;
795795
}
796796
LOGGER.debug(String.format("Volume %s needs to be migrated", volumeVO.getUuid()));
797-
Pair<List<? extends StoragePool>, List<? extends StoragePool>> poolsPair = managementService.listStoragePoolsForMigrationOfVolumeInternal(profile.getVolumeId(), null, null, null, null, false, true);
797+
Pair<List<? extends StoragePool>, List<? extends StoragePool>> poolsPair = managementService.listStoragePoolsForSystemMigrationOfVolume(profile.getVolumeId(), null, null, null, null, false, true);
798798
if (CollectionUtils.isEmpty(poolsPair.first()) && CollectionUtils.isEmpty(poolsPair.second())) {
799799
cleanupFailedImportVM(vm);
800800
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("VM import failed for unmanaged vm: %s during volume ID: %s migration as no suitable pool(s) found", userVm.getInstanceName(), volumeVO.getUuid()));

0 commit comments

Comments
 (0)