This is an automated email from the ASF dual-hosted git repository.
joao pushed a commit to branch 4.20
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.20 by this push:
new 5886780240b Change vmsnapshot.max config to be dynamic (#9883)
5886780240b is described below
commit 5886780240bbb9ee75e805cd750eb192a9126344
Author: Lucas Martins <[email protected]>
AuthorDate: Thu Nov 28 14:49:05 2024 -0300
Change vmsnapshot.max config to be dynamic (#9883)
Co-authored-by: Lucas Martins <[email protected]>
---
.../main/java/com/cloud/vm/snapshot/VMSnapshotManager.java | 2 +-
server/src/main/java/com/cloud/configuration/Config.java | 1 -
.../java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java | 11 +++++------
.../java/com/cloud/vm/snapshot/VMSnapshotManagerTest.java | 3 ---
4 files changed, 6 insertions(+), 11 deletions(-)
diff --git
a/engine/components-api/src/main/java/com/cloud/vm/snapshot/VMSnapshotManager.java
b/engine/components-api/src/main/java/com/cloud/vm/snapshot/VMSnapshotManager.java
index 82456004cc3..a01d4ee5cae 100644
---
a/engine/components-api/src/main/java/com/cloud/vm/snapshot/VMSnapshotManager.java
+++
b/engine/components-api/src/main/java/com/cloud/vm/snapshot/VMSnapshotManager.java
@@ -31,7 +31,7 @@ public interface VMSnapshotManager extends VMSnapshotService,
Manager {
static final ConfigKey<Integer> VMSnapshotExpireInterval = new
ConfigKey<Integer>("Advanced", Integer.class, "vmsnapshot.expire.interval",
"-1",
"VM Snapshot expire interval in hours", true,
ConfigKey.Scope.Account);
- public static final int VMSNAPSHOTMAX = 10;
+ ConfigKey<Integer> VMSnapshotMax = new ConfigKey<Integer>("Advanced",
Integer.class, "vmsnapshot.max", "10", "Maximum vm snapshots for a single vm",
true, ConfigKey.Scope.Global);
/**
* Delete all VM snapshots belonging to one VM
diff --git a/server/src/main/java/com/cloud/configuration/Config.java
b/server/src/main/java/com/cloud/configuration/Config.java
index ce3ac768468..b9de906ba46 100644
--- a/server/src/main/java/com/cloud/configuration/Config.java
+++ b/server/src/main/java/com/cloud/configuration/Config.java
@@ -1740,7 +1740,6 @@ DefaultMaxAccountProjects(
null),
// VMSnapshots
- VMSnapshotMax("Advanced", VMSnapshotManager.class, Integer.class,
"vmsnapshot.max", "10", "Maximum vm snapshots for a vm", null),
VMSnapshotCreateWait("Advanced", VMSnapshotManager.class, Integer.class,
"vmsnapshot.create.wait", "1800", "In second, timeout for create vm snapshot",
null),
CloudDnsName("Advanced", ManagementServer.class, String.class,
"cloud.dns.name", null, "DNS name of the cloud for the GSLB service", null),
diff --git
a/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java
b/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java
index cd67c720b49..2061367cf4d 100644
--- a/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java
+++ b/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java
@@ -174,7 +174,6 @@ public class VMSnapshotManagerImpl extends
MutualExclusiveIdsManagerBase impleme
VmWorkJobHandlerProxy _jobHandlerProxy = new VmWorkJobHandlerProxy(this);
- int _vmSnapshotMax;
int _wait;
static final ConfigKey<Long> VmJobCheckInterval = new
ConfigKey<Long>("Advanced",
@@ -188,8 +187,6 @@ public class VMSnapshotManagerImpl extends
MutualExclusiveIdsManagerBase impleme
throw new ConfigurationException("Unable to get the configuration
dao.");
}
- _vmSnapshotMax =
NumbersUtil.parseInt(_configDao.getValue("vmsnapshot.max"), VMSNAPSHOTMAX);
-
String value = _configDao.getValue("vmsnapshot.create.wait");
_wait = NumbersUtil.parseInt(value, 1800);
@@ -398,8 +395,10 @@ public class VMSnapshotManagerImpl extends
MutualExclusiveIdsManagerBase impleme
_accountMgr.checkAccess(caller, null, true, userVmVo);
// check max snapshot limit for per VM
- if (_vmSnapshotDao.findByVm(vmId).size() >= _vmSnapshotMax) {
- throw new CloudRuntimeException("Creating vm snapshot failed due
to a VM can just have : " + _vmSnapshotMax + " VM snapshots. Please delete old
ones");
+ int vmSnapshotMax = VMSnapshotManager.VMSnapshotMax.value();
+
+ if (_vmSnapshotDao.findByVm(vmId).size() >= vmSnapshotMax) {
+ throw new CloudRuntimeException("Creating vm snapshot failed due
to a VM can just have : " + vmSnapshotMax + " VM snapshots. Please delete old
ones");
}
// check if there are active volume snapshots tasks
@@ -1391,6 +1390,6 @@ public class VMSnapshotManagerImpl extends
MutualExclusiveIdsManagerBase impleme
@Override
public ConfigKey<?>[] getConfigKeys() {
- return new ConfigKey<?>[] {VMSnapshotExpireInterval};
+ return new ConfigKey<?>[] {VMSnapshotExpireInterval, VMSnapshotMax};
}
}
diff --git
a/server/src/test/java/com/cloud/vm/snapshot/VMSnapshotManagerTest.java
b/server/src/test/java/com/cloud/vm/snapshot/VMSnapshotManagerTest.java
index 0ed17fcce76..440431086ee 100644
--- a/server/src/test/java/com/cloud/vm/snapshot/VMSnapshotManagerTest.java
+++ b/server/src/test/java/com/cloud/vm/snapshot/VMSnapshotManagerTest.java
@@ -136,7 +136,6 @@ public class VMSnapshotManagerTest {
VMSnapshotDetailsDao _vmSnapshotDetailsDao;
@Mock
UserVmManager _userVmManager;
- int _vmSnapshotMax = 10;
private static final long TEST_VM_ID = 3L;
private static final long SERVICE_OFFERING_ID = 1L;
@@ -194,8 +193,6 @@ public class VMSnapshotManagerTest {
doNothing().when(_accountMgr).checkAccess(any(Account.class),
any(AccessType.class), any(Boolean.class), any(ControlledEntity.class));
- _vmSnapshotMgr._vmSnapshotMax = _vmSnapshotMax;
-
_vmSnapshotMgr._serviceOfferingDao = _serviceOfferingDao;
_vmSnapshotMgr._userVmDetailsDao = _userVmDetailsDao;
_vmSnapshotMgr._vmSnapshotDetailsDao = _vmSnapshotDetailsDao;