mirror of https://github.com/apache/jclouds.git
612: Changed Tag filters to use Multimap and Collection to Iterable
This commit is contained in:
parent
e30f0f626e
commit
d4f7140071
|
@ -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.Multimap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Needed to sign and verify requests and responses.
|
* Needed to sign and verify requests and responses.
|
||||||
|
@ -68,6 +69,7 @@ public class AWSUtils {
|
||||||
private final Provider<ErrorHandler> errorHandlerProvider;
|
private final Provider<ErrorHandler> errorHandlerProvider;
|
||||||
private final String requestId;
|
private final String requestId;
|
||||||
private final String requestToken;
|
private final String requestToken;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
|
@ -140,7 +142,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 + "]"));
|
||||||
}
|
}
|
||||||
|
@ -149,15 +151,35 @@ public class AWSUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <R extends HttpRequest> R indexMapToFormValuesWithPrefix(R request, String prefix, String keySuffix, String valueSuffix, Object input) {
|
public static <R extends HttpRequest> R indexMapToFormValuesWithPrefix(R request, String prefix, String keySuffix, String valueSuffix, Object input) {
|
||||||
checkArgument(checkNotNull(input, "input") instanceof Map<?,?>, "this binder is only valid for Map<?,?>: "
|
checkArgument(checkNotNull(input, "input") instanceof Map<?, ?>, "this binder is only valid for Map<?,?>: " + input.getClass());
|
||||||
+ input.getClass());
|
Map<?, ?> map = (Map<?, ?>) input;
|
||||||
Map<?,?> map = (Map<?,?>) input;
|
|
||||||
Builder<String, String> builder = ImmutableMultimap.<String, String> builder();
|
Builder<String, String> builder = ImmutableMultimap.<String, String> builder();
|
||||||
int i = 1;
|
int i = 1;
|
||||||
for (Map.Entry<?,?> e : map.entrySet()) {
|
for (Map.Entry<?, ?> e : map.entrySet()) {
|
||||||
builder.put(prefix + "." + i + "." + keySuffix, checkNotNull(e.getKey().toString(), keySuffix.toLowerCase() + "s[" + i + "]"));
|
builder.put(prefix + "." + i + "." + keySuffix, checkNotNull(e.getKey().toString(), keySuffix.toLowerCase() + "s[" + i + "]"));
|
||||||
if (e.getValue() != null) {
|
if (e.getValue() != null) {
|
||||||
builder.put(prefix + "." + i + "." + valueSuffix, e.getValue().toString());
|
builder.put(prefix + "." + i + "." + valueSuffix, e.getValue().toString());
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
ImmutableMultimap<String, String> forms = builder.build();
|
||||||
|
return forms.size() == 0 ? request : ModifyRequest.putFormParams(request, forms);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <R extends HttpRequest> R indexMultimapToFormValuesWithPrefix(R request, String prefix, String keySuffix, String valueSuffix, Object input) {
|
||||||
|
checkArgument(checkNotNull(input, "input") instanceof Multimap<?, ?>, "this binder is only valid for Multimap<?,?>: " + input.getClass());
|
||||||
|
Multimap<Object, Object> map = (Multimap<Object, 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 (!map.get(k).isEmpty()) {
|
||||||
|
int j = 1;
|
||||||
|
for (Object v : map.get(k)) {
|
||||||
|
builder.put(prefix + "." + i + "." + valueSuffix + "." + j, v.toString());
|
||||||
|
j++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,27 +20,19 @@ package org.jclouds.aws.ec2.binders;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.*;
|
import static com.google.common.base.Preconditions.*;
|
||||||
|
|
||||||
import org.jclouds.aws.ec2.domain.TagFilter;
|
import org.jclouds.aws.util.AWSUtils;
|
||||||
import org.jclouds.aws.ec2.util.TagFilters;
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.utils.ModifyRequest;
|
|
||||||
import org.jclouds.rest.Binder;
|
import org.jclouds.rest.Binder;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.common.collect.ImmutableMultimap.Builder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author grkvlt@apache.org
|
* @author grkvlt@apache.org
|
||||||
*/
|
*/
|
||||||
public class BindTagFiltersToIndexedFormParams implements Binder {
|
public class BindTagFiltersToIndexedFormParams implements Binder {
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@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 Iterable, "this binder is only valid for Iterable<TagFilter>");
|
checkArgument(checkNotNull(input, "input") instanceof Multimap, "this binder is only valid for Multimap<Filtername, ?>");
|
||||||
Builder<String, String> headers = ImmutableMultimap.<String, String> builder();
|
return AWSUtils.indexMultimapToFormValuesWithPrefix(request, "Filter", "Name", "Value", input);
|
||||||
int index = 1;
|
|
||||||
for (TagFilter filter : (Iterable<TagFilter>) input)
|
|
||||||
headers.putAll(TagFilters.buildFormParametersForIndex(index++, filter));
|
|
||||||
return ModifyRequest.putFormParams(request, headers.build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,12 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.ec2.domain;
|
package org.jclouds.aws.ec2.domain;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.*;
|
||||||
|
|
||||||
|
import org.jclouds.aws.ec2.util.TagFilters.ResourceType;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.collect.ComparisonChain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see <a href= "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-ItemType-TagSetItemType.html" />
|
* @see <a href= "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-ItemType-TagSetItemType.html" />
|
||||||
|
@ -31,7 +36,7 @@ public class Tag implements Comparable<Tag> {
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
private String resourceId;
|
private String resourceId;
|
||||||
private String resourceType;
|
private ResourceType resourceType;
|
||||||
private String key;
|
private String key;
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
|
@ -47,7 +52,7 @@ public class Tag implements Comparable<Tag> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder resourceType(String resourceType) {
|
public Builder resourceType(ResourceType resourceType) {
|
||||||
this.resourceType = resourceType;
|
this.resourceType = resourceType;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -68,11 +73,11 @@ public class Tag implements Comparable<Tag> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String resourceId;
|
private final String resourceId;
|
||||||
private final String resourceType;
|
private final ResourceType resourceType;
|
||||||
private final String key;
|
private final String key;
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
public Tag(String resourceId, String resourceType, String key, String value) {
|
public Tag(String resourceId, ResourceType resourceType, String key, String value) {
|
||||||
this.resourceId = checkNotNull(resourceId, "resourceId");
|
this.resourceId = checkNotNull(resourceId, "resourceId");
|
||||||
this.resourceType = checkNotNull(resourceType, "resourceType");
|
this.resourceType = checkNotNull(resourceType, "resourceType");
|
||||||
this.key = checkNotNull(key, "key");
|
this.key = checkNotNull(key, "key");
|
||||||
|
@ -83,7 +88,7 @@ public class Tag implements Comparable<Tag> {
|
||||||
return resourceId;
|
return resourceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getResourceType() {
|
public ResourceType getResourceType() {
|
||||||
return resourceType;
|
return resourceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,18 +102,17 @@ public class Tag implements Comparable<Tag> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Tag t) {
|
public int compareTo(Tag t) {
|
||||||
return key.compareTo(t.key);
|
return ComparisonChain.start()
|
||||||
|
.compare(resourceId, t.resourceId)
|
||||||
|
.compare(resourceType, t.resourceType)
|
||||||
|
.compare(key, t.key)
|
||||||
|
.compare(value, t.value)
|
||||||
|
.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
return Objects.hashCode(resourceId, resourceType, key, value);
|
||||||
int result = 1;
|
|
||||||
result = prime * result + ((resourceId == null) ? 0 : resourceId.hashCode());
|
|
||||||
result = prime * result + ((resourceType == null) ? 0 : resourceType.hashCode());
|
|
||||||
result = prime * result + ((key == null) ? 0 : key.hashCode());
|
|
||||||
result = prime * result + ((value == null) ? 0 : value.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,162 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.domain;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.*;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* tag filter.
|
|
||||||
*
|
|
||||||
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeTags.html" />
|
|
||||||
* @author grkvlt@apache.org
|
|
||||||
*/
|
|
||||||
public class TagFilter implements Comparable<TagFilter> {
|
|
||||||
public static enum FilterName {
|
|
||||||
KEY,
|
|
||||||
RESOURCE_ID,
|
|
||||||
RESOURCE_TYPE,
|
|
||||||
VALUE;
|
|
||||||
|
|
||||||
public String value() {
|
|
||||||
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return value();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static FilterName fromValue(String name) {
|
|
||||||
try {
|
|
||||||
return valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(name, "name")));
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static enum ResourceType {
|
|
||||||
CUSTOMER_GATEWAY,
|
|
||||||
DHCP_OPTIONS,
|
|
||||||
IMAGE,
|
|
||||||
INSTANCE,
|
|
||||||
INTERNET_GATEWAY,
|
|
||||||
NETWORK_ACL,
|
|
||||||
RESERVED_INSTANCES,
|
|
||||||
ROUTE_TABLE,
|
|
||||||
SECURITY_GROUP,
|
|
||||||
SNAPSHOT,
|
|
||||||
SPOT_INSTANCES_REQUEST,
|
|
||||||
SUBNET,
|
|
||||||
VOLUME,
|
|
||||||
VPC,
|
|
||||||
VPN_CONNECTION,
|
|
||||||
VPN_GATEWAY;
|
|
||||||
|
|
||||||
public String value() {
|
|
||||||
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return value();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ResourceType fromValue(String name) {
|
|
||||||
try {
|
|
||||||
return valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(name, "name")));
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final FilterName name;
|
|
||||||
private final Collection<String> values;
|
|
||||||
|
|
||||||
public TagFilter(FilterName name, Collection<String> values) {
|
|
||||||
this.name = checkNotNull(name, "name");
|
|
||||||
this.values = checkNotNull(values, "values");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(TagFilter o) {
|
|
||||||
return name.compareTo(o.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Name of the filter type.
|
|
||||||
*/
|
|
||||||
public FilterName getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Values to filter on.
|
|
||||||
*/
|
|
||||||
public Collection<String> getValues() {
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
final int prime = 31;
|
|
||||||
int result = 1;
|
|
||||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
|
||||||
result = prime * result + ((values == null) ? 0 : values.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj)
|
|
||||||
return true;
|
|
||||||
if (obj == null)
|
|
||||||
return false;
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
TagFilter other = (TagFilter) obj;
|
|
||||||
if (name == null) {
|
|
||||||
if (other.name != null)
|
|
||||||
return false;
|
|
||||||
} else if (!name.equals(other.name))
|
|
||||||
return false;
|
|
||||||
if (name == null) {
|
|
||||||
if (other.name != null)
|
|
||||||
return false;
|
|
||||||
} else if (!name.equals(other.name))
|
|
||||||
return false;
|
|
||||||
if (values == null) {
|
|
||||||
if (other.values != null)
|
|
||||||
return false;
|
|
||||||
} else if (!values.equals(other.values))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "[name=" + name + ", values=" + values + "]";
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -20,8 +20,6 @@ package org.jclouds.aws.ec2.services;
|
||||||
|
|
||||||
import static org.jclouds.aws.reference.FormParameters.*;
|
import static org.jclouds.aws.reference.FormParameters.*;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -33,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.domain.TagFilter;
|
import org.jclouds.aws.ec2.util.TagFilters;
|
||||||
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;
|
||||||
|
@ -48,6 +46,7 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,28 +59,28 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
@VirtualHost
|
@VirtualHost
|
||||||
public interface TagAsyncClient {
|
public interface TagAsyncClient {
|
||||||
/**
|
/**
|
||||||
* @see TagClient#createTagsInRegion(String, Collection, Map)
|
* @see TagClient#createTagsInRegion(String, Iterable, Map)
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("/")
|
@Path("/")
|
||||||
@FormParams(keys = ACTION, values = "CreateTags")
|
@FormParams(keys = ACTION, values = "CreateTags")
|
||||||
ListenableFuture<Void> createTagsInRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
|
ListenableFuture<Void> createTagsInRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
|
||||||
@BinderParam(BindResourceIdsToIndexedFormParams.class) Collection<String> resourceIds,
|
@BinderParam(BindResourceIdsToIndexedFormParams.class) Iterable<String> resourceIds,
|
||||||
@BinderParam(BindTagsToIndexedFormParams.class) Map<String, String> tags);
|
@BinderParam(BindTagsToIndexedFormParams.class) Map<String, String> tags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TagClient#deleteTagsInRegion(String, Collection, Map)
|
* @see TagClient#deleteTagsInRegion(String, Iterable, Map)
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("/")
|
@Path("/")
|
||||||
@FormParams(keys = ACTION, values = "DeleteTags")
|
@FormParams(keys = ACTION, values = "DeleteTags")
|
||||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||||
ListenableFuture<Void> deleteTagsInRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
|
ListenableFuture<Void> deleteTagsInRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
|
||||||
@BinderParam(BindResourceIdsToIndexedFormParams.class) Collection<String> resourceIds,
|
@BinderParam(BindResourceIdsToIndexedFormParams.class) Iterable<String> resourceIds,
|
||||||
@BinderParam(BindTagsToIndexedFormParams.class) Map<String, String> tags);
|
@BinderParam(BindTagsToIndexedFormParams.class) Map<String, String> tags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TagClient#describeTagsInRegion(String, Collection)
|
* @see TagClient#describeTagsInRegion(String, Multimap)
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("/")
|
@Path("/")
|
||||||
|
@ -89,5 +88,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) Collection<TagFilter> filters);
|
@BinderParam(BindTagFiltersToIndexedFormParams.class) Multimap<TagFilters.FilterName, ?> filters);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,16 +18,17 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.ec2.services;
|
package org.jclouds.aws.ec2.services;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
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.domain.TagFilter;
|
import org.jclouds.aws.ec2.util.TagFilters;
|
||||||
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.
|
||||||
|
@ -45,12 +46,12 @@ 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, Collection)
|
* @see #describeTagsInRegion(String, Multimap)
|
||||||
* @see #deleteTagsInRegion(String, Collection, 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" />
|
||||||
*/
|
*/
|
||||||
void createTagsInRegion(@Nullable String region, Collection<String> resourceIds, Map<String, String> tags);
|
void createTagsInRegion(@Nullable String region, Iterable<String> resourceIds, Map<String, String> tags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes tags.
|
* Deletes tags.
|
||||||
|
@ -62,12 +63,12 @@ public interface TagClient {
|
||||||
* @param tags
|
* @param tags
|
||||||
* The tags to delete.
|
* The tags to delete.
|
||||||
*
|
*
|
||||||
* @see #describeTagsInRegion(String, Collection)
|
* @see #describeTagsInRegion(String, Multimap)
|
||||||
* @see #createTagsInRegion(String, Collection, 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" />
|
||||||
*/
|
*/
|
||||||
void deleteTagsInRegion(@Nullable String region, Collection<String> resourceIds, Map<String, String> tags);
|
void deleteTagsInRegion(@Nullable String region, Iterable<String> resourceIds, Map<String, String> tags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns filtered information about tags.
|
* Returns filtered information about tags.
|
||||||
|
@ -77,9 +78,9 @@ public interface TagClient {
|
||||||
* @param filters
|
* @param filters
|
||||||
* A collection of filters to apply before selecting the tags.
|
* A collection of filters to apply before selecting the tags.
|
||||||
*
|
*
|
||||||
* @see #deleteTagsInRegion(String, Collection, Map)
|
* @see #deleteTagsInRegion(String, Iterable, Map)
|
||||||
* @see #createTagsInRegion(String, Collection, 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, Collection<TagFilter> filters);
|
Set<Tag> describeTagsInRegion(@Nullable String region, Multimap<TagFilters.FilterName, ?> filters);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,163 +18,268 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.ec2.util;
|
package org.jclouds.aws.ec2.util;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import static com.google.common.base.Preconditions.*;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.jclouds.aws.ec2.domain.TagFilter;
|
import com.google.common.base.CaseFormat;
|
||||||
import org.jclouds.aws.ec2.domain.TagFilter.FilterName;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import org.jclouds.aws.ec2.domain.TagFilter.ResourceType;
|
import com.google.common.collect.ImmutableSetMultimap;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.common.collect.Multimaps;
|
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author grkvlt@apache.org
|
* @author grkvlt@apache.org
|
||||||
*/
|
*/
|
||||||
public class TagFilters {
|
public class TagFilters {
|
||||||
protected final FilterName name;
|
public static enum FilterName {
|
||||||
protected final Collection<String> values;
|
KEY,
|
||||||
|
RESOURCE_ID,
|
||||||
|
RESOURCE_TYPE,
|
||||||
|
VALUE;
|
||||||
|
|
||||||
protected TagFilters(FilterName name, Collection<String> values) {
|
public String value() {
|
||||||
this.name = name;
|
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name());
|
||||||
this.values = values != null ? values : Sets.<String>newHashSet();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Multimap<String, String> buildFormParametersForIndex(int index, TagFilter filter) {
|
|
||||||
Map<String, String> headers = Maps.newLinkedHashMap();
|
|
||||||
headers.put(String.format("Filter.%d.Name", index), filter.getName().value());
|
|
||||||
int i = 0;
|
|
||||||
for (String value : filter.getValues()) {
|
|
||||||
headers.put(String.format("Filter.%d.Value.%d", index, ++i), value);
|
|
||||||
}
|
|
||||||
return Multimaps.forMap(headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static StringTagFilter key() {
|
|
||||||
return new StringTagFilter(FilterName.KEY);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static StringTagFilter resourceId() {
|
|
||||||
return new StringTagFilter(FilterName.RESOURCE_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ResourceTypeTagFilter resourceType() {
|
|
||||||
return new ResourceTypeTagFilter();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static NamedTagFilter value() {
|
|
||||||
return new StringTagFilter(FilterName.VALUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class NamedTagFilter extends TagFilters {
|
|
||||||
public NamedTagFilter(FilterName name) {
|
|
||||||
super(name, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagFilter filter() {
|
@Override
|
||||||
return new TagFilter(name, values);
|
public String toString() {
|
||||||
|
return value();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FilterName fromValue(String name) {
|
||||||
|
try {
|
||||||
|
return valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(name, "name")));
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class StringTagFilter extends NamedTagFilter {
|
public static enum ResourceType {
|
||||||
public StringTagFilter(FilterName name) {
|
CUSTOMER_GATEWAY,
|
||||||
super(name);
|
DHCP_OPTIONS,
|
||||||
|
IMAGE,
|
||||||
|
INSTANCE,
|
||||||
|
INTERNET_GATEWAY,
|
||||||
|
NETWORK_ACL,
|
||||||
|
RESERVED_INSTANCES,
|
||||||
|
ROUTE_TABLE,
|
||||||
|
SECURITY_GROUP,
|
||||||
|
SNAPSHOT,
|
||||||
|
SPOT_INSTANCES_REQUEST,
|
||||||
|
SUBNET,
|
||||||
|
VOLUME,
|
||||||
|
VPC,
|
||||||
|
VPN_CONNECTION,
|
||||||
|
VPN_GATEWAY;
|
||||||
|
|
||||||
|
public String value() {
|
||||||
|
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name());
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringTagFilter exact(String value) {
|
@Override
|
||||||
return value(value);
|
public String toString() {
|
||||||
|
return value();
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringTagFilter contains(String value) {
|
public static ResourceType fromValue(String name) {
|
||||||
return value(String.format("*%s*", value));
|
try {
|
||||||
}
|
return valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(name, "name")));
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
public StringTagFilter value(String value) {
|
return null;
|
||||||
this.values.add(value);
|
}
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StringTagFilter values(String... values) {
|
|
||||||
this.values.addAll(Arrays.asList(values));
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ResourceTypeTagFilter extends NamedTagFilter {
|
protected final ImmutableSetMultimap.Builder<FilterName, Object> map;
|
||||||
public ResourceTypeTagFilter() {
|
|
||||||
super(FilterName.RESOURCE_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResourceTypeTagFilter resourceType(ResourceType resourceType) {
|
protected TagFilters() {
|
||||||
values.add(resourceType.value());
|
map = ImmutableSetMultimap.<FilterName, Object>builder();
|
||||||
return this;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public ResourceTypeTagFilter customerGateway() {
|
public static TagFilters filters() {
|
||||||
return resourceType(ResourceType.CUSTOMER_GATEWAY);
|
return new TagFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceTypeTagFilter dhcpOptions() {
|
public Multimap<FilterName, Object> build() {
|
||||||
return resourceType(ResourceType.DHCP_OPTIONS);
|
return map.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceTypeTagFilter image() {
|
public TagFilters resourceId(String resourceId) {
|
||||||
return resourceType(ResourceType.IMAGE);
|
map.put(FilterName.RESOURCE_ID, resourceId);
|
||||||
}
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public ResourceTypeTagFilter instance() {
|
public TagFilters key(String key) {
|
||||||
return resourceType(ResourceType.INSTANCE);
|
map.put(FilterName.KEY, key);
|
||||||
}
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public ResourceTypeTagFilter internetGateway() {
|
public TagFilters keys(String...keys) {
|
||||||
return resourceType(ResourceType.INTERNET_GATEWAY);
|
map.putAll(FilterName.KEY, ImmutableSet.<String>copyOf(keys));
|
||||||
}
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public ResourceTypeTagFilter networkAcl() {
|
public TagFilters keys(Iterable<String> keys) {
|
||||||
return resourceType(ResourceType.NETWORK_ACL);
|
map.putAll(FilterName.KEY, ImmutableSet.<String>copyOf(keys));
|
||||||
}
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public ResourceTypeTagFilter reservedInstance() {
|
public TagFilters value(String value) {
|
||||||
return resourceType(ResourceType.RESERVED_INSTANCES);
|
map.put(FilterName.VALUE, value);
|
||||||
}
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public ResourceTypeTagFilter routeTable() {
|
public TagFilters values(String...values) {
|
||||||
return resourceType(ResourceType.ROUTE_TABLE);
|
map.putAll(FilterName.VALUE, ImmutableSet.<String>copyOf(values));
|
||||||
}
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public ResourceTypeTagFilter securityGroup() {
|
public TagFilters values(Iterable<String> values) {
|
||||||
return resourceType(ResourceType.SECURITY_GROUP);
|
map.putAll(FilterName.VALUE, ImmutableSet.<String>copyOf(values));
|
||||||
}
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public ResourceTypeTagFilter snapshot() {
|
public TagFilters keyContains(String key) {
|
||||||
return resourceType(ResourceType.SNAPSHOT);
|
return key(String.format("*%s*", key));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceTypeTagFilter instancesRequest() {
|
public TagFilters valueContains(String value) {
|
||||||
return resourceType(ResourceType.SPOT_INSTANCES_REQUEST);
|
return value(String.format("*%s*", value));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceTypeTagFilter subnet() {
|
public TagFilters resourceIdContains(String value) {
|
||||||
return resourceType(ResourceType.SUBNET);
|
return resourceId(String.format("*%s*", value));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceTypeTagFilter volume() {
|
public TagFilters keyStartsWith(String key) {
|
||||||
return resourceType(ResourceType.VOLUME);
|
return key(String.format("%s*", key));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceTypeTagFilter vpc() {
|
public TagFilters valueStartsWith(String value) {
|
||||||
return resourceType(ResourceType.VPC);
|
return value(String.format("%s*", value));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceTypeTagFilter vpnConnection() {
|
public TagFilters resourceIdStartsWith(String value) {
|
||||||
return resourceType(ResourceType.VPN_CONNECTION);
|
return resourceId(String.format("%s*", value));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceTypeTagFilter vpnGateway() {
|
public TagFilters keyEndsWith(String key) {
|
||||||
return resourceType(ResourceType.VPN_GATEWAY);
|
return key(String.format("*%s", key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TagFilters valueEndsWith(String value) {
|
||||||
|
return value(String.format("*%s", value));
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters resourceIdEndsWith(String value) {
|
||||||
|
return resourceId(String.format("*%s", value));
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters keyValuePair(String key, String value) {
|
||||||
|
return key(key).value(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters keyValueSet(String key, Iterable<String> values) {
|
||||||
|
return key(key).values(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters keyValueSet(String key, String...values) {
|
||||||
|
return key(key).values(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters anyKey() {
|
||||||
|
return key("*");
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters anyValue() {
|
||||||
|
return value("*");
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters anyResourceId() {
|
||||||
|
return resourceId("*");
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters anyResourceType() {
|
||||||
|
map.put(FilterName.RESOURCE_TYPE, "*");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters customerGateway() {
|
||||||
|
map.put(FilterName.RESOURCE_TYPE, ResourceType.CUSTOMER_GATEWAY);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters dhcpOptions() {
|
||||||
|
map.put(FilterName.RESOURCE_TYPE, ResourceType.DHCP_OPTIONS);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters image() {
|
||||||
|
map.put(FilterName.RESOURCE_TYPE, ResourceType.IMAGE);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters instance() {
|
||||||
|
map.put(FilterName.RESOURCE_TYPE, ResourceType.INSTANCE);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters internetGateway() {
|
||||||
|
map.put(FilterName.RESOURCE_TYPE, ResourceType.INTERNET_GATEWAY);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters networkAcl() {
|
||||||
|
map.put(FilterName.RESOURCE_TYPE, ResourceType.NETWORK_ACL);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters reservedInstance() {
|
||||||
|
map.put(FilterName.RESOURCE_TYPE, ResourceType.RESERVED_INSTANCES);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters routeTable() {
|
||||||
|
map.put(FilterName.RESOURCE_TYPE, ResourceType.ROUTE_TABLE);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters securityGroup() {
|
||||||
|
map.put(FilterName.RESOURCE_TYPE, ResourceType.SECURITY_GROUP);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters snapshot() {
|
||||||
|
map.put(FilterName.RESOURCE_TYPE, ResourceType.SNAPSHOT);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters instancesRequest() {
|
||||||
|
map.put(FilterName.RESOURCE_TYPE, ResourceType.SPOT_INSTANCES_REQUEST);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters subnet() {
|
||||||
|
map.put(FilterName.RESOURCE_TYPE, ResourceType.SUBNET);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters volume() {
|
||||||
|
map.put(FilterName.RESOURCE_TYPE, ResourceType.VOLUME);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters vpc() {
|
||||||
|
map.put(FilterName.RESOURCE_TYPE, ResourceType.VPC);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters vpnConnection() {
|
||||||
|
map.put(FilterName.RESOURCE_TYPE, ResourceType.VPN_CONNECTION);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TagFilters vpnGateway() {
|
||||||
|
map.put(FilterName.RESOURCE_TYPE, ResourceType.VPN_GATEWAY);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
package org.jclouds.aws.ec2.xml;
|
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.domain.TagFilter;
|
import org.jclouds.aws.ec2.util.TagFilters.ResourceType;
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,12 +29,12 @@ public class TagsHandler extends ParseSax.HandlerForGeneratedRequestWithResult<T
|
||||||
private StringBuilder currentText = new StringBuilder();
|
private StringBuilder currentText = new StringBuilder();
|
||||||
|
|
||||||
private String resourceId;
|
private String resourceId;
|
||||||
private TagFilter.ResourceType resourceType;
|
private ResourceType resourceType;
|
||||||
private String key;
|
private String key;
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
public Tag getResult() {
|
public Tag getResult() {
|
||||||
Tag returnVal = new Tag(resourceId, resourceType.value(), key, value);
|
Tag returnVal = new Tag(resourceId, resourceType, key, value);
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ public class TagsHandler extends ParseSax.HandlerForGeneratedRequestWithResult<T
|
||||||
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")) {
|
||||||
resourceType = TagFilter.ResourceType.fromValue(currentText.toString().trim());
|
resourceType = ResourceType.fromValue(currentText.toString().trim());
|
||||||
} else if (qName.equals("key")) {
|
} else if (qName.equals("key")) {
|
||||||
key = currentText.toString().trim();
|
key = currentText.toString().trim();
|
||||||
} else if (qName.equals("value")) {
|
} else if (qName.equals("value")) {
|
||||||
|
|
|
@ -25,12 +25,13 @@ import java.net.URI;
|
||||||
|
|
||||||
import javax.ws.rs.HttpMethod;
|
import javax.ws.rs.HttpMethod;
|
||||||
|
|
||||||
import org.jclouds.aws.ec2.domain.TagFilter;
|
import org.jclouds.aws.ec2.util.TagFilters;
|
||||||
import org.jclouds.aws.ec2.domain.TagFilter.FilterName;
|
import org.jclouds.aws.ec2.util.TagFilters.FilterName;
|
||||||
|
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.ImmutableList;
|
import com.google.common.collect.ImmutableSetMultimap;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
|
|
||||||
|
@ -46,22 +47,50 @@ public class BindTagFiltersToIndexedFormParamsTest {
|
||||||
|
|
||||||
public void testResourceTypeWithValues() {
|
public void testResourceTypeWithValues() {
|
||||||
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, ImmutableList.builder().add(new TagFilter(FilterName.RESOURCE_TYPE,
|
request = binder.bindToRequest(request, ImmutableSetMultimap.<FilterName, ResourceType>builder().put(FilterName.RESOURCE_TYPE, ResourceType.VPN_GATEWAY).put(FilterName.RESOURCE_TYPE, ResourceType.INTERNET_GATEWAY).build());
|
||||||
ImmutableList.<String>builder().add(TagFilter.ResourceType.VPN_GATEWAY.value()).add(TagFilter.ResourceType.INTERNET_GATEWAY.value()).build())).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 testKeyWithValues() {
|
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, ImmutableList.builder().add(new TagFilter(FilterName.KEY,
|
request = binder.bindToRequest(request, ImmutableSetMultimap.<FilterName, String>builder().put(FilterName.KEY, "one").put(FilterName.KEY, "two").build());
|
||||||
ImmutableList.<String>builder().add("one").add("two").build())).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 testKeyWithoutValues() {
|
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, ImmutableList.builder().add(new TagFilter(FilterName.KEY, ImmutableList.<String>of())).build());
|
request = binder.bindToRequest(request, ImmutableSetMultimap.<FilterName, String>builder().put(FilterName.KEY, "one").put(FilterName.VALUE, "alpha").build());
|
||||||
assertEquals(request.getPayload().getRawContent(), "Filter.1.Name=key");
|
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() {
|
||||||
|
HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build();
|
||||||
|
request = binder.bindToRequest(request, ImmutableSetMultimap.<FilterName, String>builder().put(FilterName.KEY, "*").build());
|
||||||
|
assertEquals(request.getPayload().getRawContent(), "Filter.1.Name=key&Filter.1.Value.1=%2A");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testResourceTypeWithValuesBuilder() {
|
||||||
|
HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).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");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMultipleKeysBuilder() {
|
||||||
|
HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build();
|
||||||
|
request = binder.bindToRequest(request, TagFilters.filters().key("one").key("two").build());
|
||||||
|
assertEquals(request.getPayload().getRawContent(), "Filter.1.Name=key&Filter.1.Value.1=one&Filter.1.Value.2=two");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testkeyWithValueBuilder() {
|
||||||
|
HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).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");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAnyKeyBuilder() {
|
||||||
|
HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build();
|
||||||
|
request = binder.bindToRequest(request, TagFilters.filters().anyKey().build());
|
||||||
|
assertEquals(request.getPayload().getRawContent(), "Filter.1.Name=key&Filter.1.Value.1=%2A");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
|
|
|
@ -20,11 +20,9 @@ package org.jclouds.aws.ec2.services;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jclouds.aws.ec2.domain.TagFilter;
|
import org.jclouds.aws.ec2.util.TagFilters.FilterName;
|
||||||
import org.jclouds.aws.ec2.domain.TagFilter.FilterName;
|
|
||||||
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;
|
||||||
|
@ -36,19 +34,20 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of {@code TagsAsyncClient}
|
* Tests behavior of {@code TagsAsyncClient}
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author grkvlt@apache.org
|
||||||
*/
|
*/
|
||||||
// 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 = "TagsAsyncClientTest")
|
@Test(groups = "unit", testName = "TagsAsyncClientTest")
|
||||||
public class TagAsyncClientTest extends BaseAWSEC2AsyncClientTest<TagAsyncClient> {
|
public class TagAsyncClientTest extends BaseAWSEC2AsyncClientTest<TagAsyncClient> {
|
||||||
|
|
||||||
public void testDeleteTags() throws SecurityException, NoSuchMethodException, IOException {
|
public void testDeleteTags() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = TagAsyncClient.class.getMethod("deleteTagsInRegion", String.class, Collection.class, Map.class);
|
Method method = TagAsyncClient.class.getMethod("deleteTagsInRegion", String.class, Iterable.class, Map.class);
|
||||||
HttpRequest request = processor.createRequest(method, null, ImmutableList.<String>builder().add("xxx").build(), ImmutableMap.<String, String>builder().put("yyy", "zzz").build());
|
HttpRequest request = processor.createRequest(method, null, ImmutableList.<String>builder().add("xxx").build(), ImmutableMap.<String, String>builder().put("yyy", "zzz").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");
|
||||||
|
@ -64,7 +63,7 @@ public class TagAsyncClientTest extends BaseAWSEC2AsyncClientTest<TagAsyncClient
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateTags() throws SecurityException, NoSuchMethodException, IOException {
|
public void testCreateTags() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = TagAsyncClient.class.getMethod("createTagsInRegion", String.class, Collection.class, Map.class);
|
Method method = TagAsyncClient.class.getMethod("createTagsInRegion", String.class, Iterable.class, Map.class);
|
||||||
HttpRequest request = processor.createRequest(method, null, ImmutableList.<String>builder().add("xxx").build(), ImmutableMap.<String, String>builder().put("yyy", "zzz").build());
|
HttpRequest request = processor.createRequest(method, null, ImmutableList.<String>builder().add("xxx").build(), ImmutableMap.<String, String>builder().put("yyy", "zzz").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");
|
||||||
|
@ -80,8 +79,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, Collection.class);
|
Method method = TagAsyncClient.class.getMethod("describeTagsInRegion", String.class, Multimap.class);
|
||||||
HttpRequest request = processor.createRequest(method, null, ImmutableList.<TagFilter>of());
|
HttpRequest request = processor.createRequest(method, null, ImmutableMultimap.<FilterName, Object>of());
|
||||||
|
|
||||||
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");
|
||||||
|
@ -96,9 +95,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, Collection.class);
|
Method method = TagAsyncClient.class.getMethod("describeTagsInRegion", String.class, Multimap.class);
|
||||||
HttpRequest request = processor.createRequest(method, null, ImmutableList.builder().add(new TagFilter(FilterName.KEY,
|
HttpRequest request = processor.createRequest(method, null, ImmutableMultimap.builder().put(FilterName.KEY, "one").put(FilterName.KEY, "two").build());
|
||||||
ImmutableList.<String>builder().add("one").add("two").build())).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");
|
||||||
|
@ -117,5 +115,4 @@ public class TagAsyncClientTest extends BaseAWSEC2AsyncClientTest<TagAsyncClient
|
||||||
return new TypeLiteral<RestAnnotationProcessor<TagAsyncClient>>() {
|
return new TypeLiteral<RestAnnotationProcessor<TagAsyncClient>>() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,8 @@ 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.domain.TagFilter;
|
import org.jclouds.aws.ec2.util.TagFilters.FilterName;
|
||||||
import org.jclouds.aws.ec2.domain.TagFilter.FilterName;
|
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;
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
|
@ -44,6 +44,7 @@ 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;
|
||||||
|
@ -110,7 +111,7 @@ public class TagClientLiveTest {
|
||||||
cleanupTag(testGroup, "test-key");
|
cleanupTag(testGroup, "test-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, TagFilter.ResourceType.SECURITY_GROUP.value(), "test-key", "test-value");
|
checkTag(testGroup, ResourceType.SECURITY_GROUP, "test-key", "test-value");
|
||||||
} finally {
|
} finally {
|
||||||
cleanupTag(testGroup, "test-key");
|
cleanupTag(testGroup, "test-key");
|
||||||
}
|
}
|
||||||
|
@ -124,12 +125,12 @@ public class TagClientLiveTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkTag(String resourceId, String resourceType, String key, String value) {
|
protected void checkTag(String resourceId, ResourceType resourceType, String key, String value) {
|
||||||
Set<Tag> results = client.describeTagsInRegion(null, ImmutableList.<TagFilter>builder()
|
Set<Tag> results = client.describeTagsInRegion(null, ImmutableMultimap.<FilterName,Object>builder()
|
||||||
.add(new TagFilter(FilterName.RESOURCE_ID, ImmutableList.<String>builder().add(resourceId).build()))
|
.put(FilterName.RESOURCE_ID, resourceId)
|
||||||
.add(new TagFilter(FilterName.RESOURCE_TYPE, ImmutableList.<String>builder().add(resourceType).build()))
|
.put(FilterName.RESOURCE_TYPE, resourceType)
|
||||||
.add(new TagFilter(FilterName.KEY, ImmutableList.<String>builder().add(key).build()))
|
.put(FilterName.KEY, key)
|
||||||
.add(new TagFilter(FilterName.VALUE, ImmutableList.<String>builder().add(value).build()))
|
.put(FilterName.VALUE, value)
|
||||||
.build());
|
.build());
|
||||||
assertNotNull(results);
|
assertNotNull(results);
|
||||||
assertEquals(results.size(), 1);
|
assertEquals(results.size(), 1);
|
||||||
|
|
Loading…
Reference in New Issue