[ 
https://issues.apache.org/jira/browse/CLOUDSTACK-9602?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16305292#comment-16305292
 ] 

ASF GitHub Bot commented on CLOUDSTACK-9602:
--------------------------------------------

rhtyd closed pull request #1554: CLOUDSTACK-9602: API: improve resource limits 
comprehension
URL: https://github.com/apache/cloudstack/pull/1554
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/api/src/com/cloud/configuration/Resource.java 
b/api/src/com/cloud/configuration/Resource.java
index 5550e29eca4..7ef1b0bb90e 100644
--- a/api/src/com/cloud/configuration/Resource.java
+++ b/api/src/com/cloud/configuration/Resource.java
@@ -71,6 +71,15 @@ public boolean supportsOwner(ResourceOwnerType ownerType) {
         public int getOrdinal() {
             return ordinal;
         }
+
+        public static ResourceType fromOrdinal(int ordinal) {
+            for (ResourceType r : ResourceType.values()) {
+                if (r.ordinal == ordinal) {
+                    return r;
+                }
+            }
+            return null;
+        }
     }
 
     public static class ResourceOwnerType {
diff --git a/api/src/com/cloud/user/ResourceLimitService.java 
b/api/src/com/cloud/user/ResourceLimitService.java
index fef16da942f..8e9f2c2de89 100644
--- a/api/src/com/cloud/user/ResourceLimitService.java
+++ b/api/src/com/cloud/user/ResourceLimitService.java
@@ -64,11 +64,11 @@
      *            TODO
      * @param domainId
      *            TODO
-     * @param type
+     * @param resourceType
      *            TODO
      * @return a list of limits that match the criteria
      */
-    public List<? extends ResourceLimit> searchForLimits(Long id, Long 
accountId, Long domainId, Integer type, Long startIndex, Long pageSizeVal);
+    public List<? extends ResourceLimit> searchForLimits(Long id, Long 
accountId, Long domainId, ResourceType resourceType, Long startIndex, Long 
pageSizeVal);
 
     /**
      * Finds the resource limit for a specified account and type. If the 
account has an infinite limit, will check
diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java 
b/api/src/org/apache/cloudstack/api/ApiConstants.java
index 1d0b4a3756a..df6f86c9352 100644
--- a/api/src/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/org/apache/cloudstack/api/ApiConstants.java
@@ -216,6 +216,7 @@
     public static final String RECEIVED_BYTES = "receivedbytes";
     public static final String REQUIRES_HVM = "requireshvm";
     public static final String RESOURCE_TYPE = "resourcetype";
+    public static final String RESOURCE_TYPE_NAME = "resourcetypename";
     public static final String RESPONSE = "response";
     public static final String REVERTABLE = "revertable";
     public static final String REGISTERED = "registered";
diff --git 
a/api/src/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmd.java
 
b/api/src/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmd.java
index 14d1d55ff8b..68c09c27fb0 100644
--- 
a/api/src/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmd.java
+++ 
b/api/src/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmd.java
@@ -19,6 +19,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import com.cloud.configuration.Resource;
+import com.cloud.exception.InvalidParameterValueException;
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
@@ -58,6 +60,21 @@
         + "11 - SecondaryStorage. Total secondary storage space (in GiB) a 
user can use. ")
     private Integer resourceType;
 
+    @Parameter(name = ApiConstants.RESOURCE_TYPE_NAME, type = 
CommandType.STRING, description = "Type of resource (wins over resourceType if 
both are provided). Values are: "
+            + "user_vm - Instance. Number of instances a user can create. "
+            + "public_ip - IP. Number of public IP addresses an account can 
own. "
+            + "volume - Volume. Number of disk volumes an account can own. "
+            + "snapshot - Snapshot. Number of snapshots an account can own. "
+            + "template - Template. Number of templates an account can 
register/create. "
+            + "project - Project. Number of projects an account can own. "
+            + "network - Network. Number of networks an account can own. "
+            + "vpc - VPC. Number of VPC an account can own. "
+            + "cpu - CPU. Number of CPU an account can allocate for his 
resources. "
+            + "memory - Memory. Amount of RAM an account can allocate for his 
resources. "
+            + "primary_storage - PrimaryStorage. Total primary storage space 
(in GiB) a user can use. "
+            + "secondary_storage - SecondaryStorage. Total secondary storage 
space (in GiB) a user can use. ")
+    private String resourceTypeName;
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -70,6 +87,10 @@ public Integer getResourceType() {
         return resourceType;
     }
 
+    public String getResourceTypeName() {
+        return resourceTypeName;
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
@@ -83,7 +104,7 @@ public String getCommandName() {
     public void execute() {
         List<? extends ResourceLimit> result =
                 _resourceLimitService.searchForLimits(id, 
_accountService.finalyzeAccountId(this.getAccountName(), this.getDomainId(), 
this.getProjectId(), false), this.getDomainId(),
-                resourceType, this.getStartIndex(), this.getPageSizeVal());
+                        getResourceTypeEnum(), this.getStartIndex(), 
this.getPageSizeVal());
         ListResponse<ResourceLimitResponse> response = new 
ListResponse<ResourceLimitResponse>();
         List<ResourceLimitResponse> limitResponses = new 
ArrayList<ResourceLimitResponse>();
         for (ResourceLimit limit : result) {
@@ -96,4 +117,23 @@ public void execute() {
         response.setResponseName(getCommandName());
         this.setResponseObject(response);
     }
+
+    private Resource.ResourceType getResourceTypeEnum() {
+        // Map resource type
+        Resource.ResourceType resourceTypeResult = null;
+        if (resourceTypeName != null) {
+            try {
+                resourceTypeResult = 
Resource.ResourceType.valueOf(resourceTypeName);
+            } catch (IllegalArgumentException e) {
+                throw new InvalidParameterValueException("Please specify a 
valid resource type name.");
+            }
+        } else if (resourceType != null) {
+            resourceTypeResult = 
Resource.ResourceType.fromOrdinal(resourceType);
+            if (resourceTypeResult == null) {
+                throw new InvalidParameterValueException("Please specify a 
valid resource type.");
+            }
+        }
+
+        return resourceTypeResult;
+    }
 }
diff --git 
a/api/src/org/apache/cloudstack/api/response/ResourceCountResponse.java 
b/api/src/org/apache/cloudstack/api/response/ResourceCountResponse.java
index 7173235608e..d0a4982f872 100644
--- a/api/src/org/apache/cloudstack/api/response/ResourceCountResponse.java
+++ b/api/src/org/apache/cloudstack/api/response/ResourceCountResponse.java
@@ -16,6 +16,7 @@
 // under the License.
 package org.apache.cloudstack.api.response;
 
+import com.cloud.configuration.Resource;
 import com.google.gson.annotations.SerializedName;
 
 import org.apache.cloudstack.api.ApiConstants;
@@ -49,6 +50,10 @@
     @Param(description = "resource type. Values include 0, 1, 2, 3, 4, 5, 6, 
7, 8, 9, 10, 11. See the resourceType parameter for more information on these 
values.")
     private String resourceType;
 
+    @SerializedName(ApiConstants.RESOURCE_TYPE_NAME)
+    @Param(description = "resource type name. Values include user_vm, 
public_ip, volume, snapshot, template, project, network, vpc, cpu, memory, 
primary_storage, secondary_storage.")
+    private String resourceTypeName;
+
     @SerializedName("resourcecount")
     @Param(description = "resource count")
     private long resourceCount;
@@ -68,8 +73,9 @@ public void setDomainName(String domainName) {
         this.domainName = domainName;
     }
 
-    public void setResourceType(String resourceType) {
-        this.resourceType = resourceType;
+    public void setResourceType(Resource.ResourceType resourceType) {
+        this.resourceType = 
Integer.valueOf(resourceType.getOrdinal()).toString();
+        this.resourceTypeName = resourceType.getName();
     }
 
     public void setResourceCount(Long resourceCount) {
diff --git 
a/api/src/org/apache/cloudstack/api/response/ResourceLimitResponse.java 
b/api/src/org/apache/cloudstack/api/response/ResourceLimitResponse.java
index 6890915fdde..13e1198177d 100644
--- a/api/src/org/apache/cloudstack/api/response/ResourceLimitResponse.java
+++ b/api/src/org/apache/cloudstack/api/response/ResourceLimitResponse.java
@@ -16,6 +16,7 @@
 // under the License.
 package org.apache.cloudstack.api.response;
 
+import com.cloud.configuration.Resource;
 import com.google.gson.annotations.SerializedName;
 
 import org.apache.cloudstack.api.ApiConstants;
@@ -44,6 +45,10 @@
     @Param(description = "resource type. Values include 0, 1, 2, 3, 4, 6, 7, 
8, 9, 10, 11. See the resourceType parameter for more information on these 
values.")
     private String resourceType;
 
+    @SerializedName(ApiConstants.RESOURCE_TYPE_NAME)
+    @Param(description = "resource type name. Values include user_vm, 
public_ip, volume, snapshot, template, project, network, vpc, cpu, memory, 
primary_storage, secondary_storage.")
+    private String resourceTypeName;
+
     @SerializedName("max")
     @Param(description = "the maximum number of the resource. A -1 means the 
resource currently has no limit.")
     private Long max;
@@ -76,8 +81,9 @@ public void setDomainName(String domainName) {
         this.domainName = domainName;
     }
 
-    public void setResourceType(String resourceType) {
-        this.resourceType = resourceType;
+    public void setResourceType(Resource.ResourceType resourceType) {
+        this.resourceType = 
Integer.valueOf(resourceType.getOrdinal()).toString();
+        this.resourceTypeName = resourceType.getName();
     }
 
     public void setMax(Long max) {
diff --git a/server/src/com/cloud/api/ApiResponseHelper.java 
b/server/src/com/cloud/api/ApiResponseHelper.java
index 39ac5c4a208..9ed34456cd3 100644
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -411,7 +411,7 @@ public ResourceLimitResponse 
createResourceLimitResponse(ResourceLimit limit) {
             populateAccount(resourceLimitResponse, limit.getOwnerId());
             populateDomain(resourceLimitResponse, accountTemp.getDomainId());
         }
-        
resourceLimitResponse.setResourceType(Integer.toString(limit.getType().getOrdinal()));
+        resourceLimitResponse.setResourceType(limit.getType());
 
         if ((limit.getType() == ResourceType.primary_storage || 
limit.getType() == ResourceType.secondary_storage) && limit.getMax() >= 0) {
             
resourceLimitResponse.setMax((long)Math.ceil((double)limit.getMax() / 
ResourceType.bytesToGiB));
@@ -437,7 +437,7 @@ public ResourceCountResponse 
createResourceCountResponse(ResourceCount resourceC
             populateDomain(resourceCountResponse, resourceCount.getOwnerId());
         }
 
-        
resourceCountResponse.setResourceType(Integer.toString(resourceCount.getType().getOrdinal()));
+        resourceCountResponse.setResourceType(resourceCount.getType());
         resourceCountResponse.setResourceCount(resourceCount.getCount());
         resourceCountResponse.setObjectName("resourcecount");
         return resourceCountResponse;
diff --git a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java 
b/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
index 25afd0115ea..09cb932c588 100644
--- a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
+++ b/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
@@ -477,7 +477,7 @@ public void doInTransactionWithoutResult(TransactionStatus 
status) throws Resour
     }
 
     @Override
-    public List<ResourceLimitVO> searchForLimits(Long id, Long accountId, Long 
domainId, Integer type, Long startIndex, Long pageSizeVal) {
+    public List<ResourceLimitVO> searchForLimits(Long id, Long accountId, Long 
domainId, ResourceType resourceType, Long startIndex, Long pageSizeVal) {
         Account caller = CallContext.current().getCallingAccount();
         List<ResourceLimitVO> limits = new ArrayList<ResourceLimitVO>();
         boolean isAccount = true;
@@ -510,16 +510,6 @@ public void doInTransactionWithoutResult(TransactionStatus 
status) throws Resour
             }
         }
 
-        // Map resource type
-        ResourceType resourceType = null;
-        if (type != null) {
-            try {
-                resourceType = ResourceType.values()[type];
-            } catch (ArrayIndexOutOfBoundsException e) {
-                throw new InvalidParameterValueException("Please specify a 
valid resource type.");
-            }
-        }
-
         // If id is passed in, get the record and return it if permission 
check has passed
         if (id != null) {
             ResourceLimitVO vo = _resourceLimitDao.findById(id);
diff --git a/server/test/com/cloud/vpc/MockResourceLimitManagerImpl.java 
b/server/test/com/cloud/vpc/MockResourceLimitManagerImpl.java
index d2d7c3313e0..0be5b1bc6e8 100644
--- a/server/test/com/cloud/vpc/MockResourceLimitManagerImpl.java
+++ b/server/test/com/cloud/vpc/MockResourceLimitManagerImpl.java
@@ -54,10 +54,10 @@ public ResourceLimit updateResourceLimit(Long accountId, 
Long domainId, Integer
     }
 
     /* (non-Javadoc)
-     * @see 
com.cloud.user.ResourceLimitService#searchForLimits(java.lang.Long, 
java.lang.Long, java.lang.Long, java.lang.Integer, java.lang.Long, 
java.lang.Long)
+     * @see 
com.cloud.user.ResourceLimitService#searchForLimits(java.lang.Long, 
java.lang.Long, java.lang.Long, com.cloud.user.ResourceLimitService, 
java.lang.Long, java.lang.Long)
      */
     @Override
-    public List<? extends ResourceLimit> searchForLimits(Long id, Long 
accountId, Long domainId, Integer type, Long startIndex, Long pageSizeVal) {
+    public List<? extends ResourceLimit> searchForLimits(Long id, Long 
accountId, Long domainId, ResourceType resourceType, Long startIndex, Long 
pageSizeVal) {
         // TODO Auto-generated method stub
         return null;
     }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Add resource type name in response
> ----------------------------------
>
>                 Key: CLOUDSTACK-9602
>                 URL: https://issues.apache.org/jira/browse/CLOUDSTACK-9602
>             Project: CloudStack
>          Issue Type: Improvement
>      Security Level: Public(Anyone can view this level - this is the 
> default.) 
>          Components: API
>            Reporter: Marc-Aurèle Brothier
>            Assignee: Marc-Aurèle Brothier
>
> Output the resource type name along with its id to be more human readable for 
> all API call returning a resource.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to