Skip to content

Commit 650386c

Browse files
Likitha Shettyprachi
authored andcommitted
CS-14986. ec2-describe-volumes supported filters. Component: awsapi. Fix for two filters, attachment.attach-time and create-time.
Signed-off-by: Likitha Shetty <likitha.shetty@citrix.com>
1 parent 3a89d33 commit 650386c

2 files changed

Lines changed: 27 additions & 12 deletions

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,12 @@ public static DescribeVolumesResponse toDescribeVolumesResponse( EC2DescribeVolu
11001100
String devicePath = engine.cloudDeviceIdToDevicePath( vol.getHypervisor(), vol.getDeviceId());
11011101
param5.setDevice( devicePath );
11021102
param5.setStatus( toVolumeAttachmentState( vol.getInstanceId(), vol.getVMState()));
1103-
param5.setAttachTime( cal );
1103+
if (vol.getAttached() == null) {
1104+
param5.setAttachTime( cal );
1105+
} else {
1106+
Calendar attachTime = EC2RestAuth.parseDateString(vol.getAttached());
1107+
param5.setAttachTime( attachTime );
1108+
}
11041109
param5.setDeleteOnTermination( false );
11051110
param4.addItem( param5 );
11061111
}

‎awsapi/src/com/cloud/bridge/service/core/ec2/EC2VolumeFilterSet.java‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
import java.util.HashMap;
2222
import java.util.List;
2323
import java.util.Map;
24+
import java.util.TimeZone;
25+
import java.util.Date;
2426

2527
import com.cloud.bridge.service.exception.EC2ServiceException;
26-
import com.cloud.bridge.util.DateHelper;
2728
import com.cloud.bridge.util.EC2RestAuth;
2829

2930

@@ -123,8 +124,14 @@ else if (filterName.equalsIgnoreCase( "status" ))
123124
return containsString(vol.getState(), valueSet );
124125
else if (filterName.equalsIgnoreCase( "volume-id" ))
125126
return containsString(vol.getId().toString(), valueSet );
126-
else if (filterName.equalsIgnoreCase( "attachment.attach-time" ))
127-
return containsTime(vol.getAttached(), valueSet );
127+
else if (filterName.equalsIgnoreCase( "attachment.attach-time" )) {
128+
if (vol.getAttached() != null)
129+
return containsTime(vol.getAttached(), valueSet );
130+
else if (vol.getInstanceId() != null)
131+
return containsTime(vol.getCreated(), valueSet);
132+
else
133+
return false;
134+
}
128135
else if (filterName.equalsIgnoreCase( "attachment.device" ))
129136
return containsDevice(vol.getDeviceId(), valueSet );
130137
else if (filterName.equalsIgnoreCase( "attachment.instance-id" ))
@@ -155,14 +162,17 @@ private boolean containsLong( long lookingFor, String[] set )
155162

156163
private boolean containsTime(String lookingForDate, String[] set ) throws ParseException
157164
{
158-
Calendar lookingFor = EC2RestAuth.parseDateString(lookingForDate);
159-
for (String s : set) {
160-
Calendar toMatch = Calendar.getInstance();
161-
toMatch.setTime( DateHelper.parseISO8601DateString( s ));
162-
if (0 == lookingFor.compareTo( toMatch )) return true;
163-
}
164-
return false;
165-
}
165+
Calendar lookingFor = EC2RestAuth.parseDateString(lookingForDate);
166+
lookingFor.setTimeZone(TimeZone.getTimeZone("GMT"));
167+
Date lookForDate = lookingFor.getTime();
168+
for (String s : set) {
169+
Calendar toMatch = EC2RestAuth.parseDateString(s);
170+
toMatch.setTimeZone(TimeZone.getTimeZone("GMT"));
171+
Date toMatchDate = toMatch.getTime();
172+
if ( 0 == lookForDate.compareTo(toMatchDate)) return true;
173+
}
174+
return false;
175+
}
166176

167177

168178
private boolean containsDevice(String deviceId, String[] set )

0 commit comments

Comments
 (0)