You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mc...@apache.org on 2013/10/03 02:53:23 UTC
[1/2] git commit: updated refs/heads/rbac to b633950
Updated Branches:
refs/heads/rbac bcd4cdd29 -> b633950a6
Separate Admin and User command and response for ListVMsCmd.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/d84d62a1
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/d84d62a1
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/d84d62a1
Branch: refs/heads/rbac
Commit: d84d62a1e0417bd2d77f4aed723f6e5ddb2600e6
Parents: bcd4cdd
Author: Min Chen <mi...@citrix.com>
Authored: Wed Oct 2 17:45:14 2013 -0700
Committer: Min Chen <mi...@citrix.com>
Committed: Wed Oct 2 17:45:14 2013 -0700
----------------------------------------------------------------------
.../org/apache/cloudstack/api/APICommand.java | 4 ++
.../cloudstack/api/ResponseGenerator.java | 5 ++
.../apache/cloudstack/api/ResponseObject.java | 5 ++
.../api/command/admin/vm/ListVMsCmdByAdmin.java | 69 ++++++++++++++++++++
.../api/command/user/vm/ListVMsCmd.java | 34 ++--------
server/src/com/cloud/api/ApiDBUtils.java | 9 +--
server/src/com/cloud/api/ApiResponseHelper.java | 17 ++++-
server/src/com/cloud/api/ApiServer.java | 38 +++++++++--
.../com/cloud/api/query/QueryManagerImpl.java | 17 +++--
.../com/cloud/api/query/ViewResponseHelper.java | 11 ++--
.../com/cloud/api/query/dao/UserVmJoinDao.java | 5 +-
.../cloud/api/query/dao/UserVmJoinDaoImpl.java | 19 +++---
.../com/cloud/server/ManagementServerImpl.java | 2 +
tools/apidoc/gen_toc.py | 3 +-
14 files changed, 174 insertions(+), 64 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d84d62a1/api/src/org/apache/cloudstack/api/APICommand.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/APICommand.java b/api/src/org/apache/cloudstack/api/APICommand.java
index 4d024c1..621b347 100644
--- a/api/src/org/apache/cloudstack/api/APICommand.java
+++ b/api/src/org/apache/cloudstack/api/APICommand.java
@@ -22,6 +22,8 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
+
@Retention(RetentionPolicy.RUNTIME)
@Target({ TYPE })
public @interface APICommand {
@@ -36,4 +38,6 @@ public @interface APICommand {
boolean includeInApiDoc() default true;
String since() default "";
+
+ ResponseView responseView() default ResponseView.Admin;
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d84d62a1/api/src/org/apache/cloudstack/api/ResponseGenerator.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ResponseGenerator.java b/api/src/org/apache/cloudstack/api/ResponseGenerator.java
index 3f58158..aeb7521 100644
--- a/api/src/org/apache/cloudstack/api/ResponseGenerator.java
+++ b/api/src/org/apache/cloudstack/api/ResponseGenerator.java
@@ -28,6 +28,7 @@ import org.apache.cloudstack.affinity.AffinityGroup;
import org.apache.cloudstack.affinity.AffinityGroupResponse;
import org.apache.cloudstack.api.ApiConstants.HostDetails;
import org.apache.cloudstack.api.ApiConstants.VMDetails;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.command.user.job.QueryAsyncJobResultCmd;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.AclGroupResponse;
@@ -219,6 +220,10 @@ public interface ResponseGenerator {
List<UserVmResponse> createUserVmResponse(String objectName, EnumSet<VMDetails> details, UserVm... userVms);
+ List<UserVmResponse> createUserVmResponse(ResponseView view, String objectName, UserVm... userVms);
+
+ List<UserVmResponse> createUserVmResponse(ResponseView view, String objectName, EnumSet<VMDetails> details, UserVm... userVms);
+
SystemVmResponse createSystemVmResponse(VirtualMachine systemVM);
DomainRouterResponse createDomainRouterResponse(VirtualRouter router);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d84d62a1/api/src/org/apache/cloudstack/api/ResponseObject.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ResponseObject.java b/api/src/org/apache/cloudstack/api/ResponseObject.java
index c8bd457..6c32016 100644
--- a/api/src/org/apache/cloudstack/api/ResponseObject.java
+++ b/api/src/org/apache/cloudstack/api/ResponseObject.java
@@ -76,4 +76,9 @@ public interface ResponseObject {
* @param jobStatus
*/
void setJobStatus(Integer jobStatus);
+
+ public enum ResponseView {
+ Admin,
+ User
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d84d62a1/api/src/org/apache/cloudstack/api/command/admin/vm/ListVMsCmdByAdmin.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/vm/ListVMsCmdByAdmin.java b/api/src/org/apache/cloudstack/api/command/admin/vm/ListVMsCmdByAdmin.java
new file mode 100644
index 0000000..5699fbd
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/admin/vm/ListVMsCmdByAdmin.java
@@ -0,0 +1,69 @@
+// 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.command.admin.vm;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
+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.api.response.UserVmResponse;
+
+
+@APICommand(name = "listVirtualMachines", description = "List the virtual machines owned by the account.", responseObject = UserVmResponse.class, responseView = ResponseView.Admin)
+public class ListVMsCmdByAdmin extends ListVMsCmd {
+ public static final Logger s_logger = Logger.getLogger(ListVMsCmdByAdmin.class.getName());
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.HOST_ID, type=CommandType.UUID, entityType=HostResponse.class,
+ description="the host ID")
+ private Long hostId;
+
+ @Parameter(name=ApiConstants.POD_ID, type=CommandType.UUID, entityType=PodResponse.class,
+ description="the pod ID")
+ private Long podId;
+
+ @Parameter(name=ApiConstants.STORAGE_ID, type=CommandType.UUID, entityType=StoragePoolResponse.class,
+ description="the storage ID where vm's volumes belong to")
+ private Long storageId;
+
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getHostId() {
+ return hostId;
+ }
+
+ public Long getPodId() {
+ return podId;
+ }
+
+ public Long getStorageId() {
+ return storageId;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d84d62a1/api/src/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java
index cb31393..a08b359 100644
--- a/api/src/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java
@@ -20,6 +20,8 @@ import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
+import org.apache.log4j.Logger;
+
import org.apache.cloudstack.affinity.AffinityGroupResponse;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiCommandJobType;
@@ -27,23 +29,20 @@ import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiConstants.VMDetails;
import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.response.HostResponse;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.response.InstanceGroupResponse;
import org.apache.cloudstack.api.response.IsoVmResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.NetworkResponse;
-import org.apache.cloudstack.api.response.PodResponse;
-import org.apache.cloudstack.api.response.StoragePoolResponse;
import org.apache.cloudstack.api.response.TemplateResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.api.response.VpcResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
-import org.apache.log4j.Logger;
import com.cloud.exception.InvalidParameterValueException;
-@APICommand(name = "listVirtualMachines", description="List the virtual machines owned by the account.", responseObject=UserVmResponse.class)
+@APICommand(name = "listVirtualMachines", description = "List the virtual machines owned by the account.", responseObject = UserVmResponse.class, responseView = ResponseView.User)
public class ListVMsCmd extends BaseListTaggedResourcesCmd {
public static final Logger s_logger = Logger.getLogger(ListVMsCmd.class.getName());
@@ -57,10 +56,6 @@ public class ListVMsCmd extends BaseListTaggedResourcesCmd {
description="the group ID")
private Long groupId;
- @Parameter(name=ApiConstants.HOST_ID, type=CommandType.UUID, entityType=HostResponse.class,
- description="the host ID")
- private Long hostId;
-
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=UserVmResponse.class,
description="the ID of the virtual machine")
private Long id;
@@ -68,10 +63,6 @@ public class ListVMsCmd extends BaseListTaggedResourcesCmd {
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="name of the virtual machine")
private String name;
- @Parameter(name=ApiConstants.POD_ID, type=CommandType.UUID, entityType=PodResponse.class,
- description="the pod ID")
- private Long podId;
-
@Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="state of the virtual machine")
private String state;
@@ -89,10 +80,6 @@ public class ListVMsCmd extends BaseListTaggedResourcesCmd {
@Parameter(name=ApiConstants.HYPERVISOR, type=CommandType.STRING, description="the target hypervisor for the template")
private String hypervisor;
- @Parameter(name=ApiConstants.STORAGE_ID, type=CommandType.UUID, entityType=StoragePoolResponse.class,
- description="the storage ID where vm's volumes belong to")
- private Long storageId;
-
@Parameter(name=ApiConstants.DETAILS, type=CommandType.LIST, collectionType=CommandType.STRING,
description="comma separated list of host details requested, " +
"value can be a list of [all, group, nics, stats, secgrp, tmpl, servoff, iso, volume, min, affgrp]." +
@@ -122,10 +109,6 @@ public class ListVMsCmd extends BaseListTaggedResourcesCmd {
return groupId;
}
- public Long getHostId() {
- return hostId;
- }
-
public Long getId() {
return id;
}
@@ -134,10 +117,6 @@ public class ListVMsCmd extends BaseListTaggedResourcesCmd {
return name;
}
- public Long getPodId() {
- return podId;
- }
-
public String getState() {
return state;
}
@@ -162,9 +141,6 @@ public class ListVMsCmd extends BaseListTaggedResourcesCmd {
return hypervisor;
}
- public Long getStorageId() {
- return storageId;
- }
public Long getTemplateId() {
return templateId;
@@ -219,6 +195,6 @@ public class ListVMsCmd extends BaseListTaggedResourcesCmd {
public void execute(){
ListResponse<UserVmResponse> response = _queryService.searchForUserVMs(this);
response.setResponseName(getCommandName());
- this.setResponseObject(response);
+ setResponseObject(response);
}
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d84d62a1/server/src/com/cloud/api/ApiDBUtils.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java
index 3ede856..1409961 100755
--- a/server/src/com/cloud/api/ApiDBUtils.java
+++ b/server/src/com/cloud/api/ApiDBUtils.java
@@ -33,6 +33,7 @@ import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
import org.apache.cloudstack.api.ApiCommandJobType;
import org.apache.cloudstack.api.ApiConstants.HostDetails;
import org.apache.cloudstack.api.ApiConstants.VMDetails;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.AclGroupResponse;
import org.apache.cloudstack.api.response.AclRoleResponse;
@@ -1423,12 +1424,12 @@ public class ApiDBUtils {
return _domainRouterJoinDao.newDomainRouterView(vr);
}
- public static UserVmResponse newUserVmResponse(String objectName, UserVmJoinVO userVm, EnumSet<VMDetails> details, Account caller) {
- return _userVmJoinDao.newUserVmResponse(objectName, userVm, details, caller);
+ public static UserVmResponse newUserVmResponse(ResponseView view, String objectName, UserVmJoinVO userVm, EnumSet<VMDetails> details, Account caller) {
+ return _userVmJoinDao.newUserVmResponse(view, objectName, userVm, details, caller);
}
- public static UserVmResponse fillVmDetails(UserVmResponse vmData, UserVmJoinVO vm){
- return _userVmJoinDao.setUserVmResponse(vmData, vm);
+ public static UserVmResponse fillVmDetails(ResponseView view, UserVmResponse vmData, UserVmJoinVO vm) {
+ return _userVmJoinDao.setUserVmResponse(view, vmData, vm);
}
public static List<UserVmJoinVO> newUserVmView(UserVm... userVms){
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d84d62a1/server/src/com/cloud/api/ApiResponseHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java
index b19d6ef..be574a0 100755
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -42,6 +42,7 @@ import org.apache.cloudstack.affinity.AffinityGroupResponse;
import org.apache.cloudstack.api.ApiConstants.HostDetails;
import org.apache.cloudstack.api.ApiConstants.VMDetails;
import org.apache.cloudstack.api.ResponseGenerator;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.command.user.job.QueryAsyncJobResultCmd;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.AclGroupResponse;
@@ -1085,16 +1086,26 @@ public class ApiResponseHelper implements ResponseGenerator {
}
@Override
+ public List<UserVmResponse> createUserVmResponse(String objectName, UserVm... userVms) {
+ return createUserVmResponse(null, objectName, userVms);
+ }
+
+ @Override
public List<UserVmResponse> createUserVmResponse(String objectName, EnumSet<VMDetails> details, UserVm... userVms) {
+ return createUserVmResponse(null, objectName, userVms);
+ }
+
+ @Override
+ public List<UserVmResponse> createUserVmResponse(ResponseView view, String objectName, EnumSet<VMDetails> details, UserVm... userVms) {
List<UserVmJoinVO> viewVms = ApiDBUtils.newUserVmView(userVms);
- return ViewResponseHelper.createUserVmResponse(objectName, details, viewVms.toArray(new UserVmJoinVO[viewVms.size()]));
+ return ViewResponseHelper.createUserVmResponse(view, objectName, details, viewVms.toArray(new UserVmJoinVO[viewVms.size()]));
}
@Override
- public List<UserVmResponse> createUserVmResponse(String objectName, UserVm... userVms) {
+ public List<UserVmResponse> createUserVmResponse(ResponseView view, String objectName, UserVm... userVms) {
List<UserVmJoinVO> viewVms = ApiDBUtils.newUserVmView(userVms);
- return ViewResponseHelper.createUserVmResponse(objectName, viewVms.toArray(new UserVmJoinVO[viewVms.size()]));
+ return ViewResponseHelper.createUserVmResponse(view, objectName, viewVms.toArray(new UserVmJoinVO[viewVms.size()]));
}
@Override
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d84d62a1/server/src/com/cloud/api/ApiServer.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java
index 1a93e9a..846cd53 100755
--- a/server/src/com/cloud/api/ApiServer.java
+++ b/server/src/com/cloud/api/ApiServer.java
@@ -91,6 +91,7 @@ import org.apache.cloudstack.api.BaseAsyncCreateCmd;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.ResponseObject;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
import org.apache.cloudstack.api.command.admin.router.ListRoutersCmd;
@@ -176,7 +177,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
protected ApiAsyncJobDispatcher _asyncDispatcher;
private static int _workerCount = 0;
private static final DateFormat _dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
- private static Map<String, Class<?>> _apiNameCmdClassMap = new HashMap<String, Class<?>>();
+ private static Map<String, List<Class<?>>> _apiNameCmdClassMap = new HashMap<String, List<Class<?>>>();
private static ExecutorService _executor = new ThreadPoolExecutor(10, 150, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("ApiServer"));
@@ -232,11 +233,12 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
throw new CloudRuntimeException(String.format("%s is claimed as a API command, but it doesn't have @APICommand annotation", cmdClass.getName()));
}
String apiName = at.name();
- if (_apiNameCmdClassMap.containsKey(apiName)) {
- s_logger.error("API Cmd class " + cmdClass.getName() + " has non-unique apiname" + apiName);
- continue;
+ List<Class<?>> apiCmdList = _apiNameCmdClassMap.get(apiName);
+ if (apiCmdList == null) {
+ apiCmdList = new ArrayList<Class<?>>();
+ _apiNameCmdClassMap.put(apiName, apiCmdList);
}
- _apiNameCmdClassMap.put(apiName, cmdClass);
+ apiCmdList.add(cmdClass);
}
encodeApiResponse = Boolean.valueOf(_configDao.getValue(Config.EncodeApiResponse.key()));
@@ -882,7 +884,31 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
}
private Class<?> getCmdClass(String cmdName) {
- return _apiNameCmdClassMap.get(cmdName);
+ List<Class<?>> cmdList = _apiNameCmdClassMap.get(cmdName);
+ if (cmdList == null || cmdList.size() == 0)
+ return null;
+ else if (cmdList.size() == 1)
+ return cmdList.get(0);
+ else {
+ // determine the cmd class based on calling context
+ ResponseView view = ResponseView.User;
+ if (_accountMgr.isRootAdmin(CallContext.current().getCallingAccount().getId())) {
+ view = ResponseView.Admin;
+ }
+ for (Class<?> cmdClass : cmdList) {
+ APICommand at = cmdClass.getAnnotation(APICommand.class);
+ if (at == null) {
+ throw new CloudRuntimeException(String.format("%s is claimed as a API command, but it doesn't have @APICommand annotation", cmdClass.getName()));
+ }
+ if (at.responseView() == null) {
+ throw new CloudRuntimeException(String.format(
+ "%s @APICommand annotation should specify responseView attribute to distinguish multiple command classes for a single api name", cmdClass.getName()));
+ } else if (at.responseView() == view) {
+ return cmdClass;
+ }
+ }
+ return null;
+ }
}
// FIXME: rather than isError, we might was to pass in the status code to give more flexibility
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d84d62a1/server/src/com/cloud/api/query/QueryManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java
index ee2d931..9022070 100644
--- a/server/src/com/cloud/api/query/QueryManagerImpl.java
+++ b/server/src/com/cloud/api/query/QueryManagerImpl.java
@@ -41,6 +41,7 @@ import org.apache.cloudstack.affinity.AffinityGroupVMMapVO;
import org.apache.cloudstack.affinity.dao.AffinityGroupDomainMapDao;
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
import org.apache.cloudstack.api.command.admin.internallb.ListInternalLBVMsCmd;
import org.apache.cloudstack.api.command.admin.router.ListRoutersCmd;
@@ -48,6 +49,7 @@ import org.apache.cloudstack.api.command.admin.storage.ListImageStoresCmd;
import org.apache.cloudstack.api.command.admin.storage.ListSecondaryStagingStoresCmd;
import org.apache.cloudstack.api.command.admin.storage.ListStoragePoolsCmd;
import org.apache.cloudstack.api.command.admin.user.ListUsersCmd;
+import org.apache.cloudstack.api.command.admin.vm.ListVMsCmdByAdmin;
import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd;
import org.apache.cloudstack.api.command.user.event.ListEventsCmd;
@@ -715,7 +717,11 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
public ListResponse<UserVmResponse> searchForUserVMs(ListVMsCmd cmd) {
Pair<List<UserVmJoinVO>, Integer> result = searchForUserVMsInternal(cmd);
ListResponse<UserVmResponse> response = new ListResponse<UserVmResponse>();
- List<UserVmResponse> vmResponses = ViewResponseHelper.createUserVmResponse("virtualmachine", cmd.getDetails(),
+ ResponseView respView = ResponseView.User;
+ if (cmd instanceof ListVMsCmdByAdmin) {
+ respView = ResponseView.Admin;
+ }
+ List<UserVmResponse> vmResponses = ViewResponseHelper.createUserVmResponse(respView, "virtualmachine", cmd.getDetails(),
result.first().toArray(new UserVmJoinVO[result.first().size()]));
response.setResponses(vmResponses, result.second());
return response;
@@ -764,10 +770,11 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
}
// ignore these search requests if it's not an admin
- if (_accountMgr.isAdmin(caller.getType())) {
- c.addCriteria(Criteria.PODID, cmd.getPodId());
- c.addCriteria(Criteria.HOSTID, cmd.getHostId());
- c.addCriteria(Criteria.STORAGE_ID, cmd.getStorageId());
+ if (cmd instanceof ListVMsCmdByAdmin) {
+ ListVMsCmdByAdmin adCmd = (ListVMsCmdByAdmin)cmd;
+ c.addCriteria(Criteria.PODID, adCmd.getPodId());
+ c.addCriteria(Criteria.HOSTID, adCmd.getHostId());
+ c.addCriteria(Criteria.STORAGE_ID, adCmd.getStorageId());
}
if (!permittedAccounts.isEmpty()) {
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d84d62a1/server/src/com/cloud/api/query/ViewResponseHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/ViewResponseHelper.java b/server/src/com/cloud/api/query/ViewResponseHelper.java
index 5abe14c..f3bc796 100644
--- a/server/src/com/cloud/api/query/ViewResponseHelper.java
+++ b/server/src/com/cloud/api/query/ViewResponseHelper.java
@@ -26,6 +26,7 @@ import org.apache.log4j.Logger;
import org.apache.cloudstack.affinity.AffinityGroupResponse;
import org.apache.cloudstack.api.ApiConstants.HostDetails;
import org.apache.cloudstack.api.ApiConstants.VMDetails;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.AclGroupResponse;
import org.apache.cloudstack.api.response.AclRoleResponse;
@@ -118,11 +119,11 @@ public class ViewResponseHelper {
}
- public static List<UserVmResponse> createUserVmResponse(String objectName, UserVmJoinVO... userVms) {
- return createUserVmResponse(objectName, EnumSet.of(VMDetails.all), userVms);
+ public static List<UserVmResponse> createUserVmResponse(ResponseView view, String objectName, UserVmJoinVO... userVms) {
+ return createUserVmResponse(view, objectName, EnumSet.of(VMDetails.all), userVms);
}
- public static List<UserVmResponse> createUserVmResponse(String objectName, EnumSet<VMDetails> details, UserVmJoinVO... userVms) {
+ public static List<UserVmResponse> createUserVmResponse(ResponseView view, String objectName, EnumSet<VMDetails> details, UserVmJoinVO... userVms) {
Account caller = CallContext.current().getCallingAccount();
Hashtable<Long, UserVmResponse> vmDataList = new Hashtable<Long, UserVmResponse>();
@@ -133,10 +134,10 @@ public class ViewResponseHelper {
UserVmResponse userVmData = vmDataList.get(userVm.getId());
if ( userVmData == null ){
// first time encountering this vm
- userVmData = ApiDBUtils.newUserVmResponse(objectName, userVm, details, caller);
+ userVmData = ApiDBUtils.newUserVmResponse(view, objectName, userVm, details, caller);
} else{
// update nics, securitygroups, tags, affinitygroups for 1 to many mapping fields
- userVmData = ApiDBUtils.fillVmDetails(userVmData, userVm);
+ userVmData = ApiDBUtils.fillVmDetails(view, userVmData, userVm);
}
vmDataList.put(userVm.getId(), userVmData);
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d84d62a1/server/src/com/cloud/api/query/dao/UserVmJoinDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/dao/UserVmJoinDao.java b/server/src/com/cloud/api/query/dao/UserVmJoinDao.java
index bfff839..87af584 100644
--- a/server/src/com/cloud/api/query/dao/UserVmJoinDao.java
+++ b/server/src/com/cloud/api/query/dao/UserVmJoinDao.java
@@ -20,6 +20,7 @@ import java.util.EnumSet;
import java.util.List;
import org.apache.cloudstack.api.ApiConstants.VMDetails;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.response.UserVmResponse;
import com.cloud.api.query.vo.UserVmJoinVO;
@@ -29,9 +30,9 @@ import com.cloud.utils.db.GenericDao;
public interface UserVmJoinDao extends GenericDao<UserVmJoinVO, Long> {
- UserVmResponse newUserVmResponse(String objectName, UserVmJoinVO userVm, EnumSet<VMDetails> details, Account caller);
+ UserVmResponse newUserVmResponse(ResponseView view, String objectName, UserVmJoinVO userVm, EnumSet<VMDetails> details, Account caller);
- UserVmResponse setUserVmResponse(UserVmResponse userVmData, UserVmJoinVO uvo);
+ UserVmResponse setUserVmResponse(ResponseView view, UserVmResponse userVmData, UserVmJoinVO uvo);
List<UserVmJoinVO> newUserVmView(UserVm... userVms);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d84d62a1/server/src/com/cloud/api/query/dao/UserVmJoinDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/dao/UserVmJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/UserVmJoinDaoImpl.java
index f2af38d..01ceb10 100644
--- a/server/src/com/cloud/api/query/dao/UserVmJoinDaoImpl.java
+++ b/server/src/com/cloud/api/query/dao/UserVmJoinDaoImpl.java
@@ -26,16 +26,17 @@ import java.util.Set;
import javax.ejb.Local;
import javax.inject.Inject;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
import org.apache.cloudstack.affinity.AffinityGroupResponse;
import org.apache.cloudstack.api.ApiConstants.VMDetails;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.response.NicResponse;
import org.apache.cloudstack.api.response.SecurityGroupResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
import com.cloud.api.ApiDBUtils;
import com.cloud.api.query.vo.ResourceTagJoinVO;
import com.cloud.api.query.vo.UserVmJoinVO;
@@ -46,8 +47,8 @@ import com.cloud.uservm.UserVm;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
-import com.cloud.vm.VmStats;
import com.cloud.vm.VirtualMachine.State;
+import com.cloud.vm.VmStats;
@Component
@@ -68,7 +69,7 @@ public class UserVmJoinDaoImpl extends GenericDaoBase<UserVmJoinVO, Long> implem
VmDetailSearch.and("idIN", VmDetailSearch.entity().getId(), SearchCriteria.Op.IN);
VmDetailSearch.done();
- this._count = "select count(distinct id) from user_vm_view WHERE ";
+ _count = "select count(distinct id) from user_vm_view WHERE ";
activeVmByIsoSearch = createSearchBuilder();
activeVmByIsoSearch.and("isoId", activeVmByIsoSearch.entity().getIsoId(), SearchCriteria.Op.EQ);
@@ -89,7 +90,7 @@ public class UserVmJoinDaoImpl extends GenericDaoBase<UserVmJoinVO, Long> implem
@Override
- public UserVmResponse newUserVmResponse(String objectName, UserVmJoinVO userVm, EnumSet<VMDetails> details, Account caller) {
+ public UserVmResponse newUserVmResponse(ResponseView view, String objectName, UserVmJoinVO userVm, EnumSet<VMDetails> details, Account caller) {
UserVmResponse userVmResponse = new UserVmResponse();
if (userVm.getHypervisorType() != null){
@@ -123,7 +124,7 @@ public class UserVmJoinDaoImpl extends GenericDaoBase<UserVmJoinVO, Long> implem
}
userVmResponse.setZoneId(userVm.getDataCenterUuid());
userVmResponse.setZoneName(userVm.getDataCenterName());
- if ((caller == null) || (_accountMgr.isRootAdmin(caller.getId()))) {
+ if (view == ResponseView.Admin || ((view == null) && ((caller == null) || (_accountMgr.isRootAdmin(caller.getId()))))) {
userVmResponse.setInstanceName(userVm.getInstanceName());
userVmResponse.setHostId(userVm.getHostUuid());
userVmResponse.setHostName(userVm.getHostName());
@@ -177,7 +178,7 @@ public class UserVmJoinDaoImpl extends GenericDaoBase<UserVmJoinVO, Long> implem
userVmResponse.setNetworkKbsWrite((long) vmStats.getNetworkWriteKBs());
- if ((userVm.getHypervisorType() != null)
+ if ((userVm.getHypervisorType() != null)
&& (userVm.getHypervisorType().equals(HypervisorType.KVM)
|| userVm.getHypervisorType().equals(HypervisorType.XenServer))) { // support KVM and XenServer only util 2013.06.25
userVmResponse.setDiskKbsRead((long) vmStats.getDiskReadKBs());
@@ -274,7 +275,7 @@ public class UserVmJoinDaoImpl extends GenericDaoBase<UserVmJoinVO, Long> implem
}
@Override
- public UserVmResponse setUserVmResponse(UserVmResponse userVmData, UserVmJoinVO uvo) {
+ public UserVmResponse setUserVmResponse(ResponseView view, UserVmResponse userVmData, UserVmJoinVO uvo) {
Long securityGroupId = uvo.getSecurityGroupId();
if (securityGroupId != null && securityGroupId.longValue() != 0) {
SecurityGroupResponse resp = new SecurityGroupResponse();
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d84d62a1/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index ae06643..1144330 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -211,6 +211,7 @@ import org.apache.cloudstack.api.command.admin.vlan.DeleteVlanIpRangeCmd;
import org.apache.cloudstack.api.command.admin.vlan.ListVlanIpRangesCmd;
import org.apache.cloudstack.api.command.admin.vlan.ReleasePublicIpRangeCmd;
import org.apache.cloudstack.api.command.admin.vm.AssignVMCmd;
+import org.apache.cloudstack.api.command.admin.vm.ListVMsCmdByAdmin;
import org.apache.cloudstack.api.command.admin.vm.MigrateVMCmd;
import org.apache.cloudstack.api.command.admin.vm.MigrateVirtualMachineWithVolumeCmd;
import org.apache.cloudstack.api.command.admin.vm.RecoverVMCmd;
@@ -2759,6 +2760,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
cmdList.add(DestroyVMCmd.class);
cmdList.add(GetVMPasswordCmd.class);
cmdList.add(ListVMsCmd.class);
+ cmdList.add(ListVMsCmdByAdmin.class);
cmdList.add(ScaleVMCmd.class);
cmdList.add(RebootVMCmd.class);
cmdList.add(RemoveNicFromVMCmd.class);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d84d62a1/tools/apidoc/gen_toc.py
----------------------------------------------------------------------
diff --git a/tools/apidoc/gen_toc.py b/tools/apidoc/gen_toc.py
index 9c53a48..d9b87d4 100644
--- a/tools/apidoc/gen_toc.py
+++ b/tools/apidoc/gen_toc.py
@@ -157,7 +157,8 @@ known_categories = {
'UCS' : 'UCS',
'Ucs' : 'UCS',
'CacheStores' : 'Cache Stores',
- 'CacheStore' : 'Cache Store'
+ 'CacheStore' : 'Cache Store',
+ 'Acl' : 'Acl'
}
[2/2] git commit: updated refs/heads/rbac to b633950
Posted by mc...@apache.org.
Fix a bug in generating account response, passed wrong parameter to get
account resource limit.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/b633950a
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/b633950a
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/b633950a
Branch: refs/heads/rbac
Commit: b633950a687941191127770e8196a19085a48104
Parents: d84d62a
Author: Min Chen <mi...@citrix.com>
Authored: Wed Oct 2 17:46:00 2013 -0700
Committer: Min Chen <mi...@citrix.com>
Committed: Wed Oct 2 17:46:00 2013 -0700
----------------------------------------------------------------------
.../cloud/api/query/dao/AccountJoinDaoImpl.java | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b633950a/server/src/com/cloud/api/query/dao/AccountJoinDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/dao/AccountJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/AccountJoinDaoImpl.java
index dc65687..bcc5e1a 100644
--- a/server/src/com/cloud/api/query/dao/AccountJoinDaoImpl.java
+++ b/server/src/com/cloud/api/query/dao/AccountJoinDaoImpl.java
@@ -123,7 +123,7 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
response.setVmTotal(vmTotal);
response.setVmAvailable(vmAvail);
- long ipLimit = ApiDBUtils.findCorrectResourceLimit(account.getIpLimit(), account.getType(), ResourceType.public_ip);
+ long ipLimit = ApiDBUtils.findCorrectResourceLimit(account.getIpLimit(), account.getId(), ResourceType.public_ip);
String ipLimitDisplay = (accountIsAdmin || ipLimit == -1) ? "Unlimited" : String.valueOf(ipLimit);
long ipTotal = (account.getIpTotal() == null) ? 0 : account.getIpTotal();
@@ -143,7 +143,7 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
response.setIpTotal(ipTotal);
response.setIpAvailable(ipAvail);
- long volumeLimit = ApiDBUtils.findCorrectResourceLimit(account.getVolumeLimit(), account.getType(), ResourceType.volume);
+ long volumeLimit = ApiDBUtils.findCorrectResourceLimit(account.getVolumeLimit(), account.getId(), ResourceType.volume);
String volumeLimitDisplay = (accountIsAdmin || volumeLimit == -1) ? "Unlimited" : String.valueOf(volumeLimit);
long volumeTotal = (account.getVolumeTotal() == 0) ? 0 : account.getVolumeTotal();
String volumeAvail = (accountIsAdmin || volumeLimit == -1) ? "Unlimited" : String.valueOf(volumeLimit - volumeTotal);
@@ -151,7 +151,7 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
response.setVolumeTotal(volumeTotal);
response.setVolumeAvailable(volumeAvail);
- long snapshotLimit = ApiDBUtils.findCorrectResourceLimit(account.getSnapshotLimit(), account.getType(), ResourceType.snapshot);
+ long snapshotLimit = ApiDBUtils.findCorrectResourceLimit(account.getSnapshotLimit(), account.getId(), ResourceType.snapshot);
String snapshotLimitDisplay = (accountIsAdmin || snapshotLimit == -1) ? "Unlimited" : String.valueOf(snapshotLimit);
long snapshotTotal = (account.getSnapshotTotal() == null) ? 0 : account.getSnapshotTotal();
String snapshotAvail = (accountIsAdmin || snapshotLimit == -1) ? "Unlimited" : String.valueOf(snapshotLimit - snapshotTotal);
@@ -159,7 +159,7 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
response.setSnapshotTotal(snapshotTotal);
response.setSnapshotAvailable(snapshotAvail);
- Long templateLimit = ApiDBUtils.findCorrectResourceLimit(account.getTemplateLimit(), account.getType(), ResourceType.template);
+ Long templateLimit = ApiDBUtils.findCorrectResourceLimit(account.getTemplateLimit(), account.getId(), ResourceType.template);
String templateLimitDisplay = (accountIsAdmin || templateLimit == -1) ? "Unlimited" : String.valueOf(templateLimit);
Long templateTotal = (account.getTemplateTotal() == null) ? 0 : account.getTemplateTotal();
String templateAvail = (accountIsAdmin || templateLimit == -1) ? "Unlimited" : String.valueOf(templateLimit - templateTotal);
@@ -172,7 +172,7 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
response.setVmRunning(account.getVmRunning());
//get resource limits for networks
- long networkLimit = ApiDBUtils.findCorrectResourceLimit(account.getNetworkLimit(), account.getType(), ResourceType.network);
+ long networkLimit = ApiDBUtils.findCorrectResourceLimit(account.getNetworkLimit(), account.getId(), ResourceType.network);
String networkLimitDisplay = (accountIsAdmin || networkLimit == -1) ? "Unlimited" : String.valueOf(networkLimit);
long networkTotal = (account.getNetworkTotal() == null) ? 0 : account.getNetworkTotal();
String networkAvail = (accountIsAdmin || networkLimit == -1) ? "Unlimited" : String.valueOf(networkLimit - networkTotal);
@@ -181,7 +181,7 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
response.setNetworkAvailable(networkAvail);
//get resource limits for vpcs
- long vpcLimit = ApiDBUtils.findCorrectResourceLimit(account.getVpcLimit(), account.getType(), ResourceType.vpc);
+ long vpcLimit = ApiDBUtils.findCorrectResourceLimit(account.getVpcLimit(), account.getId(), ResourceType.vpc);
String vpcLimitDisplay = (accountIsAdmin || vpcLimit == -1) ? "Unlimited" : String.valueOf(vpcLimit);
long vpcTotal = (account.getVpcTotal() == null) ? 0 : account.getVpcTotal();
String vpcAvail = (accountIsAdmin || vpcLimit == -1) ? "Unlimited" : String.valueOf(vpcLimit - vpcTotal);
@@ -190,7 +190,7 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
response.setVpcAvailable(vpcAvail);
//get resource limits for cpu cores
- long cpuLimit = ApiDBUtils.findCorrectResourceLimit(account.getCpuLimit(), account.getType(), ResourceType.cpu);
+ long cpuLimit = ApiDBUtils.findCorrectResourceLimit(account.getCpuLimit(), account.getId(), ResourceType.cpu);
String cpuLimitDisplay = (accountIsAdmin || cpuLimit == -1) ? "Unlimited" : String.valueOf(cpuLimit);
long cpuTotal = (account.getCpuTotal() == null) ? 0 : account.getCpuTotal();
String cpuAvail = (accountIsAdmin || cpuLimit == -1) ? "Unlimited" : String.valueOf(cpuLimit - cpuTotal);
@@ -199,7 +199,7 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
response.setCpuAvailable(cpuAvail);
//get resource limits for memory
- long memoryLimit = ApiDBUtils.findCorrectResourceLimit(account.getMemoryLimit(), account.getType(), ResourceType.memory);
+ long memoryLimit = ApiDBUtils.findCorrectResourceLimit(account.getMemoryLimit(), account.getId(), ResourceType.memory);
String memoryLimitDisplay = (accountIsAdmin || memoryLimit == -1) ? "Unlimited" : String.valueOf(memoryLimit);
long memoryTotal = (account.getMemoryTotal() == null) ? 0 : account.getMemoryTotal();
String memoryAvail = (accountIsAdmin || memoryLimit == -1) ? "Unlimited" : String.valueOf(memoryLimit - memoryTotal);
@@ -208,7 +208,7 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
response.setMemoryAvailable(memoryAvail);
//get resource limits for primary storage space and convert it from Bytes to GiB
- long primaryStorageLimit = ApiDBUtils.findCorrectResourceLimit(account.getPrimaryStorageLimit(), account.getType(), ResourceType.primary_storage);
+ long primaryStorageLimit = ApiDBUtils.findCorrectResourceLimit(account.getPrimaryStorageLimit(), account.getId(), ResourceType.primary_storage);
String primaryStorageLimitDisplay = (accountIsAdmin || primaryStorageLimit == -1) ? "Unlimited" : String.valueOf(primaryStorageLimit / ResourceType.bytesToGiB);
long primaryStorageTotal = (account.getPrimaryStorageTotal() == null) ? 0 : (account.getPrimaryStorageTotal() / ResourceType.bytesToGiB);
String primaryStorageAvail = (accountIsAdmin || primaryStorageLimit == -1) ? "Unlimited" : String.valueOf((primaryStorageLimit / ResourceType.bytesToGiB) - primaryStorageTotal);
@@ -217,7 +217,7 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
response.setPrimaryStorageAvailable(primaryStorageAvail);
//get resource limits for secondary storage space and convert it from Bytes to GiB
- long secondaryStorageLimit = ApiDBUtils.findCorrectResourceLimit(account.getSecondaryStorageLimit(), account.getType(), ResourceType.secondary_storage);
+ long secondaryStorageLimit = ApiDBUtils.findCorrectResourceLimit(account.getSecondaryStorageLimit(), account.getId(), ResourceType.secondary_storage);
String secondaryStorageLimitDisplay = (accountIsAdmin || secondaryStorageLimit == -1) ? "Unlimited" : String.valueOf(secondaryStorageLimit / ResourceType.bytesToGiB);
long secondaryStorageTotal = (account.getSecondaryStorageTotal() == null) ? 0 : (account.getSecondaryStorageTotal() / ResourceType.bytesToGiB);
String secondaryStorageAvail = (accountIsAdmin || secondaryStorageLimit == -1) ? "Unlimited" : String.valueOf((secondaryStorageLimit / ResourceType.bytesToGiB) - secondaryStorageTotal);