Skip to content

Commit 4715dc6

Browse files
lucas-a-martinsLucas Martins
authored andcommitted
Change vmsnapshot.max config to be dynamic (apache#9883)
Co-authored-by: Lucas Martins <[email protected]>
1 parent 813f9bf commit 4715dc6

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
@@ -1765,7 +1765,6 @@ public enum Config {
17651765
null),
17661766

17671767
// VMSnapshots
1768-
VMSnapshotMax("Advanced", VMSnapshotManager.class, Integer.class, "vmsnapshot.max", "10", "Maximum vm snapshots for a vm", null),
17691768
VMSnapshotCreateWait("Advanced", VMSnapshotManager.class, Integer.class, "vmsnapshot.create.wait", "1800", "In second, timeout for create vm snapshot", null),
17701769

17711770
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
@@ -178,7 +178,6 @@ public class VMSnapshotManagerImpl extends MutualExclusiveIdsManagerBase impleme
178178

179179
VmWorkJobHandlerProxy _jobHandlerProxy = new VmWorkJobHandlerProxy(this);
180180

181-
int _vmSnapshotMax;
182181
int _wait;
183182

184183
static final ConfigKey<Long> VmJobCheckInterval = new ConfigKey<Long>("Advanced",
@@ -192,8 +191,6 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
192191
throw new ConfigurationException("Unable to get the configuration dao.");
193192
}
194193

195-
_vmSnapshotMax = NumbersUtil.parseInt(_configDao.getValue("vmsnapshot.max"), VMSNAPSHOTMAX);
196-
197194
String value = _configDao.getValue("vmsnapshot.create.wait");
198195
_wait = NumbersUtil.parseInt(value, 1800);
199196

@@ -403,8 +400,10 @@ public VMSnapshot allocVMSnapshot(Long vmId, String vsDisplayName, String vsDesc
403400
_accountMgr.checkAccess(caller, null, true, userVmVo);
404401

405402
// check max snapshot limit for per VM
406-
if (_vmSnapshotDao.findByVm(vmId).size() >= _vmSnapshotMax) {
407-
throw new CloudRuntimeException("Creating vm snapshot failed due to a VM can just have : " + _vmSnapshotMax + " VM snapshots. Please delete old ones");
403+
int vmSnapshotMax = VMSnapshotManager.VMSnapshotMax.value();
404+
405+
if (_vmSnapshotDao.findByVm(vmId).size() >= vmSnapshotMax) {
406+
throw new CloudRuntimeException("Creating vm snapshot failed due to a VM can just have : " + vmSnapshotMax + " VM snapshots. Please delete old ones");
408407
}
409408

410409
// check if there are active volume snapshots tasks
@@ -1400,6 +1399,6 @@ public String getConfigComponentName() {
14001399

14011400
@Override
14021401
public ConfigKey<?>[] getConfigKeys() {
1403-
return new ConfigKey<?>[] {VMSnapshotExpireInterval};
1402+
return new ConfigKey<?>[] {VMSnapshotExpireInterval, VMSnapshotMax};
14041403
}
14051404
}

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)