You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bf...@apache.org on 2013/02/13 23:04:22 UTC

[10/50] [abbrv] git commit: refs/heads/ui-plugins - CLOUDSTACK-1131

CLOUDSTACK-1131

[EC2 Query API] RunInstances allows negative values for paramters 'MinCount' and 'MaxCount'
Add parameter validation to ensure MinCount is greater than 0 and MaxCount is great than or equal to MinCount


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/33371066
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/33371066
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/33371066

Branch: refs/heads/ui-plugins
Commit: 333710669351b93a04b07d8aba81f95e79ca20f0
Parents: b0b2fd4
Author: Likitha Shetty <Li...@citrix.com>
Authored: Tue Feb 12 14:01:01 2013 -0800
Committer: Prachi Damle <pr...@cloud.com>
Committed: Tue Feb 12 14:01:10 2013 -0800

----------------------------------------------------------------------
 .../com/cloud/bridge/service/EC2RestServlet.java   |   24 +++++++++++----
 .../cloud/bridge/service/EC2SoapServiceImpl.java   |   13 +++++++-
 2 files changed, 29 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/33371066/awsapi/src/com/cloud/bridge/service/EC2RestServlet.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/service/EC2RestServlet.java b/awsapi/src/com/cloud/bridge/service/EC2RestServlet.java
index b5296a4..fe93038 100644
--- a/awsapi/src/com/cloud/bridge/service/EC2RestServlet.java
+++ b/awsapi/src/com/cloud/bridge/service/EC2RestServlet.java
@@ -1142,14 +1142,26 @@ public class EC2RestServlet extends HttpServlet {
         else { response.sendError(530, "Missing ImageId parameter" ); return; }
 
         String[] minCount = request.getParameterValues( "MinCount" );
-        if ( null != minCount && 0 < minCount.length ) 
-            EC2request.setMinCount( Integer.parseInt( minCount[0] ));
-        else { response.sendError(530, "Missing MinCount parameter" ); return; }
+        if ( minCount == null || minCount.length < 1) {
+            response.sendError(530, "Missing MinCount parameter" );
+            return;
+        } else if ( Integer.parseInt(minCount[0]) < 1) {
+            throw new EC2ServiceException(ClientError.InvalidParameterValue,
+                    "Value of parameter MinCount should be greater than 0");
+        } else {
+            EC2request.setMinCount( Integer.parseInt( minCount[0]) );
+        }
 
         String[] maxCount = request.getParameterValues( "MaxCount" );
-        if ( null != maxCount && 0 < maxCount.length ) 
-            EC2request.setMaxCount( Integer.parseInt( maxCount[0] ));
-        else { response.sendError(530, "Missing MaxCount parameter" ); return; }
+        if ( maxCount == null || maxCount.length < 1) {
+            response.sendError(530, "Missing MaxCount parameter" );
+            return;
+        } else if ( Integer.parseInt(maxCount[0]) < 1) {
+            throw new EC2ServiceException(ClientError.InvalidParameterValue,
+                    "Value of parameter MaxCount should be greater than 0");
+        } else {
+            EC2request.setMaxCount( Integer.parseInt( maxCount[0]) );
+        }
 
         String[] instanceType = request.getParameterValues( "InstanceType" );
         if ( null != instanceType && 0 < instanceType.length ) 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/33371066/awsapi/src/com/cloud/bridge/service/EC2SoapServiceImpl.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/service/EC2SoapServiceImpl.java b/awsapi/src/com/cloud/bridge/service/EC2SoapServiceImpl.java
index 2fefb28..4e9445e 100644
--- a/awsapi/src/com/cloud/bridge/service/EC2SoapServiceImpl.java
+++ b/awsapi/src/com/cloud/bridge/service/EC2SoapServiceImpl.java
@@ -731,8 +731,17 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface  {
 		EC2RunInstances request = new EC2RunInstances();
 		
 		request.setTemplateId(rit.getImageId());
-		request.setMinCount(rit.getMinCount());
-		request.setMaxCount(rit.getMaxCount());
+
+        if (rit.getMinCount() < 1) {
+            throw new EC2ServiceException(ClientError.InvalidParameterValue,
+                    "Value of parameter MinCount should be greater than 0");
+        } else request.setMinCount( rit.getMinCount() );
+
+        if (rit.getMaxCount() < 1) {
+            throw new EC2ServiceException(ClientError.InvalidParameterValue,
+                    "Value of parameter MaxCount should be greater than 0");
+        } else request.setMaxCount(rit.getMaxCount());
+
 		if (null != type) request.setInstanceType(type);
 		if (null != prt) request.setZoneName(prt.getAvailabilityZone());
 		if (null != userData) request.setUserData(userData.getData());