You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by pr...@apache.org on 2013/02/14 02:57:06 UTC

git commit: refs/heads/4.1 - CLOUDSTACK-1134: [EC2 Query API] DescribeSnapshots, 'n' ListVolumes get fired on CS for displaying 'n' Snapshots taken from the same Volume

Updated Branches:
  refs/heads/4.1 9b9f3e2e0 -> da2713ebf


CLOUDSTACK-1134: [EC2 Query API] DescribeSnapshots, 'n' ListVolumes get fired on CS for displaying 'n' Snapshots taken from the same Volume

For snapshots taken from the same volume re-use the response obtained by calling listVolumes


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

Branch: refs/heads/4.1
Commit: da2713ebf51f0af685ee002a166716aea8873e87
Parents: 9b9f3e2
Author: Likitha Shetty <Li...@citrix.com>
Authored: Wed Feb 13 17:51:55 2013 -0800
Committer: Prachi Damle <pr...@cloud.com>
Committed: Wed Feb 13 17:55:48 2013 -0800

----------------------------------------------------------------------
 .../cloud/bridge/service/EC2SoapServiceImpl.java   |    5 ++-
 .../cloud/bridge/service/core/ec2/EC2Engine.java   |   29 +++++++++++----
 2 files changed, 25 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/da2713eb/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 9fc581b..cebac0b 100644
--- a/awsapi/src/com/cloud/bridge/service/EC2SoapServiceImpl.java
+++ b/awsapi/src/com/cloud/bridge/service/EC2SoapServiceImpl.java
@@ -1905,7 +1905,10 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface  {
 	         param3.setStartTime( cal );
 	         
 	         param3.setOwnerId(ownerId);
-	         param3.setVolumeSize( snap.getVolumeSize().toString());
+             if ( snap.getVolumeSize() == null )
+                 param3.setVolumeSize("0");
+             else
+                 param3.setVolumeSize( snap.getVolumeSize().toString() );
 	         param3.setDescription( snap.getName());
 	         param3.setOwnerAlias( snap.getAccountName() );
 	         

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/da2713eb/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java
index a835d8a..281ecbd 100644
--- a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java
+++ b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java
@@ -25,9 +25,12 @@ import java.security.SignatureException;
 import java.sql.SQLException;
 import java.text.ParseException;
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Set;
 import java.util.UUID;
 
 import javax.inject.Inject;
@@ -443,25 +446,35 @@ public class EC2Engine extends ManagerBase {
      */
     public EC2DescribeSnapshotsResponse handleRequest( EC2DescribeSnapshots request ) 
     {
-        EC2DescribeVolumesResponse volumes = new EC2DescribeVolumesResponse();
         EC2SnapshotFilterSet sfs = request.getFilterSet();
         EC2TagKeyValue[] tagKeyValueSet = request.getResourceTagSet();
 
         try { 
-            // -> query to get the volume size for each snapshot
             EC2DescribeSnapshotsResponse response = listSnapshots( request.getSnapshotSet(),
                     getResourceTags(tagKeyValueSet));
             if (response == null) {
                 return new EC2DescribeSnapshotsResponse();
             }
             EC2Snapshot[] snapshots = response.getSnapshotSet();
-            for (EC2Snapshot snap : snapshots) {
-                volumes = listVolumes(snap.getVolumeId(), null, volumes, null);
-                EC2Volume[] volSet = volumes.getVolumeSet();
-                if (0 < volSet.length) snap.setVolumeSize(volSet[0].getSize());
-                volumes.reset();
+            // -> query to get the volume size for each snapshot
+            HashMap<String, Long> volumeIdSize = new HashMap<String, Long>();
+            for( EC2Snapshot snap : snapshots ) {
+                Boolean duplicateVolume = false;
+                Long size = null;
+                if ( volumeIdSize.containsKey(snap.getVolumeId()) ) {
+                    size = volumeIdSize.get(snap.getVolumeId());
+                    duplicateVolume = true;
+                    break;
+                }
+                if ( !duplicateVolume ) {
+                    EC2DescribeVolumesResponse volumes = new EC2DescribeVolumesResponse();
+                    volumes = listVolumes(snap.getVolumeId(), null, volumes, null);
+                    EC2Volume[] volumeSet = volumes.getVolumeSet();
+                    if (volumeSet.length > 0) size = volumeSet[0].getSize();
+                    volumeIdSize.put(snap.getVolumeId(), size);
+                }
+                snap.setVolumeSize(size);
             }
-
             if ( null == sfs )
                 return response;
             else return sfs.evaluate( response );