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 5 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 5 commits into
apache:mainfrom
shapeblue:scheduled-asg-actions

Conversation

@vishesh92
Copy link
Copy Markdown
Member

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

  • 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 44.27313% with 506 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.11%. Comparing base (cbc1ae7) to head (cc2d5df).
⚠️ Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
...apache/cloudstack/schedule/BaseScheduleWorker.java 37.82% 112 Missing and 8 partials ⚠️
...oudstack/schedule/ResourceScheduleManagerImpl.java 65.12% 53 Missing and 30 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 ⚠️
.../cloudstack/schedule/ResourceScheduleDetailVO.java 0.00% 25 Missing ⚠️
...mmand/user/schedule/DeleteResourceScheduleCmd.java 0.00% 24 Missing ⚠️
...tack/schedule/dao/ResourceScheduledJobDaoImpl.java 0.00% 18 Missing ⚠️
...apache/cloudstack/schedule/ResourceScheduleVO.java 19.04% 17 Missing ⚠️
... and 11 more
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     
Flag Coverage Δ
uitests 3.51% <ø> (-0.01%) ⬇️
unittests 19.27% <44.27%> (+0.02%) ⬆️

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.

Comment on lines +432 to +441
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);
Comment on lines +432 to +435
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());
Comment on lines +75 to +80
@Override
public void execute() {
resourceScheduleManager.removeSchedule(getResourceType(), getResourceId(), getId(), getIds());
SuccessResponse response = new SuccessResponse(getCommandName());
setResponseObject(response);
}
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.

3 participants