Skip to content

Commit f4aa2bc

Browse files
committed
Address review comments
1 parent 410a882 commit f4aa2bc

File tree

25 files changed

+134
-427
lines changed

25 files changed

+134
-427
lines changed

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ public class ApiConstants {
524524
public static final String INSTANCE_LEASE_DURATION = "leaseduration";
525525
public static final String INSTANCE_LEASE_EXPIRY_DATE= "leaseexpirydate";
526526
public static final String INSTANCE_LEASE_EXPIRY_ACTION = "leaseexpiryaction";
527-
public static final String ONLY_LEASED_INSTANCES = "onlyleasedinstances";
527+
public static final String LEASED = "leased";
528528

529529
public static final String USER_DATA_NAME = "userdataname";
530530
public static final String USER_DATA_ID = "userdataid";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public class CreateServiceOfferingCmd extends BaseCmd {
257257
private Long leaseDuration;
258258

259259
@Parameter(name = ApiConstants.INSTANCE_LEASE_EXPIRY_ACTION, type = CommandType.STRING, since = "4.21.0",
260-
description = "Action to be taken on lease expiration, valid values are STOP and DESTROY")
260+
description = "Lease expiry action, valid values are STOP and DESTROY")
261261
private String leaseExpiryAction;
262262

263263
/////////////////////////////////////////////////////

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG
283283
private Long leaseDuration;
284284

285285
@Parameter(name = ApiConstants.INSTANCE_LEASE_EXPIRY_ACTION, type = CommandType.STRING, since = "4.21.0",
286-
description = "Lease expiry action")
286+
description = "Lease expiry action, valid values are STOP and DESTROY")
287287
private String leaseExpiryAction;
288288

289289
/////////////////////////////////////////////////////

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ public class ListVMsCmd extends BaseListRetrieveOnlyResourceCountCmd implements
149149
@Parameter(name = ApiConstants.USER_DATA, type = CommandType.BOOLEAN, description = "Whether to return the VMs' user data or not. By default, user data will not be returned.", since = "4.18.0.0")
150150
private Boolean showUserData;
151151

152-
@Parameter(name = ApiConstants.ONLY_LEASED_INSTANCES, type = CommandType.BOOLEAN,
153-
description = "Whether to return the Leased instances",
152+
@Parameter(name = ApiConstants.LEASED, type = CommandType.BOOLEAN,
153+
description = "Whether to return only leased instances",
154154
since = "4.21.0")
155155
private Boolean onlyLeasedInstances = false;
156156

@@ -328,9 +328,7 @@ protected void updateVMResponse(List<UserVmResponse> response) {
328328
}
329329
}
330330

331-
332331
public Boolean getOnlyLeasedInstances() {
333332
return onlyLeasedInstances;
334333
}
335-
336334
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public class UpdateVMCmd extends BaseCustomIdCmd implements SecurityGroupAction,
159159
private Long leaseDuration;
160160

161161
@Parameter(name = ApiConstants.INSTANCE_LEASE_EXPIRY_ACTION, type = CommandType.STRING, since = "4.21.0",
162-
description = "Lease expiry action")
162+
description = "Lease expiry action, valid values are STOP and DESTROY")
163163
private String leaseExpiryAction;
164164

165165
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/api/response/UserVmResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public class UserVmResponse extends BaseResponseWithTagInformation implements Co
396396
private String vmType;
397397

398398
@SerializedName(ApiConstants.INSTANCE_LEASE_DURATION)
399-
@Param(description = "Instance lease duration", since = "4.21.0")
399+
@Param(description = "Instance lease duration in days", since = "4.21.0")
400400
private Long leaseDuration;
401401

402402
@SerializedName(ApiConstants.INSTANCE_LEASE_EXPIRY_DATE)

engine/schema/src/main/resources/META-INF/db/schema-42010to42100.sql

Lines changed: 0 additions & 312 deletions
Large diffs are not rendered by default.

framework/db/src/main/java/com/cloud/utils/db/SearchBase.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,24 @@ public J and() {
359359
return (J)this;
360360
}
361361

362+
/**
363+
* Adds an AND NOT condition to the search. Normally you should use this to
364+
* perform an 'AND NOT' with a big conditional in parenthesis. For example,
365+
*
366+
* search.andNot().op(entity.getId(), Op.Eq, "abc").cp()
367+
*
368+
* The above fragment produces something similar to
369+
*
370+
* "AND NOT (id = $abc) where abc is the token to be replaced by a value later.
371+
*
372+
* @return this
373+
*/
374+
@SuppressWarnings("unchecked")
375+
public J andNot() {
376+
constructCondition(null, " AND NOT ", null, null);
377+
return (J)this;
378+
}
379+
362380
/**
363381
* Closes a parenthesis that's started by op()
364382
* @return this

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,11 @@ private Pair<List<Long>, Integer> searchForUserVMIdsAndCount(ListVMsCmd cmd) {
13291329
}
13301330
}
13311331

1332+
boolean requestingOnlyLeasedInstances = cmd.getOnlyLeasedInstances() != null && cmd.getOnlyLeasedInstances();
1333+
if (!VMLeaseManagerImpl.InstanceLeaseEnabled.value() && requestingOnlyLeasedInstances) {
1334+
throw new InvalidParameterValueException("Enable lease feature to use leased=true");
1335+
}
1336+
13321337
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(cmd.getDomainId(), cmd.isRecursive(), null);
13331338
accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, listAll, false);
13341339
Long domainId = domainIdRecursiveListProject.first();
@@ -1478,14 +1483,11 @@ private Pair<List<Long>, Integer> searchForUserVMIdsAndCount(ListVMsCmd cmd) {
14781483
userVmSearchBuilder.join("tags", resourceTagSearch, resourceTagSearch.entity().getResourceId(), userVmSearchBuilder.entity().getId(), JoinBuilder.JoinType.INNER);
14791484
}
14801485

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-
}
1486+
if (requestingOnlyLeasedInstances) {
1487+
SearchBuilder<UserVmDetailVO> leasedInstancesSearch = userVmDetailsDao.createSearchBuilder();
1488+
leasedInstancesSearch.and(leasedInstancesSearch.entity().getName(), SearchCriteria.Op.EQ).values(VmDetailConstants.INSTANCE_LEASE_EXPIRY_DATE);
1489+
userVmSearchBuilder.join("userVmToLeased", leasedInstancesSearch, leasedInstancesSearch.entity().getResourceId(),
1490+
userVmSearchBuilder.entity().getId(), JoinBuilder.JoinType.INNER);
14891491
}
14901492

14911493
if (keyPairName != null) {

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
@@ -177,7 +177,7 @@ public ServiceOfferingResponse newServiceOfferingResponse(ServiceOfferingJoinVO
177177
}
178178
}
179179

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

0 commit comments

Comments
 (0)