From 00492c0e7602586ef34a781506ef0dd313e78a57 Mon Sep 17 00:00:00 2001 From: Lucas Martins Date: Wed, 30 Oct 2024 18:36:40 -0300 Subject: [PATCH] Change vmsnapshot.max config to be dynamic --- .../java/com/cloud/vm/snapshot/VMSnapshotManager.java | 2 +- .../src/main/java/com/cloud/configuration/Config.java | 1 - .../com/cloud/vm/snapshot/VMSnapshotManagerImpl.java | 11 +++++------ .../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 82456004cc3c..a01d4ee5cae7 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 VMSnapshotExpireInterval = new ConfigKey("Advanced", Integer.class, "vmsnapshot.expire.interval", "-1", "VM Snapshot expire interval in hours", true, ConfigKey.Scope.Account); - public static final int VMSNAPSHOTMAX = 10; + ConfigKey VMSnapshotMax = new ConfigKey("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 ce3ac7684681..b9de906ba46e 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 @@ public enum Config { 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 cd67c720b49f..2061367cf4d4 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 VmJobCheckInterval = new ConfigKey("Advanced", @@ -188,8 +187,6 @@ public boolean configure(String name, Map params) throws Configu 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 VMSnapshot allocVMSnapshot(Long vmId, String vsDisplayName, String vsDesc _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 String getConfigComponentName() { @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 0ed17fcce76a..440431086eeb 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 void setup() { 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;