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