Skip to content

Commit e886cb2

Browse files
committed
Incorporate following changes:
1. Execute lease action once on the instance 2. Cancel lease on instance when feature is disabled 3. Relevant events when lease gets disabled, cancelled, executed 4. Disable associating lease after deployment 5. UI elements and flow changes 6. Changes based on feedback from demo
1 parent bd10721 commit e886cb2

File tree

35 files changed

+511
-433
lines changed

35 files changed

+511
-433
lines changed

Diff for: .github/workflows/ci.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ jobs:
164164
component/test_cpu_limits
165165
component/test_cpu_max_limits
166166
component/test_cpu_project_limits
167-
component/test_deploy_vm_userdata_multi_nic",
167+
component/test_deploy_vm_userdata_multi_nic
168+
component/test_deploy_vm_lease",
168169
"component/test_egress_fw_rules
169170
component/test_invalid_gw_nm
170171
component/test_ip_reservation",

Diff for: api/src/main/java/com/cloud/event/EventTypes.java

+11
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,11 @@ public class EventTypes {
788788
// Resource Limit
789789
public static final String EVENT_RESOURCE_LIMIT_UPDATE = "RESOURCE.LIMIT.UPDATE";
790790

791+
public static final String VM_LEASE_EXPIRED = "VM.LEASE.EXPIRED";
792+
public static final String VM_LEASE_DISABLED = "VM.LEASE.DISABLED";
793+
public static final String VM_LEASE_CANCELLED = "VM.LEASE.CANCELLED";
794+
public static final String VM_LEASE_EXPIRING = "VM.LEASE.EXPIRING";
795+
791796
static {
792797

793798
// TODO: need a way to force author adding event types to declare the entity details as well, with out braking
@@ -1276,6 +1281,12 @@ public class EventTypes {
12761281
entityEventDetails.put(EVENT_SHAREDFS_DESTROY, SharedFS.class);
12771282
entityEventDetails.put(EVENT_SHAREDFS_EXPUNGE, SharedFS.class);
12781283
entityEventDetails.put(EVENT_SHAREDFS_RECOVER, SharedFS.class);
1284+
1285+
// VM Lease
1286+
entityEventDetails.put(VM_LEASE_EXPIRED, VirtualMachine.class);
1287+
entityEventDetails.put(VM_LEASE_EXPIRING, VirtualMachine.class);
1288+
entityEventDetails.put(VM_LEASE_DISABLED, VirtualMachine.class);
1289+
entityEventDetails.put(VM_LEASE_CANCELLED, VirtualMachine.class);
12791290
}
12801291

12811292
public static boolean isNetworkEvent(String eventType) {

Diff for: api/src/main/java/com/cloud/vm/VmDetailConstants.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,5 @@ public interface VmDetailConstants {
104104

105105
String INSTANCE_LEASE_EXPIRY_DATE = "leaseexpirydate";
106106
String INSTANCE_LEASE_EXPIRY_ACTION = "leaseexpiryaction";
107-
String INSTANCE_LEASE_ACTION_EXECUTION_DATE = "leaseactionexecutiondate";
107+
String INSTANCE_LEASE_EXECUTION = "leaseactionexecution";
108108
}

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,11 @@ public class CreateServiceOfferingCmd extends BaseCmd {
251251
since="4.20")
252252
private Boolean purgeResources;
253253

254-
@Parameter(name = ApiConstants.INSTANCE_LEASE_DURATION, type = CommandType.LONG,
254+
@Parameter(name = ApiConstants.INSTANCE_LEASE_DURATION,
255+
type = CommandType.INTEGER,
255256
description = "Number of days instance is leased for.",
256257
since = "4.21.0")
257-
private Long leaseDuration;
258+
private Integer leaseDuration;
258259

259260
@Parameter(name = ApiConstants.INSTANCE_LEASE_EXPIRY_ACTION, type = CommandType.STRING, since = "4.21.0",
260261
description = "Lease expiry action, valid values are STOP and DESTROY")
@@ -498,7 +499,7 @@ public String getLeaseExpiryAction() {
498499
return leaseExpiryAction;
499500
}
500501

501-
public Long getLeaseDuration() {
502+
public Integer getLeaseDuration() {
502503
return leaseDuration;
503504
}
504505

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

+30-32
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,24 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.vm;
1818

19-
import java.util.ArrayList;
20-
import java.util.Arrays;
21-
import java.util.Collection;
22-
import java.util.HashMap;
23-
import java.util.Iterator;
24-
import java.util.LinkedHashMap;
25-
import java.util.List;
26-
import java.util.Map;
27-
28-
import javax.annotation.Nonnull;
29-
19+
import com.cloud.agent.api.LogLevel;
20+
import com.cloud.event.EventTypes;
21+
import com.cloud.exception.ConcurrentOperationException;
22+
import com.cloud.exception.InsufficientCapacityException;
23+
import com.cloud.exception.InsufficientServerCapacityException;
24+
import com.cloud.exception.InvalidParameterValueException;
25+
import com.cloud.exception.ResourceAllocationException;
26+
import com.cloud.exception.ResourceUnavailableException;
27+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
28+
import com.cloud.network.Network;
29+
import com.cloud.network.Network.IpAddresses;
30+
import com.cloud.offering.DiskOffering;
31+
import com.cloud.template.VirtualMachineTemplate;
32+
import com.cloud.uservm.UserVm;
33+
import com.cloud.utils.net.Dhcp;
34+
import com.cloud.utils.net.NetUtils;
35+
import com.cloud.vm.VirtualMachine;
36+
import com.cloud.vm.VmDetailConstants;
3037
import org.apache.cloudstack.acl.RoleType;
3138
import org.apache.cloudstack.affinity.AffinityGroupResponse;
3239
import org.apache.cloudstack.api.ACL;
@@ -58,24 +65,15 @@
5865
import org.apache.commons.lang3.BooleanUtils;
5966
import org.apache.commons.lang3.StringUtils;
6067

61-
import com.cloud.agent.api.LogLevel;
62-
import com.cloud.event.EventTypes;
63-
import com.cloud.exception.ConcurrentOperationException;
64-
import com.cloud.exception.InsufficientCapacityException;
65-
import com.cloud.exception.InsufficientServerCapacityException;
66-
import com.cloud.exception.InvalidParameterValueException;
67-
import com.cloud.exception.ResourceAllocationException;
68-
import com.cloud.exception.ResourceUnavailableException;
69-
import com.cloud.hypervisor.Hypervisor.HypervisorType;
70-
import com.cloud.network.Network;
71-
import com.cloud.network.Network.IpAddresses;
72-
import com.cloud.offering.DiskOffering;
73-
import com.cloud.template.VirtualMachineTemplate;
74-
import com.cloud.uservm.UserVm;
75-
import com.cloud.utils.net.Dhcp;
76-
import com.cloud.utils.net.NetUtils;
77-
import com.cloud.vm.VirtualMachine;
78-
import com.cloud.vm.VmDetailConstants;
68+
import javax.annotation.Nonnull;
69+
import java.util.ArrayList;
70+
import java.util.Arrays;
71+
import java.util.Collection;
72+
import java.util.HashMap;
73+
import java.util.Iterator;
74+
import java.util.LinkedHashMap;
75+
import java.util.List;
76+
import java.util.Map;
7977

8078
@APICommand(name = "deployVirtualMachine", description = "Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
8179
requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
@@ -278,9 +276,9 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG
278276
description = "Enable packed virtqueues or not.")
279277
private Boolean nicPackedVirtQueues;
280278

281-
@Parameter(name = ApiConstants.INSTANCE_LEASE_DURATION, type = CommandType.LONG, since = "4.21.0",
279+
@Parameter(name = ApiConstants.INSTANCE_LEASE_DURATION, type = CommandType.INTEGER, since = "4.21.0",
282280
description = "Number of days instance is leased for.")
283-
private Long leaseDuration;
281+
private Integer leaseDuration;
284282

285283
@Parameter(name = ApiConstants.INSTANCE_LEASE_EXPIRY_ACTION, type = CommandType.STRING, since = "4.21.0",
286284
description = "Lease expiry action, valid values are STOP and DESTROY")
@@ -483,7 +481,7 @@ public String getPassword() {
483481
return password;
484482
}
485483

486-
public Long getLeaseDuration() {
484+
public Integer getLeaseDuration() {
487485
return leaseDuration;
488486
}
489487

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ protected void updateVMResponse(List<UserVmResponse> response) {
336336
}
337337
}
338338

339-
public Boolean getOnlyLeasedInstances() {
340-
return onlyLeasedInstances;
339+
public boolean getOnlyLeasedInstances() {
340+
return BooleanUtils.toBoolean(onlyLeasedInstances);
341341
}
342342
}

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

+15-18
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,18 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.vm;
1818

19-
import java.util.Collection;
20-
import java.util.HashMap;
21-
import java.util.List;
22-
import java.util.Map;
23-
19+
import com.cloud.exception.InsufficientCapacityException;
20+
import com.cloud.exception.ResourceUnavailableException;
21+
import com.cloud.user.Account;
22+
import com.cloud.uservm.UserVm;
2423
import com.cloud.utils.exception.CloudRuntimeException;
25-
26-
import org.apache.cloudstack.api.ApiArgValidator;
27-
import org.apache.cloudstack.api.response.UserDataResponse;
28-
24+
import com.cloud.utils.net.Dhcp;
25+
import com.cloud.vm.VirtualMachine;
2926
import org.apache.cloudstack.acl.RoleType;
3027
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
3128
import org.apache.cloudstack.api.ACL;
3229
import org.apache.cloudstack.api.APICommand;
30+
import org.apache.cloudstack.api.ApiArgValidator;
3331
import org.apache.cloudstack.api.ApiCommandResourceType;
3432
import org.apache.cloudstack.api.ApiConstants;
3533
import org.apache.cloudstack.api.ApiErrorCode;
@@ -40,15 +38,14 @@
4038
import org.apache.cloudstack.api.command.user.UserCmd;
4139
import org.apache.cloudstack.api.response.GuestOSResponse;
4240
import org.apache.cloudstack.api.response.SecurityGroupResponse;
41+
import org.apache.cloudstack.api.response.UserDataResponse;
4342
import org.apache.cloudstack.api.response.UserVmResponse;
4443
import org.apache.cloudstack.context.CallContext;
4544

46-
import com.cloud.exception.InsufficientCapacityException;
47-
import com.cloud.exception.ResourceUnavailableException;
48-
import com.cloud.user.Account;
49-
import com.cloud.uservm.UserVm;
50-
import com.cloud.utils.net.Dhcp;
51-
import com.cloud.vm.VirtualMachine;
45+
import java.util.Collection;
46+
import java.util.HashMap;
47+
import java.util.List;
48+
import java.util.Map;
5249

5350
@APICommand(name = "updateVirtualMachine", description="Updates properties of a virtual machine. The VM has to be stopped and restarted for the " +
5451
"new properties to take effect. UpdateVirtualMachine does not first check whether the VM is stopped. " +
@@ -154,9 +151,9 @@ public class UpdateVMCmd extends BaseCustomIdCmd implements SecurityGroupAction,
154151
" autoscaling groups or CKS, delete protection will be ignored.")
155152
private Boolean deleteProtection;
156153

157-
@Parameter(name = ApiConstants.INSTANCE_LEASE_DURATION, type = CommandType.LONG, since = "4.21.0",
154+
@Parameter(name = ApiConstants.INSTANCE_LEASE_DURATION, type = CommandType.INTEGER, since = "4.21.0",
158155
description = "Number of days instance is leased for.")
159-
private Long leaseDuration;
156+
private Integer leaseDuration;
160157

161158
@Parameter(name = ApiConstants.INSTANCE_LEASE_EXPIRY_ACTION, type = CommandType.STRING, since = "4.21.0",
162159
description = "Lease expiry action, valid values are STOP and DESTROY")
@@ -333,7 +330,7 @@ public ApiCommandResourceType getApiResourceType() {
333330
return ApiCommandResourceType.VirtualMachine;
334331
}
335332

336-
public Long getLeaseDuration() {
333+
public Integer getLeaseDuration() {
337334
return leaseDuration;
338335
}
339336

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public class ServiceOfferingResponse extends BaseResponseWithAnnotations {
240240

241241
@SerializedName(ApiConstants.INSTANCE_LEASE_DURATION)
242242
@Param(description = "Instance lease duration for service offering", since = "4.21.0")
243-
private Long leaseDuration;
243+
private Integer leaseDuration;
244244

245245
@SerializedName(ApiConstants.INSTANCE_LEASE_EXPIRY_ACTION)
246246
@Param(description = "Action to be taken once lease is over", since = "4.21.0")
@@ -513,11 +513,11 @@ public void setCacheMode(String cacheMode) {
513513
this.cacheMode = cacheMode;
514514
}
515515

516-
public Long getLeaseDuration() {
516+
public Integer getLeaseDuration() {
517517
return leaseDuration;
518518
}
519519

520-
public void setLeaseDuration(Long leaseDuration) {
520+
public void setLeaseDuration(Integer leaseDuration) {
521521
this.leaseDuration = leaseDuration;
522522
}
523523

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ public class UserVmResponse extends BaseResponseWithTagInformation implements Co
397397

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

402402
@SerializedName(ApiConstants.INSTANCE_LEASE_EXPIRY_DATE)
403403
@Param(description = "Instance lease expiry date", since = "4.21.0")
@@ -1181,11 +1181,11 @@ public void setIpAddress(String ipAddress) {
11811181
this.ipAddress = ipAddress;
11821182
}
11831183

1184-
public Long getLeaseDuration() {
1184+
public Integer getLeaseDuration() {
11851185
return leaseDuration;
11861186
}
11871187

1188-
public void setLeaseDuration(Long leaseDuration) {
1188+
public void setLeaseDuration(Integer leaseDuration) {
11891189
this.leaseDuration = leaseDuration;
11901190
}
11911191

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void testIsPurgeResourcesTrue() {
5858

5959
@Test
6060
public void testGetLeaseDuration() {
61-
ReflectionTestUtils.setField(createServiceOfferingCmd, "leaseDuration", 10L);
61+
ReflectionTestUtils.setField(createServiceOfferingCmd, "leaseDuration", 10);
6262
Assert.assertEquals(10, createServiceOfferingCmd.getLeaseDuration().longValue());
6363
}
6464

Diff for: engine/schema/src/main/resources/META-INF/db/views/cloud.user_vm_view.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ SELECT
171171
`vm_template`.`user_data_link_policy` AS `user_data_policy`,
172172
`lease_expiry_date`.`value` AS `lease_expiry_date`,
173173
`lease_expiry_action`.`value` AS `lease_expiry_action`,
174-
`lease_action_execution_date`.`value` AS `lease_action_execution_date`
174+
`lease_action_execution`.`value` AS `lease_action_execution`
175175
FROM
176176
(((((((((((((((((((((((((((((((((((`user_vm`
177177
JOIN `vm_instance` ON (((`vm_instance`.`id` = `user_vm`.`id`)
@@ -221,7 +221,7 @@ FROM
221221
AND (`custom_ram_size`.`name` = 'memory')))
222222
LEFT JOIN `user_vm_details` `lease_expiry_date` ON ((`lease_expiry_date`.`vm_id` = `vm_instance`.`id`)
223223
AND (`lease_expiry_date`.`name` = 'leaseexpirydate'))
224-
LEFT JOIN `user_vm_details` `lease_action_execution_date` ON ((`lease_action_execution_date`.`vm_id` = `vm_instance`.`id`)
225-
AND (`lease_action_execution_date`.`name` = 'leaseactionexecutiondate'))
224+
LEFT JOIN `user_vm_details` `lease_action_execution` ON ((`lease_action_execution`.`vm_id` = `vm_instance`.`id`)
225+
AND (`lease_action_execution`.`name` = 'leaseactionexecution'))
226226
LEFT JOIN `user_vm_details` `lease_expiry_action` ON (((`lease_expiry_action`.`vm_id` = `vm_instance`.`id`)
227227
AND (`lease_expiry_action`.`name` = 'leaseexpiryaction'))));

Diff for: framework/db/src/main/java/com/cloud/utils/db/SearchBase.java

-18
Original file line numberDiff line numberDiff line change
@@ -359,24 +359,6 @@ 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-
380362
/**
381363
* Closes a parenthesis that's started by op()
382364
* @return this

0 commit comments

Comments
 (0)