mirror of https://github.com/apache/cloudstack.git
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
This commit is contained in:
parent
9b9f3e2e03
commit
da2713ebf5
|
|
@ -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() );
|
||||
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
|
|
|||
Loading…
Reference in New Issue