Skip to content

Commit f0086df

Browse files
Likitha ShettyPrachi Damle
authored andcommitted
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
1 parent 35cf568 commit f0086df

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

awsapi/src/com/cloud/bridge/service/EC2SoapServiceImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1905,7 +1905,10 @@ public static DescribeSnapshotsResponse toDescribeSnapshotsResponse(EC2DescribeS
19051905
param3.setStartTime( cal );
19061906

19071907
param3.setOwnerId(ownerId);
1908-
param3.setVolumeSize( snap.getVolumeSize().toString());
1908+
if ( snap.getVolumeSize() == null )
1909+
param3.setVolumeSize("0");
1910+
else
1911+
param3.setVolumeSize( snap.getVolumeSize().toString() );
19091912
param3.setDescription( snap.getName());
19101913
param3.setOwnerAlias( snap.getAccountName() );
19111914

awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@
2525
import java.sql.SQLException;
2626
import java.text.ParseException;
2727
import java.util.ArrayList;
28+
import java.util.HashMap;
29+
import java.util.Iterator;
2830
import java.util.List;
2931
import java.util.Map;
3032
import java.util.Properties;
33+
import java.util.Set;
3134
import java.util.UUID;
3235

3336
import javax.inject.Inject;
@@ -443,25 +446,35 @@ private String doesRuleMatch(EC2IpPermission permLeft, EC2IpPermission permRight
443446
*/
444447
public EC2DescribeSnapshotsResponse handleRequest( EC2DescribeSnapshots request )
445448
{
446-
EC2DescribeVolumesResponse volumes = new EC2DescribeVolumesResponse();
447449
EC2SnapshotFilterSet sfs = request.getFilterSet();
448450
EC2TagKeyValue[] tagKeyValueSet = request.getResourceTagSet();
449451

450452
try {
451-
// -> query to get the volume size for each snapshot
452453
EC2DescribeSnapshotsResponse response = listSnapshots( request.getSnapshotSet(),
453454
getResourceTags(tagKeyValueSet));
454455
if (response == null) {
455456
return new EC2DescribeSnapshotsResponse();
456457
}
457458
EC2Snapshot[] snapshots = response.getSnapshotSet();
458-
for (EC2Snapshot snap : snapshots) {
459-
volumes = listVolumes(snap.getVolumeId(), null, volumes, null);
460-
EC2Volume[] volSet = volumes.getVolumeSet();
461-
if (0 < volSet.length) snap.setVolumeSize(volSet[0].getSize());
462-
volumes.reset();
459+
// -> query to get the volume size for each snapshot
460+
HashMap<String, Long> volumeIdSize = new HashMap<String, Long>();
461+
for( EC2Snapshot snap : snapshots ) {
462+
Boolean duplicateVolume = false;
463+
Long size = null;
464+
if ( volumeIdSize.containsKey(snap.getVolumeId()) ) {
465+
size = volumeIdSize.get(snap.getVolumeId());
466+
duplicateVolume = true;
467+
break;
468+
}
469+
if ( !duplicateVolume ) {
470+
EC2DescribeVolumesResponse volumes = new EC2DescribeVolumesResponse();
471+
volumes = listVolumes(snap.getVolumeId(), null, volumes, null);
472+
EC2Volume[] volumeSet = volumes.getVolumeSet();
473+
if (volumeSet.length > 0) size = volumeSet[0].getSize();
474+
volumeIdSize.put(snap.getVolumeId(), size);
475+
}
476+
snap.setVolumeSize(size);
463477
}
464-
465478
if ( null == sfs )
466479
return response;
467480
else return sfs.evaluate( response );

0 commit comments

Comments
 (0)