|
25 | 25 | import java.sql.SQLException; |
26 | 26 | import java.text.ParseException; |
27 | 27 | import java.util.ArrayList; |
| 28 | +import java.util.HashMap; |
| 29 | +import java.util.Iterator; |
28 | 30 | import java.util.List; |
29 | 31 | import java.util.Map; |
30 | 32 | import java.util.Properties; |
| 33 | +import java.util.Set; |
31 | 34 | import java.util.UUID; |
32 | 35 |
|
33 | 36 | import javax.inject.Inject; |
@@ -443,25 +446,35 @@ private String doesRuleMatch(EC2IpPermission permLeft, EC2IpPermission permRight |
443 | 446 | */ |
444 | 447 | public EC2DescribeSnapshotsResponse handleRequest( EC2DescribeSnapshots request ) |
445 | 448 | { |
446 | | - EC2DescribeVolumesResponse volumes = new EC2DescribeVolumesResponse(); |
447 | 449 | EC2SnapshotFilterSet sfs = request.getFilterSet(); |
448 | 450 | EC2TagKeyValue[] tagKeyValueSet = request.getResourceTagSet(); |
449 | 451 |
|
450 | 452 | try { |
451 | | - // -> query to get the volume size for each snapshot |
452 | 453 | EC2DescribeSnapshotsResponse response = listSnapshots( request.getSnapshotSet(), |
453 | 454 | getResourceTags(tagKeyValueSet)); |
454 | 455 | if (response == null) { |
455 | 456 | return new EC2DescribeSnapshotsResponse(); |
456 | 457 | } |
457 | 458 | 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); |
463 | 477 | } |
464 | | - |
465 | 478 | if ( null == sfs ) |
466 | 479 | return response; |
467 | 480 | else return sfs.evaluate( response ); |
|
0 commit comments