Skip to content

Async jobs improvements - #14270

Draft
sureshanaparti wants to merge 29 commits into
apache:mainfrom
shapeblue:async-jobs-improvements
Draft

sureshanaparti wants to merge 29 commits into
apache:mainfrom
shapeblue:async-jobs-improvements

Conversation

@sureshanaparti

@sureshanaparti sureshanaparti commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR has the following async jobs related improvements.

  • Lists async jobs by their status, and duration.
  • Support cancel async jobs (wherever possible, cancels underlying hypervisor jobs, mainly VMware, XenServer)
  • Links jobs to events
  • Lists usage server jobs
  • Adds new 'Activity' section in the UI with Jobs, Events, Alerts. Jobs tabs on Instances, Volumes and Management Servers.

More details here: https://cwiki.apache.org/confluence/spaces/CLOUDSTACK/pages/451979060/Async+Jobs+Improvements

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?

- status (0 - Pending, 1 - Success, 2 - Failed, 3 - Cancelled), use comma-seperated list for multiple status
- end date (jobs created on or before this date)
- duration (in hours) up to now
- usage server: name / ip of the host where usage server is running
- start date: usage jobs started on or after this date
- end date: usage jobs started on or before this date
- duration in hours up to now: usage jobs started or completed within that period up to now
Drop the OperationCancelledException catch and throws plumbing that the
exception no longer needs now that it is unchecked: every one of those
handlers only relabelled a cancellation as a timeout or an unavailable
agent. Pass the agent request sequence to the resource thread
(RequestExecutionContext) so a resource can track its backend work by
the same sequence the agent layer cancels by.
A completed job keeps the server that completed it: async_job_view
exposes job_complete_msid, the response falls back to it once
executing_msid is cleared, and the managementserverid filter matches
either column. Without this a completed job had no management server in
the API and a server's finished jobs could not be listed.
cancelAsyncJob takes jobid, not id.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Cancellation races can terminate refused jobs or finalize jobs while backend work continues, and several API/UI fields are ineffective or omitted.

Review effort: Balanced
Findings: 3 High severity · 3 Medium severity

Open (6)
What changed in this PR

Adds async-job filtering, cancellation, event linkage, usage-job visibility, and an Activity-focused UI across CloudStack.

Changes:

  • Adds cross-layer async-job cancellation for KVM, VMware, and XenServer.
  • Extends job/event/usage APIs with filtering, status, duration, and linkage data.
  • Adds Activity, resource job tabs, usage-job views, and automated tests.
File Description
vmware-base/​.../​VmwareTaskRegistryTest.java Tests VMware task tracking and cancellation.
vmware-base/​.../​VmwareTaskRegistry.java Tracks cancellable VMware tasks.
vmware-base/​.../​VmwareClient.java Registers, cancels, and polls VMware tasks.
utils/​.../​SerialVersionUID.java Adds cancellation exception UID.
utils/​.../​CSExceptionErrorCode.java Registers cancellation error code.
ui/​.../​UsageJobsTab.vue Adds usage-job table.
ui/​.../​AsyncJobsTab.vue Adds filtering, pagination, and cancellation UI.
ui/​.../​InstanceTab.vue Adds instance Jobs tab.
ui/​.../​JobsView.vue Adds global Jobs view.
ui/​.../​storage.js Adds volume Jobs tab.
ui/​.../​managementServers.js Adds management and usage job tabs.
ui/​.../​infra.js Moves alerts out of Infrastructure.
ui/​.../​event.js Removes standalone Events section.
ui/​.../​activity.js Adds Activity section.
ui/​.../​router.js Registers Activity routing.
ui/​public/​locales/​en.json Adds job-related labels.
test/​.../​test_async_jobs.py Adds async-job smoke coverage.
server/​.../​UsageServiceImpl.java Implements usage-job listing.
server/​.../​ManagementServerImpl.java Registers usage-job API.
server/​.../​EventJoinDaoImpl.java Exposes event job IDs.
server/​.../​ActionEventUtils.java Links events to current jobs.
server/​.../​ConfigurationManagerImpl.java Validates cancellation interval.
server/​.../​EventJoinVO.java Maps event job columns.
server/​.../​AsyncJobJoinVO.java Maps completion server and related job.
server/​.../​QueryManagerImpl.java Adds job/event filtering.
server/​.../​AsyncJobJoinDaoImpl.java Reports executing/completing server.
server/​.../​ApiResponseHelper.java Creates cancellation responses.
server/​.../​ApiAsyncJobDispatcher.java Preserves terminal cancellation status.
plugins/​.../​XenServerTaskRegistryTest.java Tests XenServer cancellation registry.
plugins/​.../​CitrixResourceBaseTest.java Tests unknown XenServer requests.
plugins/​.../​XenServerTaskRegistry.java Tracks XenAPI tasks.
plugins/​.../​CitrixResourceBase.java Integrates XenServer cancellation.
plugins/​.../​VmwareResourceTest.java Tests unknown VMware requests.
plugins/​.../​VmwareResource.java Integrates VMware cancellation.
plugins/​.../​LibvirtCancelCommandWrapperTest.java Tests KVM cancel wrapper.
plugins/​.../​KvmCancellableRequestsTest.java Tests KVM request tracking.
plugins/​.../​LibvirtCancelCommandWrapper.java Handles KVM cancel commands.
plugins/​.../​LibvirtComputingResource.java Integrates KVM cancellation hooks.
plugins/​.../​KvmCancellableRequests.java Tracks KVM cancellation hooks.
framework/​jobs/​.../​AsyncJobMonitor.java Tracks active job IDs.
framework/​jobs/​.../​AsyncJobManagerImpl.java Implements job cancellation lifecycle.
framework/​jobs/​.../​AsyncJobDaoImpl.java Queries related/cancelled jobs.
framework/​jobs/​.../​AsyncJobDao.java Extends job DAO contract.
framework/​jobs/​.../​AsyncJobManager.java Extends cancellation lifecycle API.
framework/​jobs/​.../​AsyncJobExecutionContext.java Handles missing join records.
engine/​schema/​.../​cloud.event_view.sql Adds event/job linkage.
engine/​schema/​.../​cloud.async_job_view.sql Adds related and completion fields.
engine/​schema/​.../​schema-42300to2400.sql Migrates event job linkage.
engine/​schema/​.../​EventVO.java Persists event job IDs.
engine/​orchestration/​.../​DirectAgentAttacheTest.java Tests direct-agent cancellation.
engine/​orchestration/​.../​ConnectedAgentAttacheTest.java Tests connected-agent cancellation.
engine/​orchestration/​.../​DirectAgentAttache.java Tracks and cancels direct tasks.
engine/​orchestration/​.../​ConnectedAgentAttache.java Sends agent cancel commands.
engine/​orchestration/​.../​AgentManagerImpl.java Coordinates job/agent cancellation.
engine/​orchestration/​.../​AgentAttache.java Adds cancellation-aware request handling.
engine/​components-api/​.../​AgentManager.java Exposes cancellation services.
core/​.../​CancelCommandTest.java Tests cancellation probe mode.
core/​.../​ServerResource.java Adds resource cancellation hooks.
core/​.../​RequestExecutionContext.java Carries request sequence context.
core/​.../​Request.java Tracks request cancellation.
core/​.../​CancelCommand.java Adds probe-only cancellation mode.
api/​.../​UsageService.java Exposes usage-job listing.
api/​.../​JobInfo.java Adds explicit status values.
api/​.../​JobCancellationHandler.java Defines cancellation handler contract.
api/​.../​AsyncJobService.java Defines cancellation service/configuration.
api/​.../​ResponseGenerator.java Adds cancellation response contract.
api/​.../​UsageJobResponse.java Defines usage-job response.
api/​.../​MigrateVolumeCmd.java Marks migration cancellable.
api/​.../​DetachVolumeCmd.java Marks detach cancellable.
api/​.../​DestroyVolumeCmd.java Marks volume destruction cancellable.
api/​.../​CreateVolumeCmd.java Marks volume creation cancellable.
api/​.../​AttachVolumeCmd.java Marks attach cancellable.
api/​.../​RevertToVMSnapshotCmd.java Marks revert cancellable.
api/​.../​DeleteVMSnapshotCmd.java Marks deletion cancellable.
api/​.../​CreateVMSnapshotCmd.java Marks creation cancellable.
api/​.../​StopVMCmd.java Marks stop cancellable.
api/​.../​StartVMCmd.java Marks start cancellable.
api/​.../​RebootVMCmd.java Marks reboot cancellable.
api/​.../​DestroyVMCmd.java Marks VM destruction cancellable.
api/​.../​BaseDeployVMCmd.java Declares deploy cancellation intent.
api/​.../​RevertSnapshotCmd.java Marks snapshot revert cancellable.
api/​.../​DeleteSnapshotCmd.java Marks snapshot deletion cancellable.
api/​.../​CreateSnapshotCmd.java Marks snapshot creation cancellable.
api/​.../​ListAsyncJobsCmd.java Adds status/date/duration filters.
api/​.../​CancelAsyncJobCmd.java Adds cancellation API.
api/​.../​ListEventsCmd.java Adds job-based event filtering.
api/​.../​MigrateVolumeCmdByAdmin.java Marks admin migration cancellable.
api/​.../​DetachVolumeCmdByAdmin.java Marks admin detach cancellable.
api/​.../​DestroyVolumeCmdByAdmin.java Marks admin destruction cancellable.
api/​.../​CreateVolumeCmdByAdmin.java Marks admin creation cancellable.
api/​.../​AttachVolumeCmdByAdmin.java Marks admin attach cancellable.
api/​.../​RevertToVMSnapshotCmdByAdmin.java Marks admin revert cancellable.
api/​.../​StopVMCmdByAdmin.java Marks admin stop cancellable.
api/​.../​StartVMCmdByAdmin.java Marks admin start cancellable.
api/​.../​RebootVMCmdByAdmin.java Marks admin reboot cancellable.
api/​.../​MigrateVMCmd.java Marks VM migration cancellable.
api/​.../​MigrateVirtualMachineWithVolumeCmd.java Marks combined migration cancellable.
api/​.../​DestroyVMCmdByAdmin.java Marks admin VM destruction cancellable.
api/​.../​ListUsageJobsCmd.java Adds usage-job API.
api/​.../​ApiConstants.java Adds usage-server constant.
api/​.../​ApiCommandResourceType.java Adds Job resource type.
api/​.../​APICommand.java Adds cancellable command metadata.
api/​.../​VirtualMachine.java Adds Starting-to-Stopping transition.
api/​.../​OperationCancelledException.java Adds cancellation exception.
api/​.../​EventTypes.java Adds job-cancel event type.
api/​.../​Answer.java Adds cancelled-answer state.
agent/​.../​Agent.java Propagates request sequences.
.github/​workflows/​ci.yml Runs new smoke tests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread api/src/main/java/org/apache/cloudstack/api/command/user/vm/BaseDeployVMCmd.java Outdated
Comment thread server/src/main/java/com/cloud/usage/UsageServiceImpl.java
Comment thread ui/src/config/section/activity.js Outdated
@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 36.26108% with 791 lines in your changes missing coverage. Please review.
✅ Project coverage is 19.95%. Comparing base (510d0ec) to head (e584280).

Files with missing lines Patch % Lines
...stack/framework/jobs/impl/AsyncJobManagerImpl.java 10.68% 114 Missing and 3 partials ⚠️
...java/com/cloud/agent/manager/AgentManagerImpl.java 37.83% 64 Missing and 5 partials ⚠️
...va/com/cloud/agent/manager/DirectAgentAttache.java 38.73% 59 Missing and 9 partials ⚠️
...n/java/com/cloud/vm/VirtualMachineManagerImpl.java 3.70% 50 Missing and 2 partials ⚠️
...rc/main/java/com/cloud/usage/UsageServiceImpl.java 0.00% 47 Missing ⚠️
...com/cloud/hypervisor/vmware/util/VmwareClient.java 0.00% 35 Missing ⚠️
...udstack/api/command/user/job/ListAsyncJobsCmd.java 0.00% 34 Missing ⚠️
...dstack/api/command/user/job/CancelAsyncJobCmd.java 0.00% 31 Missing ⚠️
...m/cloud/exception/OperationCancelledException.java 0.00% 29 Missing ⚠️
...ain/java/com/cloud/api/query/QueryManagerImpl.java 10.34% 25 Missing and 1 partial ⚠️
... and 28 more
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #14270      +/-   ##
============================================
+ Coverage     19.91%   19.95%   +0.04%     
- Complexity    20194    20324     +130     
============================================
  Files          6373     6385      +12     
  Lines        577230   578451    +1221     
  Branches      70696    70876     +180     
============================================
+ Hits         114942   115446     +504     
- Misses       449722   450383     +661     
- Partials      12566    12622      +56     
Flag Coverage Δ
uitests 3.70% <ø> (-0.01%) ⬇️
unittests 21.23% <36.26%> (+0.04%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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.

@sureshanaparti

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@sureshanaparti 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 19353

@sureshanaparti

Copy link
Copy Markdown
Contributor Author

@blueorangutan test keepEnv

@blueorangutan

Copy link
Copy Markdown

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

@sureshanaparti

Copy link
Copy Markdown
Contributor Author

@blueorangutan test matrix

@blueorangutan

Copy link
Copy Markdown

@sureshanaparti a [SL] Trillian-Jenkins matrix job (ol8 mgmt + kvm-ol8, ubuntu22 mgmt + kvm-ubuntu22, ol8 mgmt + vmware-70u3, ol9 mgmt + xcpng82) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian Build Failed (tid-17049)

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-17046)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 57737 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr14270-t17046-kvm-ol8.zip
Smoke tests completed. 157 look OK, 0 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-17048)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 65082 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr14270-t17048-kvm-ol8.zip
Smoke tests completed. 157 look OK, 0 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-17051)
Environment: xcpng82 (x2), zone: Advanced Networking with Mgmt server ol9
Total time taken: 92954 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr14270-t17051-xcpng82.zip
Smoke tests completed. 147 look OK, 10 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File
test_01_events_resource Error 245.25 test_events_resource.py
test_12_deploy_vm_with_root_disk_encryption Error 12.06 test_kms_lifecycle.py
test_08_upgrade_kubernetes_ha_cluster Failure 966.38 test_kubernetes_clusters.py
test_09_vpc_source_nat_ip_update Error 25.55 test_network_extension_namespace.py
test_01_non_strict_host_anti_affinity Error 234.93 test_nonstrict_affinity_group.py
test_02_non_strict_host_affinity Error 62.44 test_nonstrict_affinity_group.py
test_05_disk_offering_strictness_true Failure 630.02 test_service_offerings.py
test_06_disk_offering_strictness_false Failure 635.13 test_service_offerings.py
test_01_volume_usage Failure 96.02 test_usage.py
test_01_vpn_usage Error 1.08 test_usage.py
test_11_destroy_vm_and_volumes Error 21.02 test_vm_life_cycle.py
test_change_service_offering_for_vm_with_snapshots Failure 1023.13 test_vm_snapshots.py
test_01_migrate_vm_strict_tags_success Error 52.86 test_vm_strict_host_tags.py

This branch has not been deployed

No deployments
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