added policy client to elb

This commit is contained in:
Adrian Cole 2012-07-01 20:58:35 -07:00
parent 98741b40fe
commit c016bcc8fd
35 changed files with 2564 additions and 186 deletions

View File

@ -36,7 +36,7 @@
<properties>
<test.elb.zone>us-east-1a</test.elb.zone>
<test.elb.endpoint>https://elasticloadbalancing.us-east-1.amazonaws.com</test.elb.endpoint>
<test.elb.api-version>2010-07-01</test.elb.api-version>
<test.elb.api-version>2012-06-01</test.elb.api-version>
<test.elb.build-version></test.elb.build-version>
<test.elb.identity>${test.aws.identity}</test.elb.identity>
<test.elb.credential>${test.aws.credential}</test.elb.credential>
@ -99,10 +99,16 @@
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<artifactId>jclouds-log4j</artifactId>
<artifactId>jclouds-slf4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>

View File

@ -25,7 +25,7 @@ public class ELB {
*
* @return iterable of loadBalancers fitting the criteria
*/
public static Iterable<LoadBalancer> list(final LoadBalancerClient loadBalancerClient, final ListLoadBalancersOptions options) {
public static Iterable<LoadBalancer> listLoadBalancers(final LoadBalancerClient loadBalancerClient, final ListLoadBalancersOptions options) {
return PaginatedSets.lazyContinue(loadBalancerClient.list(options), new Function<String, PaginatedSet<LoadBalancer>>() {
@Override
@ -40,8 +40,8 @@ public class ELB {
});
}
public static Iterable<LoadBalancer> list(LoadBalancerClient loadBalancerClient) {
return list(loadBalancerClient, new ListLoadBalancersOptions());
public static Iterable<LoadBalancer> listLoadBalancers(LoadBalancerClient loadBalancerClient) {
return listLoadBalancers(loadBalancerClient, new ListLoadBalancersOptions());
}
}

View File

@ -33,6 +33,7 @@ import org.jclouds.elb.binders.BindInstanceIdsToIndexedFormParams;
import org.jclouds.elb.binders.BindLoadBalancerNamesToIndexedFormParams;
import org.jclouds.elb.domain.CrappyLoadBalancer;
import org.jclouds.elb.features.LoadBalancerAsyncClient;
import org.jclouds.elb.features.PolicyAsyncClient;
import org.jclouds.elb.xml.CreateLoadBalancerResponseHandler;
import org.jclouds.elb.xml.DescribeLoadBalancersResponseHandler;
import org.jclouds.elb.xml.RegisterInstancesWithLoadBalancerResponseHandler;
@ -78,9 +79,12 @@ public interface ELBAsyncClient {
@Delegate
LoadBalancerAsyncClient getLoadBalancerClientForRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
/**
* Provides asynchronous access to Policy features.
*/
@Delegate
PolicyAsyncClient getPolicyClientForRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
/// old stuff
public static final String VERSION = "2012-06-01";

View File

@ -26,6 +26,7 @@ import javax.annotation.Nullable;
import org.jclouds.concurrent.Timeout;
import org.jclouds.elb.domain.CrappyLoadBalancer;
import org.jclouds.elb.features.LoadBalancerClient;
import org.jclouds.elb.features.PolicyClient;
import org.jclouds.location.Region;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.rest.annotations.Delegate;
@ -58,6 +59,11 @@ public interface ELBClient {
@Delegate
LoadBalancerClient getLoadBalancerClientForRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
/**
* Provides synchronous access to Policy features.
*/
@Delegate
PolicyClient getPolicyClientForRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
/// old stuff
/**

View File

@ -0,0 +1,40 @@
/**
* 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.elb.binders;
import static org.jclouds.aws.util.AWSUtils.indexIterableToFormValuesWithPrefix;
import javax.inject.Singleton;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder;
/**
* Binds the Iterable<String> to form parameters named with PolicyTypeNames.member.N
*
* @author Adrian Cole
*/
@Singleton
public class BindPolicyTypeNamesToIndexedFormParams implements Binder {
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
return indexIterableToFormValuesWithPrefix(request, "PolicyTypeNames.member", input);
}
}

View File

@ -25,6 +25,8 @@ import org.jclouds.elb.ELBAsyncClient;
import org.jclouds.elb.ELBClient;
import org.jclouds.elb.features.LoadBalancerAsyncClient;
import org.jclouds.elb.features.LoadBalancerClient;
import org.jclouds.elb.features.PolicyAsyncClient;
import org.jclouds.elb.features.PolicyClient;
import org.jclouds.rest.ConfiguresRestClient;
import com.google.common.collect.ImmutableMap;
@ -38,7 +40,9 @@ import com.google.common.reflect.TypeToken;
@ConfiguresRestClient
public class ELBRestClientModule extends FormSigningRestClientModule<ELBClient, ELBAsyncClient> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
.put(LoadBalancerClient.class, LoadBalancerAsyncClient.class).build();
.put(LoadBalancerClient.class, LoadBalancerAsyncClient.class)
.put(PolicyClient.class, PolicyAsyncClient.class)
.build();
public ELBRestClientModule() {
super(TypeToken.of(ELBClient.class), TypeToken.of(ELBAsyncClient.class), DELEGATE_MAP);

View File

@ -0,0 +1,235 @@
/**
* 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.elb.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Optional;
/**
* This data type is used to describe values that are acceptable for the policy attribute.
*
* @see <a
* href="http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference/API_PolicyAttributeTypeDescription.html"
* >doc</a>
*
* @author Adrian Cole
*/
public class AttributeMetadata<V> {
/**
* The cardinality of the attribute.
*/
public static enum Cardinality {
/**
* ONE(1) : Single value required
*/
ONE,
/**
* ZERO_OR_ONE(0..1) : Up to one value can be supplied
*/
ZERO_OR_ONE,
/**
* ZERO_OR_MORE(0..*) : Optional. Multiple values are allowed
*/
ZERO_OR_MORE,
/**
* ONE_OR_MORE(1..*0) : Required. Multiple values are allowed *
*/
ONE_OR_MORE;
}
public static <V> Builder<V> builder() {
return new Builder<V>();
}
public Builder<V> toBuilder() {
return new Builder<V>().fromAttributeMetadata(this);
}
public static class Builder<V> {
protected String name;
protected Class<V> type;
protected String rawType;
protected Cardinality cardinality;
protected Optional<V> defaultValue = Optional.absent();
protected Optional<String> description = Optional.absent();
/**
* @see AttributeMetadata#getName()
*/
public Builder<V> name(String name) {
this.name = name;
return this;
}
/**
* @see AttributeMetadata#getType()
*/
public Builder<V> type(Class<V> type) {
this.type = type;
return this;
}
/**
* @see AttributeMetadata#getRawType()
*/
public Builder<V> rawType(String rawType) {
this.rawType = rawType;
return this;
}
/**
* @see AttributeMetadata#getCardinality()
*/
public Builder<V> cardinality(Cardinality cardinality) {
this.cardinality = cardinality;
return this;
}
/**
* @see AttributeMetadata#getDefaultValue()
*/
public Builder<V> defaultValue(V defaultValue) {
this.defaultValue = Optional.fromNullable(defaultValue);
return this;
}
/**
* @see AttributeMetadata#getDescription()
*/
public Builder<V> description(String description) {
this.description = Optional.fromNullable(description);
return this;
}
public AttributeMetadata<V> build() {
return new AttributeMetadata<V>(name, type, rawType, cardinality, defaultValue, description);
}
public Builder<V> fromAttributeMetadata(AttributeMetadata<V> in) {
return this.name(in.getName()).type(in.getType()).rawType(in.getRawType()).cardinality(in.getCardinality())
.defaultValue(in.getDefaultValue().orNull()).description(in.getDescription().orNull());
}
}
protected final String name;
protected final Class<V> type;
protected final String rawType;
protected final Cardinality cardinality;
protected final Optional<V> defaultValue;
protected final Optional<String> description;
protected AttributeMetadata(String name, Class<V> type, String rawType, Cardinality cardinality,
Optional<V> defaultValue, Optional<String> description) {
this.name = checkNotNull(name, "name");
this.type = checkNotNull(type, "type");
this.rawType = checkNotNull(rawType, "rawType");
this.cardinality = checkNotNull(cardinality, "cardinality");
this.defaultValue = checkNotNull(defaultValue, "defaultValue");
this.description = checkNotNull(description, "description");
}
/**
* The name of the attribute associated with the policy type.
*/
public String getName() {
return name;
}
/**
* The type of attribute. For example, Boolean, Long, String, etc.
*/
public Class<V> getType() {
return type;
}
/**
* Literal type of the value, noting that if it doesn't correspond to a primitive or String,
* {@link #getType() will return String.class}
*/
public String getRawType() {
return rawType;
}
/**
* The cardinality of the attribute.
*/
public Cardinality getCardinality() {
return cardinality;
}
/**
* The default value of the attribute, if applicable.
*/
public Optional<V> getDefaultValue() {
return defaultValue;
}
/**
* A human-readable description of the attribute.
*/
public Optional<String> getDescription() {
return description;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(name, type, rawType, cardinality, defaultValue, description);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AttributeMetadata<?> other = AttributeMetadata.class.cast(obj);
return Objects.equal(this.name, other.name) && Objects.equal(this.type, other.type)
&& Objects.equal(this.rawType, other.rawType) && Objects.equal(this.cardinality, other.cardinality)
&& Objects.equal(this.defaultValue, other.defaultValue)
&& Objects.equal(this.description, other.description);
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return string().toString();
}
protected ToStringHelper string() {
return Objects.toStringHelper(this).omitNullValues().add("name", name).add("type", type).add("rawType", rawType)
.add("cardinality", cardinality).add("defaultValue", defaultValue.orNull())
.add("description", description.orNull());
}
}

View File

@ -18,6 +18,8 @@
*/
package org.jclouds.elb.domain;
import static com.google.common.base.Preconditions.*;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
@ -46,11 +48,11 @@ public class HealthCheck {
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected int healthyThreshold;
protected int interval;
protected int healthyThreshold = -1;
protected int interval = -1;
protected String target;
protected int timeout;
protected int unhealthyThreshold;
protected int timeout = -1;
protected int unhealthyThreshold = -1;
/**
* @see HealthCheck#getHealthyThreshold()
@ -116,13 +118,18 @@ public class HealthCheck {
protected final int unhealthyThreshold;
protected HealthCheck(int healthyThreshold, int interval, String target, int timeout, int unhealthyThreshold) {
this.healthyThreshold = healthyThreshold;
this.interval = interval;
this.target = target;
this.timeout = timeout;
this.unhealthyThreshold = unhealthyThreshold;
this.healthyThreshold = checkNonNegative(healthyThreshold, "healthyThreshold");
this.interval = checkNonNegative(interval, "interval");
this.target = checkNotNull(target, "target");
this.timeout = checkNonNegative(timeout, "timeout");
this.unhealthyThreshold = checkNonNegative(unhealthyThreshold, "unhealthyThreshold");
}
static int checkNonNegative(int in, String name) {
checkArgument(in > 0, "%s must be non-negative", name);
return in;
}
/**
* Specifies the number of consecutive health probe successes required before moving the instance
* to the Healthy state.

View File

@ -18,6 +18,9 @@
*/
package org.jclouds.elb.domain;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.base.Objects.ToStringHelper;
@ -51,9 +54,9 @@ public class Listener {
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected int instancePort;
protected int instancePort = -1;
protected Protocol instanceProtocol;
protected int port;
protected int port = -1;
protected Protocol protocol;
protected Optional<String> SSLCertificateId = Optional.absent();
@ -124,13 +127,18 @@ public class Listener {
protected Listener(int instancePort, Protocol instanceProtocol, int port, Protocol protocol,
Optional<String> SSLCertificateId) {
this.instancePort = instancePort;
this.instanceProtocol = instanceProtocol;
this.port = port;
this.protocol = protocol;
this.SSLCertificateId = SSLCertificateId;
this.instancePort = checkNonNegative(instancePort, "instancePort");
this.instanceProtocol = checkNotNull(instanceProtocol, "instanceProtocol");
this.port = checkNonNegative(port, "port");
this.protocol = checkNotNull(protocol, "protocol");
this.SSLCertificateId = checkNotNull(SSLCertificateId, "SSLCertificateId");
}
static int checkNonNegative(int in, String name) {
checkArgument(in > 0, "%s must be non-negative", name);
return in;
}
/**
* The name associated with the LoadBalancer. The name must be unique within your set of
* LoadBalancers.

View File

@ -19,6 +19,7 @@
package org.jclouds.elb.domain;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set;
@ -49,8 +50,8 @@ public class ListenerWithPolicies extends Listener {
/**
* @see ListenerWithPolicies#getPolicyNames()
*/
public T policyNames(Iterable<String> policyName) {
this.policyNames.addAll(policyName);
public T policyNames(Iterable<String> policyNames) {
this.policyNames.addAll(checkNotNull(policyNames, "policyNames"));
return self();
}
@ -58,7 +59,7 @@ public class ListenerWithPolicies extends Listener {
* @see ListenerWithPolicies#getPolicyNames()
*/
public T policyName(String policyName) {
this.policyNames.add(policyName);
this.policyNames.add(checkNotNull(policyName, "policyName"));
return self();
}
@ -83,9 +84,9 @@ public class ListenerWithPolicies extends Listener {
private final Set<String> policyNames;
protected ListenerWithPolicies(int instancePort, Protocol instanceProtocol, int port, Protocol protocol,
Optional<String> SSLCertificateId, Iterable<String> policiesNames) {
Optional<String> SSLCertificateId, Iterable<String> policyNames) {
super(instancePort, instanceProtocol, port, protocol, SSLCertificateId);
this.policyNames = ImmutableSet.copyOf(policiesNames);
this.policyNames = ImmutableSet.copyOf(checkNotNull(policyNames, "policyNames"));
}
/**

View File

@ -143,8 +143,8 @@ public class LoadBalancer {
/**
* @see LoadBalancer#getInstanceIds()
*/
public T instanceIds(Iterable<String> instanceId) {
this.instanceIds.addAll(instanceId);
public T instanceIds(Iterable<String> instanceIds) {
this.instanceIds.addAll(checkNotNull(instanceIds, "instanceIds"));
return self();
}
@ -152,15 +152,15 @@ public class LoadBalancer {
* @see LoadBalancer#getInstanceIds()
*/
public T instanceId(String instanceId) {
this.instanceIds.add(instanceId);
this.instanceIds.add(checkNotNull(instanceId, "instanceId"));
return self();
}
/**
* @see LoadBalancer#getListeners()
*/
public T listeners(Iterable<ListenerWithPolicies> listener) {
this.listeners.addAll(listener);
public T listeners(Iterable<ListenerWithPolicies> listeners) {
this.listeners.addAll(checkNotNull(listeners, "listeners"));
return self();
}
@ -168,7 +168,7 @@ public class LoadBalancer {
* @see LoadBalancer#getListeners()
*/
public T listener(ListenerWithPolicies listener) {
this.listeners.add(listener);
this.listeners.add(checkNotNull(listener, "listener"));
return self();
}
@ -194,9 +194,9 @@ public class LoadBalancer {
}
public T fromLoadBalancer(LoadBalancer in) {
return this.name(in.getName()).createdTime(in.getCreatedTime()).dnsName(in.getDnsName()).healthCheck(
in.getHealthCheck()).instanceIds(in.getInstanceIds()).scheme(in.getScheme().orNull()).VPCId(
in.getVPCId().orNull());
return this.name(in.getName()).createdTime(in.getCreatedTime()).dnsName(in.getDnsName())
.healthCheck(in.getHealthCheck()).listeners(in.getListeners()).instanceIds(in.getInstanceIds())
.scheme(in.getScheme().orNull()).VPCId(in.getVPCId().orNull());
}
}
@ -219,14 +219,14 @@ public class LoadBalancer {
protected LoadBalancer(String name, Date createdTime, String dnsName, HealthCheck healthCheck,
Iterable<String> instanceIds, Iterable<ListenerWithPolicies> listeners, Optional<Scheme> scheme,
Optional<String> VPCId) {
this.name = name;
this.createdTime = createdTime;
this.dnsName = dnsName;
this.healthCheck = healthCheck;
this.instanceIds = ImmutableSet.copyOf(instanceIds);
this.listeners = ImmutableSet.copyOf(listeners);
this.scheme = scheme;
this.VPCId = VPCId;
this.name = checkNotNull(name, "name");
this.createdTime = checkNotNull(createdTime, "createdTime");
this.dnsName = checkNotNull(dnsName, "dnsName");
this.healthCheck = checkNotNull(healthCheck, "healthCheck");
this.instanceIds = ImmutableSet.copyOf(checkNotNull(instanceIds, "instanceIds"));
this.listeners = ImmutableSet.copyOf(checkNotNull(listeners, "listeners"));
this.scheme = checkNotNull(scheme, "scheme");
this.VPCId = checkNotNull(VPCId, "VPCId");
}
/**

View File

@ -0,0 +1,164 @@
/**
* 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.elb.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
/**
*
* @see <a
* href="http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference/API_DescribeLoadBalancerPolicies.html"
* >doc</a>
*
* @author Adrian Cole
*/
public class Policy {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromPolicy(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String name;
protected String typeName;
protected ImmutableMultimap.Builder<String, Object> attributes = ImmutableMultimap.<String, Object> builder();
/**
* @see Policy#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
/**
* @see Policy#getTypeName()
*/
public T typeName(String typeName) {
this.typeName = typeName;
return self();
}
/**
* @see Policy#getAttributes()
*/
public T attributes(Multimap<String, Object> attributes) {
this.attributes.putAll(checkNotNull(attributes, "attributes"));
return self();
}
/**
* @see Policy#getAttributes()
*/
public T attribute(String key, Object value) {
this.attributes.put(checkNotNull(key, "key"), checkNotNull(value, "value"));
return self();
}
public Policy build() {
return new Policy(name, typeName, attributes.build());
}
public T fromPolicy(Policy in) {
return this.name(in.getName()).typeName(in.getTypeName()).attributes(in.getAttributes());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
protected final String name;
protected final String typeName;
protected final Multimap<String, Object> attributes;
protected Policy(String name, String typeName, Multimap<String, Object> attributes) {
this.name = checkNotNull(name, "name");
this.typeName = checkNotNull(typeName, "typeName");
this.attributes = ImmutableMultimap.copyOf(checkNotNull(attributes, "attributes"));
}
/**
* The name of the policy associated with the LoadBalancer
*/
public String getName() {
return name;
}
/**
* The name of the policy type associated with the LoadBalancer.
*/
public String getTypeName() {
return typeName;
}
/**
* A list of policy attribute description structures. Note that values are either Long, Boolean,
* or String, depending on {@link AttributeMetadata#getType()}
*/
public Multimap<String, Object> getAttributes() {
return attributes;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(name, typeName);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Policy other = (Policy) obj;
return Objects.equal(this.name, other.name) && Objects.equal(this.typeName, other.typeName);
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return Objects.toStringHelper(this).omitNullValues().add("name", name).add("typeName", typeName)
.add("attributes", attributes).toString();
}
}

View File

@ -0,0 +1,165 @@
/**
* 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.elb.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
/**
*
* @see <a
* href="http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference/API_PolicyTypeDescription.html"
* >doc</a>
*
* @author Adrian Cole
*/
public class PolicyType {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromPolicyType(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String name;
protected String description;
protected ImmutableSet.Builder<AttributeMetadata<?>> attributeMetadata = ImmutableSet.<AttributeMetadata<?>> builder();
/**
* @see PolicyType#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
/**
* @see PolicyType#getDescription()
*/
public T description(String description) {
this.description = description;
return self();
}
/**
* @see PolicyType#getAttributeMetadata()
*/
public T attributeMetadata(Iterable<AttributeMetadata<?>> attributeMetadata) {
this.attributeMetadata.addAll(checkNotNull(attributeMetadata, "attributeMetadata"));
return self();
}
/**
* @see PolicyType#getAttributeMetadata()
*/
public T attributeMetadata(AttributeMetadata<?> attributeMetadata) {
this.attributeMetadata.add(checkNotNull(attributeMetadata, "attributeMetadata"));
return self();
}
public PolicyType build() {
return new PolicyType(name, description, attributeMetadata.build());
}
public T fromPolicyType(PolicyType in) {
return this.name(in.getName()).description(in.getDescription()).attributeMetadata(in.getAttributeMetadata());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
protected final String name;
protected final String description;
protected final Set<AttributeMetadata<?>> attributeMetadata;
protected PolicyType(String name, String description, Iterable<AttributeMetadata<?>> attributeMetadata) {
this.name = checkNotNull(name, "name");
this.description = checkNotNull(description, "description");
this.attributeMetadata = ImmutableSet.copyOf(checkNotNull(attributeMetadata, "attributeMetadata"));
}
/**
* The name of the policy type.
*/
public String getName() {
return name;
}
/**
* A human-readable description of the policy type.
*/
public String getDescription() {
return description;
}
/**
* The description of the policy attributes associated with the LoadBalancer policies defined by
* the Elastic Load Balancing service.
*/
public Set<AttributeMetadata<?>> getAttributeMetadata() {
return attributeMetadata;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(name);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
PolicyType other = (PolicyType) obj;
return Objects.equal(this.name, other.name);
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return Objects.toStringHelper(this).omitNullValues().add("name", name).add("description", description)
.add("attributeMetadata", attributeMetadata).toString();
}
}

View File

@ -0,0 +1,120 @@
/**
* 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.elb.features;
import java.util.Set;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.elb.binders.BindPolicyTypeNamesToIndexedFormParams;
import org.jclouds.elb.domain.Policy;
import org.jclouds.elb.domain.PolicyType;
import org.jclouds.elb.options.ListPoliciesOptions;
import org.jclouds.elb.xml.DescribeLoadBalancerPoliciesResultHandler;
import org.jclouds.elb.xml.DescribeLoadBalancerPolicyTypesResultHandler;
import org.jclouds.elb.xml.PolicyHandler;
import org.jclouds.elb.xml.PolicyTypeHandler;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.FormParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides access to Amazon ELB via the Query API
* <p/>
*
* @see <a href="http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference" >doc</a>
* @see PolicyClient
* @author Adrian Cole
*/
@RequestFilters(FormSigner.class)
@VirtualHost
public interface PolicyAsyncClient {
/**
* @see PolicyClient#get()
*/
@POST
@Path("/")
@XMLResponseParser(PolicyHandler.class)
@FormParams(keys = "Action", values = "DescribeLoadBalancerPolicies")
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Policy> get(@FormParam("PolicyNames.member.1") String name);
/**
* @see PolicyClient#list()
*/
@POST
@Path("/")
@XMLResponseParser(DescribeLoadBalancerPoliciesResultHandler.class)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
@FormParams(keys = "Action", values = "DescribeLoadBalancerPolicies")
ListenableFuture<Set<Policy>> list();
/**
* @see PolicyClient#list(ListPoliciesOptions)
*/
@POST
@Path("/")
@XMLResponseParser(DescribeLoadBalancerPoliciesResultHandler.class)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
@FormParams(keys = "Action", values = "DescribeLoadBalancerPolicies")
ListenableFuture<Set<Policy>> list(ListPoliciesOptions options);
/**
* @see PolicyClient#getType()
*/
@POST
@Path("/")
@XMLResponseParser(PolicyTypeHandler.class)
@FormParams(keys = "Action", values = "DescribeLoadBalancerPolicyTypes")
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<PolicyType> getType(@FormParam("PolicyTypeNames.member.1") String name);
/**
* @see PolicyClient#listTypes()
*/
@POST
@Path("/")
@XMLResponseParser(DescribeLoadBalancerPolicyTypesResultHandler.class)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
@FormParams(keys = "Action", values = "DescribeLoadBalancerPolicyTypes")
ListenableFuture<Set<PolicyType>> listTypes();
/**
* @see PolicyClient#listTypes(Iterable<String>)
*/
@POST
@Path("/")
@XMLResponseParser(DescribeLoadBalancerPolicyTypesResultHandler.class)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
@FormParams(keys = "Action", values = "DescribeLoadBalancerPolicyTypes")
ListenableFuture<Set<PolicyType>> listTypes(@BinderParam(BindPolicyTypeNamesToIndexedFormParams.class) Iterable<String> names);
}

View File

@ -0,0 +1,101 @@
/**
* 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.elb.features;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.elb.domain.Policy;
import org.jclouds.elb.domain.PolicyType;
import org.jclouds.elb.options.ListPoliciesOptions;
import org.jclouds.javax.annotation.Nullable;
/**
* Provides access to Amazon ELB via the Query API
* <p/>
*
* @see <a href="http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference" />
* @author Adrian Cole
*/
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface PolicyClient {
/**
* Retrieves information about the specified policy.
*
* @param name
* Name of the policy to get information about.
* @return null if not found
*/
@Nullable
Policy get(String name);
/**
* Returns detailed descriptions of the policies.
*
* If you specify a LoadBalancer name, the operation returns either the descriptions of the
* specified policies, or descriptions of all the policies created for the LoadBalancer. If you
* don't specify a LoadBalancer name, the operation returns descriptions of the specified sample
* policies, or descriptions of all the sample policies. The names of the sample policies have
* the ELBSample- prefix.
*
* @param options
* the options describing the policies query
*
* @return the response object
*/
Set<Policy> list(ListPoliciesOptions options);
/**
* returns descriptions of the specified sample policies, or descriptions of all the sample
* policies.
*
* @return the response object
*/
Set<Policy> list();
/**
* Retrieves information about the specified policy type.
*
* @param name
* Name of the policy type to get information about.
* @return null if not found
*/
@Nullable
PolicyType getType(String name);
/**
* Returns meta-information on the specified LoadBalancer policies defined by the Elastic Load
* Balancing service. The policy types that are returned from this action can be used in a
* CreateLoadBalancerPolicy action to instantiate specific policy configurations that will be
* applied to an Elastic LoadBalancer.
*
* @return the response object
*/
Set<PolicyType> listTypes();
/**
* @param names Specifies the name of the policy types. If no names are specified, returns the description of all the policy types defined by Elastic Load Balancing service.
*
* @see #listTypes()
*/
Set<PolicyType> listTypes(Iterable<String> names);
}

View File

@ -0,0 +1,159 @@
/**
* 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.elb.options;
import java.util.Set;
import org.jclouds.http.options.BaseHttpRequestOptions;
import com.google.common.base.Objects;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
/**
* Options used to list available policies.
*
* @see <a
* href="http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference/API_DescribeLoadBalancerPolicies.html"
* >docs</a>
*
* @author Adrian Cole
*/
public class ListPoliciesOptions extends BaseHttpRequestOptions implements Cloneable {
private String loadBalancerName;
private Set<String> names = Sets.newLinkedHashSet();
/**
* @see ListPoliciesOptions#getLoadBalancerName()
*/
public ListPoliciesOptions loadBalancerName(String loadBalancerName) {
this.loadBalancerName = loadBalancerName;
return this;
}
/**
* @see ListPoliciesOptions#getNames()
*/
public ListPoliciesOptions names(Set<String> names) {
this.names = names;
return this;
}
/**
* @see ListPoliciesOptions#getNames()
*/
public ListPoliciesOptions name(String name) {
this.names.add(name);
return this;
}
/**
* The mnemonic name associated with the LoadBalancer. If no name is specified, the operation
* returns the attributes of either all the sample policies pre-defined by Elastic Load Balancing
* or the specified sample polices.
*/
public String getLoadBalancerName() {
return loadBalancerName;
}
/**
* The names of LoadBalancer policies you've created or Elastic Load Balancing sample policy
* names.
*/
public Set<String> getNames() {
return names;
}
public static class Builder {
/**
* @see ListPoliciesOptions#getLoadBalancerName()
*/
public static ListPoliciesOptions loadBalancerName(String loadBalancerName) {
return new ListPoliciesOptions().loadBalancerName(loadBalancerName);
}
/**
* @see ListPoliciesOptions#getNames()
*/
public static ListPoliciesOptions name(String name) {
return new ListPoliciesOptions().name(name);
}
/**
* @see ListPoliciesOptions#getNames()
*/
public static ListPoliciesOptions names(Set<String> names) {
return new ListPoliciesOptions().names(names);
}
}
@Override
public Multimap<String, String> buildFormParameters() {
Multimap<String, String> params = super.buildFormParameters();
if (loadBalancerName != null)
params.put("LoadBalancerName", loadBalancerName);
if (names.size() > 0) {
int nameIndex = 1;
for (String name : names) {
params.put("PolicyNames.member." + nameIndex, name);
nameIndex++;
}
}
return params;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(loadBalancerName, names);
}
@Override
public ListPoliciesOptions clone() {
return new ListPoliciesOptions().loadBalancerName(loadBalancerName).names(names);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ListPoliciesOptions other = ListPoliciesOptions.class.cast(obj);
return Objects.equal(this.loadBalancerName, other.loadBalancerName) && Objects.equal(this.names, other.names);
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return Objects.toStringHelper(this).omitNullValues().add("loadBalancerName", loadBalancerName)
.add("names", names).toString();
}
}

View File

@ -0,0 +1,98 @@
/**
* 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.elb.xml;
import static org.jclouds.util.SaxUtils.currentOrNull;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import org.jclouds.elb.domain.AttributeMetadata;
import org.jclouds.elb.domain.AttributeMetadata.Cardinality;
import org.jclouds.http.functions.ParseSax;
import org.xml.sax.SAXException;
/**
* @see <a
* href="http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference/API_PolicyAttributeTypeDescription.html"
* >xml</a>
*
* @author Adrian Cole
*/
public class AttributeMetadataHandler extends ParseSax.HandlerForGeneratedRequestWithResult<AttributeMetadata<?>> {
private StringBuilder currentText = new StringBuilder();
@SuppressWarnings("rawtypes")
private AttributeMetadata.Builder builder = AttributeMetadata.builder();
@SuppressWarnings("rawtypes")
private Class currentType = String.class;
/**
* {@inheritDoc}
*/
@Override
public AttributeMetadata<?> getResult() {
try {
return builder.build();
} finally {
builder = AttributeMetadata.builder();
}
}
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public void endElement(String uri, String name, String qName) throws SAXException {
if (equalsOrSuffix(qName, "AttributeName")) {
builder.name(currentOrNull(currentText));
} else if (equalsOrSuffix(qName, "AttributeType")) {
String rawType = currentOrNull(currentText);
if ("Long".equals(rawType)) {
currentType = Long.class;
} else if ("Boolean".equals(rawType)) {
currentType = Boolean.class;
} else {
currentType = String.class;
}
builder.type(currentType);
builder.rawType(rawType);
} else if (equalsOrSuffix(qName, "Cardinality")) {
builder.cardinality(Cardinality.valueOf(currentOrNull(currentText)));
} else if (equalsOrSuffix(qName, "DefaultValue")) {
Object value = currentOrNull(currentText);
if (currentType == Long.class)
value = Long.valueOf(currentOrNull(currentText));
else if (currentType == Boolean.class)
value = Boolean.valueOf(currentOrNull(currentText));
builder.defaultValue(value);
} else if (equalsOrSuffix(qName, "UnhealthyThreshold")) {
builder.description(currentOrNull(currentText));
}
currentText = new StringBuilder();
}
/**
* {@inheritDoc}
*/
@Override
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -0,0 +1,118 @@
/**
* 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.elb.xml;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Set;
import org.jclouds.elb.domain.Policy;
import org.jclouds.http.functions.ParseSax;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
import com.google.inject.Inject;
/**
* @see <a
* href="http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference/API_DescribeLoadBalancers.html"
* >docs</a>
*
* @author Adrian Cole
*/
public class DescribeLoadBalancerPoliciesResultHandler extends
ParseSax.HandlerForGeneratedRequestWithResult<Set<Policy>> {
private final PolicyHandler policyHandler;
private StringBuilder currentText = new StringBuilder();
private Builder<Policy> policies = ImmutableSet.<Policy> builder();
private boolean inPolicies;
protected int memberDepth;
@Inject
public DescribeLoadBalancerPoliciesResultHandler(PolicyHandler policyHandler) {
this.policyHandler = policyHandler;
}
/**
* {@inheritDoc}
*/
@Override
public Set<Policy> getResult() {
return policies.build();
}
/**
* {@inheritDoc}
*/
@Override
public void startElement(String url, String name, String qName, Attributes attributes) throws SAXException {
if (equalsOrSuffix(qName, "member")) {
memberDepth++;
} else if (equalsOrSuffix(qName, "PolicyDescriptions")) {
inPolicies = true;
}
if (inPolicies) {
policyHandler.startElement(url, name, qName, attributes);
}
}
/**
* {@inheritDoc}
*/
@Override
public void endElement(String uri, String name, String qName) throws SAXException {
if (equalsOrSuffix(qName, "member")) {
endMember(uri, name, qName);
memberDepth--;
} else if (equalsOrSuffix(qName, "PolicyDescriptions")) {
inPolicies = false;
} else if (inPolicies) {
policyHandler.endElement(uri, name, qName);
}
currentText = new StringBuilder();
}
protected void endMember(String uri, String name, String qName) throws SAXException {
if (inPolicies) {
if (memberDepth == 1)
policies.add(policyHandler.getResult());
else
policyHandler.endElement(uri, name, qName);
}
}
/**
* {@inheritDoc}
*/
@Override
public void characters(char ch[], int start, int length) {
if (inPolicies) {
policyHandler.characters(ch, start, length);
} else {
currentText.append(ch, start, length);
}
}
}

View File

@ -0,0 +1,118 @@
/**
* 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.elb.xml;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Set;
import org.jclouds.elb.domain.PolicyType;
import org.jclouds.http.functions.ParseSax;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
import com.google.inject.Inject;
/**
* @see <a
* href="http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference/API_DescribeLoadBalancerPolicyTypeTypes.html"
* >docs</a>
*
* @author Adrian Cole
*/
public class DescribeLoadBalancerPolicyTypesResultHandler extends
ParseSax.HandlerForGeneratedRequestWithResult<Set<PolicyType>> {
private final PolicyTypeHandler policyTypeHandler;
private StringBuilder currentText = new StringBuilder();
private Builder<PolicyType> policyTypes = ImmutableSet.<PolicyType> builder();
private boolean inPolicyTypeTypes;
protected int memberDepth;
@Inject
public DescribeLoadBalancerPolicyTypesResultHandler(PolicyTypeHandler policyTypeHandler) {
this.policyTypeHandler = policyTypeHandler;
}
/**
* {@inheritDoc}
*/
@Override
public Set<PolicyType> getResult() {
return policyTypes.build();
}
/**
* {@inheritDoc}
*/
@Override
public void startElement(String url, String name, String qName, Attributes attributes) throws SAXException {
if (equalsOrSuffix(qName, "member")) {
memberDepth++;
} else if (equalsOrSuffix(qName, "PolicyTypeDescriptions")) {
inPolicyTypeTypes = true;
}
if (inPolicyTypeTypes) {
policyTypeHandler.startElement(url, name, qName, attributes);
}
}
/**
* {@inheritDoc}
*/
@Override
public void endElement(String uri, String name, String qName) throws SAXException {
if (equalsOrSuffix(qName, "member")) {
endMember(uri, name, qName);
memberDepth--;
} else if (equalsOrSuffix(qName, "PolicyTypeDescriptions")) {
inPolicyTypeTypes = false;
} else if (inPolicyTypeTypes) {
policyTypeHandler.endElement(uri, name, qName);
}
currentText = new StringBuilder();
}
protected void endMember(String uri, String name, String qName) throws SAXException {
if (inPolicyTypeTypes) {
if (memberDepth == 1)
policyTypes.add(policyTypeHandler.getResult());
else
policyTypeHandler.endElement(uri, name, qName);
}
}
/**
* {@inheritDoc}
*/
@Override
public void characters(char ch[], int start, int length) {
if (inPolicyTypeTypes) {
policyTypeHandler.characters(ch, start, length);
} else {
currentText.append(ch, start, length);
}
}
}

View File

@ -0,0 +1,87 @@
/**
* 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.elb.xml;
import static org.jclouds.util.SaxUtils.currentOrNull;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import org.jclouds.elb.domain.Policy;
import org.jclouds.http.functions.ParseSax;
import org.xml.sax.SAXException;
import com.google.common.primitives.Ints;
/**
* @see <a
* href="http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference/API_PolicyDescription.html"
* >xml</a>
*
* @author Adrian Cole
*/
public class PolicyHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Policy> {
private StringBuilder currentText = new StringBuilder();
private Policy.Builder<?> builder = Policy.builder();
private String key;
/**
* {@inheritDoc}
*/
@Override
public Policy getResult() {
try {
return builder.build();
} finally {
builder = Policy.builder();
}
}
/**
* {@inheritDoc}
*/
@Override
public void endElement(String uri, String name, String qName) throws SAXException {
if (equalsOrSuffix(qName, "PolicyName")) {
builder.name(currentOrNull(currentText));
} else if (equalsOrSuffix(qName, "PolicyTypeName")) {
builder.typeName(currentOrNull(currentText));
} else if (equalsOrSuffix(qName, "AttributeName")) {
key = currentOrNull(currentText);
} else if (equalsOrSuffix(qName, "AttributeValue")) {
String value = currentOrNull(currentText);
if ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value))
builder.attribute(key, Boolean.valueOf(value));
else if (Ints.tryParse(value) != null)
builder.attribute(key, Long.valueOf(value));
else
builder.attribute(key, value);
key = null;
}
currentText = new StringBuilder();
}
/**
* {@inheritDoc}
*/
@Override
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -0,0 +1,113 @@
/**
* 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.elb.xml;
import static org.jclouds.util.SaxUtils.currentOrNull;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import javax.inject.Inject;
import org.jclouds.elb.domain.PolicyType;
import org.jclouds.http.functions.ParseSax;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
/**
* @see <a
* href="http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference/API_PolicyTypeDescription.html"
* >doc</a>
*
* @author Adrian Cole
*/
public class PolicyTypeHandler extends ParseSax.HandlerForGeneratedRequestWithResult<PolicyType> {
protected final AttributeMetadataHandler attributeTypeHandler;
@Inject
protected PolicyTypeHandler(AttributeMetadataHandler attributeTypeHandler) {
this.attributeTypeHandler = attributeTypeHandler;
}
private StringBuilder currentText = new StringBuilder();
private PolicyType.Builder<?> builder = PolicyType.builder();
private boolean inAttributeTypes;
/**
* {@inheritDoc}
*/
@Override
public PolicyType getResult() {
try {
return builder.build();
} finally {
builder = PolicyType.builder();
}
}
/**
* {@inheritDoc}
*/
@Override
public void startElement(String url, String name, String qName, Attributes attributes) throws SAXException {
if (equalsOrSuffix(qName, "PolicyAttributeTypeDescriptions")) {
inAttributeTypes = true;
}
if (inAttributeTypes) {
attributeTypeHandler.startElement(url, name, qName, attributes);
}
}
/**
* {@inheritDoc}
*/
@Override
public void endElement(String uri, String name, String qName) throws SAXException {
if (equalsOrSuffix(qName, "member")) {
endMember(uri, name, qName);
} else if (equalsOrSuffix(qName, "PolicyAttributeTypeDescriptions")) {
inAttributeTypes = false;
} else if (equalsOrSuffix(qName, "PolicyTypeName")) {
builder.name(currentOrNull(currentText));
} else if (equalsOrSuffix(qName, "Description")) {
builder.description(currentOrNull(currentText));
} else if (inAttributeTypes) {
attributeTypeHandler.endElement(uri, name, qName);
}
currentText = new StringBuilder();
}
protected void endMember(String uri, String name, String qName) throws SAXException {
if (inAttributeTypes) {
builder.attributeMetadata(attributeTypeHandler.getResult());
}
}
/**
* {@inheritDoc}
*/
@Override
public void characters(char ch[], int start, int length) {
if (inAttributeTypes) {
attributeTypeHandler.characters(ch, start, length);
} else {
currentText.append(ch, start, length);
}
}
}

View File

@ -36,7 +36,7 @@ public class ELBTest {
EasyMock.replay(loadBalancerClient);
Assert.assertEquals(1, Iterables.size(ELB.list(loadBalancerClient, options)));
Assert.assertEquals(1, Iterables.size(ELB.listLoadBalancers(loadBalancerClient, options)));
}
@ -56,7 +56,7 @@ public class ELBTest {
EasyMock.replay(loadBalancerClient);
Assert.assertEquals(2, Iterables.size(ELB.list(loadBalancerClient, options)));
Assert.assertEquals(2, Iterables.size(ELB.listLoadBalancers(loadBalancerClient, options)));
}
}

View File

@ -0,0 +1,271 @@
/**
* 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
*
* Unles 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 expres or implied. See the License for the
* specific language governing permisions and limitations
* under the License.
*/
package org.jclouds.elb.features;
import static org.jclouds.elb.options.ListPoliciesOptions.Builder.loadBalancerName;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import java.net.URI;
import java.util.TimeZone;
import org.jclouds.elb.ELBClient;
import org.jclouds.elb.internal.BaseELBClientExpectTest;
import org.jclouds.elb.parse.DescribeLoadBalancerPoliciesResponseTest;
import org.jclouds.elb.parse.DescribeLoadBalancerPolicyTypesResponseTest;
import org.jclouds.elb.parse.GetPolicyResponseTest;
import org.jclouds.elb.parse.GetPolicyTypeResponseTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "PolicyClientExpectTest")
public class PolicyClientExpectTest extends BaseELBClientExpectTest {
public PolicyClientExpectTest() {
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
}
HttpRequest get = HttpRequest.builder()
.method("POST")
.endpoint(URI.create("https://elasticloadbalancing.us-east-1.amazonaws.com/"))
.headers(ImmutableMultimap.<String, String> builder()
.put("Host", "elasticloadbalancing.us-east-1.amazonaws.com")
.build())
.payload(
payloadFromStringWithContentType(
"Action=DescribeLoadBalancerPolicies" +
"&PolicyNames.member.1=name" +
"&Signature=kroGA7XRZYqiw4zgAXkWRdF9ff3RcnZKgvfcPG5f%2Bjs%3D" +
"&SignatureMethod=HmacSHA256" +
"&SignatureVersion=2" +
"&Timestamp=2009-11-08T15%3A54%3A08.897Z" +
"&Version=2012-06-01" +
"&AWSAccessKeyId=identity",
"application/x-www-form-urlencoded"))
.build();
public void testGetWhenResponseIs2xx() throws Exception {
HttpResponse getResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/describe_policy.xml", "text/xml")).build();
ELBClient clientWhenExist = requestSendsResponse(
get, getResponse);
assertEquals(clientWhenExist.getPolicyClientForRegion(null).get("name").toString(), new GetPolicyResponseTest().expected().toString());
}
public void testGetWhenResponseIs404() throws Exception {
HttpResponse getResponse = HttpResponse.builder().statusCode(404).build();
ELBClient clientWhenDontExist = requestSendsResponse(
get, getResponse);
assertNull(clientWhenDontExist.getPolicyClientForRegion(null).get("name"));
}
HttpRequest list = HttpRequest.builder()
.method("POST")
.endpoint(URI.create("https://elasticloadbalancing.us-east-1.amazonaws.com/"))
.headers(ImmutableMultimap.<String, String> builder()
.put("Host", "elasticloadbalancing.us-east-1.amazonaws.com")
.build())
.payload(
payloadFromStringWithContentType(
"Action=DescribeLoadBalancerPolicies" +
"&Signature=0LPrgeysYoQe6PyK2nh3mCgo0lxPNiERxm46W%2FN5GpU%3D" +
"&SignatureMethod=HmacSHA256" +
"&SignatureVersion=2" +
"&Timestamp=2009-11-08T15%3A54%3A08.897Z" +
"&Version=2012-06-01" +
"&AWSAccessKeyId=identity",
"application/x-www-form-urlencoded"))
.build();
public void testListWhenResponseIs2xx() throws Exception {
HttpResponse listResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/describe_policies.xml", "text/xml")).build();
ELBClient clientWhenExist = requestSendsResponse(
list, listResponse);
assertEquals(clientWhenExist.getPolicyClientForRegion(null).list().toString(), new DescribeLoadBalancerPoliciesResponseTest().expected().toString());
}
public void testListWhenResponseIs404() throws Exception {
HttpResponse listResponse = HttpResponse.builder().statusCode(404).build();
ELBClient clientWhenDontExist = requestSendsResponse(
list, listResponse);
clientWhenDontExist.getPolicyClientForRegion(null).list();
}
public void testListWithOptionsWhenResponseIs2xx() throws Exception {
HttpRequest listWithOptions =
HttpRequest.builder()
.method("POST")
.endpoint(URI.create("https://elasticloadbalancing.us-east-1.amazonaws.com/"))
.headers(ImmutableMultimap.<String, String>builder()
.put("Host", "elasticloadbalancing.us-east-1.amazonaws.com")
.build())
.payload(payloadFromStringWithContentType(
"Action=DescribeLoadBalancerPolicies" +
"&LoadBalancerName=moo" +
"&Signature=c8PG1b5wI5YMU0motVEo5Mz7d5w8gy8u51kfCR6SnRI%3D" +
"&SignatureMethod=HmacSHA256" +
"&SignatureVersion=2" +
"&Timestamp=2009-11-08T15%3A54%3A08.897Z" +
"&Version=2012-06-01" +
"&AWSAccessKeyId=identity",
"application/x-www-form-urlencoded"))
.build();
HttpResponse listWithOptionsResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/describe_policies.xml", "text/xml")).build();
ELBClient clientWhenWithOptionsExist = requestSendsResponse(listWithOptions,
listWithOptionsResponse);
assertEquals(clientWhenWithOptionsExist.getPolicyClientForRegion(null).list(loadBalancerName("moo")).toString(),
new DescribeLoadBalancerPoliciesResponseTest().expected().toString());
}
HttpRequest getType = HttpRequest.builder()
.method("POST")
.endpoint(URI.create("https://elasticloadbalancing.us-east-1.amazonaws.com/"))
.headers(ImmutableMultimap.<String, String> builder()
.put("Host", "elasticloadbalancing.us-east-1.amazonaws.com")
.build())
.payload(
payloadFromStringWithContentType(
"Action=DescribeLoadBalancerPolicyTypes" +
"&PolicyTypeNames.member.1=name" +
"&Signature=WC5tQK0TacaxSRrCEKqbpIPFrrrgsBV4I1%2B9W2Lx58M%3D" +
"&SignatureMethod=HmacSHA256" +
"&SignatureVersion=2" +
"&Timestamp=2009-11-08T15%3A54%3A08.897Z" +
"&Version=2012-06-01" +
"&AWSAccessKeyId=identity",
"application/x-www-form-urlencoded"))
.build();
public void testGetTypeWhenResponseIs2xx() throws Exception {
HttpResponse getResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/describe_policy_type.xml", "text/xml")).build();
ELBClient clientWhenExist = requestSendsResponse(
getType, getResponse);
assertEquals(clientWhenExist.getPolicyClientForRegion(null).getType("name").toString(), new GetPolicyTypeResponseTest().expected().toString());
}
public void testGetTypeWhenResponseIs404() throws Exception {
HttpResponse getResponse = HttpResponse.builder().statusCode(404).build();
ELBClient clientWhenDontExist = requestSendsResponse(
getType, getResponse);
assertNull(clientWhenDontExist.getPolicyClientForRegion(null).getType("name"));
}
HttpRequest listTypes = HttpRequest.builder()
.method("POST")
.endpoint(URI.create("https://elasticloadbalancing.us-east-1.amazonaws.com/"))
.headers(ImmutableMultimap.<String, String> builder()
.put("Host", "elasticloadbalancing.us-east-1.amazonaws.com")
.build())
.payload(
payloadFromStringWithContentType(
"Action=DescribeLoadBalancerPolicyTypes" +
"&Signature=%2F1mMjugJD8Zvb%2BK%2FQgOZMYVenlveCKtvGBiHaZVc%2B9w%3D" +
"&SignatureMethod=HmacSHA256" +
"&SignatureVersion=2" +
"&Timestamp=2009-11-08T15%3A54%3A08.897Z" +
"&Version=2012-06-01" +
"&AWSAccessKeyId=identity",
"application/x-www-form-urlencoded"))
.build();
public void testListTypeWhenResponseIs2xx() throws Exception {
HttpResponse listResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/describe_policy_types.xml", "text/xml")).build();
ELBClient clientWhenExist = requestSendsResponse(
listTypes, listResponse);
assertEquals(clientWhenExist.getPolicyClientForRegion(null).listTypes().toString(), new DescribeLoadBalancerPolicyTypesResponseTest().expected().toString());
}
public void testListTypesWhenResponseIs404() throws Exception {
HttpResponse listResponse = HttpResponse.builder().statusCode(404).build();
ELBClient clientWhenDontExist = requestSendsResponse(
listTypes, listResponse);
clientWhenDontExist.getPolicyClientForRegion(null).listTypes();
}
public void testListTypesByNamesWhenResponseIs2xx() throws Exception {
HttpRequest listWithOptions =
HttpRequest.builder()
.method("POST")
.endpoint(URI.create("https://elasticloadbalancing.us-east-1.amazonaws.com/"))
.headers(ImmutableMultimap.<String, String>builder()
.put("Host", "elasticloadbalancing.us-east-1.amazonaws.com")
.build())
.payload(payloadFromStringWithContentType(
"Action=DescribeLoadBalancerPolicyTypes" +
"&PolicyTypeNames.member.1=moo" +
"&Signature=cX8twwn2E6%2B7V3CGZ4ac69NhyolJLsV1nzpQl3wQXW8%3D" +
"&SignatureMethod=HmacSHA256" +
"&SignatureVersion=2" +
"&Timestamp=2009-11-08T15%3A54%3A08.897Z" +
"&Version=2012-06-01" +
"&AWSAccessKeyId=identity",
"application/x-www-form-urlencoded"))
.build();
HttpResponse listWithOptionsResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/describe_policy_types.xml", "text/xml")).build();
ELBClient clientWhenWithOptionsExist = requestSendsResponse(listWithOptions,
listWithOptionsResponse);
assertEquals(clientWhenWithOptionsExist.getPolicyClientForRegion(null).listTypes(ImmutableSet.of("moo")).toString(),
new DescribeLoadBalancerPolicyTypesResponseTest().expected().toString());
}
}

View File

@ -0,0 +1,110 @@
/**
* 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.elb.features;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set;
import javax.annotation.Nullable;
import org.jclouds.elb.domain.AttributeMetadata;
import org.jclouds.elb.domain.Policy;
import org.jclouds.elb.domain.PolicyType;
import org.jclouds.elb.internal.BaseELBClientLiveTest;
import org.testng.Assert;
import org.testng.annotations.Test;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
/**
* @author Adrian Cole
*/
@Test(groups = "live", testName = "PolicyClientLiveTest")
public class PolicyClientLiveTest extends BaseELBClientLiveTest {
private void checkPolicy(Policy policy) {
checkNotNull(policy.getName(), "Name cannot be null for a Policy.");
checkNotNull(policy.getTypeName(), "TypeName cannot be null for a Policy.");
checkNotNull(policy.getAttributes(), "While it is ok to have no attributes, the map cannot be null.");
}
@Test
protected void testDescribePolicies() {
Set<Policy> response = client().list();
for (Policy policy : response) {
checkPolicy(policy);
}
if (response.size() > 0) {
Policy policy = response.iterator().next();
Assert.assertEquals(client().get(policy.getName()), policy);
}
}
private void checkPolicyType(PolicyType policyType) {
checkNotNull(policyType.getName(), "Name cannot be null for a PolicyType.");
checkNotNull(policyType.getDescription(), "Description cannot be null for a PolicyType.");
checkNotNull(policyType.getAttributeMetadata(), "While it is ok to have no attributes, the set cannot be null.");
for (AttributeMetadata<?> attributeMetadata: policyType.getAttributeMetadata()) {
checkAttributeMetadata(attributeMetadata);
}
}
private void checkAttributeMetadata(AttributeMetadata<?> attributeMetadata) {
checkNotNull(attributeMetadata.getName(), "Name cannot be null for a AttributeMetadata.");
checkNotNull(attributeMetadata.getType(), "Type cannot be null for a AttributeMetadata.");
checkNotNull(attributeMetadata.getCardinality(), "Cardinality cannot be null for a AttributeMetadata.");
checkNotNull(attributeMetadata.getDefaultValue(), "While DefaultValue can be null, its optional wrapper cannot");
checkNotNull(attributeMetadata.getDescription(), "While Description can be null, its optional wrapper cannot");
}
@Test
protected void testDescribePolicyTypes() {
Set<PolicyType> response = client().listTypes();
for (PolicyType policyType : response) {
checkPolicyType(policyType);
}
if (response.size() > 0) {
PolicyType policyType = response.iterator().next();
Assert.assertEquals(client().getType(policyType.getName()), policyType);
}
if (response.size() > 0) {
Iterable<String> names = Iterables.transform(response, new Function<PolicyType, String>() {
@Override
public String apply(@Nullable PolicyType input) {
return input.getName();
}
});
Assert.assertEquals(client().listTypes(names), response);
}
}
protected PolicyClient client() {
return context.getApi().getPolicyClientForRegion(null);
}
}

View File

@ -0,0 +1,57 @@
/**
* 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.elb.options;
import static org.jclouds.elb.options.ListPoliciesOptions.Builder.loadBalancerName;
import static org.jclouds.elb.options.ListPoliciesOptions.Builder.name;
import static org.testng.Assert.assertEquals;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
* Tests behavior of {@code ListPoliciesOptions}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ListPoliciesOptionsTest")
public class ListPoliciesOptionsTest {
public void testLoadBalancerName() {
ListPoliciesOptions options = new ListPoliciesOptions().loadBalancerName("FFFFF");
assertEquals(ImmutableSet.of("FFFFF"), options.buildFormParameters().get("LoadBalancerName"));
}
public void testLoadBalancerNameStatic() {
ListPoliciesOptions options = loadBalancerName("FFFFF");
assertEquals(ImmutableSet.of("FFFFF"), options.buildFormParameters().get("LoadBalancerName"));
}
public void testName() {
ListPoliciesOptions options = new ListPoliciesOptions().name("my-load-balancer");
assertEquals(ImmutableSet.of("my-load-balancer"), options.buildFormParameters().get("PolicyNames.member.1"));
}
public void testNameStatic() {
ListPoliciesOptions options = name("my-load-balancer");
assertEquals(ImmutableSet.of("my-load-balancer"), options.buildFormParameters().get("PolicyNames.member.1"));
}
}

View File

@ -0,0 +1,69 @@
/**
* 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.elb.parse;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.util.Set;
import org.jclouds.elb.domain.Policy;
import org.jclouds.elb.xml.DescribeLoadBalancerPoliciesResultHandler;
import org.jclouds.http.functions.BaseHandlerTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "DescribePoliciesResponseTest")
public class DescribeLoadBalancerPoliciesResponseTest extends BaseHandlerTest {
public void test() {
InputStream is = getClass().getResourceAsStream("/describe_policies.xml");
Set<Policy> expected = expected();
DescribeLoadBalancerPoliciesResultHandler handler = injector.getInstance(DescribeLoadBalancerPoliciesResultHandler.class);
Set<Policy> result = factory.create(handler).parse(is);
assertEquals(result.toString(), expected.toString());
}
public Set<Policy> expected() {
return ImmutableSet.of(
Policy.builder()
.name("ELBSample-OpenSSLDefaultNegotiationPolicy")
.typeName("SSLNegotiationPolicyType")
.attribute("Protocol-SSLv2", false)
.attribute("ADH-AES256-SHA", false)
.attribute("DHE-RSA-AES256-SHA", true)
.build(),
Policy.builder()
.name("ELBSample-ELBDefaultNegotiationPolicy")
.typeName("SSLNegotiationPolicyType")
.attribute("Protocol-SSLv2", false)
.attribute("EDH-DSS-DES-CBC3-SHA", false)
.build()
);
}
}

View File

@ -0,0 +1,110 @@
/**
* 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.elb.parse;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.util.Set;
import org.jclouds.elb.domain.AttributeMetadata;
import org.jclouds.elb.domain.AttributeMetadata.Cardinality;
import org.jclouds.elb.domain.PolicyType;
import org.jclouds.elb.xml.DescribeLoadBalancerPolicyTypesResultHandler;
import org.jclouds.http.functions.BaseHandlerTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "DescribeLoadBalancerPolicyTypesResponseTest")
public class DescribeLoadBalancerPolicyTypesResponseTest extends BaseHandlerTest {
public void test() {
InputStream is = getClass().getResourceAsStream("/describe_policy_types.xml");
Set<PolicyType> expected = expected();
DescribeLoadBalancerPolicyTypesResultHandler handler = injector.getInstance(DescribeLoadBalancerPolicyTypesResultHandler.class);
Set<PolicyType> result = factory.create(handler).parse(is);
assertEquals(result.toString(), expected.toString());
}
public Set<PolicyType> expected() {
return ImmutableSet.<PolicyType>builder()
.add(PolicyType.builder()
.attributeMetadata(AttributeMetadata.<String>builder()
.name("PublicKey")
.type(String.class)
.rawType("String")
.cardinality(Cardinality.ONE)
.build())
.name("PublicKeyPolicyType")
.description("Policy containing a list of public keys to accept when authenticating the back-end server(s). This policy cannot be applied directly to back-end servers or listeners but must be part of a BackendServerAuthenticationPolicyType.")
.build())
.add(PolicyType.builder()
.attributeMetadata(AttributeMetadata.<String>builder()
.name("CookieName")
.type(String.class)
.rawType("String")
.cardinality(Cardinality.ONE).build())
.name("AppCookieStickinessPolicyType")
.description("Stickiness policy with session lifetimes controlled by the lifetime of the application-generated cookie. This policy can be associated only with HTTP/HTTPS listeners.")
.build())
.add(PolicyType.builder()
.attributeMetadata(AttributeMetadata.<Long>builder()
.name("CookieExpirationPeriod")
.type(Long.class)
.rawType("Long")
.cardinality(Cardinality.ZERO_OR_ONE).build())
.name("LBCookieStickinessPolicyType")
.description("Stickiness policy with session lifetimes controlled by the browser (user-agent) or a specified expiration period. This policy can be associated only with HTTP/HTTPS listeners.")
.build())
.add(PolicyType.builder()
.attributeMetadata(AttributeMetadata.<Boolean>builder()
.name("Protocol-SSLv2")
.type(Boolean.class)
.rawType("Boolean")
.defaultValue(false)
.cardinality(Cardinality.ZERO_OR_ONE).build())
.attributeMetadata(AttributeMetadata.<Boolean>builder()
.name("Protocol-TLSv1")
.type(Boolean.class)
.rawType("Boolean")
.defaultValue(true)
.cardinality(Cardinality.ZERO_OR_ONE).build())
.name("SSLNegotiationPolicyType")
.description("Listener policy that defines the ciphers and protocols that will be accepted by the load balancer. This policy can be associated only with HTTPS/SSL listeners.")
.build())
.add(PolicyType.builder()
.attributeMetadata(AttributeMetadata.<String>builder()
.name("PublicKeyPolicyName")
.type(String.class)
.rawType("PolicyName")
.cardinality(Cardinality.ONE_OR_MORE).build())
.name("BackendServerAuthenticationPolicyType")
.description("Policy that controls authentication to back-end server(s) and contains one or more policies, such as an instance of a PublicKeyPolicyType. This policy can be associated only with back-end servers that are using HTTPS/SSL.")
.build()).build();
}
}

View File

@ -0,0 +1,58 @@
/**
* 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.elb.parse;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import org.jclouds.elb.domain.Policy;
import org.jclouds.elb.xml.PolicyHandler;
import org.jclouds.http.functions.BaseHandlerTest;
import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "GetPolicyResponseTest")
public class GetPolicyResponseTest extends BaseHandlerTest {
public void test() {
InputStream is = getClass().getResourceAsStream("/describe_policy.xml");
Policy expected = expected();
PolicyHandler handler = injector.getInstance(PolicyHandler.class);
Policy result = factory.create(handler).parse(is);
assertEquals(result, expected);
assertEquals(result.getAttributes(), expected.getAttributes());
}
public Policy expected() {
return Policy.builder()
.name("ELBSample-OpenSSLDefaultNegotiationPolicy")
.typeName("SSLNegotiationPolicyType")
.attribute("Protocol-SSLv2", false)
.attribute("ADH-AES256-SHA", false)
.attribute("DHE-RSA-AES256-SHA", true)
.build();
}
}

View File

@ -0,0 +1,62 @@
/**
* 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.elb.parse;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import org.jclouds.elb.domain.AttributeMetadata;
import org.jclouds.elb.domain.AttributeMetadata.Cardinality;
import org.jclouds.elb.domain.PolicyType;
import org.jclouds.elb.xml.PolicyTypeHandler;
import org.jclouds.http.functions.BaseHandlerTest;
import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "GetPolicyTypeResponseTest")
public class GetPolicyTypeResponseTest extends BaseHandlerTest {
public void test() {
InputStream is = getClass().getResourceAsStream("/describe_policy_type.xml");
PolicyType expected = expected();
PolicyTypeHandler handler = injector.getInstance(PolicyTypeHandler.class);
PolicyType result = factory.create(handler).parse(is);
assertEquals(result, expected);
}
public PolicyType expected() {
return PolicyType.builder()
.attributeMetadata(AttributeMetadata.<String>builder()
.name("PublicKey")
.type(String.class)
.rawType("String")
.cardinality(Cardinality.ONE)
.build())
.name("PublicKeyPolicyType")
.description("Policy containing a list of public keys to accept when authenticating the back-end server(s). This policy cannot be applied directly to back-end servers or listeners but must be part of a BackendServerAuthenticationPolicyType.")
.build();
}
}

View File

@ -0,0 +1,41 @@
<DescribeLoadBalancerPoliciesResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
<DescribeLoadBalancerPoliciesResult>
<PolicyDescriptions>
<member>
<PolicyName>ELBSample-OpenSSLDefaultNegotiationPolicy</PolicyName>
<PolicyTypeName>SSLNegotiationPolicyType</PolicyTypeName>
<PolicyAttributeDescriptions>
<member>
<AttributeName>Protocol-SSLv2</AttributeName>
<AttributeValue>false</AttributeValue>
</member>
<member>
<AttributeName>ADH-AES256-SHA</AttributeName>
<AttributeValue>false</AttributeValue>
</member>
<member>
<AttributeName>DHE-RSA-AES256-SHA</AttributeName>
<AttributeValue>true</AttributeValue>
</member>
</PolicyAttributeDescriptions>
</member>
<member>
<PolicyName>ELBSample-ELBDefaultNegotiationPolicy</PolicyName>
<PolicyTypeName>SSLNegotiationPolicyType</PolicyTypeName>
<PolicyAttributeDescriptions>
<member>
<AttributeName>Protocol-SSLv2</AttributeName>
<AttributeValue>false</AttributeValue>
</member>
<member>
<AttributeName>EDH-DSS-DES-CBC3-SHA</AttributeName>
<AttributeValue>false</AttributeValue>
</member>
</PolicyAttributeDescriptions>
</member>
</PolicyDescriptions>
</DescribeLoadBalancerPoliciesResult>
<ResponseMetadata>
<RequestId>a60aacd5-c3c0-11e1-afb7-8f588567225c</RequestId>
</ResponseMetadata>
</DescribeLoadBalancerPoliciesResponse>

View File

@ -0,0 +1,27 @@
<DescribeLoadBalancerPoliciesResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
<DescribeLoadBalancerPoliciesResult>
<PolicyDescriptions>
<member>
<PolicyName>ELBSample-OpenSSLDefaultNegotiationPolicy</PolicyName>
<PolicyTypeName>SSLNegotiationPolicyType</PolicyTypeName>
<PolicyAttributeDescriptions>
<member>
<AttributeName>Protocol-SSLv2</AttributeName>
<AttributeValue>false</AttributeValue>
</member>
<member>
<AttributeName>ADH-AES256-SHA</AttributeName>
<AttributeValue>false</AttributeValue>
</member>
<member>
<AttributeName>DHE-RSA-AES256-SHA</AttributeName>
<AttributeValue>true</AttributeValue>
</member>
</PolicyAttributeDescriptions>
</member>
</PolicyDescriptions>
</DescribeLoadBalancerPoliciesResult>
<ResponseMetadata>
<RequestId>a60aacd5-c3c0-11e1-afb7-8f588567225c</RequestId>
</ResponseMetadata>
</DescribeLoadBalancerPoliciesResponse>

View File

@ -0,0 +1,20 @@
<DescribeLoadBalancerPolicyTypesResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
<DescribeLoadBalancerPolicyTypesResult>
<PolicyTypeDescriptions>
<member>
<PolicyAttributeTypeDescriptions>
<member>
<AttributeName>PublicKey</AttributeName>
<AttributeType>String</AttributeType>
<Cardinality>ONE</Cardinality>
</member>
</PolicyAttributeTypeDescriptions>
<PolicyTypeName>PublicKeyPolicyType</PolicyTypeName>
<Description>Policy containing a list of public keys to accept when authenticating the back-end server(s). This policy cannot be applied directly to back-end servers or listeners but must be part of a BackendServerAuthenticationPolicyType.</Description>
</member>
</PolicyTypeDescriptions>
</DescribeLoadBalancerPolicyTypesResult>
<ResponseMetadata>
<RequestId>261327c5-c3d7-11e1-8582-35377554a47d</RequestId>
</ResponseMetadata>
</DescribeLoadBalancerPolicyTypesResponse>

View File

@ -0,0 +1,71 @@
<DescribeLoadBalancerPolicyTypesResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
<DescribeLoadBalancerPolicyTypesResult>
<PolicyTypeDescriptions>
<member>
<PolicyAttributeTypeDescriptions>
<member>
<AttributeName>PublicKey</AttributeName>
<AttributeType>String</AttributeType>
<Cardinality>ONE</Cardinality>
</member>
</PolicyAttributeTypeDescriptions>
<PolicyTypeName>PublicKeyPolicyType</PolicyTypeName>
<Description>Policy containing a list of public keys to accept when authenticating the back-end server(s). This policy cannot be applied directly to back-end servers or listeners but must be part of a BackendServerAuthenticationPolicyType.</Description>
</member>
<member>
<PolicyAttributeTypeDescriptions>
<member>
<AttributeName>CookieName</AttributeName>
<AttributeType>String</AttributeType>
<Cardinality>ONE</Cardinality>
</member>
</PolicyAttributeTypeDescriptions>
<PolicyTypeName>AppCookieStickinessPolicyType</PolicyTypeName>
<Description>Stickiness policy with session lifetimes controlled by the lifetime of the application-generated cookie. This policy can be associated only with HTTP/HTTPS listeners.</Description>
</member>
<member>
<PolicyAttributeTypeDescriptions>
<member>
<AttributeName>CookieExpirationPeriod</AttributeName>
<AttributeType>Long</AttributeType>
<Cardinality>ZERO_OR_ONE</Cardinality>
</member>
</PolicyAttributeTypeDescriptions>
<PolicyTypeName>LBCookieStickinessPolicyType</PolicyTypeName>
<Description>Stickiness policy with session lifetimes controlled by the browser (user-agent) or a specified expiration period. This policy can be associated only with HTTP/HTTPS listeners.</Description>
</member>
<member>
<PolicyAttributeTypeDescriptions>
<member>
<AttributeName>Protocol-SSLv2</AttributeName>
<AttributeType>Boolean</AttributeType>
<DefaultValue>false</DefaultValue>
<Cardinality>ZERO_OR_ONE</Cardinality>
</member>
<member>
<AttributeName>Protocol-TLSv1</AttributeName>
<AttributeType>Boolean</AttributeType>
<DefaultValue>true</DefaultValue>
<Cardinality>ZERO_OR_ONE</Cardinality>
</member>
</PolicyAttributeTypeDescriptions>
<PolicyTypeName>SSLNegotiationPolicyType</PolicyTypeName>
<Description>Listener policy that defines the ciphers and protocols that will be accepted by the load balancer. This policy can be associated only with HTTPS/SSL listeners.</Description>
</member>
<member>
<PolicyAttributeTypeDescriptions>
<member>
<AttributeName>PublicKeyPolicyName</AttributeName>
<AttributeType>PolicyName</AttributeType>
<Cardinality>ONE_OR_MORE</Cardinality>
</member>
</PolicyAttributeTypeDescriptions>
<PolicyTypeName>BackendServerAuthenticationPolicyType</PolicyTypeName>
<Description>Policy that controls authentication to back-end server(s) and contains one or more policies, such as an instance of a PublicKeyPolicyType. This policy can be associated only with back-end servers that are using HTTPS/SSL.</Description>
</member>
</PolicyTypeDescriptions>
</DescribeLoadBalancerPolicyTypesResult>
<ResponseMetadata>
<RequestId>261327c5-c3d7-11e1-8582-35377554a47d</RequestId>
</ResponseMetadata>
</DescribeLoadBalancerPolicyTypesResponse>

View File

@ -1,136 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!--
For more configuration infromation and examples see the Apache
Log4j website: http://logging.apache.org/log4j/
-->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false">
<!-- A time/date based rolling appender -->
<appender name="WIREFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-wire.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<!-- A time/date based rolling appender -->
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<!-- A time/date based rolling appender -->
<appender name="LOADBALANCERFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-loadbalancer.log" />
<param name="Append" value="true" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
</layout>
</appender>
<!-- A time/date based rolling appender -->
<appender name="COMPUTEFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-compute.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<appender name="ASYNCCOMPUTE" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="COMPUTEFILE" />
</appender>
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="FILE" />
</appender>
<appender name="ASYNCWIRE" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="WIREFILE" />
</appender>
<appender name="ASYNCLOADBALANCER" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="LOADBALANCERFILE" />
</appender>
<!-- ================ -->
<!-- Limit categories -->
<!-- ================ -->
<category name="org.jclouds">
<priority value="DEBUG" />
<appender-ref ref="ASYNC" />
</category>
<category name="jclouds.headers">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
<category name="jclouds.wire">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
<category name="jclouds.loadbalancer">
<priority value="DEBUG" />
<appender-ref ref="ASYNCLOADBALANCER" />
</category>
<category name="jclouds.compute">
<priority value="TRACE" />
<appender-ref ref="ASYNCCOMPUTE" />
</category>
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
<root>
<priority value="WARN" />
</root>
</log4j:configuration>

View File

@ -0,0 +1,64 @@
<?xml version="1.0"?>
<configuration scan="false">
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>target/test-data/jclouds.log</file>
<encoder>
<Pattern>%d %-5p [%c] [%thread] %m%n</Pattern>
</encoder>
</appender>
<appender name="WIREFILE" class="ch.qos.logback.core.FileAppender">
<file>target/test-data/jclouds-wire.log</file>
<encoder>
<Pattern>%d %-5p [%c] [%thread] %m%n</Pattern>
</encoder>
</appender>
<appender name="COMPUTEFILE" class="ch.qos.logback.core.FileAppender">
<file>target/test-data/jclouds-compute.log</file>
<encoder>
<Pattern>%d %-5p [%c] [%thread] %m%n</Pattern>
</encoder>
</appender>
<appender name="SSHFILE" class="ch.qos.logback.core.FileAppender">
<file>target/test-data/jclouds-ssh.log</file>
<encoder>
<Pattern>%d %-5p [%c] [%thread] %m%n</Pattern>
</encoder>
</appender>
<root>
<level value="warn" />
</root>
<logger name="org.jclouds">
<level value="DEBUG" />
<appender-ref ref="FILE" />
</logger>
<logger name="jclouds.wire">
<level value="DEBUG" />
<appender-ref ref="WIREFILE" />
</logger>
<logger name="jclouds.headers">
<level value="DEBUG" />
<appender-ref ref="WIREFILE" />
</logger>
<logger name="jclouds.compute">
<level value="DEBUG" />
<appender-ref ref="COMPUTEFILE" />
</logger>
<logger name="jclouds.ssh">
<level value="DEBUG" />
<appender-ref ref="SSHFILE" />
</logger>
</configuration>