mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Separate Admin and User command and response for ListVMsCmd.
This commit is contained in:
parent
bcd4cdd295
commit
d84d62a1e0
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -76,4 +76,9 @@ public interface ResponseObject {
|
||||
* @param jobStatus
|
||||
*/
|
||||
void setJobStatus(Integer jobStatus);
|
||||
|
||||
public enum ResponseView {
|
||||
Admin,
|
||||
User
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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){
|
||||
|
||||
@ -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;
|
||||
@ -1084,17 +1085,27 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
return response;
|
||||
}
|
||||
|
||||
@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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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()) {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -157,7 +157,8 @@ known_categories = {
|
||||
'UCS' : 'UCS',
|
||||
'Ucs' : 'UCS',
|
||||
'CacheStores' : 'Cache Stores',
|
||||
'CacheStore' : 'Cache Store'
|
||||
'CacheStore' : 'Cache Store',
|
||||
'Acl' : 'Acl'
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user