Skip to content

Commit 5886780

Browse files
lucas-a-martinsLucas Martins
andauthored
Change vmsnapshot.max config to be dynamic (#9883)
Co-authored-by: Lucas Martins <[email protected]>
1 parent 2c412f8 commit 5886780

File tree

4 files changed

+6
-11
lines changed

4 files changed

+6
-11
lines changed

engine/components-api/src/main/java/com/cloud/vm/snapshot/VMSnapshotManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public interface VMSnapshotManager extends VMSnapshotService, Manager {
3131
static final ConfigKey<Integer> VMSnapshotExpireInterval = new ConfigKey<Integer>("Advanced", Integer.class, "vmsnapshot.expire.interval", "-1",
3232
"VM Snapshot expire interval in hours", true, ConfigKey.Scope.Account);
3333

34-
public static final int VMSNAPSHOTMAX = 10;
34+
ConfigKey<Integer> VMSnapshotMax = new ConfigKey<Integer>("Advanced", Integer.class, "vmsnapshot.max", "10", "Maximum vm snapshots for a single vm", true, ConfigKey.Scope.Global);
3535

3636
/**
3737
* Delete all VM snapshots belonging to one VM

server/src/main/java/com/cloud/configuration/Config.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,6 @@ public enum Config {
17401740
null),
17411741

17421742
// VMSnapshots
1743-
VMSnapshotMax("Advanced", VMSnapshotManager.class, Integer.class, "vmsnapshot.max", "10", "Maximum vm snapshots for a vm", null),
17441743
VMSnapshotCreateWait("Advanced", VMSnapshotManager.class, Integer.class, "vmsnapshot.create.wait", "1800", "In second, timeout for create vm snapshot", null),
17451744

17461745
CloudDnsName("Advanced", ManagementServer.class, String.class, "cloud.dns.name", null, "DNS name of the cloud for the GSLB service", null),

server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ public class VMSnapshotManagerImpl extends MutualExclusiveIdsManagerBase impleme
174174

175175
VmWorkJobHandlerProxy _jobHandlerProxy = new VmWorkJobHandlerProxy(this);
176176

177-
int _vmSnapshotMax;
178177
int _wait;
179178

180179
static final ConfigKey<Long> VmJobCheckInterval = new ConfigKey<Long>("Advanced",
@@ -188,8 +187,6 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
188187
throw new ConfigurationException("Unable to get the configuration dao.");
189188
}
190189

191-
_vmSnapshotMax = NumbersUtil.parseInt(_configDao.getValue("vmsnapshot.max"), VMSNAPSHOTMAX);
192-
193190
String value = _configDao.getValue("vmsnapshot.create.wait");
194191
_wait = NumbersUtil.parseInt(value, 1800);
195192

@@ -398,8 +395,10 @@ public VMSnapshot allocVMSnapshot(Long vmId, String vsDisplayName, String vsDesc
398395
_accountMgr.checkAccess(caller, null, true, userVmVo);
399396

400397
// check max snapshot limit for per VM
401-
if (_vmSnapshotDao.findByVm(vmId).size() >= _vmSnapshotMax) {
402-
throw new CloudRuntimeException("Creating vm snapshot failed due to a VM can just have : " + _vmSnapshotMax + " VM snapshots. Please delete old ones");
398+
int vmSnapshotMax = VMSnapshotManager.VMSnapshotMax.value();
399+
400+
if (_vmSnapshotDao.findByVm(vmId).size() >= vmSnapshotMax) {
401+
throw new CloudRuntimeException("Creating vm snapshot failed due to a VM can just have : " + vmSnapshotMax + " VM snapshots. Please delete old ones");
403402
}
404403

405404
// check if there are active volume snapshots tasks
@@ -1391,6 +1390,6 @@ public String getConfigComponentName() {
13911390

13921391
@Override
13931392
public ConfigKey<?>[] getConfigKeys() {
1394-
return new ConfigKey<?>[] {VMSnapshotExpireInterval};
1393+
return new ConfigKey<?>[] {VMSnapshotExpireInterval, VMSnapshotMax};
13951394
}
13961395
}

server/src/test/java/com/cloud/vm/snapshot/VMSnapshotManagerTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ public class VMSnapshotManagerTest {
136136
VMSnapshotDetailsDao _vmSnapshotDetailsDao;
137137
@Mock
138138
UserVmManager _userVmManager;
139-
int _vmSnapshotMax = 10;
140139

141140
private static final long TEST_VM_ID = 3L;
142141
private static final long SERVICE_OFFERING_ID = 1L;
@@ -194,8 +193,6 @@ public void setup() {
194193

195194
doNothing().when(_accountMgr).checkAccess(any(Account.class), any(AccessType.class), any(Boolean.class), any(ControlledEntity.class));
196195

197-
_vmSnapshotMgr._vmSnapshotMax = _vmSnapshotMax;
198-
199196
_vmSnapshotMgr._serviceOfferingDao = _serviceOfferingDao;
200197
_vmSnapshotMgr._userVmDetailsDao = _userVmDetailsDao;
201198
_vmSnapshotMgr._vmSnapshotDetailsDao = _vmSnapshotDetailsDao;

0 commit comments

Comments
 (0)