mirror of https://github.com/apache/jclouds.git
612: Change Multimap occurences to Maps with Iterable values
This commit is contained in:
parent
d4f7140071
commit
410b947160
|
@ -47,6 +47,7 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
import com.google.common.collect.ImmutableMultimap;
|
||||||
import com.google.common.collect.ImmutableMultimap.Builder;
|
import com.google.common.collect.ImmutableMultimap.Builder;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -142,7 +143,7 @@ public class AWSUtils {
|
||||||
checkArgument(checkNotNull(input, "input") instanceof String[], "this binder is only valid for String[] : "
|
checkArgument(checkNotNull(input, "input") instanceof String[], "this binder is only valid for String[] : "
|
||||||
+ input.getClass());
|
+ input.getClass());
|
||||||
String[] values = (String[]) input;
|
String[] values = (String[]) input;
|
||||||
Builder<String, String> builder = ImmutableMultimap.<String, String>builder();
|
Builder<String, String> builder = ImmutableMultimap.<String, String> builder();
|
||||||
for (int i = 0; i < values.length; i++) {
|
for (int i = 0; i < values.length; i++) {
|
||||||
builder.put(prefix + "." + (i + 1), checkNotNull(values[i], prefix.toLowerCase() + "s[" + i + "]"));
|
builder.put(prefix + "." + (i + 1), checkNotNull(values[i], prefix.toLowerCase() + "s[" + i + "]"));
|
||||||
}
|
}
|
||||||
|
@ -174,7 +175,26 @@ public class AWSUtils {
|
||||||
int i = 1;
|
int i = 1;
|
||||||
for (Object k : map.keySet()) {
|
for (Object k : map.keySet()) {
|
||||||
builder.put(prefix + "." + i + "." + keySuffix, checkNotNull(k.toString(), keySuffix.toLowerCase() + "s[" + i + "]"));
|
builder.put(prefix + "." + i + "." + keySuffix, checkNotNull(k.toString(), keySuffix.toLowerCase() + "s[" + i + "]"));
|
||||||
if (!map.get(k).isEmpty()) {
|
int j = 1;
|
||||||
|
for (Object v : map.get(k)) {
|
||||||
|
builder.put(prefix + "." + i + "." + valueSuffix + "." + j, v.toString());
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
ImmutableMultimap<String, String> forms = builder.build();
|
||||||
|
return forms.size() == 0 ? request : ModifyRequest.putFormParams(request, forms);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <R extends HttpRequest> R indexMapOfIterableToFormValuesWithPrefix(R request, String prefix, String keySuffix, String valueSuffix, Object input) {
|
||||||
|
checkArgument(checkNotNull(input, "input") instanceof Map<?, ?>, "this binder is only valid for Map<?,Iterable<?>>: " + input.getClass());
|
||||||
|
Map<Object, Iterable<Object>> map = (Map<Object, Iterable<Object>>) input;
|
||||||
|
Builder<String, String> builder = ImmutableMultimap.<String, String> builder();
|
||||||
|
int i = 1;
|
||||||
|
for (Object k : map.keySet()) {
|
||||||
|
builder.put(prefix + "." + i + "." + keySuffix, checkNotNull(k.toString(), keySuffix.toLowerCase() + "s[" + i + "]"));
|
||||||
|
if (!Iterables.isEmpty(map.get(k))) {
|
||||||
int j = 1;
|
int j = 1;
|
||||||
for (Object v : map.get(k)) {
|
for (Object v : map.get(k)) {
|
||||||
builder.put(prefix + "." + i + "." + valueSuffix + "." + j, v.toString());
|
builder.put(prefix + "." + i + "." + valueSuffix + "." + j, v.toString());
|
||||||
|
|
|
@ -20,19 +20,19 @@ package org.jclouds.aws.ec2.binders;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.*;
|
import static com.google.common.base.Preconditions.*;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jclouds.aws.util.AWSUtils;
|
import org.jclouds.aws.util.AWSUtils;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.rest.Binder;
|
import org.jclouds.rest.Binder;
|
||||||
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author grkvlt@apache.org
|
* @author grkvlt@apache.org
|
||||||
*/
|
*/
|
||||||
public class BindTagFiltersToIndexedFormParams implements Binder {
|
public class BindTagFiltersToIndexedFormParams implements Binder {
|
||||||
@Override
|
@Override
|
||||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||||
checkArgument(checkNotNull(input, "input") instanceof Multimap, "this binder is only valid for Multimap<Filtername, ?>");
|
checkArgument(checkNotNull(input, "input") instanceof Map<?,?>, "this binder is only valid for Map<?, Iterable<?>>");
|
||||||
return AWSUtils.indexMultimapToFormValuesWithPrefix(request, "Filter", "Name", "Value", input);
|
return AWSUtils.indexMapOfIterableToFormValuesWithPrefix(request, "Filter", "Name", "Value", input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.jclouds.aws.ec2.binders.BindResourceIdsToIndexedFormParams;
|
||||||
import org.jclouds.aws.ec2.binders.BindTagFiltersToIndexedFormParams;
|
import org.jclouds.aws.ec2.binders.BindTagFiltersToIndexedFormParams;
|
||||||
import org.jclouds.aws.ec2.binders.BindTagsToIndexedFormParams;
|
import org.jclouds.aws.ec2.binders.BindTagsToIndexedFormParams;
|
||||||
import org.jclouds.aws.ec2.domain.Tag;
|
import org.jclouds.aws.ec2.domain.Tag;
|
||||||
import org.jclouds.aws.ec2.util.TagFilters;
|
import org.jclouds.aws.ec2.util.TagFilters.FilterName;
|
||||||
import org.jclouds.aws.ec2.xml.DescribeTagsResponseHandler;
|
import org.jclouds.aws.ec2.xml.DescribeTagsResponseHandler;
|
||||||
import org.jclouds.aws.filters.FormSigner;
|
import org.jclouds.aws.filters.FormSigner;
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
@ -46,7 +46,6 @@ import org.jclouds.rest.annotations.XMLResponseParser;
|
||||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||||
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,7 +79,7 @@ public interface TagAsyncClient {
|
||||||
@BinderParam(BindTagsToIndexedFormParams.class) Map<String, String> tags);
|
@BinderParam(BindTagsToIndexedFormParams.class) Map<String, String> tags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TagClient#describeTagsInRegion(String, Multimap)
|
* @see TagClient#describeTagsInRegion(String, Map)
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("/")
|
@Path("/")
|
||||||
|
@ -88,5 +87,5 @@ public interface TagAsyncClient {
|
||||||
@XMLResponseParser(DescribeTagsResponseHandler.class)
|
@XMLResponseParser(DescribeTagsResponseHandler.class)
|
||||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||||
ListenableFuture<? extends Set<Tag>> describeTagsInRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
|
ListenableFuture<? extends Set<Tag>> describeTagsInRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
|
||||||
@BinderParam(BindTagFiltersToIndexedFormParams.class) Multimap<TagFilters.FilterName, ?> filters);
|
@BinderParam(BindTagFiltersToIndexedFormParams.class) Map<FilterName, Iterable<?>> filters);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,12 +23,10 @@ import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.jclouds.aws.ec2.domain.Tag;
|
import org.jclouds.aws.ec2.domain.Tag;
|
||||||
import org.jclouds.aws.ec2.util.TagFilters;
|
import org.jclouds.aws.ec2.util.TagFilters.FilterName;
|
||||||
import org.jclouds.concurrent.Timeout;
|
import org.jclouds.concurrent.Timeout;
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides Tag services for EC2. For more information, refer to the Amazon EC2
|
* Provides Tag services for EC2. For more information, refer to the Amazon EC2
|
||||||
* Developer Guide.
|
* Developer Guide.
|
||||||
|
@ -46,7 +44,7 @@ public interface TagClient {
|
||||||
* IDs of the resources to tag.
|
* IDs of the resources to tag.
|
||||||
* @param tags
|
* @param tags
|
||||||
* The tags to create.
|
* The tags to create.
|
||||||
* @see #describeTagsInRegion(String, Multimap)
|
* @see #describeTagsInRegion(String, Map)
|
||||||
* @see #deleteTagsInRegion(String, Iterable, Map)
|
* @see #deleteTagsInRegion(String, Iterable, Map)
|
||||||
*
|
*
|
||||||
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateTags.html" />
|
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateTags.html" />
|
||||||
|
@ -63,7 +61,7 @@ public interface TagClient {
|
||||||
* @param tags
|
* @param tags
|
||||||
* The tags to delete.
|
* The tags to delete.
|
||||||
*
|
*
|
||||||
* @see #describeTagsInRegion(String, Multimap)
|
* @see #describeTagsInRegion(String, Map)
|
||||||
* @see #createTagsInRegion(String, Iterable, Map)
|
* @see #createTagsInRegion(String, Iterable, Map)
|
||||||
*
|
*
|
||||||
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DeleteTags.html" />
|
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DeleteTags.html" />
|
||||||
|
@ -82,5 +80,5 @@ public interface TagClient {
|
||||||
* @see #createTagsInRegion(String, Iterable, Map)
|
* @see #createTagsInRegion(String, Iterable, Map)
|
||||||
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeTags.html" />
|
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeTags.html" />
|
||||||
*/
|
*/
|
||||||
Set<Tag> describeTagsInRegion(@Nullable String region, Multimap<TagFilters.FilterName, ?> filters);
|
Set<Tag> describeTagsInRegion(@Nullable String region, Map<FilterName, Iterable<?>> filters);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,14 @@ package org.jclouds.aws.ec2.util;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.*;
|
import static com.google.common.base.Preconditions.*;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
import com.google.common.base.CaseFormat;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.ImmutableSetMultimap;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author grkvlt@apache.org
|
* @author grkvlt@apache.org
|
||||||
|
@ -89,52 +93,52 @@ public class TagFilters {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final ImmutableSetMultimap.Builder<FilterName, Object> map;
|
protected final Map<FilterName, Iterable<?>> map;
|
||||||
|
|
||||||
protected TagFilters() {
|
protected TagFilters() {
|
||||||
map = ImmutableSetMultimap.<FilterName, Object>builder();
|
map = Maps.<FilterName, Iterable<?>>newLinkedHashMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TagFilters filters() {
|
public static TagFilters filters() {
|
||||||
return new TagFilters();
|
return new TagFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Multimap<FilterName, Object> build() {
|
public Map<FilterName, Iterable<?>> build() {
|
||||||
return map.build();
|
return ImmutableMap.copyOf(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters resourceId(String resourceId) {
|
public TagFilters resourceId(String resourceId) {
|
||||||
map.put(FilterName.RESOURCE_ID, resourceId);
|
put(FilterName.RESOURCE_ID, resourceId);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters key(String key) {
|
public TagFilters key(String key) {
|
||||||
map.put(FilterName.KEY, key);
|
put(FilterName.KEY, key);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters keys(String...keys) {
|
public TagFilters keys(String...keys) {
|
||||||
map.putAll(FilterName.KEY, ImmutableSet.<String>copyOf(keys));
|
put(FilterName.KEY, ImmutableSet.<String>copyOf(keys));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters keys(Iterable<String> keys) {
|
public TagFilters keys(Iterable<String> keys) {
|
||||||
map.putAll(FilterName.KEY, ImmutableSet.<String>copyOf(keys));
|
putAll(FilterName.KEY, ImmutableSet.<String>copyOf(keys));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters value(String value) {
|
public TagFilters value(String value) {
|
||||||
map.put(FilterName.VALUE, value);
|
put(FilterName.VALUE, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters values(String...values) {
|
public TagFilters values(String...values) {
|
||||||
map.putAll(FilterName.VALUE, ImmutableSet.<String>copyOf(values));
|
putAll(FilterName.VALUE, ImmutableSet.<String>copyOf(values));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters values(Iterable<String> values) {
|
public TagFilters values(Iterable<String> values) {
|
||||||
map.putAll(FilterName.VALUE, ImmutableSet.<String>copyOf(values));
|
putAll(FilterName.VALUE, ImmutableSet.<String>copyOf(values));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,99 +191,125 @@ public class TagFilters {
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters anyKey() {
|
public TagFilters anyKey() {
|
||||||
return key("*");
|
putAll(FilterName.KEY, ImmutableSet.<String>of());
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters anyValue() {
|
public TagFilters anyValue() {
|
||||||
return value("*");
|
putAll(FilterName.VALUE, ImmutableSet.<String>of());
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters anyResourceId() {
|
public TagFilters anyResourceId() {
|
||||||
return resourceId("*");
|
putAll(FilterName.RESOURCE_TYPE, ImmutableSet.<String>of());
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters anyResourceType() {
|
public TagFilters anyResourceType() {
|
||||||
map.put(FilterName.RESOURCE_TYPE, "*");
|
putAll(FilterName.RESOURCE_TYPE, ImmutableSet.<ResourceType>of());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters resourceType(ResourceType resourceType) {
|
||||||
|
put(FilterName.RESOURCE_TYPE, resourceType);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters customerGateway() {
|
public TagFilters customerGateway() {
|
||||||
map.put(FilterName.RESOURCE_TYPE, ResourceType.CUSTOMER_GATEWAY);
|
put(FilterName.RESOURCE_TYPE, ResourceType.CUSTOMER_GATEWAY);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters dhcpOptions() {
|
public TagFilters dhcpOptions() {
|
||||||
map.put(FilterName.RESOURCE_TYPE, ResourceType.DHCP_OPTIONS);
|
put(FilterName.RESOURCE_TYPE, ResourceType.DHCP_OPTIONS);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters image() {
|
public TagFilters image() {
|
||||||
map.put(FilterName.RESOURCE_TYPE, ResourceType.IMAGE);
|
put(FilterName.RESOURCE_TYPE, ResourceType.IMAGE);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters instance() {
|
public TagFilters instance() {
|
||||||
map.put(FilterName.RESOURCE_TYPE, ResourceType.INSTANCE);
|
put(FilterName.RESOURCE_TYPE, ResourceType.INSTANCE);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters internetGateway() {
|
public TagFilters internetGateway() {
|
||||||
map.put(FilterName.RESOURCE_TYPE, ResourceType.INTERNET_GATEWAY);
|
put(FilterName.RESOURCE_TYPE, ResourceType.INTERNET_GATEWAY);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters networkAcl() {
|
public TagFilters networkAcl() {
|
||||||
map.put(FilterName.RESOURCE_TYPE, ResourceType.NETWORK_ACL);
|
put(FilterName.RESOURCE_TYPE, ResourceType.NETWORK_ACL);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters reservedInstance() {
|
public TagFilters reservedInstance() {
|
||||||
map.put(FilterName.RESOURCE_TYPE, ResourceType.RESERVED_INSTANCES);
|
put(FilterName.RESOURCE_TYPE, ResourceType.RESERVED_INSTANCES);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters routeTable() {
|
public TagFilters routeTable() {
|
||||||
map.put(FilterName.RESOURCE_TYPE, ResourceType.ROUTE_TABLE);
|
put(FilterName.RESOURCE_TYPE, ResourceType.ROUTE_TABLE);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters securityGroup() {
|
public TagFilters securityGroup() {
|
||||||
map.put(FilterName.RESOURCE_TYPE, ResourceType.SECURITY_GROUP);
|
put(FilterName.RESOURCE_TYPE, ResourceType.SECURITY_GROUP);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters snapshot() {
|
public TagFilters snapshot() {
|
||||||
map.put(FilterName.RESOURCE_TYPE, ResourceType.SNAPSHOT);
|
put(FilterName.RESOURCE_TYPE, ResourceType.SNAPSHOT);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters instancesRequest() {
|
public TagFilters instancesRequest() {
|
||||||
map.put(FilterName.RESOURCE_TYPE, ResourceType.SPOT_INSTANCES_REQUEST);
|
put(FilterName.RESOURCE_TYPE, ResourceType.SPOT_INSTANCES_REQUEST);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters subnet() {
|
public TagFilters subnet() {
|
||||||
map.put(FilterName.RESOURCE_TYPE, ResourceType.SUBNET);
|
put(FilterName.RESOURCE_TYPE, ResourceType.SUBNET);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters volume() {
|
public TagFilters volume() {
|
||||||
map.put(FilterName.RESOURCE_TYPE, ResourceType.VOLUME);
|
put(FilterName.RESOURCE_TYPE, ResourceType.VOLUME);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters vpc() {
|
public TagFilters vpc() {
|
||||||
map.put(FilterName.RESOURCE_TYPE, ResourceType.VPC);
|
put(FilterName.RESOURCE_TYPE, ResourceType.VPC);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters vpnConnection() {
|
public TagFilters vpnConnection() {
|
||||||
map.put(FilterName.RESOURCE_TYPE, ResourceType.VPN_CONNECTION);
|
put(FilterName.RESOURCE_TYPE, ResourceType.VPN_CONNECTION);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilters vpnGateway() {
|
public TagFilters vpnGateway() {
|
||||||
map.put(FilterName.RESOURCE_TYPE, ResourceType.VPN_GATEWAY);
|
put(FilterName.RESOURCE_TYPE, ResourceType.VPN_GATEWAY);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void put(FilterName key, Object value) {
|
||||||
|
putAll(key, Sets.newHashSet(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void putAll(FilterName key, Iterable<?> values) {
|
||||||
|
if (values == null || Iterables.isEmpty(values)) {
|
||||||
|
// If we add an empty or null set of values, replace the value in the map entirely
|
||||||
|
map.put(key, ImmutableSet.of());
|
||||||
|
} else {
|
||||||
|
// Add the values, to a new set if required
|
||||||
|
if (!map.containsKey(key)) {
|
||||||
|
map.put(key, Sets.newHashSet());
|
||||||
|
}
|
||||||
|
Iterable<?> entries = map.get(key);
|
||||||
|
map.put(key, Iterables.concat(entries, values));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,8 @@ import org.jclouds.aws.ec2.util.TagFilters.ResourceType;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSetMultimap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
|
|
||||||
|
@ -45,31 +46,31 @@ public class BindTagFiltersToIndexedFormParamsTest {
|
||||||
Injector injector = Guice.createInjector();
|
Injector injector = Guice.createInjector();
|
||||||
BindTagFiltersToIndexedFormParams binder = injector.getInstance(BindTagFiltersToIndexedFormParams.class);
|
BindTagFiltersToIndexedFormParams binder = injector.getInstance(BindTagFiltersToIndexedFormParams.class);
|
||||||
|
|
||||||
public void testResourceTypeWithValues() {
|
public void testMultipleResourceTypes() {
|
||||||
HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build();
|
HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build();
|
||||||
request = binder.bindToRequest(request, ImmutableSetMultimap.<FilterName, ResourceType>builder().put(FilterName.RESOURCE_TYPE, ResourceType.VPN_GATEWAY).put(FilterName.RESOURCE_TYPE, ResourceType.INTERNET_GATEWAY).build());
|
request = binder.bindToRequest(request, ImmutableMap.<FilterName, Iterable<ResourceType>>builder().put(FilterName.RESOURCE_TYPE, ImmutableSet.<ResourceType>of(ResourceType.VPN_GATEWAY, ResourceType.INTERNET_GATEWAY)).build());
|
||||||
assertEquals(request.getPayload().getRawContent(), "Filter.1.Name=resource-type&Filter.1.Value.1=vpn-gateway&Filter.1.Value.2=internet-gateway");
|
assertEquals(request.getPayload().getRawContent(), "Filter.1.Name=resource-type&Filter.1.Value.1=vpn-gateway&Filter.1.Value.2=internet-gateway");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultipleKeys() {
|
public void testMultipleKeys() {
|
||||||
HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build();
|
HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build();
|
||||||
request = binder.bindToRequest(request, ImmutableSetMultimap.<FilterName, String>builder().put(FilterName.KEY, "one").put(FilterName.KEY, "two").build());
|
request = binder.bindToRequest(request, ImmutableMap.<FilterName, Iterable<String>>builder().put(FilterName.KEY, ImmutableSet.<String>of("one", "two")).build());
|
||||||
assertEquals(request.getPayload().getRawContent(), "Filter.1.Name=key&Filter.1.Value.1=one&Filter.1.Value.2=two");
|
assertEquals(request.getPayload().getRawContent(), "Filter.1.Name=key&Filter.1.Value.1=one&Filter.1.Value.2=two");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testkeyWithValue() {
|
public void testkeyWithValue() {
|
||||||
HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build();
|
HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build();
|
||||||
request = binder.bindToRequest(request, ImmutableSetMultimap.<FilterName, String>builder().put(FilterName.KEY, "one").put(FilterName.VALUE, "alpha").build());
|
request = binder.bindToRequest(request, ImmutableMap.<FilterName, Iterable<String>>builder().put(FilterName.KEY, ImmutableSet.<String>of("one")).put(FilterName.VALUE, ImmutableSet.<String>of("alpha")).build());
|
||||||
assertEquals(request.getPayload().getRawContent(), "Filter.1.Name=key&Filter.1.Value.1=one&Filter.2.Name=value&Filter.2.Value.1=alpha");
|
assertEquals(request.getPayload().getRawContent(), "Filter.1.Name=key&Filter.1.Value.1=one&Filter.2.Name=value&Filter.2.Value.1=alpha");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAnyKey() {
|
public void testAnyKey() {
|
||||||
HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build();
|
HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build();
|
||||||
request = binder.bindToRequest(request, ImmutableSetMultimap.<FilterName, String>builder().put(FilterName.KEY, "*").build());
|
request = binder.bindToRequest(request, ImmutableMap.<FilterName, Iterable<String>>builder().put(FilterName.KEY, ImmutableSet.<String>of()).build());
|
||||||
assertEquals(request.getPayload().getRawContent(), "Filter.1.Name=key&Filter.1.Value.1=%2A");
|
assertEquals(request.getPayload().getRawContent(), "Filter.1.Name=key");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testResourceTypeWithValuesBuilder() {
|
public void testMultipleResourceTypesBuilder() {
|
||||||
HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build();
|
HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build();
|
||||||
request = binder.bindToRequest(request, TagFilters.filters().vpnGateway().internetGateway().build());
|
request = binder.bindToRequest(request, TagFilters.filters().vpnGateway().internetGateway().build());
|
||||||
assertEquals(request.getPayload().getRawContent(), "Filter.1.Name=resource-type&Filter.1.Value.1=vpn-gateway&Filter.1.Value.2=internet-gateway");
|
assertEquals(request.getPayload().getRawContent(), "Filter.1.Name=resource-type&Filter.1.Value.1=vpn-gateway&Filter.1.Value.2=internet-gateway");
|
||||||
|
@ -81,7 +82,7 @@ public class BindTagFiltersToIndexedFormParamsTest {
|
||||||
assertEquals(request.getPayload().getRawContent(), "Filter.1.Name=key&Filter.1.Value.1=one&Filter.1.Value.2=two");
|
assertEquals(request.getPayload().getRawContent(), "Filter.1.Name=key&Filter.1.Value.1=one&Filter.1.Value.2=two");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testkeyWithValueBuilder() {
|
public void testKeyWithValueBuilder() {
|
||||||
HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build();
|
HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build();
|
||||||
request = binder.bindToRequest(request, TagFilters.filters().keyValuePair("one", "alpha").build());
|
request = binder.bindToRequest(request, TagFilters.filters().keyValuePair("one", "alpha").build());
|
||||||
assertEquals(request.getPayload().getRawContent(), "Filter.1.Name=key&Filter.1.Value.1=one&Filter.2.Name=value&Filter.2.Value.1=alpha");
|
assertEquals(request.getPayload().getRawContent(), "Filter.1.Name=key&Filter.1.Value.1=one&Filter.2.Name=value&Filter.2.Value.1=alpha");
|
||||||
|
@ -90,7 +91,7 @@ public class BindTagFiltersToIndexedFormParamsTest {
|
||||||
public void testAnyKeyBuilder() {
|
public void testAnyKeyBuilder() {
|
||||||
HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build();
|
HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build();
|
||||||
request = binder.bindToRequest(request, TagFilters.filters().anyKey().build());
|
request = binder.bindToRequest(request, TagFilters.filters().anyKey().build());
|
||||||
assertEquals(request.getPayload().getRawContent(), "Filter.1.Name=key&Filter.1.Value.1=%2A");
|
assertEquals(request.getPayload().getRawContent(), "Filter.1.Name=key");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
|
|
|
@ -22,7 +22,7 @@ import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jclouds.aws.ec2.util.TagFilters.FilterName;
|
import org.jclouds.aws.ec2.util.TagFilters;
|
||||||
import org.jclouds.aws.ec2.xml.DescribeTagsResponseHandler;
|
import org.jclouds.aws.ec2.xml.DescribeTagsResponseHandler;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
@ -34,8 +34,6 @@ import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,8 +77,8 @@ public class TagAsyncClientTest extends BaseAWSEC2AsyncClientTest<TagAsyncClient
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDescribeTags() throws SecurityException, NoSuchMethodException, IOException {
|
public void testDescribeTags() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = TagAsyncClient.class.getMethod("describeTagsInRegion", String.class, Multimap.class);
|
Method method = TagAsyncClient.class.getMethod("describeTagsInRegion", String.class, Map.class);
|
||||||
HttpRequest request = processor.createRequest(method, null, ImmutableMultimap.<FilterName, Object>of());
|
HttpRequest request = processor.createRequest(method, null, TagFilters.filters().build());
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||||
|
@ -95,8 +93,8 @@ public class TagAsyncClientTest extends BaseAWSEC2AsyncClientTest<TagAsyncClient
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDescribeTagsArgs() throws SecurityException, NoSuchMethodException, IOException {
|
public void testDescribeTagsArgs() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = TagAsyncClient.class.getMethod("describeTagsInRegion", String.class, Multimap.class);
|
Method method = TagAsyncClient.class.getMethod("describeTagsInRegion", String.class, Map.class);
|
||||||
HttpRequest request = processor.createRequest(method, null, ImmutableMultimap.builder().put(FilterName.KEY, "one").put(FilterName.KEY, "two").build());
|
HttpRequest request = processor.createRequest(method, null, TagFilters.filters().key("one").key("two").build());
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.jclouds.aws.ec2.AWSEC2AsyncClient;
|
||||||
import org.jclouds.aws.ec2.AWSEC2Client;
|
import org.jclouds.aws.ec2.AWSEC2Client;
|
||||||
import org.jclouds.aws.ec2.domain.AWSRunningInstance;
|
import org.jclouds.aws.ec2.domain.AWSRunningInstance;
|
||||||
import org.jclouds.aws.ec2.domain.Tag;
|
import org.jclouds.aws.ec2.domain.Tag;
|
||||||
import org.jclouds.aws.ec2.util.TagFilters.FilterName;
|
import org.jclouds.aws.ec2.util.TagFilters;
|
||||||
import org.jclouds.aws.ec2.util.TagFilters.ResourceType;
|
import org.jclouds.aws.ec2.util.TagFilters.ResourceType;
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||||
|
@ -44,7 +44,6 @@ import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
|
@ -126,12 +125,7 @@ public class TagClientLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkTag(String resourceId, ResourceType resourceType, String key, String value) {
|
protected void checkTag(String resourceId, ResourceType resourceType, String key, String value) {
|
||||||
Set<Tag> results = client.describeTagsInRegion(null, ImmutableMultimap.<FilterName,Object>builder()
|
Set<Tag> results = client.describeTagsInRegion(null, TagFilters.filters().resourceId(resourceId).resourceType(resourceType).keyValuePair(key, value).build());
|
||||||
.put(FilterName.RESOURCE_ID, resourceId)
|
|
||||||
.put(FilterName.RESOURCE_TYPE, resourceType)
|
|
||||||
.put(FilterName.KEY, key)
|
|
||||||
.put(FilterName.VALUE, value)
|
|
||||||
.build());
|
|
||||||
assertNotNull(results);
|
assertNotNull(results);
|
||||||
assertEquals(results.size(), 1);
|
assertEquals(results.size(), 1);
|
||||||
Tag tag = Iterables.getOnlyElement(results);
|
Tag tag = Iterables.getOnlyElement(results);
|
||||||
|
|
Loading…
Reference in New Issue