Skip to content

User vm manager cleanup#12779

Draft
DaanHoogland wants to merge 9 commits intomainfrom
UserVmManagerCleanup
Draft

User vm manager cleanup#12779
DaanHoogland wants to merge 9 commits intomainfrom
UserVmManagerCleanup

Conversation

@DaanHoogland
Copy link
Copy Markdown
Contributor

Description

This PR cleans static analysis warnings from UserVmManagerImpl and some in dependencies.

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 Mar 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 18.09%. Comparing base (1e512ab) to head (e336a8f).

Additional details and impacted files
@@            Coverage Diff            @@
##               main   #12779   +/-   ##
=========================================
  Coverage     18.08%   18.09%           
- Complexity    16706    16717   +11     
=========================================
  Files          6037     6037           
  Lines        542437   542389   -48     
  Branches      66420    66409   -11     
=========================================
+ Hits          98088    98120   +32     
+ Misses       433333   433251   -82     
- Partials      11016    11018    +2     
Flag Coverage Δ
uitests 3.52% <ø> (ø)
unittests 19.25% <ø> (+<0.01%) ⬆️

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 cleans up static analysis warnings in UserVmManagerImpl and related files, including the service interface and a template interface. The changes address issues like raw types, unnecessary casts, unused variables, inefficient null checks, and missing throw keywords.

Changes:

  • Removed unused imports, fields (statsCollector, vmScheduleManager), unused constants (MAX_HTTP_GET_LENGTH, etc.), and dead code (unused constructors/methods in VmAndCountDetails, getName(), getRandomPrivateTemplateName())
  • Simplified conditionals: replaced == null ? false : value with direct Boolean.parseBoolean, replaced !list.stream().anyMatch(...) with list.stream().noneMatch(...), replaced size() > 0 with !isEmpty(), etc.
  • Fixed multiple bugs: missing throw for InvalidParameterValueException at validation, NPE in error messages using null objects' methods, removed caller parameter from methods where it was unused, improved method signatures to remove unchecked exceptions

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

File Description
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Major cleanup: remove unused imports/fields/methods, fix bugs (missing throw, null NPE in error messages), simplify conditionals/collections usage
server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java Update test method calls to match new method signatures (removed caller parameters, replaced 1l with 1L)
api/src/main/java/com/cloud/vm/UserVmService.java Remove StorageUnavailableException from method signatures, remove redundant public modifier from interface method
api/src/main/java/com/cloud/template/VirtualMachineTemplate.java Add generic type parameter to getDetails() return type

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
@DaanHoogland
Copy link
Copy Markdown
Contributor Author

@sureshanaparti can you have a look as well, please?

Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Outdated
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
12.5% Coverage on New Code (required ≥ 40%)

See analysis details on SonarQube Cloud

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 4 out of 5 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Outdated
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 4 out of 5 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Outdated
Comment thread utils/src/main/java/com/cloud/utils/StringUtils.java Outdated
Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
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 3 out of 4 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +4591 to +4593
// Check is hostName is RFC compliant
checkNameForRFCCompliance(hostName);

Comment on lines +1149 to +1153
if (vm.getState() != State.Running || vm.getHostId() == null) {
logger.error("Vm {} is not in Running state, failed to reboot", vm);
return null;
}
if ( null == vm.getHostId() ) {
Comment on lines +4245 to +4261
@Nullable
private static HypervisorType getHypervisorTypeFromHypervisorAndTemplate(HypervisorType hypervisor, VMTemplateVO template) {
HypervisorType hypervisorType = null;
if (template != null) {
if (template.getHypervisorType() == null || template.getHypervisorType() == HypervisorType.None) {
if (hypervisor == null || hypervisor == HypervisorType.None) {
throw new InvalidParameterValueException("Hypervisor parameter is needed to deploy VM or the hypervisor parameter value passed is invalid");
}
hypervisorType = hypervisor;
} else {
if (hypervisor != null && hypervisor != HypervisorType.None && hypervisor != template.getHypervisorType()) {
throw new InvalidParameterValueException("Hypervisor passed to the deployVm call, is different from the hypervisor type of the Template");
}
hypervisorType = template.getHypervisorType();
}
}
return hypervisorType;
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 5, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
11.8% Coverage on New Code (required ≥ 40%)

See analysis details on SonarQube Cloud

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