-
Notifications
You must be signed in to change notification settings - Fork 1.3k
api,server: fix listing vm metrics for infra resources #6851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1d4be98
de4cd2a
b88d76e
b8ceeef
01a9505
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package org.apache.cloudstack.api; | ||
|
|
||
| import org.apache.cloudstack.acl.RoleType; | ||
| import org.apache.cloudstack.api.command.admin.AdminCmd; | ||
| import org.apache.cloudstack.api.response.ClusterResponse; | ||
| import org.apache.cloudstack.api.response.HostResponse; | ||
| import org.apache.cloudstack.api.response.PodResponse; | ||
| import org.apache.cloudstack.api.response.StoragePoolResponse; | ||
| import org.apache.cloudstack.response.VmMetricsResponse; | ||
|
|
||
| @APICommand(name = ListVMsMetricsCmd.APINAME, description = "Lists VM metrics", responseObject = VmMetricsResponse.class, | ||
| requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, responseView = ResponseObject.ResponseView.Full, | ||
| authorized = {RoleType.Admin}) | ||
| public class ListVMsMetricsCmdByAdmin extends ListVMsMetricsCmd implements AdminCmd { | ||
|
|
||
| ///////////////////////////////////////////////////// | ||
| //////////////// API parameters ///////////////////// | ||
| ///////////////////////////////////////////////////// | ||
|
|
||
| @Parameter(name=ApiConstants.HOST_ID, type= BaseCmd.CommandType.UUID, entityType= HostResponse.class, | ||
| description="the host ID") | ||
| private Long hostId; | ||
|
|
||
| @Parameter(name=ApiConstants.POD_ID, type= BaseCmd.CommandType.UUID, entityType= PodResponse.class, | ||
| description="the pod ID") | ||
| private Long podId; | ||
|
|
||
| @Parameter(name=ApiConstants.STORAGE_ID, type= BaseCmd.CommandType.UUID, entityType= StoragePoolResponse.class, | ||
| description="the storage ID where vm's volumes belong to") | ||
| private Long storageId; | ||
|
|
||
| @Parameter(name = ApiConstants.CLUSTER_ID, type = BaseCmd.CommandType.UUID, entityType = ClusterResponse.class, | ||
| description = "the cluster ID") | ||
| private Long clusterId; | ||
|
|
||
|
|
||
| ///////////////////////////////////////////////////// | ||
| /////////////////// Accessors /////////////////////// | ||
| ///////////////////////////////////////////////////// | ||
|
|
||
| public Long getHostId() { | ||
| return hostId; | ||
| } | ||
|
|
||
| public Long getPodId() { | ||
| return podId; | ||
| } | ||
|
|
||
| public Long getStorageId() { | ||
| return storageId; | ||
| } | ||
|
|
||
| public Long getClusterId() { | ||
| return clusterId; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,6 +16,8 @@ | |||||
| // under the License. | ||||||
| package com.cloud.api.query; | ||||||
|
|
||||||
| import java.lang.reflect.InvocationTargetException; | ||||||
| import java.lang.reflect.Method; | ||||||
| import java.util.ArrayList; | ||||||
| import java.util.Arrays; | ||||||
| import java.util.Collections; | ||||||
|
|
@@ -65,7 +67,6 @@ | |||||
| import org.apache.cloudstack.api.command.admin.storage.ListStorageTagsCmd; | ||||||
| import org.apache.cloudstack.api.command.admin.template.ListTemplatesCmdByAdmin; | ||||||
| import org.apache.cloudstack.api.command.admin.user.ListUsersCmd; | ||||||
| import org.apache.cloudstack.api.command.admin.vm.ListVMsCmdByAdmin; | ||||||
| import org.apache.cloudstack.api.command.admin.zone.ListZonesCmdByAdmin; | ||||||
| import org.apache.cloudstack.api.command.user.account.ListAccountsCmd; | ||||||
| import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd; | ||||||
|
|
@@ -971,6 +972,17 @@ public ListResponse<UserVmResponse> searchForUserVMs(ListVMsCmd cmd) { | |||||
| return response; | ||||||
| } | ||||||
|
|
||||||
| private Object getObjectPossibleMethodValue(Object obj, String methodName) { | ||||||
| Object result = null; | ||||||
|
|
||||||
| try { | ||||||
| Method m = obj.getClass().getMethod(methodName); | ||||||
| result = m.invoke(obj); | ||||||
| } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ignored) {} | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not even logged?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps log here? @DaanHoogland or do you think we may never hit this?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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.
Suggested change
|
||||||
|
|
||||||
| return result; | ||||||
| } | ||||||
|
|
||||||
| private Pair<List<UserVmJoinVO>, Integer> searchForUserVMsInternal(ListVMsCmd cmd) { | ||||||
| Account caller = CallContext.current().getCallingAccount(); | ||||||
| List<Long> permittedAccounts = new ArrayList<Long>(); | ||||||
|
|
@@ -1035,16 +1047,14 @@ private Pair<List<UserVmJoinVO>, Integer> searchForUserVMsInternal(ListVMsCmd cm | |||||
| Object backupOfferingId = cmd.getBackupOfferingId(); | ||||||
| Object isHaEnabled = cmd.getHaEnabled(); | ||||||
| Object pod = null; | ||||||
| Long clusterId = null; | ||||||
| Object clusterId = null; | ||||||
| Object hostId = null; | ||||||
| Object storageId = null; | ||||||
| if (_accountMgr.isRootAdmin(caller.getId())) { | ||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DaanHoogland I am afraid the below code may not work as cmd will be an instance of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||||||
| if (cmd instanceof ListVMsCmdByAdmin) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we remove this, do we still need the extra class, or can we just implement the extra parameters in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does that matter? they will just not be able to use the extra parameters.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think is this a common pattern (unless we want to deprecate this) used across 54 APIs:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But these use the |
||||||
| pod = ((ListVMsCmdByAdmin) cmd).getPodId(); | ||||||
| clusterId = ((ListVMsCmdByAdmin) cmd).getClusterId(); | ||||||
| hostId = ((ListVMsCmdByAdmin) cmd).getHostId(); | ||||||
| storageId = ((ListVMsCmdByAdmin) cmd).getStorageId(); | ||||||
| } | ||||||
| pod = getObjectPossibleMethodValue(cmd, "getPodId"); | ||||||
| clusterId = getObjectPossibleMethodValue(cmd, "getClusterId"); | ||||||
| hostId = getObjectPossibleMethodValue(cmd, "getHostId"); | ||||||
| storageId = getObjectPossibleMethodValue(cmd, "getStorageId"); | ||||||
| } | ||||||
|
|
||||||
| sb.and("displayName", sb.entity().getDisplayName(), SearchCriteria.Op.LIKE); | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DaanHoogland could you add a unit test to cover this method?