This is an automated email from the ASF dual-hosted git repository.

bhaisaab pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/master by this push:
     new afbbb81  CLOUDSTACK-9405: add details parameter in listDomains API to 
reduce the execution time
afbbb81 is described below

commit afbbb810f09afb66944d1fb5132df0e6059fba8e
Author: Wei Zhou <w.z...@tech.leaseweb.com>
AuthorDate: Mon Nov 14 11:57:59 2016 +0100

    CLOUDSTACK-9405: add details parameter in listDomains API to reduce the 
execution time
---
 .../org/apache/cloudstack/api/ApiConstants.java    |  4 ++
 .../api/command/admin/domain/ListDomainsCmd.java   | 31 +++++++++++++++
 server/src/com/cloud/api/ApiDBUtils.java           |  5 ++-
 .../src/com/cloud/api/query/QueryManagerImpl.java  |  2 +-
 .../com/cloud/api/query/ViewResponseHelper.java    |  5 ++-
 .../src/com/cloud/api/query/dao/DomainJoinDao.java |  5 ++-
 .../com/cloud/api/query/dao/DomainJoinDaoImpl.java | 28 +++++++------
 ui/scripts/accounts.js                             |  6 ++-
 ui/scripts/configuration.js                        | 12 +++++-
 ui/scripts/system.js                               | 46 ++++++++++++++++++----
 10 files changed, 116 insertions(+), 28 deletions(-)

diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java 
b/api/src/org/apache/cloudstack/api/ApiConstants.java
index febbb0f..10470b5 100644
--- a/api/src/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/org/apache/cloudstack/api/ApiConstants.java
@@ -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;
+    }
 }
diff --git 
a/api/src/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmd.java 
b/api/src/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmd.java
index e382ed9..9c1ae22 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmd.java
@@ -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///////////////////
     /////////////////////////////////////////////////////
diff --git a/server/src/com/cloud/api/ApiDBUtils.java 
b/server/src/com/cloud/api/ApiDBUtils.java
index a0e74aa..e88a102 100644
--- 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.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) {
diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java 
b/server/src/com/cloud/api/query/QueryManagerImpl.java
index be165ba..f8e0307 100644
--- a/server/src/com/cloud/api/query/QueryManagerImpl.java
+++ b/server/src/com/cloud/api/query/QueryManagerImpl.java
@@ -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;
diff --git a/server/src/com/cloud/api/query/ViewResponseHelper.java 
b/server/src/com/cloud/api/query/ViewResponseHelper.java
index bc41843..dfed7ba 100644
--- a/server/src/com/cloud/api/query/ViewResponseHelper.java
+++ b/server/src/com/cloud/api/query/ViewResponseHelper.java
@@ -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;
     }
diff --git a/server/src/com/cloud/api/query/dao/DomainJoinDao.java 
b/server/src/com/cloud/api/query/dao/DomainJoinDao.java
index 164679c..94efc28 100644
--- a/server/src/com/cloud/api/query/dao/DomainJoinDao.java
+++ b/server/src/com/cloud/api/query/dao/DomainJoinDao.java
@@ -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);
 
diff --git a/server/src/com/cloud/api/query/dao/DomainJoinDaoImpl.java 
b/server/src/com/cloud/api/query/dao/DomainJoinDaoImpl.java
index 6aecb81..1f123cd 100644
--- a/server/src/com/cloud/api/query/dao/DomainJoinDaoImpl.java
+++ b/server/src/com/cloud/api/query/dao/DomainJoinDaoImpl.java
@@ -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);
-
-        //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);
+        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);
+        }
 
         domainResponse.setObjectName("domain");
 
diff --git a/ui/scripts/accounts.js b/ui/scripts/accounts.js
index 439683f..77c528f 100644
--- a/ui/scripts/accounts.js
+++ b/ui/scripts/accounts.js
@@ -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({
diff --git a/ui/scripts/configuration.js b/ui/scripts/configuration.js
index 921735b..8fb7ebe 100644
--- a/ui/scripts/configuration.js
+++ b/ui/scripts/configuration.js
@@ -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) {
diff --git a/ui/scripts/system.js b/ui/scripts/system.js
index 6c1b89d..f16ffe8 100755
--- a/ui/scripts/system.js
+++ b/ui/scripts/system.js
@@ -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) {

-- 
To stop receiving notification emails like this one, please contact
['"commits@cloudstack.apache.org" <commits@cloudstack.apache.org>'].

Reply via email to