Refactors VM Schedule to make it more generic & add option to schedule min & max for autoscaling groups#13148
Refactors VM Schedule to make it more generic & add option to schedule min & max for autoscaling groups#13148vishesh92 wants to merge 7 commits into
Conversation
8ae7085 to
497891c
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #13148 +/- ##
============================================
+ Coverage 18.09% 18.11% +0.02%
- Complexity 16723 16785 +62
============================================
Files 6037 6046 +9
Lines 542580 543027 +447
Branches 66427 66458 +31
============================================
+ Hits 98155 98390 +235
- Misses 433399 433595 +196
- Partials 11026 11042 +16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
497891c to
cc2d5df
Compare
There was a problem hiding this comment.
Pull request overview
This PR generalizes the existing VM scheduling feature into a resource-agnostic “Resource Schedule” system (API, persistence, workers, and UI), while keeping legacy VM schedule APIs as deprecated wrappers.
Changes:
- Introduces generic
create/list/update/deleteResourceScheduleAPIs with a worker-based execution model (BaseScheduleWorker+VMScheduleWorker). - Migrates DB schema from
vm_schedule/vm_scheduled_jobtoresource_schedule/resource_scheduled_joband addsresource_schedule_details. - Updates the UI and integration/unit tests to use the new resource schedule APIs (with legacy VM schedule APIs mapped to the new backend).
Reviewed changes
Copilot reviewed 52 out of 52 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| ui/src/views/compute/ResourceSchedules.vue | Refactors schedule UI to operate on generic resources and new resource schedule APIs. |
| ui/src/views/compute/InstanceTab.vue | Switches VM “Schedules” tab to listResourceSchedule and the new ResourceSchedules component. |
| ui/src/components/view/ListView.vue | Replaces hardcoded VM schedule action buttons with a reusable slot (scheduleActions). |
| ui/public/locales/te.json | Updates UI strings/keys for generalized schedule actions and messages. |
| ui/public/locales/en.json | Updates UI strings/keys for generalized schedule actions and messages. |
| tools/marvin/marvin/lib/base.py | Adds Marvin ResourceSchedule helper for creating/listing/updating/deleting schedules. |
| tools/apidoc/gen_toc.py | Adds TOC category entry for Resource Schedule APIs. |
| test/integration/smoke/test_vm_schedule.py | Migrates integration tests from VMSchedule to ResourceSchedule. |
| server/src/test/java/org/apache/cloudstack/schedule/vm/VMScheduleWorkerTest.java | Adds unit tests for the VM schedule worker built on the generic scheduler. |
| server/src/test/java/org/apache/cloudstack/schedule/ResourceScheduleManagerImplTest.java | Adds unit tests for the new generic schedule manager. |
| server/src/main/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml | Wires ResourceScheduleManagerImpl and VMScheduleWorker beans. |
| server/src/main/java/org/apache/cloudstack/schedule/vm/VMScheduleWorker.java | Implements VM-specific scheduling logic on top of BaseScheduleWorker. |
| server/src/main/java/org/apache/cloudstack/schedule/ResourceScheduleManagerImpl.java | Implements generic schedule create/list/update/delete and worker dispatching. |
| server/src/main/java/org/apache/cloudstack/schedule/BaseScheduleWorker.java | Introduces shared polling/scheduling/execution framework for resource schedulers. |
| server/src/main/java/com/cloud/vm/UserVmManagerImpl.java | Ensures schedules are removed when expunging a VM (via ResourceScheduleManager). |
| engine/schema/src/main/resources/META-INF/db/schema-42210to42300.sql | DB migration to resource schedule tables + config/event type renames. |
| engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml | Replaces VM schedule DAO beans with resource schedule DAO beans. |
| engine/schema/src/main/java/org/apache/cloudstack/schedule/ResourceScheduleVO.java | New ResourceScheduleVO entity replacing VMScheduleVO with resource typing. |
| engine/schema/src/main/java/org/apache/cloudstack/schedule/ResourceScheduledJobVO.java | New ResourceScheduledJobVO entity replacing VMScheduledJobVO with resource typing. |
| engine/schema/src/main/java/org/apache/cloudstack/schedule/ResourceScheduleDetailVO.java | Adds persistent “details” storage for action-specific scheduling parameters. |
| engine/schema/src/main/java/org/apache/cloudstack/schedule/dao/ResourceScheduledJobDaoImpl.java | Implements scheduled job DAO for resource scheduler. |
| engine/schema/src/main/java/org/apache/cloudstack/schedule/dao/ResourceScheduledJobDao.java | Defines scheduled job DAO interface for resource scheduler. |
| engine/schema/src/main/java/org/apache/cloudstack/schedule/dao/ResourceScheduleDetailsDaoImpl.java | Implements details DAO for resource schedule details. |
| engine/schema/src/main/java/org/apache/cloudstack/schedule/dao/ResourceScheduleDetailsDao.java | Defines details DAO interface for resource schedule details. |
| engine/schema/src/main/java/org/apache/cloudstack/schedule/dao/ResourceScheduleDaoImpl.java | Implements schedule DAO for resource schedule entity. |
| engine/schema/src/main/java/org/apache/cloudstack/schedule/dao/ResourceScheduleDao.java | Defines schedule DAO interface for resource schedules. |
| api/src/test/java/org/apache/cloudstack/api/command/user/vm/UpdateVMScheduleCmdTest.java | Updates legacy VM schedule cmd test to use ResourceScheduleManager under the hood. |
| api/src/test/java/org/apache/cloudstack/api/command/user/vm/ListVMScheduleCmdTest.java | Updates legacy VM schedule list cmd test to translate from ResourceScheduleResponse. |
| api/src/test/java/org/apache/cloudstack/api/command/user/vm/DeleteVMScheduleCmdTest.java | Updates legacy VM schedule delete cmd test to use generic manager. |
| api/src/test/java/org/apache/cloudstack/api/command/user/vm/CreateVMScheduleCmdTest.java | Updates legacy VM schedule create cmd test to use generic manager. |
| api/src/main/java/org/apache/cloudstack/schedule/vm/VMScheduleAction.java | Introduces VM action enum implementing generic ResourceSchedule.Action. |
| api/src/main/java/org/apache/cloudstack/schedule/ResourceScheduleManager.java | Defines the new generic scheduling manager interface. |
| api/src/main/java/org/apache/cloudstack/schedule/ResourceScheduledJob.java | Defines the new generic scheduled job API interface. |
| api/src/main/java/org/apache/cloudstack/schedule/ResourceSchedule.java | Defines the new generic schedule API interface and action contract. |
| api/src/main/java/org/apache/cloudstack/api/response/VMScheduleResponse.java | Retargets entity reference + adds adapter ctor from ResourceScheduleResponse. |
| api/src/main/java/org/apache/cloudstack/api/response/ResourceScheduleResponse.java | Adds the new generic schedule response object. |
| api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVMScheduleCmd.java | Deprecates VM cmd and forwards updates to ResourceScheduleManager. |
| api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListVMScheduleCmd.java | Deprecates VM cmd and forwards listing to ResourceScheduleManager. |
| api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeleteVMScheduleCmd.java | Deprecates VM cmd and forwards deletion to ResourceScheduleManager. |
| api/src/main/java/org/apache/cloudstack/api/command/user/vm/CreateVMScheduleCmd.java | Deprecates VM cmd and forwards creation to ResourceScheduleManager. |
| api/src/main/java/org/apache/cloudstack/api/command/user/schedule/UpdateResourceScheduleCmd.java | Adds update API command for generic resource schedules. |
| api/src/main/java/org/apache/cloudstack/api/command/user/schedule/ListResourceScheduleCmd.java | Adds list API command for generic resource schedules. |
| api/src/main/java/org/apache/cloudstack/api/command/user/schedule/DeleteResourceScheduleCmd.java | Adds delete API command for generic resource schedules. |
| api/src/main/java/org/apache/cloudstack/api/command/user/schedule/CreateResourceScheduleCmd.java | Adds create API command for generic resource schedules. |
| api/src/main/java/com/cloud/event/EventTypes.java | Introduces generic schedule CRUD event types and remaps schedule events to ResourceSchedule. |
Comments suppressed due to low confidence (2)
ui/src/views/compute/ResourceSchedules.vue:346
apiParamsis populated only fromcreateResourceSchedule. If a role can list schedules but cannot create them,$getApiParams('createResourceSchedule')returns{}, and the template’sapiParams.<param>.descriptionaccesses will throw even though the “Add” button is disabled. Consider populatingapiParamsfrom whichever schedule API is available (e.g. create/update) and/or guarding template access with optional chaining / defaults so the tab can render read-only.
ui/src/views/compute/ResourceSchedules.vue:375- The watcher on
resourceisdeep: true, so any reactive change inside the resource object (e.g. VM state updates) will re-triggerfetchSchedules()and can cause unnecessary API traffic. Watching onlyresource.id(or using a shallow watch) should be sufficient and avoids repeated list calls.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 59 out of 59 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (3)
ui/src/views/compute/InstanceTab.vue:1
- This import points to
ResourceSchedules.vue, but the refactor shown updatesui/src/views/compute/InstanceSchedules.vuein-place (including settingname: 'ResourceSchedules'). IfResourceSchedules.vueis not actually present/renamed in the filesystem, the UI will fail to build. Either renameInstanceSchedules.vuetoResourceSchedules.vue(updating routes/async imports too) or adjust imports to the actual file path.
server/src/main/java/com/cloud/network/as/AutoScaleManagerImpl.java:1 - The exception message is missing a space after
)in")cannot be greater than", producing a user-facing typo. Update the string to include the missing space (and consider also standardizing the message format with the other validation errors).
tools/marvin/marvin/lib/base.py:1 - This uses a list comprehension purely for side effects, which is discouraged and makes intent less clear. Replace it with a simple
for k, v in kwargs.items(): setattr(cmd, k, v)loop.
f84692b to
9ecc535
Compare
9ecc535 to
80f4b0d
Compare
|
@blueorangutan package |
|
@vishesh92 a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 17842 |
|
@blueorangutan package |
|
@vishesh92 a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 17843 |
|
@blueorangutan test |
|
@vishesh92 a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
Description
Documentation PR: apache/cloudstack-documentation#650
This PR refactors the VM schedule to make it more generic and allow creation of scheduled actions based on cron format for other resources with minimal changes. Apart from the existing schedules for VM, this PR adds support for scheduling min & max members of a autoscaling group.
Existing VM Schedule related APIs have been marked as deprecated (Used
@Deprecatedannotation but still available for use.).Existing vm_schedule & related tables are renamed and reused to store schedules for different resource types (VM & ASG for now). After these changes, it should be easy to add cron based schedules to other resources like networks, VRs, etc.
Details
This pull request introduces a new, generic resource scheduling API for CloudStack, deprecating the previous VM-specific schedule commands and events. The main changes include adding new CRUD API commands for resource schedules, updating event types to support generic resource scheduling, and refactoring the event-to-entity mapping to use the new
ResourceScheduleclass. The changes also update the VM schedule command to use the new manager and mark it as deprecated.Resource Scheduling API and Event Refactoring:
CreateResourceScheduleCmd,UpdateResourceScheduleCmd,DeleteResourceScheduleCmd, andListResourceScheduleCmd, supporting schedule creation, update, deletion, and listing for any resource type. [1] [2] [3] [4]EventTypes.javato introduce generic resource schedule CRUD events (SCHEDULE.CREATE,SCHEDULE.UPDATE,SCHEDULE.DELETE) and reclassified VM schedule events as action-execution only. Also added an autoscale group schedule update event. [1] [2]EventTypes.javato map new schedule events toResourceScheduleand removed references to the oldVMScheduleclass.CreateVMScheduleCmdto useResourceScheduleManagerinstead ofVMScheduleManager, and marked the command as@Deprecated.EventTypes.javato useResourceScheduleinstead of the removedVMSchedule.New generic schedule APIs
createResourceScheduleCreates a schedule for a supported resource type.
resourcetype(string)resourceid(string; UUID or numeric ID path is resolved internally)schedule(cron expression)timezone(timezone string)action(resource-specific action)descriptionstartdate(defaults to current time + 1 minute if omitted)enddateenabled(defaults totrue)details(map, action/resource-specific)resourcetypeis rejected.actionis validated by the resource worker.startdatecannot be in the past;enddatecannot be in the past or beforestartdate.ResourceScheduleResponsewith fields:id,resourcetype,resourceid,description,schedule,timezone,action,enabled,startdate,enddate,details,created.listResourceScheduleLists schedules for a given resource.
resourcetyperesourceididids(list)actionenabledpage,pagesize)ResourceScheduleResponse.updateResourceScheduleUpdates an existing schedule.
iddescriptionscheduletimezonestartdateenddateenableddetails(map)detailsis provided as an empty map, existing schedule details are removed.detailsis provided with entries, details are replaced/saved.detailsis provided as null, details are ignored.deleteResourceScheduleDeletes schedule(s) scoped to a resource.
resourcetyperesourceidididsAutoScale VM Group schedule specifics (
resourcetype=AutoScaleVmGroup)UPDATE.detailsmap is required and currently supports only:minmembersmaxmembersupdateAutoScaleVmGroupwithminmembersandmaxmembersfrom schedule details.Legacy VM schedule compatibility
Legacy VM schedule APIs remain available (deprecated wrappers):
createVMSchedulelistVMScheduleupdateVMScheduledeleteVMScheduleThese continue to route through the same underlying resource schedule manager for VirtualMachine scheduling.
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
How did you try to break this feature and the system with this change?