CLOUDSTACK-9405: add details parameter in listDomains API to reduce the execution time

This commit is contained in:
Wei Zhou 2016-11-14 11:57:59 +01:00 committed by Rohit Yadav
parent 553b092601
commit afbbb810f0
10 changed files with 115 additions and 27 deletions

View File

@ -666,4 +666,8 @@ public class ApiConstants {
public enum VMDetails {
all, group, nics, stats, secgrp, tmpl, servoff, diskoff, iso, volume, min, affgrp;
}
public enum DomainDetails {
all, resource, min;
}
}

View File

@ -16,10 +16,15 @@
// under the License.
package org.apache.cloudstack.api.command.admin.domain;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiConstants.DomainDetails;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ResponseObject.ResponseView;
@ -27,6 +32,7 @@ import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.cloudstack.api.response.ListResponse;
import com.cloud.domain.Domain;
import com.cloud.exception.InvalidParameterValueException;
@APICommand(name = "listDomains", description = "Lists domains and provides detailed information for listed domains", responseObject = DomainResponse.class, responseView = ResponseView.Restricted, entityType = {Domain.class},
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
@ -53,6 +59,12 @@ public class ListDomainsCmd extends BaseListCmd {
description = "If set to false, list only resources belonging to the command's caller; if set to true - list resources that the caller is authorized to see. Default value is false")
private Boolean listAll;
@Parameter(name = ApiConstants.DETAILS,
type = CommandType.LIST,
collectionType = CommandType.STRING,
description = "comma separated list of domain details requested, value can be a list of [ all, resource, min]")
private List<String> viewDetails;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -73,6 +85,25 @@ public class ListDomainsCmd extends BaseListCmd {
return listAll == null ? false : listAll;
}
public EnumSet<DomainDetails> getDetails() throws InvalidParameterValueException {
EnumSet<DomainDetails> dv;
if (viewDetails == null || viewDetails.size() <= 0) {
dv = EnumSet.of(DomainDetails.all);
} else {
try {
ArrayList<DomainDetails> dc = new ArrayList<DomainDetails>();
for (String detail : viewDetails) {
dc.add(DomainDetails.valueOf(detail));
}
dv = EnumSet.copyOf(dc);
} catch (IllegalArgumentException e) {
throw new InvalidParameterValueException("The details parameter contains a non permitted value. The allowed values are " +
EnumSet.allOf(DomainDetails.class));
}
}
return dv;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////

View File

@ -33,6 +33,7 @@ import org.apache.cloudstack.affinity.AffinityGroup;
import org.apache.cloudstack.affinity.AffinityGroupResponse;
import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
import org.apache.cloudstack.api.ApiCommandJobType;
import org.apache.cloudstack.api.ApiConstants.DomainDetails;
import org.apache.cloudstack.api.ApiConstants.HostDetails;
import org.apache.cloudstack.api.ApiConstants.VMDetails;
import org.apache.cloudstack.api.ResponseObject.ResponseView;
@ -1852,8 +1853,8 @@ public class ApiDBUtils {
return s_imageStoreJoinDao.newImageStoreView(vr);
}
public static DomainResponse newDomainResponse(ResponseView view, DomainJoinVO ve) {
return s_domainJoinDao.newDomainResponse(view, ve);
public static DomainResponse newDomainResponse(ResponseView view, EnumSet<DomainDetails> details, DomainJoinVO ve) {
return s_domainJoinDao.newDomainResponse(view, details, ve);
}
public static AccountResponse newAccountResponse(ResponseView view, AccountJoinVO ve) {

View File

@ -1878,7 +1878,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
respView = ResponseView.Full;
}
List<DomainResponse> domainResponses = ViewResponseHelper.createDomainResponse(respView, result.first().toArray(
List<DomainResponse> domainResponses = ViewResponseHelper.createDomainResponse(respView, cmd.getDetails(), result.first().toArray(
new DomainJoinVO[result.first().size()]));
response.setResponses(domainResponses, result.second());
return response;

View File

@ -24,6 +24,7 @@ import java.util.List;
import org.apache.log4j.Logger;
import org.apache.cloudstack.affinity.AffinityGroupResponse;
import org.apache.cloudstack.api.ApiConstants.DomainDetails;
import org.apache.cloudstack.api.ApiConstants.HostDetails;
import org.apache.cloudstack.api.ApiConstants.VMDetails;
import org.apache.cloudstack.api.ResponseObject.ResponseView;
@ -348,10 +349,10 @@ public class ViewResponseHelper {
return new ArrayList<StoragePoolResponse>(vrDataList.values());
}
public static List<DomainResponse> createDomainResponse(ResponseView view, DomainJoinVO... domains) {
public static List<DomainResponse> createDomainResponse(ResponseView view, EnumSet<DomainDetails> details, DomainJoinVO... domains) {
List<DomainResponse> respList = new ArrayList<DomainResponse>();
for (DomainJoinVO vt : domains){
respList.add(ApiDBUtils.newDomainResponse(view, vt));
respList.add(ApiDBUtils.newDomainResponse(view, details, vt));
}
return respList;
}

View File

@ -16,6 +16,9 @@
// under the License.
package com.cloud.api.query.dao;
import java.util.EnumSet;
import org.apache.cloudstack.api.ApiConstants.DomainDetails;
import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.cloudstack.api.response.ResourceLimitAndCountResponse;
@ -26,7 +29,7 @@ import com.cloud.utils.db.GenericDao;
public interface DomainJoinDao extends GenericDao<DomainJoinVO, Long> {
DomainResponse newDomainResponse(ResponseView view, DomainJoinVO vol);
DomainResponse newDomainResponse(ResponseView view, EnumSet<DomainDetails> details, DomainJoinVO vol);
DomainJoinVO newDomainView(Domain vol);

View File

@ -16,9 +16,11 @@
// under the License.
package com.cloud.api.query.dao;
import java.util.EnumSet;
import java.util.List;
import org.apache.cloudstack.api.ApiConstants.DomainDetails;
import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.cloudstack.api.response.ResourceLimitAndCountResponse;
@ -49,7 +51,7 @@ public class DomainJoinDaoImpl extends GenericDaoBase<DomainJoinVO, Long> implem
}
@Override
public DomainResponse newDomainResponse(ResponseView view, DomainJoinVO domain) {
public DomainResponse newDomainResponse(ResponseView view, EnumSet<DomainDetails> details, DomainJoinVO domain) {
DomainResponse domainResponse = new DomainResponse();
domainResponse.setDomainName(domain.getName());
domainResponse.setId(domain.getUuid());
@ -72,17 +74,19 @@ public class DomainJoinDaoImpl extends GenericDaoBase<DomainJoinVO, Long> implem
domainResponse.setState(domain.getState().toString());
domainResponse.setNetworkDomain(domain.getNetworkDomain());
boolean fullView = (view == ResponseView.Full && domain.getId() == Domain.ROOT_DOMAIN);
setResourceLimits(domain, fullView, domainResponse);
if (details.contains(DomainDetails.all) || details.contains(DomainDetails.resource)) {
boolean fullView = (view == ResponseView.Full && domain.getId() == Domain.ROOT_DOMAIN);
setResourceLimits(domain, fullView, domainResponse);
//get resource limits for projects
long projectLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getProjectLimit(), fullView, ResourceType.project, domain.getId());
String projectLimitDisplay = (fullView || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit);
long projectTotal = (domain.getProjectTotal() == null) ? 0 : domain.getProjectTotal();
String projectAvail = (fullView || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit - projectTotal);
domainResponse.setProjectLimit(projectLimitDisplay);
domainResponse.setProjectTotal(projectTotal);
domainResponse.setProjectAvailable(projectAvail);
//get resource limits for projects
long projectLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getProjectLimit(), fullView, ResourceType.project, domain.getId());
String projectLimitDisplay = (fullView || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit);
long projectTotal = (domain.getProjectTotal() == null) ? 0 : domain.getProjectTotal();
String projectAvail = (fullView || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit - projectTotal);
domainResponse.setProjectLimit(projectLimitDisplay);
domainResponse.setProjectTotal(projectTotal);
domainResponse.setProjectAvailable(projectAvail);
}
domainResponse.setObjectName("domain");

View File

@ -1948,7 +1948,11 @@
select: function(args) {
if (isAdmin() || isDomainAdmin()) {
$.ajax({
url: createURL("listDomains&listAll=true"),
url: createURL('listDomains'),
data: {
listAll: true,
details: 'min'
},
success: function(json) {
var items = [];
items.push({

View File

@ -1287,7 +1287,11 @@
dependsOn: 'isPublic',
select: function(args) {
$.ajax({
url: createURL("listDomains&listAll=true"),
url: createURL('listDomains'),
data: {
listAll: true,
details: 'min'
},
dataType: "json",
async: false,
success: function(json) {
@ -1999,7 +2003,11 @@
dependsOn: 'isPublic',
select: function(args) {
$.ajax({
url: createURL("listDomains&listAll=true"),
url: createURL('listDomains'),
data: {
listAll: true,
details: 'min'
},
dataType: "json",
async: false,
success: function(json) {

View File

@ -54,6 +54,7 @@
$.ajax({
url: createURL('listDomains'),
data: {
details: 'min',
listAll: true
},
success: function (json) {
@ -78,6 +79,7 @@
url: createURL('listDomains'),
data: {
id: data.domainid,
details: 'min',
listAll: true
},
success: function (json) {
@ -552,6 +554,7 @@
$.ajax({
url: createURL('listDomains'),
data: {
details: 'min',
listAll: true
},
success: function (json) {
@ -1852,6 +1855,7 @@
$.ajax({
url: createURL('listDomains'),
data: {
details: 'min',
listAll: true
},
success: function (json) {
@ -7893,7 +7897,11 @@
},
select: function (args) {
$.ajax({
url: createURL("listDomains&listAll=true"),
url: createURL('listDomains'),
data: {
listAll: true,
details: 'min'
},
dataType: "json",
async: false,
success: function (json) {
@ -13324,7 +13332,11 @@
dependsOn: 'isDedicated',
select: function (args) {
$.ajax({
url: createURL("listDomains&listAll=true"),
url: createURL('listDomains'),
data: {
listAll: true,
details: 'min'
},
dataType: "json",
async: false,
success: function (json) {
@ -13542,7 +13554,11 @@
},
select: function (args) {
$.ajax({
url: createURL("listDomains&listAll=true"),
url: createURL('listDomains'),
data: {
listAll: true,
details: 'min'
},
dataType: "json",
async: false,
success: function (json) {
@ -14143,7 +14159,11 @@
dependsOn: 'isDedicated',
select: function (args) {
$.ajax({
url: createURL("listDomains&listAll=true"),
url: createURL('listDomains'),
data: {
listAll: true,
details: 'min'
},
dataType: "json",
async: false,
success: function (json) {
@ -14714,7 +14734,11 @@
},
select: function (args) {
$.ajax({
url: createURL("listDomains&listAll=true"),
url: createURL('listDomains'),
data: {
listAll: true,
details: 'min'
},
dataType: "json",
async: false,
success: function (json) {
@ -15699,7 +15723,11 @@
dependsOn: 'isDedicated',
select: function (args) {
$.ajax({
url: createURL("listDomains&listAll=true"),
url: createURL('listDomains'),
data: {
listAll: true,
details: 'min'
},
dataType: "json",
success: function (json) {
var domainObjs = json.listdomainsresponse.domain;
@ -16045,7 +16073,11 @@
},
select: function (args) {
$.ajax({
url: createURL("listDomains&listAll=true"),
url: createURL('listDomains'),
data: {
listAll: true,
details: 'min'
},
dataType: "json",
async: false,
success: function (json) {