mirror of https://github.com/apache/jclouds.git
openstack-nova-ec2: work-around for dates encoded as '-' when they should be null (the should not be present in the response!)
This commit is contained in:
parent
42d57c5d15
commit
7c317b80e8
|
@ -0,0 +1,119 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.nova.ec2.config;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.inject.AbstractModule;
|
||||
|
||||
/**
|
||||
* @author Adam Lowe
|
||||
*/
|
||||
public class NovaEC2ParserModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateService.class).to(Iso8601WithDashesTreatedAsNullDateService.class);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class Iso8601WithDashesTreatedAsNullDateService implements DateService {
|
||||
DateService delegate;
|
||||
|
||||
@Inject
|
||||
public Iso8601WithDashesTreatedAsNullDateService(SimpleDateFormatDateService service) {
|
||||
this.delegate = service;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date fromSeconds(long seconds) {
|
||||
return delegate.fromSeconds(seconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String cDateFormat(Date date) {
|
||||
return delegate.cDateFormat(date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String cDateFormat() {
|
||||
return delegate.cDateFormat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date cDateParse(String toParse) {
|
||||
return delegate.cDateParse(toParse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String rfc822DateFormat(Date date) {
|
||||
return delegate.rfc822DateFormat(date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String rfc822DateFormat() {
|
||||
return delegate.rfc822DateFormat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date rfc822DateParse(String toParse) {
|
||||
return delegate.rfc822DateParse(toParse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String iso8601SecondsDateFormat(Date dateTime) {
|
||||
return delegate.iso8601SecondsDateFormat(dateTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String iso8601SecondsDateFormat() {
|
||||
return delegate.iso8601SecondsDateFormat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String iso8601DateFormat(Date date) {
|
||||
return delegate.iso8601DateFormat(date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String iso8601DateFormat() {
|
||||
return delegate.iso8601DateFormat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date iso8601DateParse(String toParse) {
|
||||
if (Objects.equal("-", toParse)) return null;
|
||||
return delegate.iso8601DateParse(toParse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date iso8601SecondsDateParse(String toParse) {
|
||||
if (Objects.equal("-", toParse)) return null;
|
||||
return delegate.iso8601SecondsDateParse(toParse);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -37,12 +37,14 @@ import com.google.inject.Scopes;
|
|||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @author Adam Lowe
|
||||
*/
|
||||
@ConfiguresRestClient
|
||||
public class NovaEC2RestClientModule extends EC2RestClientModule<EC2Client, EC2AsyncClient> {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
install(new NovaEC2ParserModule());
|
||||
super.configure();
|
||||
bind(CreateVolumeResponseHandler.class).to(NovaCreateVolumeResponseHandler.class).in(Scopes.SINGLETON);
|
||||
bind(DescribeImagesResponseHandler.class).to(NovaDescribeImagesResponseHandler.class);
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package org.jclouds.openstack.nova.ec2.services;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.ec2.domain.Attachment;
|
||||
import org.jclouds.ec2.domain.BlockDevice;
|
||||
import org.jclouds.ec2.domain.Reservation;
|
||||
import org.jclouds.ec2.domain.RunningInstance;
|
||||
import org.jclouds.ec2.services.InstanceClient;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.openstack.nova.ec2.internal.BaseNovaEC2RestClientExpectTest;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* @author Adam Lowe
|
||||
*/
|
||||
public class NovaEC2InstanceClientExpectTest extends BaseNovaEC2RestClientExpectTest {
|
||||
|
||||
public void testDescribeInstancesWithDashesInPlaceOfNullDates() {
|
||||
InstanceClient client = requestsSendResponses(
|
||||
describeAvailabilityZonesRequest,
|
||||
describeAvailabilityZonesResponse,
|
||||
HttpRequest.builder().method("POST")
|
||||
.endpoint(URI.create("http://localhost:8773/services/Cloud/"))
|
||||
.headers(ImmutableMultimap.of("Host", "localhost:8773"))
|
||||
.payload(payloadFromStringWithContentType("Action=DescribeInstances&Signature=kkCE1HzyntmkICEidOizw50B9yjLdNZvAWUXVse1c8o%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2009-04-04&AWSAccessKeyId=identity", "application/x-www-form-urlencoded")).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/nova_ec2_describe_instances.xml")).build()
|
||||
).getInstanceServices();
|
||||
|
||||
Set<? extends Reservation<? extends RunningInstance>> response = client.describeInstancesInRegion("nova");
|
||||
|
||||
assertEquals(response.size(), 3);
|
||||
|
||||
Reservation<? extends RunningInstance> target = Iterables.get(response, 2);
|
||||
RunningInstance runningInstance = Iterables.getOnlyElement(target);
|
||||
BlockDevice bd = Iterables.getOnlyElement(runningInstance.getEbsBlockDevices().values());
|
||||
|
||||
// this is a '-' in the nova_ec2_describe_instances.xml
|
||||
assertNull(bd.getAttachTime());
|
||||
|
||||
// double-check the other fields
|
||||
assertFalse(bd.isDeleteOnTermination());
|
||||
assertEquals(bd.getVolumeId(), "1");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,128 @@
|
|||
<?xml version="1.0" ?>
|
||||
<DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2009-04-04/">
|
||||
<requestId>req-a68563bb-034e-4a32-aac7-5126e041cf91</requestId>
|
||||
<reservationSet>
|
||||
<item>
|
||||
<ownerId>2b25129754c145de8426896b09a42106</ownerId>
|
||||
<groupSet>
|
||||
<item>
|
||||
<groupId>default</groupId>
|
||||
</item>
|
||||
</groupSet>
|
||||
<reservationId>r-1jywe5ye</reservationId>
|
||||
<instancesSet>
|
||||
<item>
|
||||
<placement>
|
||||
<availabilityZone>nova</availabilityZone>
|
||||
</placement>
|
||||
<rootDeviceType>instance-store</rootDeviceType>
|
||||
<keyName>None (2b25129754c145de8426896b09a42106, ubuntu)</keyName>
|
||||
<instanceId>i-00000003</instanceId>
|
||||
<instanceState>
|
||||
<code>16</code>
|
||||
<name>running</name>
|
||||
</instanceState>
|
||||
<publicDnsName/>
|
||||
<imageId>ami-00000001</imageId>
|
||||
<productCodesSet/>
|
||||
<privateDnsName>mishdemo</privateDnsName>
|
||||
<dnsName>mishdemo</dnsName>
|
||||
<launchTime>2012-05-02T06:59:59.000Z</launchTime>
|
||||
<amiLaunchIndex>0</amiLaunchIndex>
|
||||
<rootDeviceName>/dev/vda</rootDeviceName>
|
||||
<kernelId>aki-00000002</kernelId>
|
||||
<ramdiskId>ari-00000003</ramdiskId>
|
||||
<ipAddress>10.77.22.4</ipAddress>
|
||||
<instanceType>m1.small</instanceType>
|
||||
<privateIpAddress>10.77.22.4</privateIpAddress>
|
||||
</item>
|
||||
</instancesSet>
|
||||
</item>
|
||||
<item>
|
||||
<ownerId>d8f0cd49971a44d187b454e14921056d</ownerId>
|
||||
<groupSet>
|
||||
<item>
|
||||
<groupId>default</groupId>
|
||||
</item>
|
||||
</groupSet>
|
||||
<reservationId>r-pctvv0ey</reservationId>
|
||||
<instancesSet>
|
||||
<item>
|
||||
<placement>
|
||||
<availabilityZone>nova</availabilityZone>
|
||||
</placement>
|
||||
<rootDeviceType>instance-store</rootDeviceType>
|
||||
<keyName>None (d8f0cd49971a44d187b454e14921056d, ubuntu)</keyName>
|
||||
<instanceId>i-00000001</instanceId>
|
||||
<instanceState>
|
||||
<code>16</code>
|
||||
<name>running</name>
|
||||
</instanceState>
|
||||
<publicDnsName/>
|
||||
<imageId>ami-00000001</imageId>
|
||||
<productCodesSet/>
|
||||
<privateDnsName>avi-server1</privateDnsName>
|
||||
<dnsName>avi-server1</dnsName>
|
||||
<launchTime>2012-05-01T09:18:37.000Z</launchTime>
|
||||
<amiLaunchIndex>0</amiLaunchIndex>
|
||||
<rootDeviceName>/dev/vda</rootDeviceName>
|
||||
<kernelId>aki-00000002</kernelId>
|
||||
<ramdiskId>ari-00000003</ramdiskId>
|
||||
<ipAddress>10.77.22.2</ipAddress>
|
||||
<instanceType>m1.tiny</instanceType>
|
||||
<privateIpAddress>10.77.22.2</privateIpAddress>
|
||||
</item>
|
||||
</instancesSet>
|
||||
</item>
|
||||
<item>
|
||||
<ownerId>d8f0cd49971a44d187b454e14921056d</ownerId>
|
||||
<groupSet>
|
||||
<item>
|
||||
<groupId>default</groupId>
|
||||
</item>
|
||||
<item>
|
||||
<groupId>avi-sg1</groupId>
|
||||
</item>
|
||||
</groupSet>
|
||||
<reservationId>r-0iwpw2u8</reservationId>
|
||||
<instancesSet>
|
||||
<item>
|
||||
<blockDeviceMapping>
|
||||
<item>
|
||||
<deviceName>/dev/vdc</deviceName>
|
||||
<ebs>
|
||||
<status>in-use</status>
|
||||
<deleteOnTermination>false</deleteOnTermination>
|
||||
<volumeId>1</volumeId>
|
||||
<attachTime>-</attachTime>
|
||||
</ebs>
|
||||
</item>
|
||||
</blockDeviceMapping>
|
||||
<placement>
|
||||
<availabilityZone>nova</availabilityZone>
|
||||
</placement>
|
||||
<rootDeviceType>instance-store</rootDeviceType>
|
||||
<keyName>avi-kp1 (d8f0cd49971a44d187b454e14921056d, ubuntu)</keyName>
|
||||
<instanceId>i-00000002</instanceId>
|
||||
<instanceState>
|
||||
<code>16</code>
|
||||
<name>running</name>
|
||||
</instanceState>
|
||||
<publicDnsName/>
|
||||
<imageId>ami-00000001</imageId>
|
||||
<productCodesSet/>
|
||||
<privateDnsName>avi-server2</privateDnsName>
|
||||
<dnsName>avi-server2</dnsName>
|
||||
<launchTime>2012-05-01T09:22:26.000Z</launchTime>
|
||||
<amiLaunchIndex>0</amiLaunchIndex>
|
||||
<rootDeviceName>/dev/vda</rootDeviceName>
|
||||
<kernelId>aki-00000002</kernelId>
|
||||
<ramdiskId>ari-00000003</ramdiskId>
|
||||
<ipAddress>10.77.22.3</ipAddress>
|
||||
<instanceType>m1.tiny</instanceType>
|
||||
<privateIpAddress>10.77.22.3</privateIpAddress>
|
||||
</item>
|
||||
</instancesSet>
|
||||
</item>
|
||||
</reservationSet>
|
||||
</DescribeInstancesResponse>
|
Loading…
Reference in New Issue