Skip to content

Commit aff544f

Browse files
committed
Added integration test for vm deployment, UI enhancements for user persona, bug fixes
1 parent 7bc5f2a commit aff544f

File tree

18 files changed

+619
-139
lines changed

18 files changed

+619
-139
lines changed

Diff for: api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

+1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ public class ApiConstants {
269269
public static final String INTERNAL_DNS2 = "internaldns2";
270270
public static final String INTERNET_PROTOCOL = "internetprotocol";
271271
public static final String INTERVAL_TYPE = "intervaltype";
272+
public static final String INSTANCE_LEASE_ENABLED = "instanceleaseenabled";
272273
public static final String LOCATION_TYPE = "locationtype";
273274
public static final String IOPS_READ_RATE = "iopsreadrate";
274275
public static final String IOPS_READ_RATE_MAX = "iopsreadratemax";

Diff for: api/src/main/java/org/apache/cloudstack/api/command/user/config/ListCapabilitiesCmd.java

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public void execute() {
7272
response.setInstancesDisksStatsRetentionTime((Integer) capabilities.get(ApiConstants.INSTANCES_DISKS_STATS_RETENTION_TIME));
7373
response.setSharedFsVmMinCpuCount((Integer)capabilities.get(ApiConstants.SHAREDFSVM_MIN_CPU_COUNT));
7474
response.setSharedFsVmMinRamSize((Integer)capabilities.get(ApiConstants.SHAREDFSVM_MIN_RAM_SIZE));
75+
response.setInstanceLeaseEnabled((Boolean) capabilities.get(ApiConstants.INSTANCE_LEASE_ENABLED));
7576
response.setObjectName("capability");
7677
response.setResponseName(getCommandName());
7778
this.setResponseObject(response);

Diff for: api/src/main/java/org/apache/cloudstack/api/response/CapabilitiesResponse.java

+8
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ public class CapabilitiesResponse extends BaseResponse {
136136
@Param(description = "the min Ram size for the service offering used by the shared filesystem instance", since = "4.20.0")
137137
private Integer sharedFsVmMinRamSize;
138138

139+
@SerializedName(ApiConstants.INSTANCE_LEASE_ENABLED)
140+
@Param(description = "true if instance lease feature is enabled", since = "4.21.0")
141+
private Boolean instanceLeaseEnabled;
142+
139143
public void setSecurityGroupsEnabled(boolean securityGroupsEnabled) {
140144
this.securityGroupsEnabled = securityGroupsEnabled;
141145
}
@@ -247,4 +251,8 @@ public void setSharedFsVmMinCpuCount(Integer sharedFsVmMinCpuCount) {
247251
public void setSharedFsVmMinRamSize(Integer sharedFsVmMinRamSize) {
248252
this.sharedFsVmMinRamSize = sharedFsVmMinRamSize;
249253
}
254+
255+
public void setInstanceLeaseEnabled(Boolean instanceLeaseEnabled) {
256+
this.instanceLeaseEnabled = instanceLeaseEnabled;
257+
}
250258
}

Diff for: server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -1478,10 +1478,14 @@ private Pair<List<Long>, Integer> searchForUserVMIdsAndCount(ListVMsCmd cmd) {
14781478
userVmSearchBuilder.join("tags", resourceTagSearch, resourceTagSearch.entity().getResourceId(), userVmSearchBuilder.entity().getId(), JoinBuilder.JoinType.INNER);
14791479
}
14801480

1481-
if (VMLeaseManagerImpl.InstanceLeaseEnabled.value() && cmd.getOnlyLeasedInstances() != null && cmd.getOnlyLeasedInstances()) {
1482-
SearchBuilder<UserVmDetailVO> leasedInstancesSearch = userVmDetailsDao.createSearchBuilder();
1483-
leasedInstancesSearch.and(VmDetailConstants.INSTANCE_LEASE_EXPIRY_DATE, leasedInstancesSearch.entity().getName(), SearchCriteria.Op.NNULL);
1484-
userVmSearchBuilder.join("userVmToLeased", leasedInstancesSearch, leasedInstancesSearch.entity().getResourceId(), userVmSearchBuilder.entity().getId(), JoinBuilder.JoinType.INNER);
1481+
if (cmd.getOnlyLeasedInstances() != null && cmd.getOnlyLeasedInstances()) {
1482+
if (VMLeaseManagerImpl.InstanceLeaseEnabled.value()) {
1483+
SearchBuilder<UserVmDetailVO> leasedInstancesSearch = userVmDetailsDao.createSearchBuilder();
1484+
leasedInstancesSearch.and(leasedInstancesSearch.entity().getName(), SearchCriteria.Op.EQ).values(VmDetailConstants.INSTANCE_LEASE_EXPIRY_DATE);
1485+
userVmSearchBuilder.join("userVmToLeased", leasedInstancesSearch, leasedInstancesSearch.entity().getResourceId(), userVmSearchBuilder.entity().getId(), JoinBuilder.JoinType.INNER);
1486+
} else {
1487+
logger.warn("Lease feature is not enabled, onlyleasedinstances will be considered as false");
1488+
}
14851489
}
14861490

14871491
if (keyPairName != null) {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ public UserVmResponse newUserVmResponse(ResponseView view, String objectName, Us
467467
if (VMLeaseManagerImpl.InstanceLeaseEnabled.value() && userVm.getLeaseExpiryDate() != null) {
468468
userVmResponse.setLeaseExpiryAction(userVm.getLeaseExpiryAction());
469469
userVmResponse.setLeaseExpiryDate(userVm.getLeaseExpiryDate());
470-
long leaseDuration = getLeaseDuration(userVm.getCreated(), userVm.getLeaseExpiryDate());
470+
long leaseDuration = getLeaseDuration(new Date(), userVm.getLeaseExpiryDate());
471471
userVmResponse.setLeaseDuration(leaseDuration);
472472
}
473473

@@ -484,7 +484,7 @@ public UserVmResponse newUserVmResponse(ResponseView view, String objectName, Us
484484
private long getLeaseDuration(Date created, Date leaseExpiryDate) {
485485
LocalDate createdDate = created.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
486486
LocalDate expiryDate = leaseExpiryDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
487-
return ChronoUnit.DAYS.between(createdDate, expiryDate) - 1;
487+
return ChronoUnit.DAYS.between(createdDate, expiryDate);
488488
}
489489

490490
private void addVnfInfoToserVmResponse(UserVmJoinVO userVm, UserVmResponse userVmResponse) {

Diff for: server/src/main/java/com/cloud/server/ManagementServerImpl.java

+2
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@
638638
import org.apache.cloudstack.userdata.UserDataManager;
639639
import org.apache.cloudstack.utils.CloudStackVersion;
640640
import org.apache.cloudstack.utils.identity.ManagementServerNode;
641+
import org.apache.cloudstack.vm.lease.VMLeaseManagerImpl;
641642
import org.apache.commons.codec.binary.Base64;
642643
import org.apache.commons.collections.CollectionUtils;
643644
import org.apache.commons.lang3.StringUtils;
@@ -4496,6 +4497,7 @@ public Map<String, Object> listCapabilities(final ListCapabilitiesCmd cmd) {
44964497
capabilities.put(ApiConstants.INSTANCES_STATS_USER_ONLY, StatsCollector.vmStatsCollectUserVMOnly.value());
44974498
capabilities.put(ApiConstants.INSTANCES_DISKS_STATS_RETENTION_ENABLED, StatsCollector.vmDiskStatsRetentionEnabled.value());
44984499
capabilities.put(ApiConstants.INSTANCES_DISKS_STATS_RETENTION_TIME, StatsCollector.vmDiskStatsMaxRetentionTime.value());
4500+
capabilities.put(ApiConstants.INSTANCE_LEASE_ENABLED, VMLeaseManagerImpl.InstanceLeaseEnabled.value());
44994501
if (apiLimitEnabled) {
45004502
capabilities.put("apiLimitInterval", apiLimitInterval);
45014503
capabilities.put("apiLimitMax", apiLimitMax);

Diff for: server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

-13
Original file line numberDiff line numberDiff line change
@@ -6297,19 +6297,6 @@ protected void validateLeaseProperties(Long leaseDuration, String leaseExpiryAct
62976297
if (!bothValuesSet) {
62986298
throw new InvalidParameterValueException("Provide values for both: leaseduration and leaseexpiryaction");
62996299
}
6300-
6301-
// // at this point any one of them have value, error out
6302-
// if (leaseDuration == null || StringUtils.isEmpty(leaseExpiryAction)) {
6303-
// throw new InvalidParameterValueException("Provide values for both: leaseduration and leaseexpiryaction");
6304-
// }
6305-
//
6306-
// // both params have value
6307-
// if (leaseDuration < -1) {
6308-
// throw new InvalidParameterValueException("Invalid value given for leaseduration, lesser than -1 is not supported ");
6309-
// }
6310-
// if (leaseDuration == -1 ) {
6311-
// return;
6312-
// }
63136300
try {
63146301
VMLeaseManager.ExpiryAction.valueOf(leaseExpiryAction);
63156302
} catch (IllegalArgumentException e) {

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

+10-5
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ protected void runInContext() {
133133
}
134134

135135
protected void alert() {
136+
// as feature is disabled, no action is required
137+
if (!InstanceLeaseEnabled.value()) {
138+
return;
139+
}
140+
136141
List<UserVmJoinVO> leaseExpiringForInstances = userVmJoinDao.listExpiringInstancesInDays(InstanceLeaseAlertStartsAt.value().intValue());
137142
for (UserVmJoinVO instance : leaseExpiringForInstances) {
138143
alertManager.sendAlert(AlertManager.AlertType.ALERT_TYPE_USERVM, instance.getDataCenterId(), instance.getPodId(),
@@ -142,6 +147,11 @@ protected void alert() {
142147

143148
@Override
144149
public void poll(Date currentTimestamp) {
150+
// as feature is disabled, no action is required
151+
if (!InstanceLeaseEnabled.value()) {
152+
return;
153+
}
154+
145155
GlobalLock scanLock = GlobalLock.getInternLock("VMLeaseScheduler");
146156
try {
147157
if (scanLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION)) {
@@ -157,11 +167,6 @@ public void poll(Date currentTimestamp) {
157167
}
158168

159169
protected void reallyRun() {
160-
// as feature is disabled, no action is required
161-
if (!InstanceLeaseEnabled.value()) {
162-
return;
163-
}
164-
165170
// fetch user_instances having leaseDuration configured and has expired
166171
List<UserVmJoinVO> leaseExpiredInstances = userVmJoinDao.listExpiredInstancesIds();
167172
List<Long> actionableInstanceIds = new ArrayList<>();

0 commit comments

Comments
 (0)