Skip to content

Commit 7cd59df

Browse files
committed
move instance.lease.enabled config to VMLeaseManager interface
1 parent aadc305 commit 7cd59df

File tree

8 files changed

+17
-23
lines changed

8 files changed

+17
-23
lines changed

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@
163163
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
164164
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
165165
import org.apache.cloudstack.vm.lease.VMLeaseManager;
166-
import org.apache.cloudstack.vm.lease.VMLeaseManagerImpl;
167166
import org.apache.commons.collections.CollectionUtils;
168167
import org.apache.commons.collections.MapUtils;
169168
import org.apache.commons.lang3.EnumUtils;
@@ -1332,7 +1331,7 @@ private Pair<List<Long>, Integer> searchForUserVMIdsAndCount(ListVMsCmd cmd) {
13321331
}
13331332
}
13341333

1335-
if (!VMLeaseManagerImpl.InstanceLeaseEnabled.value() && cmd.getOnlyLeasedInstances()) {
1334+
if (!VMLeaseManager.InstanceLeaseEnabled.value() && cmd.getOnlyLeasedInstances()) {
13361335
throw new InvalidParameterValueException(" Cannot list leased instances because the Instance Lease feature " +
13371336
"is disabled, please enable it to list leased instances");
13381337
}

server/src/main/java/com/cloud/api/query/dao/ServiceOfferingJoinDaoImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
3434
import org.apache.cloudstack.context.CallContext;
3535
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
36-
import org.apache.cloudstack.vm.lease.VMLeaseManagerImpl;
36+
import org.apache.cloudstack.vm.lease.VMLeaseManager;
3737
import org.apache.commons.lang3.StringUtils;
3838
import org.springframework.stereotype.Component;
3939

@@ -177,7 +177,7 @@ public ServiceOfferingResponse newServiceOfferingResponse(ServiceOfferingJoinVO
177177
}
178178
}
179179

180-
if (VMLeaseManagerImpl.InstanceLeaseEnabled.value() && offering.getLeaseDuration() != null && offering.getLeaseDuration() > 0L) {
180+
if (VMLeaseManager.InstanceLeaseEnabled.value() && offering.getLeaseDuration() != null && offering.getLeaseDuration() > 0L) {
181181
offeringResponse.setLeaseDuration(offering.getLeaseDuration());
182182
offeringResponse.setLeaseExpiryAction(offering.getLeaseExpiryAction());
183183
}

server/src/main/java/com/cloud/api/query/dao/UserVmJoinDaoImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
6969
import org.apache.cloudstack.query.QueryService;
7070
import org.apache.cloudstack.vm.lease.VMLeaseManager;
71-
import org.apache.cloudstack.vm.lease.VMLeaseManagerImpl;
7271
import org.apache.commons.collections.CollectionUtils;
7372
import org.apache.commons.lang3.BooleanUtils;
7473
import org.apache.commons.lang3.StringUtils;
@@ -478,7 +477,7 @@ public UserVmResponse newUserVmResponse(ResponseView view, String objectName, Us
478477
userVmResponse.setUserDataPolicy(userVm.getUserDataPolicy());
479478
}
480479

481-
if (VMLeaseManagerImpl.InstanceLeaseEnabled.value() && userVm.getLeaseExpiryDate() != null &&
480+
if (VMLeaseManager.InstanceLeaseEnabled.value() && userVm.getLeaseExpiryDate() != null &&
482481
VMLeaseManager.LeaseActionExecution.PENDING.name().equals(userVm.getLeaseActionExecution())) {
483482

484483
userVmResponse.setLeaseExpiryAction(userVm.getLeaseExpiryAction());

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@
273273
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
274274
import org.apache.cloudstack.vm.UnmanagedVMsManager;
275275
import org.apache.cloudstack.vm.lease.VMLeaseManager;
276-
import org.apache.cloudstack.vm.lease.VMLeaseManagerImpl;
277276
import org.apache.commons.collections.CollectionUtils;
278277
import org.apache.commons.collections.MapUtils;
279278
import org.apache.commons.lang3.EnumUtils;
@@ -628,7 +627,7 @@ public void onPublishMessage(String serderAddress, String subject, Object args)
628627
params.put(Config.RouterAggregationCommandEachTimeout.toString(), _configDao.getValue(Config.RouterAggregationCommandEachTimeout.toString()));
629628
params.put(Config.MigrateWait.toString(), _configDao.getValue(Config.MigrateWait.toString()));
630629
_agentManager.propagateChangeToAgents(params);
631-
} else if (VMLeaseManagerImpl.InstanceLeaseEnabled.key().equals(globalSettingUpdated)) {
630+
} else if (VMLeaseManager.InstanceLeaseEnabled.key().equals(globalSettingUpdated)) {
632631
vmLeaseManager.onLeaseFeatureToggle();
633632
}
634633
}
@@ -3493,7 +3492,7 @@ protected ServiceOfferingVO createServiceOffering(final long userId, final boole
34933492
* @return leaseExpiryAction
34943493
*/
34953494
public static String validateAndGetLeaseExpiryAction(Integer leaseDuration, String cmdExpiryAction) {
3496-
if (!VMLeaseManagerImpl.InstanceLeaseEnabled.value() || ObjectUtils.allNull(leaseDuration, cmdExpiryAction)) { // both are null
3495+
if (!VMLeaseManager.InstanceLeaseEnabled.value() || ObjectUtils.allNull(leaseDuration, cmdExpiryAction)) { // both are null
34973496
return null;
34983497
}
34993498

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@
639639
import org.apache.cloudstack.userdata.UserDataManager;
640640
import org.apache.cloudstack.utils.CloudStackVersion;
641641
import org.apache.cloudstack.utils.identity.ManagementServerNode;
642-
import org.apache.cloudstack.vm.lease.VMLeaseManagerImpl;
642+
import org.apache.cloudstack.vm.lease.VMLeaseManager;
643643
import org.apache.commons.codec.binary.Base64;
644644
import org.apache.commons.collections.CollectionUtils;
645645
import org.apache.commons.lang3.StringUtils;
@@ -4506,7 +4506,7 @@ public Map<String, Object> listCapabilities(final ListCapabilitiesCmd cmd) {
45064506
capabilities.put(ApiConstants.INSTANCES_STATS_USER_ONLY, StatsCollector.vmStatsCollectUserVMOnly.value());
45074507
capabilities.put(ApiConstants.INSTANCES_DISKS_STATS_RETENTION_ENABLED, StatsCollector.vmDiskStatsRetentionEnabled.value());
45084508
capabilities.put(ApiConstants.INSTANCES_DISKS_STATS_RETENTION_TIME, StatsCollector.vmDiskStatsMaxRetentionTime.value());
4509-
capabilities.put(ApiConstants.INSTANCE_LEASE_ENABLED, VMLeaseManagerImpl.InstanceLeaseEnabled.value());
4509+
capabilities.put(ApiConstants.INSTANCE_LEASE_ENABLED, VMLeaseManager.InstanceLeaseEnabled.value());
45104510
if (apiLimitEnabled) {
45114511
capabilities.put("apiLimitInterval", apiLimitInterval);
45124512
capabilities.put("apiLimitMax", apiLimitMax);

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@
138138
import org.apache.cloudstack.utils.bytescale.ByteScaleUtils;
139139
import org.apache.cloudstack.utils.security.ParserUtils;
140140
import org.apache.cloudstack.vm.lease.VMLeaseManager;
141-
import org.apache.cloudstack.vm.lease.VMLeaseManagerImpl;
142141
import org.apache.cloudstack.vm.schedule.VMScheduleManager;
143142
import org.apache.cloudstack.vm.UnmanagedVMsManager;
144143
import org.apache.commons.collections.CollectionUtils;
@@ -2925,7 +2924,7 @@ public UserVm updateVirtualMachine(UpdateVMCmd cmd) throws ResourceUnavailableEx
29252924
}
29262925
}
29272926

2928-
if (VMLeaseManagerImpl.InstanceLeaseEnabled.value()) {
2927+
if (VMLeaseManager.InstanceLeaseEnabled.value()) {
29292928
applyLeaseOnUpdateInstance(vmInstance, cmd.getLeaseDuration(), cmd.getLeaseExpiryAction());
29302929
}
29312930

@@ -6181,7 +6180,7 @@ public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityE
61816180
}
61826181
}
61836182

6184-
boolean isLeaseFeatureEnabled = VMLeaseManagerImpl.InstanceLeaseEnabled.value();
6183+
boolean isLeaseFeatureEnabled = VMLeaseManager.InstanceLeaseEnabled.value();
61856184
if (isLeaseFeatureEnabled) {
61866185
validateLeaseProperties(cmd.getLeaseDuration(), cmd.getLeaseExpiryAction());
61876186
}

server/src/main/java/org/apache/cloudstack/vm/lease/VMLeaseManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ enum LeaseActionExecution {
3737
CANCELLED
3838
}
3939

40+
ConfigKey<Boolean> InstanceLeaseEnabled = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Boolean.class,
41+
"instance.lease.enabled", "false", "Indicates whether to enable the Instance lease," +
42+
" will be applicable only on instances created after lease is enabled. Disabling the feature cancels lease on existing instances with lease." +
43+
"Re-enabling feature will not cause lease expiry actions on grandfathered instances",
44+
true, List.of(ConfigKey.Scope.Global));
45+
4046
ConfigKey<Long> InstanceLeaseSchedulerInterval = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Long.class,
4147
"instance.lease.scheduler.interval", "3600", "VM Lease Scheduler interval in seconds",
4248
false, List.of(ConfigKey.Scope.Global));

server/src/main/java/org/apache/cloudstack/vm/lease/VMLeaseManagerImpl.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,6 @@
5858
import java.util.concurrent.TimeUnit;
5959

6060
public class VMLeaseManagerImpl extends ManagerBase implements VMLeaseManager, Configurable {
61-
public static final String INSTANCE_LEASE_ENABLED = "instance.lease.enabled";
62-
63-
public static ConfigKey<Boolean> InstanceLeaseEnabled = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Boolean.class,
64-
INSTANCE_LEASE_ENABLED, "false", "Indicates whether to enable the Instance lease," +
65-
" will be applicable only on instances created after lease is enabled. Disabling the feature cancels lease on existing instances with lease." +
66-
"Re-enabling feature will not cause lease expiry actions on grandfathered instances",
67-
true, List.of(ConfigKey.Scope.Global));
68-
6961
private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 5; // 5 seconds
7062

7163
@Inject
@@ -133,7 +125,7 @@ public void cancelLeaseOnExistingInstances() {
133125

134126
@Override
135127
public void onLeaseFeatureToggle() {
136-
boolean isLeaseFeatureEnabled = VMLeaseManagerImpl.InstanceLeaseEnabled.value();
128+
boolean isLeaseFeatureEnabled = VMLeaseManager.InstanceLeaseEnabled.value();
137129
if (isLeaseFeatureEnabled) {
138130
scheduleLeaseExecutors();
139131
} else {

0 commit comments

Comments
 (0)