api,server: fix listing vm metrics for infra resources#6851
Conversation
listVirtualMachinesMetrics does not support some of the params that are supported by admin API call for listVirtualMachines. These parameters are used in UI. Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
|
Found UI changes, kicking a new UI QA build |
|
@acs-robot a Jenkins job has been kicked to build UI QA env. I'll keep you posted as I make progress. |
|
UI build: ✔️ |
|
@blueorangutan package |
|
@shwstppr a Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Found UI changes, kicking a new UI QA build |
|
@acs-robot a Jenkins job has been kicked to build UI QA env. I'll keep you posted as I make progress. |
|
UI build: ✔️ |
|
SonarCloud Quality Gate failed. |
|
Packaging result: ✔️ el7 ✖️ el8 ✔️ debian ✔️ suse15. SL-JID 4554 |
Codecov Report
@@ Coverage Diff @@
## 4.17 #6851 +/- ##
============================================
+ Coverage 10.34% 10.36% +0.02%
- Complexity 6610 6629 +19
============================================
Files 2451 2452 +1
Lines 242339 242367 +28
Branches 37923 37927 +4
============================================
+ Hits 25058 25123 +65
+ Misses 214195 214141 -54
- Partials 3086 3103 +17
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
| @APICommand(name = ListVMsMetricsCmd.APINAME, description = "Lists VM metrics", responseObject = VmMetricsResponse.class, | ||
| requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, responseView = ResponseObject.ResponseView.Full, | ||
| since = "4.9.3", authorized = {RoleType.Admin}) | ||
| @Deprecated(since = "4.17.0") |
There was a problem hiding this comment.
why create a deprecated class?
There was a problem hiding this comment.
I can remove the deprecated tag but the original api class has this deprecated tag
There was a problem hiding this comment.
I don´t know why it has/What the thought behind it was. But we are obviously intending to maintain it so it is not deprecated. Let's remove it.
|
|
||
| @APICommand(name = ListVMsMetricsCmd.APINAME, description = "Lists VM metrics", responseObject = VmMetricsResponse.class, | ||
| requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, responseView = ResponseObject.ResponseView.Full, | ||
| since = "4.9.3", authorized = {RoleType.Admin}) |
There was a problem hiding this comment.
| since = "4.9.3", authorized = {RoleType.Admin}) | |
| since = "4.18.0", authorized = {RoleType.Admin}) |
There was a problem hiding this comment.
Not sure if it makes sense to add 4.18 here as it is not a new API just an additional Admin class for adding some params for admin account
There was a problem hiding this comment.
I think we better remove the since attribute completely. I don't think it add value either way.
There was a problem hiding this comment.
it might cause issue with apidocs generation - to be clear this isn't adding a new API; but an admin cmd (api with admin specific params)
There was a problem hiding this comment.
it shouldn´t, there are others without this annotation parameter are there?
There was a problem hiding this comment.
| since = "4.9.3", authorized = {RoleType.Admin}) | |
| authorized = {RoleType.Admin}) |
| requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, responseView = ResponseObject.ResponseView.Full, | ||
| since = "4.9.3", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) | ||
| since = "4.9.3", authorized = {RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) | ||
| @Deprecated(since = "4.17.0") |
There was a problem hiding this comment.
what was the idea of deprecation? should we leave this annotation in?
There was a problem hiding this comment.
let's remove the deprecation annotation
| Object hostId = null; | ||
| Object storageId = null; | ||
| if (_accountMgr.isRootAdmin(caller.getId())) { | ||
| if (cmd instanceof ListVMsCmdByAdmin) { |
There was a problem hiding this comment.
if we remove this, do we still need the extra class, or can we just implement the extra parameters in ListVMsMetricsCmd?
There was a problem hiding this comment.
ListVMsMetricsCmd is accessible to all users therefore new ByAdmin class added and new params not added in the original
There was a problem hiding this comment.
does that matter? they will just not be able to use the extra parameters.
There was a problem hiding this comment.
I think is this a common pattern (unless we want to deprecate this) used across 54 APIs:
> find . | grep ByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/vmsnapshot/RevertToVMSnapshotCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/iso/ListIsosCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/iso/UpdateIsoCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/iso/DetachIsoCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/iso/ListIsoPermissionsCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/iso/AttachIsoCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/iso/CopyIsoCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/iso/RegisterIsoCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListZonesCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListNetworksCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateNetworkCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/template/ListTemplatesCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/template/CreateTemplateCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/template/RegisterTemplateCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/template/UpdateTemplateCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/template/CopyTemplateCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/template/ListTemplatePermissionsCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/loadbalancer/ListLoadBalancerRuleInstancesCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/vm/StopVMCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/vm/DestroyVMCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ScaleVMCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVMsCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/vm/DeployVMCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/vm/StartVMCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RebootVMCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RemoveNicFromVMCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UpdateDefaultNicForVMCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UpgradeVMCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ResetVMSSHKeyCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UpdateVMCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/vm/AddNicToVMCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RestoreVMCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ResetVMPasswordCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/address/ListPublicIpAddressesCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/address/AcquirePodIpCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/address/ReleasePodIpCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/address/AssociateIPAddrCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/ListVPCsCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/affinitygroup/UpdateVMAffinityGroupCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/account/ListAccountsCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/volume/ResizeVolumeCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/volume/ListVolumesCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/volume/DestroyVolumeCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/volume/UpdateVolumeCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/volume/CreateVolumeCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/volume/AttachVolumeCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/volume/RecoverVolumeCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/volume/MigrateVolumeCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/volume/UploadVolumeCmdByAdmin.java
./api/src/main/java/org/apache/cloudstack/api/command/admin/volume/DetachVolumeCmdByAdmin.java
There was a problem hiding this comment.
But these use the if (cmd instaceof <...>ByAdmin) {} pattern. Or we changing this? It is a good improvement in some ways but would justify its own PR.
|
@blueorangutan package |
|
@nvazquez a Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
@blueorangutan package |
|
@rohityadavcloud a Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result: ✔️ el7 ✔️ el8 ✔️ debian ✔️ suse15. SL-JID 4638 |
|
@blueorangutan test matrix |
|
@DaanHoogland a Trillian-Jenkins matrix job (centos7 mgmt + xs71, centos7 mgmt + vmware65, centos7 mgmt + kvmcentos7) has been kicked to run smoke tests |
|
Trillian Build Failed (tid-5270) |
|
Will merge this after this round of pkging+smoketests. |
|
Packaging result: ✔️ el7 ✔️ el8 ✔️ debian ✔️ suse15. SL-JID 4831 |
| Object clusterId = null; | ||
| Object hostId = null; | ||
| Object storageId = null; | ||
| if (_accountMgr.isRootAdmin(caller.getId())) { |
There was a problem hiding this comment.
@DaanHoogland I am afraid the below code may not work as cmd will be an instance of ListVMsMetricsCmdByAdmin and not ListVMsCmdByAdmin
There was a problem hiding this comment.
ok, you are right, thanks. so it needs to be checking for both possibilities.
You actually justified using reflection now, I didn´t see that before.
|
I re-applied your reflection bit. I created an issue to remove the |
|
@blueorangutan package |
|
@DaanHoogland a Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
| } | ||
|
|
||
| private Object getObjectPossibleMethodValue(Object obj, String methodName) { | ||
| Object result = null; |
There was a problem hiding this comment.
@DaanHoogland could you add a unit test to cover this method?
| try { | ||
| Method m = obj.getClass().getMethod(methodName); | ||
| result = m.invoke(obj); | ||
| } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ignored) {} |
There was a problem hiding this comment.
Perhaps log here? @DaanHoogland or do you think we may never hit this?
There was a problem hiding this comment.
i was thinking that as well, but didn´t want to change to much anymore. We will hit this for sure in the current state if ListVMsCmd is called in the API. It will try to add the attributes that don´t exist and we are supposed to ignore those.
| } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ignored) {} | |
| } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ignored) {/*ignored when non-ByAdmin are calling this.*/} |
|
Packaging result: ✔️ el7 ✔️ el8 ✔️ debian ✔️ suse15. SL-JID 4834 |
|
@blueorangutan test |
|
@rohityadavcloud a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests |
|
Trillian Build Failed (tid-5447) |
|
@blueorangutan test |
|
@rohityadavcloud a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests |
|
Trillian test result (tid-5455)
|
|
@blueorangutan test |
|
@rohityadavcloud a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests |
|
Trillian test result (tid-5458)
|
|
@blueorangutan package |
|
@rohityadavcloud a Jenkins job has been kicked to build packages. It will be bundled with SystemVM template(s). I'll keep you posted as I make progress. |
|
Packaging result: ✔️ el7 ✔️ el8 ✔️ debian ✔️ suse15. SL-JID 4844 |
|
@blueorangutan test |
|
@rohityadavcloud a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests |
|
Unmanage VM test issues fixed in another commit. Merging this but will monitor tests on 4.17 branch. |
|
Trillian test result (tid-5459)
|









Description
Fixes #6786
listVirtualMachinesMetrics does not support some of the params that are supported by admin API call for listVirtualMachines. These parameters are used in UI.
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?