Skip to content

Refactors VM Schedule to make it more generic & add option to schedule min & max for autoscaling groups#13148

Draft
vishesh92 wants to merge 7 commits into
apache:mainfrom
shapeblue:scheduled-asg-actions
Draft

Refactors VM Schedule to make it more generic & add option to schedule min & max for autoscaling groups#13148
vishesh92 wants to merge 7 commits into
apache:mainfrom
shapeblue:scheduled-asg-actions

Conversation

@vishesh92
Copy link
Copy Markdown
Member

@vishesh92 vishesh92 commented May 12, 2026

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 @Deprecated annotation 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 ResourceSchedule class. The changes also update the VM schedule command to use the new manager and mark it as deprecated.

Resource Scheduling API and Event Refactoring:

  • Added new API commands for resource schedule management: CreateResourceScheduleCmd, UpdateResourceScheduleCmd, DeleteResourceScheduleCmd, and ListResourceScheduleCmd, supporting schedule creation, update, deletion, and listing for any resource type. [1] [2] [3] [4]
  • Updated event types in EventTypes.java to 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]
  • Refactored event-to-entity mapping in EventTypes.java to map new schedule events to ResourceSchedule and removed references to the old VMSchedule class.
  • Updated imports and manager usage in the deprecated CreateVMScheduleCmd to use ResourceScheduleManager instead of VMScheduleManager, and marked the command as @Deprecated.
  • Changed imports in EventTypes.java to use ResourceSchedule instead of the removed VMSchedule.

New generic schedule APIs

createResourceSchedule

Creates a schedule for a supported resource type.

  • Required params
    • resourcetype (string)
    • resourceid (string; UUID or numeric ID path is resolved internally)
    • schedule (cron expression)
    • timezone (timezone string)
    • action (resource-specific action)
  • Optional params
    • description
    • startdate (defaults to current time + 1 minute if omitted)
    • enddate
    • enabled (defaults to true)
    • details (map, action/resource-specific)
  • Validation highlights
    • Invalid/unsupported resourcetype is rejected.
    • Resource must exist and be schedulable for that type.
    • action is validated by the resource worker.
    • startdate cannot be in the past; enddate cannot be in the past or before startdate.
  • Response object
    • ResourceScheduleResponse with fields: id, resourcetype, resourceid, description, schedule, timezone, action, enabled, startdate, enddate, details, created.

listResourceSchedule

Lists schedules for a given resource.

  • Required params
    • resourcetype
    • resourceid
  • Optional params
    • id
    • ids (list)
    • action
    • enabled
    • pagination (page, pagesize)
  • Behavior
    • Action filter is parsed/validated per resource type.
    • Returns list of ResourceScheduleResponse.

updateResourceSchedule

Updates an existing schedule.

  • Required params
    • id
  • Optional params
    • description
    • schedule
    • timezone
    • startdate
    • enddate
    • enabled
    • details (map)
  • Behavior
    • Supports partial updates.
    • If details is provided as an empty map, existing schedule details are removed.
    • If details is provided with entries, details are replaced/saved.
    • If details is provided as null, details are ignored.
  • Validation highlights
    • Same date/time consistency checks as create path when schedule timing fields are changed.

deleteResourceSchedule

Deletes schedule(s) scoped to a resource.

  • Required params
    • resourcetype
    • resourceid
  • Optional params
    • id
    • ids
  • Behavior
    • Removes selected schedules (or all matching schedules in scope if no specific IDs provided).

AutoScale VM Group schedule specifics (resourcetype=AutoScaleVmGroup)

  • Supported action: UPDATE.
  • details map is required and currently supports only:
    • minmembers
    • maxmembers
  • Both keys must be present and parse as integers.
  • Additional keys are rejected.
  • Min/max values are validated using AutoScale min/max member validation logic.
  • At runtime, scheduled execution triggers updateAutoScaleVmGroup with minmembers and maxmembers from schedule details.

Legacy VM schedule compatibility

Legacy VM schedule APIs remain available (deprecated wrappers):

  • createVMSchedule
  • listVMSchedule
  • updateVMSchedule
  • deleteVMSchedule

These continue to route through the same underlying resource schedule manager for VirtualMachine scheduling.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

How did you try to break this feature and the system with this change?

@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

❌ Patch coverage is 47.16599% with 522 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.11%. Comparing base (5893ba5) to head (ad2c294).

Files with missing lines Patch % Lines
...apache/cloudstack/schedule/BaseScheduleWorker.java 37.82% 112 Missing and 8 partials ⚠️
...oudstack/schedule/ResourceScheduleManagerImpl.java 68.90% 47 Missing and 27 partials ⚠️
...oudstack/schedule/dao/ResourceScheduleDaoImpl.java 0.00% 55 Missing ⚠️
...mmand/user/schedule/CreateResourceScheduleCmd.java 0.00% 45 Missing ⚠️
...mmand/user/schedule/UpdateResourceScheduleCmd.java 0.00% 34 Missing ⚠️
...command/user/schedule/ListResourceScheduleCmd.java 0.00% 29 Missing ⚠️
...mmand/user/schedule/DeleteResourceScheduleCmd.java 0.00% 24 Missing ⚠️
...ck/schedule/autoscale/AutoScaleScheduleWorker.java 58.62% 18 Missing and 6 partials ⚠️
.../cloudstack/schedule/ResourceScheduleDetailVO.java 28.00% 18 Missing ⚠️
...tack/schedule/dao/ResourceScheduledJobDaoImpl.java 0.00% 18 Missing ⚠️
... and 14 more
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     
Flag Coverage Δ
uitests 3.51% <ø> (-0.01%) ⬇️
unittests 19.28% <47.16%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/deleteResourceSchedule APIs with a worker-based execution model (BaseScheduleWorker + VMScheduleWorker).
  • Migrates DB schema from vm_schedule / vm_scheduled_job to resource_schedule / resource_scheduled_job and adds resource_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

  • apiParams is populated only from createResourceSchedule. If a role can list schedules but cannot create them, $getApiParams('createResourceSchedule') returns {}, and the template’s apiParams.<param>.description accesses will throw even though the “Add” button is disabled. Consider populating apiParams from 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 resource is deep: true, so any reactive change inside the resource object (e.g. VM state updates) will re-trigger fetchSchedules() and can cause unnecessary API traffic. Watching only resource.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.

This comment was marked as outdated.

@vishesh92 vishesh92 requested a review from Copilot May 13, 2026 10:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 updates ui/src/views/compute/InstanceSchedules.vue in-place (including setting name: 'ResourceSchedules'). If ResourceSchedules.vue is not actually present/renamed in the filesystem, the UI will fail to build. Either rename InstanceSchedules.vue to ResourceSchedules.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.

@vishesh92 vishesh92 force-pushed the scheduled-asg-actions branch from 9ecc535 to 80f4b0d Compare May 13, 2026 11:59
@apache apache deleted a comment from blueorangutan May 13, 2026
@apache apache deleted a comment from blueorangutan May 13, 2026
@vishesh92
Copy link
Copy Markdown
Member Author

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@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.

@blueorangutan
Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 17842

@vishesh92
Copy link
Copy Markdown
Member Author

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@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.

@blueorangutan
Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 17843

@vishesh92
Copy link
Copy Markdown
Member Author

@blueorangutan test

@blueorangutan
Copy link
Copy Markdown

@vishesh92 a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants