mirror of https://github.com/apache/jclouds.git
612: Added testing of tags for instances and checking for empty key values
This commit is contained in:
parent
842da34982
commit
f306137eb0
|
@ -31,6 +31,7 @@ import org.jclouds.ec2.domain.InstanceState;
|
|||
import org.jclouds.ec2.domain.RootDeviceType;
|
||||
import org.jclouds.ec2.domain.RunningInstance;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
|
@ -64,8 +65,8 @@ public class AWSRunningInstance extends RunningInstance {
|
|||
}
|
||||
|
||||
public Builder tag(String key, String value) {
|
||||
if (key != null && value != null)
|
||||
this.tags.put(key, value);
|
||||
if (key != null)
|
||||
this.tags.put(key, Strings.nullToEmpty(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.util.Map;
|
|||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
|
@ -89,8 +90,8 @@ public class SpotInstanceRequest implements Comparable<SpotInstanceRequest> {
|
|||
}
|
||||
|
||||
public Builder tag(String key, String value) {
|
||||
if (key != null && value != null)
|
||||
this.tags.put(key, value);
|
||||
if (key != null)
|
||||
this.tags.put(key, Strings.nullToEmpty(value));
|
||||
return this;
|
||||
}
|
||||
public Builder availabilityZoneGroup(String availabilityZoneGroup) {
|
||||
|
|
|
@ -53,7 +53,7 @@ public class AWSDescribeInstancesResponseHandler extends
|
|||
|
||||
@Inject
|
||||
AWSDescribeInstancesResponseHandler(DateService dateService, @Region String defaultRegion,
|
||||
Provider<AWSRunningInstance.Builder> builderProvider) {
|
||||
Provider<AWSRunningInstance.Builder> builderProvider, TagSetHandler tagSetHandler) {
|
||||
super(dateService, defaultRegion, builderProvider);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,39 +35,39 @@ import com.google.common.collect.Sets;
|
|||
* @author grkvlt@apache.org
|
||||
*/
|
||||
public class DescribeTagsResponseHandler extends ParseSax.HandlerWithResult<Set<Tag>> {
|
||||
private Set<Tag> bundleTasks = Sets.newLinkedHashSet();
|
||||
private final TagsHandler bundleTaskHandler;
|
||||
private Set<Tag> tags = Sets.newLinkedHashSet();
|
||||
private final TagHandler tagHandler;
|
||||
|
||||
@Inject
|
||||
public DescribeTagsResponseHandler(TagsHandler bundleTaskHandler) {
|
||||
this.bundleTaskHandler = bundleTaskHandler;
|
||||
public DescribeTagsResponseHandler(TagHandler tagHandler) {
|
||||
this.tagHandler = tagHandler;
|
||||
}
|
||||
|
||||
public Set<Tag> getResult() {
|
||||
return bundleTasks;
|
||||
return tags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerWithResult<Set<Tag>> setContext(HttpRequest request) {
|
||||
bundleTaskHandler.setContext(request);
|
||||
tagHandler.setContext(request);
|
||||
return super.setContext(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
if (!qName.equals("item"))
|
||||
bundleTaskHandler.startElement(uri, localName, qName, attributes);
|
||||
tagHandler.startElement(uri, localName, qName, attributes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
if (qName.equals("item")) {
|
||||
bundleTasks.add(bundleTaskHandler.getResult());
|
||||
tags.add(tagHandler.getResult());
|
||||
}
|
||||
bundleTaskHandler.endElement(uri, localName, qName);
|
||||
tagHandler.endElement(uri, localName, qName);
|
||||
}
|
||||
|
||||
public void characters(char ch[], int start, int length) {
|
||||
bundleTaskHandler.characters(ch, start, length);
|
||||
tagHandler.characters(ch, start, length);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,9 @@
|
|||
*/
|
||||
package org.jclouds.aws.ec2.xml;
|
||||
|
||||
import static org.jclouds.util.SaxUtils.currentOrNull;
|
||||
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
|
||||
import static org.jclouds.util.SaxUtils.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
@ -30,6 +31,7 @@ import org.jclouds.date.DateService;
|
|||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.location.Region;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -43,16 +45,17 @@ public class SpotInstanceHandler extends ParseSax.HandlerForGeneratedRequestWith
|
|||
protected final Builder builder;
|
||||
protected boolean inLaunchSpecification;
|
||||
protected final LaunchSpecificationHandler launchSpecificationHandler;
|
||||
private boolean inTagSet;
|
||||
private String key;
|
||||
private String value;
|
||||
protected boolean inTagSet;
|
||||
protected final TagSetHandler tagSetHandler;
|
||||
|
||||
@Inject
|
||||
public SpotInstanceHandler(DateService dateService, @Region String defaultRegion,
|
||||
LaunchSpecificationHandler launchSpecificationHandler, SpotInstanceRequest.Builder builder) {
|
||||
LaunchSpecificationHandler launchSpecificationHandler, TagSetHandler tagSetHandler,
|
||||
SpotInstanceRequest.Builder builder) {
|
||||
this.dateService = dateService;
|
||||
this.defaultRegion = defaultRegion;
|
||||
this.launchSpecificationHandler = launchSpecificationHandler;
|
||||
this.tagSetHandler = tagSetHandler;
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
|
@ -67,37 +70,37 @@ public class SpotInstanceHandler extends ParseSax.HandlerForGeneratedRequestWith
|
|||
}
|
||||
}
|
||||
|
||||
public void startElement(String uri, String name, String qName, Attributes attrs) {
|
||||
@Override
|
||||
public void startElement(String uri, String name, String qName, Attributes attrs) throws SAXException {
|
||||
if (equalsOrSuffix(qName, "launchSpecification")) {
|
||||
inLaunchSpecification = true;
|
||||
} else if (equalsOrSuffix(qName, "tagSet")) {
|
||||
inTagSet = true;
|
||||
}
|
||||
if (inLaunchSpecification)
|
||||
launchSpecificationHandler.startElement(uri, name, qName, attrs);
|
||||
if (inLaunchSpecification) {
|
||||
launchSpecificationHandler.startElement(uri, name, qName, attrs);
|
||||
} else if (inTagSet) {
|
||||
tagSetHandler.startElement(uri, name, qName, attrs);
|
||||
}
|
||||
}
|
||||
|
||||
public void endElement(String uri, String name, String qName) {
|
||||
@Override
|
||||
public void endElement(String uri, String name, String qName) throws SAXException {
|
||||
if (equalsOrSuffix(qName, "tagSet")) {
|
||||
inTagSet = false;
|
||||
builder.tags(tagSetHandler.getResult());
|
||||
} else if (inTagSet) {
|
||||
if (equalsOrSuffix(qName, "key")) {
|
||||
key = currentOrNull(currentText);
|
||||
} else if (equalsOrSuffix(qName, "value")) {
|
||||
value = currentOrNull(currentText);
|
||||
}
|
||||
tagSetHandler.endElement(uri, name, qName);
|
||||
}
|
||||
|
||||
if (qName.equals("launchSpecification")) {
|
||||
inLaunchSpecification = false;
|
||||
builder.launchSpecification(launchSpecificationHandler.getResult());
|
||||
} else if (qName.equals("item") && inTagSet) {
|
||||
builder.tag(key, value);
|
||||
key = null;
|
||||
value = null;
|
||||
}
|
||||
if (inLaunchSpecification) {
|
||||
} else if (inLaunchSpecification) {
|
||||
launchSpecificationHandler.endElement(uri, name, qName);
|
||||
} else if (qName.equals("spotInstanceRequestId")) {
|
||||
}
|
||||
|
||||
if (qName.equals("spotInstanceRequestId")) {
|
||||
builder.id(currentOrNull(currentText));
|
||||
} else if (qName.equals("instanceId")) {
|
||||
builder.instanceId(currentOrNull(currentText));
|
||||
|
@ -133,10 +136,14 @@ public class SpotInstanceHandler extends ParseSax.HandlerForGeneratedRequestWith
|
|||
currentText = new StringBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void characters(char ch[], int start, int length) {
|
||||
if (inLaunchSpecification)
|
||||
launchSpecificationHandler.characters(ch, start, length);
|
||||
else
|
||||
if (inLaunchSpecification) {
|
||||
launchSpecificationHandler.characters(ch, start, length);
|
||||
} else if (inTagSet) {
|
||||
tagSetHandler.characters(ch, start, length);
|
||||
} else {
|
||||
currentText.append(ch, start, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,11 +21,12 @@ package org.jclouds.aws.ec2.xml;
|
|||
import org.jclouds.aws.ec2.domain.Tag;
|
||||
import org.jclouds.aws.ec2.util.TagFilters.ResourceType;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* @author grkvlt@apache.org
|
||||
*/
|
||||
public class TagsHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Tag> {
|
||||
public class TagHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Tag> {
|
||||
private StringBuilder currentText = new StringBuilder();
|
||||
|
||||
private String resourceId;
|
||||
|
@ -38,7 +39,7 @@ public class TagsHandler extends ParseSax.HandlerForGeneratedRequestWithResult<T
|
|||
return returnVal;
|
||||
}
|
||||
|
||||
public void endElement(String uri, String name, String qName) {
|
||||
public void endElement(String uri, String name, String qName) throws SAXException {
|
||||
if (qName.equals("resourceId")) {
|
||||
this.resourceId = currentText.toString().trim();
|
||||
} else if (qName.equals("resourceType")) {
|
|
@ -0,0 +1,81 @@
|
|||
/**
|
||||
* 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.aws.ec2.xml;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
* @author grkvlt@apache.org
|
||||
*/
|
||||
public class TagSetHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Map<String, String>> {
|
||||
private StringBuilder currentText = new StringBuilder();
|
||||
|
||||
private ImmutableMap.Builder<String, String> result;
|
||||
private boolean inItem = false;
|
||||
private String key;
|
||||
private String value;
|
||||
|
||||
public TagSetHandler() {
|
||||
super();
|
||||
this.result = ImmutableMap.<String, String>builder();
|
||||
}
|
||||
|
||||
public Map<String, String> getResult() {
|
||||
return result.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
if (qName.equals("item")) {
|
||||
inItem = true;
|
||||
key = null;
|
||||
value = null;
|
||||
}
|
||||
currentText = new StringBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
if (qName.equals("item")) {
|
||||
inItem = false;
|
||||
if (key != null) {
|
||||
result.put(key, Strings.nullToEmpty(value));
|
||||
}
|
||||
}
|
||||
if (inItem) {
|
||||
if (qName.equals("key")) {
|
||||
key = currentText.toString().trim();
|
||||
} else if (qName.equals("value")) {
|
||||
value = currentText.toString().trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void characters(char ch[], int start, int length) {
|
||||
currentText.append(ch, start, length);
|
||||
}
|
||||
}
|
|
@ -48,6 +48,12 @@ public class BindTagsToIndexedFormParamsTest {
|
|||
assertEquals(request.getPayload().getRawContent(), "Tag.1.Key=one&Tag.1.Value=alpha&Tag.2.Key=two&Tag.2.Value=beta");
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build();
|
||||
request = binder.bindToRequest(request, ImmutableMap.<String, String>builder().put("empty", "").build());
|
||||
assertEquals(request.getPayload().getRawContent(), "Tag.1.Key=empty&Tag.1.Value=");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testMustBeArray() {
|
||||
HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost"));
|
||||
|
|
|
@ -80,43 +80,76 @@ public class AWSRunningInstanceToNodeMetadataTest {
|
|||
.<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of());
|
||||
|
||||
ImmutableSet<AWSRunningInstance> contents = ImmutableSet.of(new AWSRunningInstance.Builder()
|
||||
.region(defaultRegion).instanceId("i-911444f0").imageId("ami-63be790a").instanceState(
|
||||
InstanceState.RUNNING).privateDnsName("ip-10-212-81-7.ec2.internal").dnsName(
|
||||
"ec2-174-129-173-155.compute-1.amazonaws.com").keyName("jclouds#zkclustertest#us-east-1#23")
|
||||
.amiLaunchIndex("0").instanceType("t1.micro").launchTime(
|
||||
dateService.iso8601DateParse("2011-08-16T13:40:50.000Z")).availabilityZone("us-east-1c")
|
||||
.kernelId("aki-427d952b").monitoringState(MonitoringState.DISABLED).privateIpAddress("10.212.81.7")
|
||||
.ipAddress("174.129.173.155").securityGroupIdToNames(
|
||||
ImmutableMap.<String, String> of("sg-ef052b86", "jclouds#zkclustertest#us-east-1"))
|
||||
.rootDeviceType(RootDeviceType.EBS).rootDeviceName("/dev/sda1").device(
|
||||
"/dev/sda1",
|
||||
new BlockDevice("vol-5829fc32", Attachment.Status.ATTACHED, dateService
|
||||
.iso8601DateParse("2011-08-16T13:41:19.000Z"), true))
|
||||
.virtualizationType("paravirtual").tag("Name", "foo").build(),//
|
||||
new AWSRunningInstance.Builder().region(defaultRegion).instanceId("i-931444f2").imageId("ami-63be790a")
|
||||
.instanceState(InstanceState.RUNNING).privateDnsName("ip-10-212-185-8.ec2.internal").dnsName(
|
||||
"ec2-50-19-207-248.compute-1.amazonaws.com").keyName(
|
||||
"jclouds#zkclustertest#us-east-1#23").amiLaunchIndex("0").instanceType("t1.micro")
|
||||
.launchTime(dateService.iso8601DateParse("2011-08-16T13:40:50.000Z")).availabilityZone(
|
||||
"us-east-1c").kernelId("aki-427d952b").monitoringState(MonitoringState.DISABLED)
|
||||
.privateIpAddress("10.212.185.8").ipAddress("50.19.207.248").securityGroupIdToNames(
|
||||
ImmutableMap.<String, String> of("sg-ef052b86", "jclouds#zkclustertest#us-east-1"))
|
||||
.rootDeviceType(RootDeviceType.EBS).rootDeviceName("/dev/sda1").device(
|
||||
"/dev/sda1",
|
||||
new BlockDevice("vol-5029fc3a", Attachment.Status.ATTACHED, dateService
|
||||
.iso8601DateParse("2011-08-16T13:41:19.000Z"), true)).virtualizationType(
|
||||
"paravirtual").build());
|
||||
.region(defaultRegion)
|
||||
.instanceId("i-911444f0")
|
||||
.imageId("ami-63be790a")
|
||||
.instanceState(InstanceState.RUNNING)
|
||||
.privateDnsName("ip-10-212-81-7.ec2.internal")
|
||||
.dnsName("ec2-174-129-173-155.compute-1.amazonaws.com")
|
||||
.keyName("jclouds#zkclustertest#us-east-1#23")
|
||||
.amiLaunchIndex("0")
|
||||
.instanceType("t1.micro")
|
||||
.launchTime(dateService.iso8601DateParse("2011-08-16T13:40:50.000Z"))
|
||||
.availabilityZone("us-east-1c")
|
||||
.kernelId("aki-427d952b")
|
||||
.monitoringState(MonitoringState.DISABLED)
|
||||
.privateIpAddress("10.212.81.7")
|
||||
.ipAddress("174.129.173.155")
|
||||
.securityGroupIdToNames(ImmutableMap.<String, String> of("sg-ef052b86", "jclouds#zkclustertest#us-east-1"))
|
||||
.rootDeviceType(RootDeviceType.EBS)
|
||||
.rootDeviceName("/dev/sda1")
|
||||
.device("/dev/sda1", new BlockDevice("vol-5829fc32", Attachment.Status.ATTACHED, dateService.iso8601DateParse("2011-08-16T13:41:19.000Z"), true))
|
||||
.virtualizationType("paravirtual")
|
||||
.tag("Name", "foo")
|
||||
.tag("Empty", "")
|
||||
.build(),//
|
||||
new AWSRunningInstance.Builder()
|
||||
.region(defaultRegion)
|
||||
.instanceId("i-931444f2")
|
||||
.imageId("ami-63be790a")
|
||||
.instanceState(InstanceState.RUNNING)
|
||||
.privateDnsName("ip-10-212-185-8.ec2.internal")
|
||||
.dnsName("ec2-50-19-207-248.compute-1.amazonaws.com")
|
||||
.keyName("jclouds#zkclustertest#us-east-1#23")
|
||||
.amiLaunchIndex("0")
|
||||
.instanceType("t1.micro")
|
||||
.launchTime(dateService.iso8601DateParse("2011-08-16T13:40:50.000Z"))
|
||||
.availabilityZone("us-east-1c")
|
||||
.kernelId("aki-427d952b")
|
||||
.monitoringState(MonitoringState.DISABLED)
|
||||
.privateIpAddress("10.212.185.8")
|
||||
.ipAddress("50.19.207.248")
|
||||
.securityGroupIdToNames(ImmutableMap.<String, String>of("sg-ef052b86", "jclouds#zkclustertest#us-east-1"))
|
||||
.rootDeviceType(RootDeviceType.EBS)
|
||||
.rootDeviceName("/dev/sda1")
|
||||
.device("/dev/sda1", new BlockDevice("vol-5029fc3a", Attachment.Status.ATTACHED, dateService.iso8601DateParse("2011-08-16T13:41:19.000Z"), true))
|
||||
.virtualizationType("paravirtual")
|
||||
.build());
|
||||
|
||||
assertEquals(
|
||||
parser.apply(Iterables.get(contents, 0)).toString(),
|
||||
new NodeMetadataBuilder().state(NodeState.RUNNING).group("zkclustertest").hostname("ip-10-212-81-7")
|
||||
.privateAddresses(ImmutableSet.of("10.212.81.7")).publicAddresses(ImmutableSet.of("174.129.173.155"))
|
||||
.imageId("us-east-1/ami-63be790a").id("us-east-1/i-911444f0").providerId("i-911444f0")
|
||||
.userMetadata(ImmutableMap.of("Name", "foo")).build().toString());
|
||||
assertEquals(parser.apply(Iterables.get(contents, 1)), new NodeMetadataBuilder().state(NodeState.RUNNING).group(
|
||||
"zkclustertest").hostname("ip-10-212-185-8").privateAddresses(ImmutableSet.of("10.212.185.8"))
|
||||
.publicAddresses(ImmutableSet.of("50.19.207.248")).imageId("us-east-1/ami-63be790a").id(
|
||||
"us-east-1/i-931444f2").providerId("i-931444f2").build());
|
||||
new NodeMetadataBuilder()
|
||||
.state(NodeState.RUNNING)
|
||||
.group("zkclustertest")
|
||||
.hostname("ip-10-212-81-7")
|
||||
.privateAddresses(ImmutableSet.of("10.212.81.7"))
|
||||
.publicAddresses(ImmutableSet.of("174.129.173.155"))
|
||||
.imageId("us-east-1/ami-63be790a")
|
||||
.id("us-east-1/i-911444f0")
|
||||
.providerId("i-911444f0")
|
||||
.userMetadata(ImmutableMap.of("Name", "foo", "Empty", "")).build().toString());
|
||||
assertEquals(
|
||||
parser.apply(Iterables.get(contents, 1)),
|
||||
new NodeMetadataBuilder()
|
||||
.state(NodeState.RUNNING)
|
||||
.group("zkclustertest")
|
||||
.hostname("ip-10-212-185-8")
|
||||
.privateAddresses(ImmutableSet.of("10.212.185.8"))
|
||||
.publicAddresses(ImmutableSet.of("50.19.207.248"))
|
||||
.imageId("us-east-1/ami-63be790a")
|
||||
.id("us-east-1/i-931444f2")
|
||||
.providerId("i-931444f2")
|
||||
.build());
|
||||
}
|
||||
|
||||
protected AWSRunningInstanceToNodeMetadata createNodeParser(final ImmutableSet<Hardware> hardware,
|
||||
|
|
|
@ -33,8 +33,7 @@ import org.testng.annotations.Test;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during
|
||||
// surefire
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
@Test(groups = "unit", testName = "SpotInstanceRequestToAWSRunningInstanceTest")
|
||||
public class SpotInstanceRequestToAWSRunningInstanceTest {
|
||||
|
||||
|
@ -53,13 +52,18 @@ public class SpotInstanceRequestToAWSRunningInstanceTest {
|
|||
.mapEBSSnapshotToDevice("/dev/sda2", "snap-1ea27576", 1, true)
|
||||
.mapEphemeralDeviceToDevice("/dev/sda3", "vre1").monitoringEnabled(false).build())
|
||||
.createTime(new SimpleDateFormatDateService().iso8601DateParse("2011-03-08T03:30:36.000Z"))
|
||||
.productDescription("Linux/UNIX").tag("foo", "bar").build();
|
||||
.productDescription("Linux/UNIX")
|
||||
.tag("foo", "bar")
|
||||
.tag("empty", "")
|
||||
.build();
|
||||
|
||||
assertEquals(
|
||||
new SpotInstanceRequestToAWSRunningInstance().apply(input),
|
||||
AWSRunningInstance.builder().region("us-east-1").instanceId("sir-228e6406")
|
||||
.spotInstanceRequestId("sir-228e6406").instanceState(InstanceState.PENDING).imageId("ami-595a0a1c")
|
||||
.groupId("default").instanceType("m1.large").tag("foo", "bar")
|
||||
.groupId("default").instanceType("m1.large")
|
||||
.tag("foo", "bar")
|
||||
.tag("empty", "")
|
||||
.monitoringState(MonitoringState.PENDING).build());
|
||||
}
|
||||
|
||||
|
|
|
@ -109,11 +109,15 @@ public class TagClientLiveTest {
|
|||
@Test
|
||||
void test() {
|
||||
cleanupTag(testGroup, "test-key");
|
||||
cleanupTag(testGroup, "empty-key");
|
||||
try {
|
||||
client.createTagsInRegion(null, ImmutableList.<String>builder().add(testGroup).build(), ImmutableMap.<String, String>builder().put("test-key", "test-value").build());
|
||||
checkTag(testGroup, ResourceType.SECURITY_GROUP, "test-key", "test-value");
|
||||
client.createTagsInRegion(null, ImmutableList.<String>builder().add(testGroup).build(), ImmutableMap.<String, String>builder().put("empty-key", "").build());
|
||||
checkTag(testGroup, ResourceType.SECURITY_GROUP, "empty-key", "");
|
||||
} finally {
|
||||
cleanupTag(testGroup, "test-key");
|
||||
cleanupTag(testGroup, "empty-key");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,17 +69,30 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest
|
|||
|
||||
public void testWhenRunning() throws UnknownHostException {
|
||||
|
||||
Set<Reservation<AWSRunningInstance>> contents = ImmutableSet.of(new Reservation<AWSRunningInstance>(
|
||||
defaultRegion, ImmutableSet.of("adriancole.ec2ingress"), ImmutableSet.of(new AWSRunningInstance.Builder()
|
||||
.region(defaultRegion).groupId("adriancole.ec2ingress").amiLaunchIndex("0")
|
||||
.dnsName("ec2-174-129-81-68.compute-1.amazonaws.com").imageId("ami-82e4b5c7")
|
||||
.instanceId("i-0799056f").instanceState(InstanceState.RUNNING).instanceType(InstanceType.M1_SMALL)
|
||||
.ipAddress("174.129.81.68").kernelId("aki-a71cf9ce").keyName("adriancole.ec21")
|
||||
.launchTime(dateService.iso8601DateParse("2009-11-09T03:00:34.000Z"))
|
||||
.monitoringState(MonitoringState.DISABLED).availabilityZone("us-east-1c")
|
||||
.virtualizationType("paravirtual").privateDnsName("ip-10-243-42-70.ec2.internal")
|
||||
.privateIpAddress("10.243.42.70").ramdiskId("ari-a51cf9cc")
|
||||
.rootDeviceType(RootDeviceType.INSTANCE_STORE).build()), "993194456877", null, "r-a3c508cb"));
|
||||
Set<Reservation<AWSRunningInstance>> contents = ImmutableSet.of(
|
||||
new Reservation<AWSRunningInstance>(defaultRegion, ImmutableSet.of("adriancole.ec2ingress"), ImmutableSet.of(
|
||||
new AWSRunningInstance.Builder()
|
||||
.region(defaultRegion)
|
||||
.groupId("adriancole.ec2ingress")
|
||||
.amiLaunchIndex("0")
|
||||
.dnsName("ec2-174-129-81-68.compute-1.amazonaws.com")
|
||||
.imageId("ami-82e4b5c7")
|
||||
.instanceId("i-0799056f")
|
||||
.instanceState(InstanceState.RUNNING)
|
||||
.instanceType(InstanceType.M1_SMALL)
|
||||
.ipAddress("174.129.81.68")
|
||||
.kernelId("aki-a71cf9ce")
|
||||
.keyName("adriancole.ec21")
|
||||
.launchTime(dateService.iso8601DateParse("2009-11-09T03:00:34.000Z"))
|
||||
.monitoringState(MonitoringState.DISABLED)
|
||||
.availabilityZone("us-east-1c")
|
||||
.virtualizationType("paravirtual")
|
||||
.privateDnsName("ip-10-243-42-70.ec2.internal")
|
||||
.privateIpAddress("10.243.42.70")
|
||||
.ramdiskId("ari-a51cf9cc")
|
||||
.rootDeviceType(RootDeviceType.INSTANCE_STORE)
|
||||
.build()),
|
||||
"993194456877", null, "r-a3c508cb"));
|
||||
|
||||
Set<Reservation<? extends RunningInstance>> result = parseAWSRunningInstances("/describe_instances_running.xml");
|
||||
|
||||
|
@ -87,7 +100,6 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest
|
|||
}
|
||||
|
||||
public void testWhenRunningLatest() throws UnknownHostException {
|
||||
|
||||
Set<Reservation<AWSRunningInstance>> contents = ImmutableSet.of(new Reservation<AWSRunningInstance>(
|
||||
defaultRegion, ImmutableSet.of("jclouds#ec2-s#us-east-1"), ImmutableSet.of(
|
||||
new AWSRunningInstance.Builder()
|
||||
|
@ -108,6 +120,7 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest
|
|||
.ipAddress("174.129.173.155")
|
||||
.securityGroupIdToName("sg-ef052b86", "jclouds#zkclustertest#us-east-1")
|
||||
.tag("Name", "ec2-o")
|
||||
.tag("Empty", "")
|
||||
.rootDeviceType(RootDeviceType.EBS)
|
||||
.rootDeviceName("/dev/sda1")
|
||||
.device(
|
||||
|
|
|
@ -112,7 +112,11 @@ public class SpotInstanceHandlerTest extends BaseEC2HandlerTest {
|
|||
.instanceType("t1.micro").monitoringEnabled(false).keyName("jclouds#adriancole-ec2unssh")
|
||||
.build())
|
||||
.createTime(new SimpleDateFormatDateService().iso8601DateParse("2011-07-29T05:27:39.000Z"))
|
||||
.productDescription("Linux/UNIX").tag("Name", "ec2-o").build();
|
||||
.productDescription("Linux/UNIX")
|
||||
.tag("Name", "ec2-o")
|
||||
.tag("Spot", "spot-value")
|
||||
.tag("Empty", "")
|
||||
.build();
|
||||
SpotInstanceHandler handler = injector.getInstance(SpotInstanceHandler.class);
|
||||
addDefaultRegionToHandler(handler);
|
||||
SpotInstanceRequest result = factory.create(handler).parse(is);
|
||||
|
|
|
@ -66,6 +66,10 @@
|
|||
<key>Name</key>
|
||||
<value>ec2-o</value>
|
||||
</item>
|
||||
<item>
|
||||
<key>Empty</key>
|
||||
<value />
|
||||
</item>
|
||||
</tagSet>
|
||||
</item>
|
||||
<item>
|
||||
|
|
|
@ -30,6 +30,14 @@
|
|||
<key>Name</key>
|
||||
<value>ec2-o</value>
|
||||
</item>
|
||||
<item>
|
||||
<key>Spot</key>
|
||||
<value>spot-value</value>
|
||||
</item>
|
||||
<item>
|
||||
<key>Empty</key>
|
||||
<value />
|
||||
</item>
|
||||
</tagSet>
|
||||
<launchedAvailabilityZone>us-east-1b</launchedAvailabilityZone>
|
||||
</item>
|
||||
|
|
Loading…
Reference in New Issue