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 5 commits into
Conversation
8ae7085 to
497891c
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #13148 +/- ##
============================================
+ Coverage 18.08% 18.11% +0.02%
- Complexity 16718 16774 +56
============================================
Files 6037 6044 +7
Lines 542546 542947 +401
Branches 66431 66447 +16
============================================
+ Hits 98126 98328 +202
- Misses 433404 433578 +174
- Partials 11016 11041 +25
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.
| List<Long> ids = getIdsListFromCmd(id, idsList); | ||
| Pair<List<ResourceScheduleVO>, Integer> result = resourceScheduleDao.searchAndCount(ids, resourceType, internalResourceId, null, null, null, null); | ||
| List<ResourceScheduleVO> schedulesToRemove = result.first(); | ||
| List<Long> scheduleIdsToRemove = schedulesToRemove.stream().map(ResourceScheduleVO::getId).collect(Collectors.toList()); | ||
| return Transaction.execute((TransactionCallback<Long>) status -> { | ||
| worker.removeScheduledJobs(scheduleIdsToRemove); | ||
|
|
||
| CallContext.current().setEventResourceId(internalResourceId); | ||
| CallContext.current().setEventResourceType(worker.getApiResourceType()); | ||
| return resourceScheduleDao.removeSchedulesForResourceAndIds(resourceType, internalResourceId, scheduleIdsToRemove); |
| List<Long> ids = getIdsListFromCmd(id, idsList); | ||
| Pair<List<ResourceScheduleVO>, Integer> result = resourceScheduleDao.searchAndCount(ids, resourceType, internalResourceId, null, null, null, null); | ||
| List<ResourceScheduleVO> schedulesToRemove = result.first(); | ||
| List<Long> scheduleIdsToRemove = schedulesToRemove.stream().map(ResourceScheduleVO::getId).collect(Collectors.toList()); |
| @Override | ||
| public void execute() { | ||
| resourceScheduleManager.removeSchedule(getResourceType(), getResourceId(), getId(), getIds()); | ||
| SuccessResponse response = new SuccessResponse(getCommandName()); | ||
| setResponseObject(response); | ||
| } |
Description
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.
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?