Skip to content

Commit d9e7f86

Browse files
committed
handle review comments
1 parent 785dbf4 commit d9e7f86

File tree

13 files changed

+95
-99
lines changed

13 files changed

+95
-99
lines changed

api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
import org.apache.cloudstack.api.response.VsphereStoragePoliciesResponse;
3535
import org.apache.cloudstack.api.response.ZoneResponse;
3636
import org.apache.cloudstack.api.response.DiskOfferingResponse;
37+
import org.apache.cloudstack.vm.lease.VMLeaseManager;
3738
import org.apache.commons.collections.MapUtils;
39+
import org.apache.commons.lang3.EnumUtils;
3840
import org.apache.commons.lang3.StringUtils;
3941
import org.apache.commons.collections.CollectionUtils;
4042

@@ -495,8 +497,16 @@ public boolean getEncryptRoot() {
495497
return false;
496498
}
497499

498-
public String getLeaseExpiryAction() {
499-
return leaseExpiryAction;
500+
public VMLeaseManager.ExpiryAction getLeaseExpiryAction() {
501+
if (StringUtils.isEmpty(leaseExpiryAction)) {
502+
return null;
503+
}
504+
VMLeaseManager.ExpiryAction action = EnumUtils.getEnumIgnoreCase(VMLeaseManager.ExpiryAction.class, leaseExpiryAction);
505+
if (action == null) {
506+
throw new InvalidParameterValueException("Invalid value configured for leaseexpiryaction, valid values are: " +
507+
com.cloud.utils.EnumUtils.listValues(VMLeaseManager.ExpiryAction.values()));
508+
}
509+
return action;
500510
}
501511

502512
public Integer getLeaseDuration() {

api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@
6060
import org.apache.cloudstack.api.response.UserVmResponse;
6161
import org.apache.cloudstack.api.response.ZoneResponse;
6262
import org.apache.cloudstack.context.CallContext;
63+
import org.apache.cloudstack.vm.lease.VMLeaseManager;
6364
import org.apache.commons.collections.CollectionUtils;
6465
import org.apache.commons.collections.MapUtils;
6566
import org.apache.commons.lang3.BooleanUtils;
67+
import org.apache.commons.lang3.EnumUtils;
6668
import org.apache.commons.lang3.StringUtils;
6769

6870
import javax.annotation.Nonnull;
@@ -485,8 +487,16 @@ public Integer getLeaseDuration() {
485487
return leaseDuration;
486488
}
487489

488-
public String getLeaseExpiryAction() {
489-
return leaseExpiryAction;
490+
public VMLeaseManager.ExpiryAction getLeaseExpiryAction() {
491+
if (StringUtils.isEmpty(leaseExpiryAction)) {
492+
return null;
493+
}
494+
VMLeaseManager.ExpiryAction action = EnumUtils.getEnumIgnoreCase(VMLeaseManager.ExpiryAction.class, leaseExpiryAction);
495+
if (action == null) {
496+
throw new InvalidParameterValueException("Invalid value configured for leaseexpiryaction, valid values are: " +
497+
com.cloud.utils.EnumUtils.listValues(VMLeaseManager.ExpiryAction.values()));
498+
}
499+
return action;
490500
}
491501

492502
public List<Long> getNetworkIds() {

api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.cloudstack.api.command.user.vm;
1818

1919
import com.cloud.exception.InsufficientCapacityException;
20+
import com.cloud.exception.InvalidParameterValueException;
2021
import com.cloud.exception.ResourceUnavailableException;
2122
import com.cloud.user.Account;
2223
import com.cloud.uservm.UserVm;
@@ -41,6 +42,9 @@
4142
import org.apache.cloudstack.api.response.UserDataResponse;
4243
import org.apache.cloudstack.api.response.UserVmResponse;
4344
import org.apache.cloudstack.context.CallContext;
45+
import org.apache.cloudstack.vm.lease.VMLeaseManager;
46+
import org.apache.commons.lang3.EnumUtils;
47+
import org.apache.commons.lang3.StringUtils;
4448

4549
import java.util.Collection;
4650
import java.util.HashMap;
@@ -334,8 +338,16 @@ public Integer getLeaseDuration() {
334338
return leaseDuration;
335339
}
336340

337-
public String getLeaseExpiryAction() {
338-
return leaseExpiryAction;
341+
public VMLeaseManager.ExpiryAction getLeaseExpiryAction() {
342+
if (StringUtils.isEmpty(leaseExpiryAction)) {
343+
return null;
344+
}
345+
VMLeaseManager.ExpiryAction action = EnumUtils.getEnumIgnoreCase(VMLeaseManager.ExpiryAction.class, leaseExpiryAction);
346+
if (action == null) {
347+
throw new InvalidParameterValueException("Invalid value configured for leaseexpiryaction, valid values are: " +
348+
com.cloud.utils.EnumUtils.listValues(VMLeaseManager.ExpiryAction.values()));
349+
}
350+
return action;
339351
}
340352

341353
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.cloudstack.vm.lease;
2020

2121
import com.cloud.utils.component.Manager;
22-
import com.google.common.annotations.VisibleForTesting;
2322
import org.apache.cloudstack.framework.config.ConfigKey;
2423

2524
import java.util.List;
@@ -30,9 +29,7 @@ public interface VMLeaseManager extends Manager {
3029

3130
enum ExpiryAction {
3231
STOP,
33-
DESTROY,
34-
@VisibleForTesting
35-
UNKNOWN
32+
DESTROY
3633
}
3734

3835
enum LeaseActionExecution {
@@ -44,8 +41,8 @@ enum LeaseActionExecution {
4441

4542
ConfigKey<Boolean> InstanceLeaseEnabled = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Boolean.class,
4643
"instance.lease.enabled", "false", "Indicates whether to enable the Instance lease," +
47-
" will be applicable only on instances created after lease is enabled. Disabling the feature cancels lease on existing instances with lease. " +
48-
"Re-enabling feature will not cause lease expiry actions on grandfathered instances",
44+
" will be applicable only on instances created after lease is enabled. Disabling the feature cancels lease on existing instances with lease." +
45+
" Re-enabling feature will not cause lease expiry actions on grandfathered instances",
4946
true, List.of(ConfigKey.Scope.Global));
5047

5148
ConfigKey<Integer> InstanceLeaseSchedulerInterval = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Integer.class,

api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmdTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.cloudstack.api.command.admin.offering;
1919

20+
import com.cloud.exception.InvalidParameterValueException;
21+
import org.apache.cloudstack.vm.lease.VMLeaseManager;
2022
import org.junit.Assert;
2123
import org.junit.Test;
2224
import org.junit.runner.RunWith;
@@ -65,9 +67,15 @@ public void testGetLeaseDuration() {
6567
@Test
6668
public void testGetLeaseExpiryAction() {
6769
ReflectionTestUtils.setField(createServiceOfferingCmd, "leaseExpiryAction", "stop");
68-
Assert.assertEquals("stop", createServiceOfferingCmd.getLeaseExpiryAction());
70+
Assert.assertEquals(VMLeaseManager.ExpiryAction.STOP, createServiceOfferingCmd.getLeaseExpiryAction());
6971

7072
ReflectionTestUtils.setField(createServiceOfferingCmd, "leaseExpiryAction", "DESTROY");
71-
Assert.assertEquals("DESTROY", createServiceOfferingCmd.getLeaseExpiryAction());
73+
Assert.assertEquals(VMLeaseManager.ExpiryAction.DESTROY, createServiceOfferingCmd.getLeaseExpiryAction());
74+
}
75+
76+
@Test(expected = InvalidParameterValueException.class)
77+
public void testGetLeaseExpiryActionInvalidValue() {
78+
ReflectionTestUtils.setField(createServiceOfferingCmd, "leaseExpiryAction", "Unknown");
79+
Assert.assertEquals(null, createServiceOfferingCmd.getLeaseExpiryAction());
7280
}
7381
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public ServiceOfferingResponse newServiceOfferingResponse(ServiceOfferingJoinVO
179179

180180
if (VMLeaseManager.InstanceLeaseEnabled.value() && offering.getLeaseDuration() != null && offering.getLeaseDuration() > 0L) {
181181
offeringResponse.setLeaseDuration(offering.getLeaseDuration());
182-
offeringResponse.setLeaseExpiryAction(offering.getLeaseExpiryAction());
182+
offeringResponse.setLeaseExpiryAction(offering.getLeaseExpiryAction().name());
183183
}
184184

185185
long rootDiskSizeInGb = (long) offering.getRootDiskSize() / GB_TO_BYTES;

server/src/main/java/com/cloud/api/query/vo/ServiceOfferingJoinVO.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.cloud.utils.db.GenericDao;
2222
import org.apache.cloudstack.api.Identity;
2323
import org.apache.cloudstack.api.InternalIdentity;
24+
import org.apache.cloudstack.vm.lease.VMLeaseManager;
2425

2526
import javax.persistence.Column;
2627
import javax.persistence.Entity;
@@ -223,7 +224,8 @@ public class ServiceOfferingJoinVO extends BaseViewVO implements InternalIdentit
223224
private Integer leaseDuration;
224225

225226
@Column(name = "lease_expiry_action")
226-
private String leaseExpiryAction;
227+
@Enumerated(value = EnumType.STRING)
228+
private VMLeaseManager.ExpiryAction leaseExpiryAction;
227229

228230
public ServiceOfferingJoinVO() {
229231
}
@@ -468,7 +470,7 @@ public Integer getLeaseDuration() {
468470
return leaseDuration;
469471
}
470472

471-
public String getLeaseExpiryAction() {
473+
public VMLeaseManager.ExpiryAction getLeaseExpiryAction() {
472474
return leaseExpiryAction;
473475
}
474476
}

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3340,7 +3340,7 @@ public ServiceOffering createServiceOffering(final CreateServiceOfferingCmd cmd)
33403340

33413341
// validate lease properties and set leaseExpiryAction
33423342
Integer leaseDuration = cmd.getLeaseDuration();
3343-
String leaseExpiryAction = validateAndGetLeaseExpiryAction(leaseDuration, cmd.getLeaseExpiryAction());
3343+
VMLeaseManager.ExpiryAction leaseExpiryAction = validateAndGetLeaseExpiryAction(leaseDuration, cmd.getLeaseExpiryAction());
33443344

33453345
return createServiceOffering(userId, cmd.isSystem(), vmType, cmd.getServiceOfferingName(), cpuNumber, memory, cpuSpeed, cmd.getDisplayText(),
33463346
cmd.getProvisioningType(), localStorageRequired, offerHA, limitCpuUse, volatileVm, cmd.getTags(), cmd.getDomainIds(), cmd.getZoneIds(), cmd.getHostTag(),
@@ -3363,7 +3363,7 @@ protected ServiceOfferingVO createServiceOffering(final long userId, final boole
33633363
Long iopsWriteRate, Long iopsWriteRateMax, Long iopsWriteRateMaxLength,
33643364
final Integer hypervisorSnapshotReserve, String cacheMode, final Long storagePolicyID,
33653365
final boolean dynamicScalingEnabled, final Long diskOfferingId, final boolean diskOfferingStrictness,
3366-
final boolean isCustomized, final boolean encryptRoot, final boolean purgeResources, Integer leaseDuration, String leaseExpiryAction) {
3366+
final boolean isCustomized, final boolean encryptRoot, final boolean purgeResources, Integer leaseDuration, VMLeaseManager.ExpiryAction leaseExpiryAction) {
33673367

33683368
// Filter child domains when both parent and child domains are present
33693369
List<Long> filteredDomainIds = filterChildSubDomains(domainIds);
@@ -3471,9 +3471,9 @@ protected ServiceOfferingVO createServiceOffering(final long userId, final boole
34713471

34723472
if ((serviceOffering = _serviceOfferingDao.persist(serviceOffering)) != null) {
34733473
//persist lease properties if leaseExpiryAction is valid
3474-
if (StringUtils.isNotEmpty(leaseExpiryAction)) {
3474+
if (leaseExpiryAction != null) {
34753475
detailsVOList.add(new ServiceOfferingDetailsVO(serviceOffering.getId(), ApiConstants.INSTANCE_LEASE_DURATION, String.valueOf(leaseDuration), false));
3476-
detailsVOList.add(new ServiceOfferingDetailsVO(serviceOffering.getId(), ApiConstants.INSTANCE_LEASE_EXPIRY_ACTION, leaseExpiryAction, false));
3476+
detailsVOList.add(new ServiceOfferingDetailsVO(serviceOffering.getId(), ApiConstants.INSTANCE_LEASE_EXPIRY_ACTION, leaseExpiryAction.name(), false));
34773477
}
34783478

34793479
for (Long domainId : filteredDomainIds) {
@@ -3507,29 +3507,21 @@ protected ServiceOfferingVO createServiceOffering(final long userId, final boole
35073507
* @param cmdExpiryAction
35083508
* @return leaseExpiryAction
35093509
*/
3510-
public static String validateAndGetLeaseExpiryAction(Integer leaseDuration, String cmdExpiryAction) {
3510+
public static VMLeaseManager.ExpiryAction validateAndGetLeaseExpiryAction(Integer leaseDuration, VMLeaseManager.ExpiryAction cmdExpiryAction) {
35113511
if (!VMLeaseManager.InstanceLeaseEnabled.value() || ObjectUtils.allNull(leaseDuration, cmdExpiryAction)) { // both are null
35123512
return null;
35133513
}
35143514

35153515
// one of them is non-null
3516-
if (leaseDuration == null || StringUtils.isEmpty(cmdExpiryAction)) {
3516+
if (ObjectUtils.anyNull(leaseDuration, cmdExpiryAction)) {
35173517
throw new InvalidParameterValueException("Provide values for both: leaseduration and leaseexpiryaction");
35183518
}
35193519

35203520
if (leaseDuration < 1L || leaseDuration > VMLeaseManager.MAX_LEASE_DURATION_DAYS) {
35213521
throw new InvalidParameterValueException("Invalid leaseduration: must be a natural number (>=1), max supported value is 36500");
35223522
}
35233523

3524-
if (StringUtils.isNotEmpty(cmdExpiryAction)) {
3525-
try {
3526-
VMLeaseManager.ExpiryAction.valueOf(cmdExpiryAction);
3527-
} catch (IllegalArgumentException e) {
3528-
throw new InvalidParameterValueException("Invalid value configured for leaseexpiryaction, valid values are: " +
3529-
com.cloud.utils.EnumUtils.listValues(VMLeaseManager.ExpiryAction.values()));
3530-
}
3531-
}
3532-
return cmdExpiryAction.toUpperCase();
3524+
return cmdExpiryAction;
35333525
}
35343526

35353527
@Override

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@
148148
import org.apache.commons.lang3.StringUtils;
149149
import org.apache.commons.lang3.builder.ToStringBuilder;
150150
import org.apache.commons.lang3.builder.ToStringStyle;
151-
import org.apache.logging.log4j.util.Strings;
152151
import org.jetbrains.annotations.NotNull;
153152
import org.jetbrains.annotations.Nullable;
154153
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@@ -358,7 +357,6 @@
358357
import com.cloud.user.dao.VmDiskStatisticsDao;
359358
import com.cloud.uservm.UserVm;
360359
import com.cloud.utils.DateUtil;
361-
import com.cloud.utils.EnumUtils;
362360
import com.cloud.utils.Journal;
363361
import com.cloud.utils.NumbersUtil;
364362
import com.cloud.utils.Pair;
@@ -6294,7 +6292,7 @@ public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityE
62946292
return vm;
62956293
}
62966294

6297-
protected void validateLeaseProperties(Integer leaseDuration, String leaseExpiryAction) {
6295+
protected void validateLeaseProperties(Integer leaseDuration, VMLeaseManager.ExpiryAction leaseExpiryAction) {
62986296
if (ObjectUtils.allNull(leaseDuration, leaseExpiryAction) // both are null
62996297
|| (leaseDuration != null && leaseDuration == -1)) { // special condition to disable lease for instance
63006298
return;
@@ -6306,16 +6304,9 @@ protected void validateLeaseProperties(Integer leaseDuration, String leaseExpiry
63066304
throw new InvalidParameterValueException("Invalid leaseduration: must be a natural number (>=1) or -1, max supported value is 36500");
63076305
}
63086306

6309-
if (StringUtils.isEmpty(leaseExpiryAction)) {
6307+
if (leaseExpiryAction == null) {
63106308
throw new InvalidParameterValueException("Provide values for both: leaseduration and leaseexpiryaction");
63116309
}
6312-
6313-
try {
6314-
VMLeaseManager.ExpiryAction.valueOf(leaseExpiryAction);
6315-
} catch (IllegalArgumentException e) {
6316-
throw new InvalidParameterValueException("Invalid value provided for leaseexpiryaction, valid values are: " +
6317-
EnumUtils.listValues(VMLeaseManager.ExpiryAction.values()));
6318-
}
63196310
}
63206311

63216312
/**
@@ -6327,19 +6318,22 @@ protected void validateLeaseProperties(Integer leaseDuration, String leaseExpiry
63276318
* @param leaseExpiryAction
63286319
* @param serviceOfferingJoinVO
63296320
*/
6330-
void applyLeaseOnCreateInstance(UserVm vm, Integer leaseDuration, String leaseExpiryAction, ServiceOfferingJoinVO serviceOfferingJoinVO) {
6321+
void applyLeaseOnCreateInstance(UserVm vm, Integer leaseDuration, VMLeaseManager.ExpiryAction leaseExpiryAction, ServiceOfferingJoinVO serviceOfferingJoinVO) {
63316322
if (leaseDuration == null) {
63326323
leaseDuration = serviceOfferingJoinVO.getLeaseDuration();
63336324
}
63346325
// if leaseDuration is null or < 1, instance will never expire, nothing to be done
63356326
if (leaseDuration == null || leaseDuration < 1) {
63366327
return;
63376328
}
6338-
leaseExpiryAction = Strings.isNotEmpty(leaseExpiryAction) ? leaseExpiryAction : serviceOfferingJoinVO.getLeaseExpiryAction();
6329+
leaseExpiryAction = leaseExpiryAction != null ? leaseExpiryAction : serviceOfferingJoinVO.getLeaseExpiryAction();
6330+
if (leaseExpiryAction == null) {
6331+
return;
6332+
}
63396333
addLeaseDetailsForInstance(vm, leaseDuration, leaseExpiryAction);
63406334
}
63416335

6342-
protected void applyLeaseOnUpdateInstance(UserVm instance, Integer leaseDuration, String leaseExpiryAction) {
6336+
protected void applyLeaseOnUpdateInstance(UserVm instance, Integer leaseDuration, VMLeaseManager.ExpiryAction leaseExpiryAction) {
63436337
validateLeaseProperties(leaseDuration, leaseExpiryAction);
63446338
String instanceUuid = instance.getUuid();
63456339

@@ -6386,8 +6380,8 @@ protected void applyLeaseOnUpdateInstance(UserVm instance, Integer leaseDuration
63866380
addLeaseDetailsForInstance(instance, leaseDuration, leaseExpiryAction);
63876381
}
63886382

6389-
protected void addLeaseDetailsForInstance(UserVm vm, Integer leaseDuration, String leaseExpiryAction) {
6390-
if (ObjectUtils.anyNull(vm, leaseDuration) || leaseDuration < 1 || !Arrays.asList("STOP", "DESTROY").contains(leaseExpiryAction)) {
6383+
protected void addLeaseDetailsForInstance(UserVm vm, Integer leaseDuration, VMLeaseManager.ExpiryAction leaseExpiryAction) {
6384+
if (ObjectUtils.anyNull(vm, leaseDuration) || leaseDuration < 1) {
63916385
logger.debug("Lease can't be applied for given vm: {}, leaseduration: {} and leaseexpiryaction: {}", vm, leaseDuration, leaseExpiryAction);
63926386
return;
63936387
}
@@ -6398,7 +6392,7 @@ protected void addLeaseDetailsForInstance(UserVm vm, Integer leaseDuration, Stri
63986392
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
63996393
String formattedLeaseExpiryDate = sdf.format(leaseExpiryDate);
64006394
userVmDetailsDao.addDetail(vm.getId(), VmDetailConstants.INSTANCE_LEASE_EXPIRY_DATE, formattedLeaseExpiryDate, false);
6401-
userVmDetailsDao.addDetail(vm.getId(), VmDetailConstants.INSTANCE_LEASE_EXPIRY_ACTION, leaseExpiryAction, false);
6395+
userVmDetailsDao.addDetail(vm.getId(), VmDetailConstants.INSTANCE_LEASE_EXPIRY_ACTION, leaseExpiryAction.name(), false);
64026396
userVmDetailsDao.addDetail(vm.getId(), VmDetailConstants.INSTANCE_LEASE_EXECUTION, "PENDING", false);
64036397
logger.debug("Instance lease for instanceId: {} is configured to expire on: {} with action: {}", vm.getUuid(), formattedLeaseExpiryDate, leaseExpiryAction);
64046398
}

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import com.cloud.user.User;
2828
import com.cloud.utils.DateUtil;
2929
import com.cloud.utils.Pair;
30-
import com.cloud.utils.StringUtils;
3130
import com.cloud.utils.component.ComponentContext;
3231
import com.cloud.utils.component.ManagerBase;
3332
import com.cloud.utils.concurrency.NamedThreadFactory;
@@ -50,6 +49,7 @@
5049
import org.apache.cloudstack.framework.messagebus.MessageSubscriber;
5150
import org.apache.cloudstack.jobs.JobInfo;
5251
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
52+
import org.apache.commons.lang3.EnumUtils;
5353
import org.apache.commons.lang3.time.DateUtils;
5454

5555
import javax.inject.Inject;
@@ -167,7 +167,7 @@ private void scheduleLeaseExecutors() {
167167

168168
private void shutDownLeaseExecutors() {
169169
if (vmLeaseExecutor != null) {
170-
logger.debug("Shutting down lease executor");
170+
logger.debug("Shutting down lease executor");
171171
vmLeaseExecutor.shutdown();
172172
vmLeaseExecutor = null;
173173
}
@@ -334,18 +334,7 @@ long executeDestroyInstanceJob(UserVmJoinVO vm, long eventId) {
334334
}
335335

336336
public ExpiryAction getLeaseExpiryAction(UserVmJoinVO instance) {
337-
String action = instance.getLeaseExpiryAction();
338-
if (StringUtils.isEmpty(action)) {
339-
return null;
340-
}
341-
342-
ExpiryAction expiryAction = null;
343-
try {
344-
expiryAction = ExpiryAction.valueOf(action);
345-
} catch (Exception ex) {
346-
logger.error("Invalid expiry action configured for instance: {} (id: {})", instance.getName(), instance.getUuid(), ex);
347-
}
348-
return expiryAction;
337+
return EnumUtils.getEnumIgnoreCase(VMLeaseManager.ExpiryAction.class, instance.getLeaseExpiryAction());
349338
}
350339

351340
private void addLeaseExpiryListener() {

0 commit comments

Comments
 (0)