mirror of https://github.com/apache/jclouds.git
Issue 852: added availability zone functions
This commit is contained in:
parent
333b77c628
commit
8e88c53a3a
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.aws.elb.features;
|
||||
|
||||
import org.jclouds.elb.features.AvailabilityZoneClientLiveTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", testName = "AWSAvailabilityZoneClientLiveTest")
|
||||
public class AWSAvailabilityZoneClientLiveTest extends AvailabilityZoneClientLiveTest {
|
||||
|
||||
public AWSAvailabilityZoneClientLiveTest() {
|
||||
provider = "aws-elb";
|
||||
}
|
||||
|
||||
}
|
|
@ -26,6 +26,7 @@ import org.jclouds.aws.filters.FormSigner;
|
|||
import org.jclouds.elb.features.InstanceAsyncClient;
|
||||
import org.jclouds.elb.features.LoadBalancerAsyncClient;
|
||||
import org.jclouds.elb.features.PolicyAsyncClient;
|
||||
import org.jclouds.elb.features.AvailabilityZoneAsyncClient;
|
||||
import org.jclouds.location.Region;
|
||||
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
|
@ -86,4 +87,14 @@ public interface ELBAsyncClient {
|
|||
InstanceAsyncClient getInstanceClientForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to AvailabilityZone features.
|
||||
*/
|
||||
@Delegate
|
||||
AvailabilityZoneAsyncClient getAvailabilityZoneClient();
|
||||
|
||||
@Delegate
|
||||
AvailabilityZoneAsyncClient getAvailabilityZoneClientForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.jclouds.concurrent.Timeout;
|
|||
import org.jclouds.elb.features.InstanceClient;
|
||||
import org.jclouds.elb.features.LoadBalancerClient;
|
||||
import org.jclouds.elb.features.PolicyClient;
|
||||
import org.jclouds.elb.features.AvailabilityZoneClient;
|
||||
import org.jclouds.location.Region;
|
||||
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
|
@ -82,5 +83,15 @@ public interface ELBClient {
|
|||
@Delegate
|
||||
InstanceClient getInstanceClientForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Zone features.
|
||||
*/
|
||||
@Delegate
|
||||
AvailabilityZoneClient getAvailabilityZoneClient();
|
||||
|
||||
@Delegate
|
||||
AvailabilityZoneClient getAvailabilityZoneClientForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ 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.elb.features.AvailabilityZoneAsyncClient;
|
||||
import org.jclouds.elb.features.AvailabilityZoneClient;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
@ -45,6 +47,7 @@ public class ELBRestClientModule extends FormSigningRestClientModule<ELBClient,
|
|||
.put(LoadBalancerClient.class, LoadBalancerAsyncClient.class)
|
||||
.put(PolicyClient.class, PolicyAsyncClient.class)
|
||||
.put(InstanceClient.class, InstanceAsyncClient.class)
|
||||
.put(AvailabilityZoneClient.class, AvailabilityZoneAsyncClient.class)
|
||||
.build();
|
||||
|
||||
public ELBRestClientModule() {
|
||||
|
|
|
@ -32,7 +32,7 @@ import com.google.common.base.Optional;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class InstanceState {
|
||||
public class InstanceHealth {
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
|
@ -50,7 +50,7 @@ public class InstanceState {
|
|||
protected String state;
|
||||
|
||||
/**
|
||||
* @see InstanceState#getDescription()
|
||||
* @see InstanceHealth#getDescription()
|
||||
*/
|
||||
public Builder description(String description) {
|
||||
this.description = description;
|
||||
|
@ -58,7 +58,7 @@ public class InstanceState {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see InstanceState#getInstanceId()
|
||||
* @see InstanceHealth#getInstanceId()
|
||||
*/
|
||||
public Builder instanceId(String instanceId) {
|
||||
this.instanceId = instanceId;
|
||||
|
@ -66,7 +66,7 @@ public class InstanceState {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see InstanceState#getReasonCode()
|
||||
* @see InstanceHealth#getReasonCode()
|
||||
*/
|
||||
public Builder reasonCode(String reasonCode) {
|
||||
this.reasonCode = Optional.fromNullable(reasonCode);
|
||||
|
@ -74,18 +74,18 @@ public class InstanceState {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see InstanceState#getState()
|
||||
* @see InstanceHealth#getState()
|
||||
*/
|
||||
public Builder state(String state) {
|
||||
this.state = state;
|
||||
return this;
|
||||
}
|
||||
|
||||
public InstanceState build() {
|
||||
return new InstanceState(description, instanceId, reasonCode, state);
|
||||
public InstanceHealth build() {
|
||||
return new InstanceHealth(description, instanceId, reasonCode, state);
|
||||
}
|
||||
|
||||
public Builder fromAttributeMetadata(InstanceState in) {
|
||||
public Builder fromAttributeMetadata(InstanceHealth in) {
|
||||
return this.description(in.getDescription()).instanceId(in.getInstanceId())
|
||||
.reasonCode(in.getReasonCode().orNull()).state(in.getState());
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ public class InstanceState {
|
|||
protected final Optional<String> reasonCode;
|
||||
protected final String state;
|
||||
|
||||
protected InstanceState(String description, String instanceId, Optional<String> reasonCode, String state) {
|
||||
protected InstanceHealth(String description, String instanceId, Optional<String> reasonCode, String state) {
|
||||
this.description = checkNotNull(description, "description");
|
||||
this.instanceId = checkNotNull(instanceId, "instanceId");
|
||||
this.reasonCode = checkNotNull(reasonCode, "reasonCode");
|
||||
|
@ -151,7 +151,7 @@ public class InstanceState {
|
|||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
InstanceState other = InstanceState.class.cast(obj);
|
||||
InstanceHealth other = InstanceHealth.class.cast(obj);
|
||||
return Objects.equal(this.description, other.description) && Objects.equal(this.instanceId, other.instanceId)
|
||||
&& Objects.equal(this.reasonCode, other.reasonCode) && Objects.equal(this.state, other.state);
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
/**
|
||||
* 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 org.jclouds.aws.reference.FormParameters.ACTION;
|
||||
|
||||
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.BindAvailabilityZonesToIndexedFormParams;
|
||||
import org.jclouds.elb.xml.AvailabilityZonesResultHandler;
|
||||
import org.jclouds.rest.annotations.BinderParam;
|
||||
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 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 AvailabilityZoneClient
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(FormSigner.class)
|
||||
@VirtualHost
|
||||
public interface AvailabilityZoneAsyncClient {
|
||||
|
||||
/**
|
||||
* @see AvailabilityZoneClient#addAvailabilityZonesToLoadBalancer
|
||||
*/
|
||||
@POST
|
||||
@Path("/")
|
||||
@XMLResponseParser(AvailabilityZonesResultHandler.class)
|
||||
@FormParams(keys = ACTION, values = "EnableAvailabilityZonesForLoadBalancer")
|
||||
ListenableFuture<Set<String>> addAvailabilityZonesToLoadBalancer(
|
||||
@BinderParam(BindAvailabilityZonesToIndexedFormParams.class) Iterable<String> zones,
|
||||
@FormParam("LoadBalancerName") String loadBalancerName);
|
||||
|
||||
|
||||
/**
|
||||
* @see AvailabilityZoneClient#addAvailabilityZoneToLoadBalancer
|
||||
*/
|
||||
@POST
|
||||
@Path("/")
|
||||
@XMLResponseParser(AvailabilityZonesResultHandler.class)
|
||||
@FormParams(keys = ACTION, values = "EnableAvailabilityZonesForLoadBalancer")
|
||||
ListenableFuture<Set<String>> addAvailabilityZoneToLoadBalancer(
|
||||
@FormParam("AvailabilityZones.member.1") String zone,
|
||||
@FormParam("LoadBalancerName") String loadBalancerName);
|
||||
|
||||
/**
|
||||
* @see AvailabilityZoneClient#removeAvailabilityZonesFromLoadBalancer
|
||||
*/
|
||||
@POST
|
||||
@Path("/")
|
||||
@XMLResponseParser(AvailabilityZonesResultHandler.class)
|
||||
@FormParams(keys = ACTION, values = "DisableAvailabilityZonesForLoadBalancer")
|
||||
ListenableFuture<Set<String>> removeAvailabilityZonesFromLoadBalancer(
|
||||
@BinderParam(BindAvailabilityZonesToIndexedFormParams.class) Iterable<String> zones,
|
||||
@FormParam("LoadBalancerName") String loadBalancerName);
|
||||
|
||||
/**
|
||||
* @see AvailabilityZoneClient#removeAvailabilityZoneFromLoadBalancer
|
||||
*/
|
||||
@POST
|
||||
@Path("/")
|
||||
@XMLResponseParser(AvailabilityZonesResultHandler.class)
|
||||
@FormParams(keys = ACTION, values = "DisableAvailabilityZonesForLoadBalancer")
|
||||
ListenableFuture<Set<String>> removeAvailabilityZoneFromLoadBalancer(
|
||||
@FormParam("AvailabilityZones.member.1") String zone,
|
||||
@FormParam("LoadBalancerName") String loadBalancerName);
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Provides access to Amazon ELB via the Query API
|
||||
* <p/>
|
||||
*
|
||||
* @see <a href="http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference" />
|
||||
* @see AvailabilityZoneAsyncClient
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||
public interface AvailabilityZoneClient {
|
||||
|
||||
/**
|
||||
* Adds one or more EC2 Availability Zones to the LoadBalancer.
|
||||
*
|
||||
* The LoadBalancer evenly distributes requests across all its registered Availability Zones that
|
||||
* contain instances. As a result, the client must ensure that its LoadBalancer is appropriately
|
||||
* scaled for each registered Availability Zone.
|
||||
*
|
||||
* <h4>Note</h4>
|
||||
*
|
||||
* The new EC2 Availability Zones to be added must be in the same EC2 Region as the Availability
|
||||
* Zones for which the LoadBalancer was created.
|
||||
*
|
||||
* @param zones
|
||||
* A list of new Availability Zones for the LoadBalancer. Each Availability Zone must
|
||||
* be in the same Region as the LoadBalancer.
|
||||
*
|
||||
* @param loadBalancerName
|
||||
* The name associated with the LoadBalancer. The name must be unique within the client
|
||||
* AWS account.
|
||||
*
|
||||
* @return An updated list of Availability Zones for the LoadBalancer.
|
||||
*/
|
||||
Set<String> addAvailabilityZonesToLoadBalancer(Iterable<String> zones, String loadBalancerName);
|
||||
|
||||
Set<String> addAvailabilityZoneToLoadBalancer(String zone, String loadBalancerName);
|
||||
|
||||
/**
|
||||
* Removes the specified EC2 Availability Zones from the set of configured Availability Zones for
|
||||
* the LoadBalancer.
|
||||
*
|
||||
*
|
||||
* There must be at least one Availability Zone registered with a LoadBalancer at all times. A
|
||||
* client cannot remove all the Availability Zones from a LoadBalancer. Once an Availability Zone
|
||||
* is removed, all the instances registered with the LoadBalancer that are in the removed
|
||||
* Availability Zone go into the OutOfService state. Upon Availability Zone removal, the
|
||||
* LoadBalancer attempts to equally balance the traffic among its remaining usable Availability
|
||||
* Zones. Trying to remove an Availability Zone that was not associated with the LoadBalancer
|
||||
* does nothing.
|
||||
*
|
||||
* <h4>Note</h4>
|
||||
*
|
||||
* In order for this call to be successful, the client must have created the LoadBalancer. The
|
||||
* client must provide the same account credentials as those that were used to create the
|
||||
* LoadBalancer.
|
||||
*
|
||||
* @param zones
|
||||
* A list of Availability Zones to be removed from the LoadBalancer.
|
||||
*
|
||||
* <h4>Note</h4>
|
||||
*
|
||||
* There must be at least one Availability Zone registered with a LoadBalancer at all
|
||||
* times. The client cannot remove all the Availability Zones from a LoadBalancer.
|
||||
* Specified Availability Zones must be in the same Region.
|
||||
*
|
||||
*
|
||||
* @param loadBalancerName
|
||||
* The name associated with the LoadBalancer. The name must be unique within the client
|
||||
* AWS account.
|
||||
*
|
||||
* @return A list of updated Availability Zones for the LoadBalancer.
|
||||
*/
|
||||
Set<String> removeAvailabilityZonesFromLoadBalancer(Iterable<String> zones, String loadBalancerName);
|
||||
|
||||
Set<String> removeAvailabilityZoneFromLoadBalancer(String zone, String loadBalancerName);
|
||||
|
||||
}
|
|
@ -28,8 +28,8 @@ import javax.ws.rs.Path;
|
|||
|
||||
import org.jclouds.aws.filters.FormSigner;
|
||||
import org.jclouds.elb.binders.BindInstanceIdsToIndexedFormParams;
|
||||
import org.jclouds.elb.domain.InstanceState;
|
||||
import org.jclouds.elb.xml.DescribeLoadBalancerPoliciesResultHandler;
|
||||
import org.jclouds.elb.domain.InstanceHealth;
|
||||
import org.jclouds.elb.xml.DescribeInstanceHealthResultHandler;
|
||||
import org.jclouds.elb.xml.InstancesResultHandler;
|
||||
import org.jclouds.rest.annotations.BinderParam;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
|
@ -55,25 +55,25 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
public interface InstanceAsyncClient {
|
||||
|
||||
/**
|
||||
* @see InstanceClient#getStateOfInstancesOfLoadBalancer(String)
|
||||
* @see InstanceClient#getHealthOfInstancesOfLoadBalancer(String)
|
||||
*/
|
||||
@POST
|
||||
@Path("/")
|
||||
@XMLResponseParser(DescribeLoadBalancerPoliciesResultHandler.class)
|
||||
@XMLResponseParser(DescribeInstanceHealthResultHandler.class)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
@FormParams(keys = "Action", values = "DescribeInstanceHealth")
|
||||
ListenableFuture<Set<InstanceState>> getStateOfInstancesOfLoadBalancer(
|
||||
ListenableFuture<Set<InstanceHealth>> getHealthOfInstancesOfLoadBalancer(
|
||||
@FormParam("LoadBalancerName") String loadBalancerName);
|
||||
|
||||
/**
|
||||
* @see InstanceClient#getStateOfInstancesOfLoadBalancer(Iterable<String>, String)
|
||||
* @see InstanceClient#getHealthOfInstancesOfLoadBalancer(Iterable, String)
|
||||
*/
|
||||
@POST
|
||||
@Path("/")
|
||||
@XMLResponseParser(DescribeLoadBalancerPoliciesResultHandler.class)
|
||||
@XMLResponseParser(DescribeInstanceHealthResultHandler.class)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
@FormParams(keys = "Action", values = "DescribeInstanceHealth")
|
||||
ListenableFuture<Set<InstanceState>> getStateOfInstancesOfLoadBalancer(
|
||||
ListenableFuture<Set<InstanceHealth>> getHealthOfInstancesOfLoadBalancer(
|
||||
@BinderParam(BindInstanceIdsToIndexedFormParams.class) Iterable<String> instanceIds,
|
||||
@FormParam("LoadBalancerName") String loadBalancerName);
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import java.util.Set;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.elb.domain.InstanceState;
|
||||
import org.jclouds.elb.domain.InstanceHealth;
|
||||
|
||||
/**
|
||||
* Provides access to Amazon ELB via the Query API
|
||||
|
@ -50,7 +50,7 @@ public interface InstanceClient {
|
|||
*
|
||||
* @return state of all instances of the load balancer
|
||||
*/
|
||||
Set<InstanceState> getStateOfInstancesOfLoadBalancer(String loadBalancerName);
|
||||
Set<InstanceHealth> getHealthOfInstancesOfLoadBalancer(String loadBalancerName);
|
||||
|
||||
/**
|
||||
* Returns the current state of the instances of the specified LoadBalancer.
|
||||
|
@ -69,7 +69,7 @@ public interface InstanceClient {
|
|||
*
|
||||
* @return state of all instances of the load balancer
|
||||
*/
|
||||
Set<InstanceState> getStateOfInstancesOfLoadBalancer(Iterable<String> instanceIds, String loadBalancerName);
|
||||
Set<InstanceHealth> getHealthOfInstancesOfLoadBalancer(Iterable<String> instanceIds, String loadBalancerName);
|
||||
|
||||
/**
|
||||
* Adds new instances to the LoadBalancer.
|
||||
|
|
|
@ -45,6 +45,7 @@ import org.jclouds.logging.Logger;
|
|||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -71,7 +72,7 @@ public class ELBLoadBalanceNodesStrategy implements LoadBalanceNodesStrategy {
|
|||
checkNotNull(location, "location");
|
||||
String region = getRegionFromLocationOrNull(location);
|
||||
|
||||
Set<String> availabilityZones = ImmutableSet.copyOf(transform(nodes, new Function<NodeMetadata, String>() {
|
||||
Set<String> zonesDesired = ImmutableSet.copyOf(transform(nodes, new Function<NodeMetadata, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(NodeMetadata from) {
|
||||
|
@ -79,16 +80,22 @@ public class ELBLoadBalanceNodesStrategy implements LoadBalanceNodesStrategy {
|
|||
}
|
||||
}));
|
||||
|
||||
logger.debug(">> creating loadBalancer(%s)", name);
|
||||
logger.debug(">> creating loadBalancer(%s) in zones(%s)", name, zonesDesired);
|
||||
try {
|
||||
String dnsName = client.getLoadBalancerClientForRegion(region).createLoadBalancerListeningInAvailabilityZones(
|
||||
name,
|
||||
ImmutableSet.of(Listener.builder().port(loadBalancerPort).instancePort(instancePort)
|
||||
.protocol(Protocol.valueOf(protocol)).build()), availabilityZones);
|
||||
.protocol(Protocol.valueOf(protocol)).build()), zonesDesired);
|
||||
logger.debug("<< created loadBalancer(%s) dnsName(%s)", name, dnsName);
|
||||
} catch (IllegalStateException e) {
|
||||
logger.debug("<< reusing loadBalancer(%s)", name);
|
||||
// TODO: converge availability zones
|
||||
logger.debug("<< converging zones(%s) in loadBalancer(%s)", zonesDesired, name);
|
||||
Set<String> currentZones = client.getLoadBalancerClient().get(name).getAvailabilityZones();
|
||||
Set<String> zonesToAdd = Sets.difference(zonesDesired, currentZones);
|
||||
if (zonesToAdd.size() > 0)
|
||||
currentZones = client.getAvailabilityZoneClient().addAvailabilityZonesToLoadBalancer(zonesToAdd, name);
|
||||
Set<String> zonesToRemove = Sets.difference(currentZones, zonesDesired);
|
||||
if (zonesToRemove.size() > 0)
|
||||
client.getAvailabilityZoneClient().addAvailabilityZonesToLoadBalancer(zonesToRemove, name);
|
||||
}
|
||||
|
||||
Set<String> instanceIds = ImmutableSet.copyOf(transform(nodes, new Function<NodeMetadata, String>() {
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* 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 java.util.Set;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
public class AvailabilityZonesResultHandler extends ParseSax.HandlerWithResult<Set<String>> {
|
||||
|
||||
private Set<String> zones = Sets.newLinkedHashSet();
|
||||
private StringBuilder currentText = new StringBuilder();
|
||||
|
||||
public void endElement(String uri, String localName, String qName) {
|
||||
if (qName.equals("member"))
|
||||
zones.add(currentText.toString().trim());
|
||||
currentText = new StringBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getResult() {
|
||||
return zones;
|
||||
}
|
||||
|
||||
public void characters(char ch[], int start, int length) {
|
||||
currentText.append(ch, start, length);
|
||||
}
|
||||
}
|
|
@ -22,7 +22,7 @@ import static org.jclouds.util.SaxUtils.equalsOrSuffix;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.elb.domain.InstanceState;
|
||||
import org.jclouds.elb.domain.InstanceHealth;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
@ -39,12 +39,12 @@ import com.google.inject.Inject;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
public class DescribeInstanceHealthResultHandler extends
|
||||
ParseSax.HandlerForGeneratedRequestWithResult<Set<InstanceState>> {
|
||||
ParseSax.HandlerForGeneratedRequestWithResult<Set<InstanceHealth>> {
|
||||
|
||||
private final InstanceStateHandler instanceStateHandler;
|
||||
|
||||
private StringBuilder currentText = new StringBuilder();
|
||||
private Builder<InstanceState> instanceStates = ImmutableSet.<InstanceState> builder();
|
||||
private Builder<InstanceHealth> instanceStates = ImmutableSet.<InstanceHealth> builder();
|
||||
private boolean inStates;
|
||||
|
||||
protected int memberDepth;
|
||||
|
@ -58,7 +58,7 @@ public class DescribeInstanceHealthResultHandler extends
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Set<InstanceState> getResult() {
|
||||
public Set<InstanceHealth> getResult() {
|
||||
return instanceStates.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.jclouds.elb.xml;
|
|||
import static org.jclouds.util.SaxUtils.currentOrNull;
|
||||
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
|
||||
|
||||
import org.jclouds.elb.domain.InstanceState;
|
||||
import org.jclouds.elb.domain.InstanceHealth;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
|
@ -32,20 +32,20 @@ import org.xml.sax.SAXException;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class InstanceStateHandler extends ParseSax.HandlerForGeneratedRequestWithResult<InstanceState> {
|
||||
public class InstanceStateHandler extends ParseSax.HandlerForGeneratedRequestWithResult<InstanceHealth> {
|
||||
|
||||
private StringBuilder currentText = new StringBuilder();
|
||||
private InstanceState.Builder builder = InstanceState.builder();
|
||||
private InstanceHealth.Builder builder = InstanceHealth.builder();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public InstanceState getResult() {
|
||||
public InstanceHealth getResult() {
|
||||
try {
|
||||
return builder.build();
|
||||
} finally {
|
||||
builder = InstanceState.builder();
|
||||
builder = InstanceHealth.builder();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,221 @@
|
|||
/**
|
||||
* 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.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.jclouds.elb.ELBClient;
|
||||
import org.jclouds.elb.internal.BaseELBClientExpectTest;
|
||||
import org.jclouds.elb.parse.AvailabilityZonesResultHandlerTest;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "AvailabilityZoneClientExpectTest")
|
||||
public class AvailabilityZoneClientExpectTest extends BaseELBClientExpectTest {
|
||||
|
||||
public AvailabilityZoneClientExpectTest() {
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
|
||||
}
|
||||
|
||||
HttpRequest addZoneToLoadBalancer = 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=EnableAvailabilityZonesForLoadBalancer" +
|
||||
"&AvailabilityZones.member.1=us-east-1a" +
|
||||
"&LoadBalancerName=name" +
|
||||
"&Signature=lay8JNIpYsgWjiTbA4%2FrgKrQPWhFKToPxw%2FfCLld4SE%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 testAddZoneToLoadBalancerWhenResponseIs2xx() throws Exception {
|
||||
|
||||
HttpResponse getResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/zones.xml", "text/xml")).build();
|
||||
|
||||
ELBClient clientWhenExist = requestSendsResponse(
|
||||
addZoneToLoadBalancer, getResponse);
|
||||
|
||||
assertEquals(clientWhenExist.getAvailabilityZoneClient().addAvailabilityZoneToLoadBalancer("us-east-1a", "name").toString(), new AvailabilityZonesResultHandlerTest().expected().toString());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||
public void testAddZoneToLoadBalancerWhenResponseIs404() throws Exception {
|
||||
|
||||
HttpResponse getResponse = HttpResponse.builder().statusCode(404).build();
|
||||
|
||||
ELBClient clientWhenDontExist = requestSendsResponse(
|
||||
addZoneToLoadBalancer, getResponse);
|
||||
|
||||
clientWhenDontExist.getAvailabilityZoneClient().addAvailabilityZoneToLoadBalancer("us-east-1a", "name");
|
||||
}
|
||||
|
||||
HttpRequest addZonesToLoadBalancer = 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=EnableAvailabilityZonesForLoadBalancer" +
|
||||
"&AvailabilityZones.member.1=us-east-1a" +
|
||||
"&AvailabilityZones.member.2=us-east-1b" +
|
||||
"&LoadBalancerName=name" +
|
||||
"&Signature=RAX1VLJU30B47RFUiywtknhgD2DxZygJ2niOO4UnW3U%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 testAddZonesToLoadBalancerWhenResponseIs2xx() throws Exception {
|
||||
|
||||
HttpResponse getResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/zones.xml", "text/xml")).build();
|
||||
|
||||
ELBClient clientWhenExist = requestSendsResponse(addZonesToLoadBalancer, getResponse);
|
||||
|
||||
assertEquals(
|
||||
clientWhenExist.getAvailabilityZoneClient().addAvailabilityZonesToLoadBalancer(ImmutableSet.of("us-east-1a", "us-east-1b"), "name")
|
||||
.toString(), new AvailabilityZonesResultHandlerTest().expected().toString());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||
public void testAddZonesToLoadBalancerWhenResponseIs404() throws Exception {
|
||||
|
||||
HttpResponse getResponse = HttpResponse.builder().statusCode(404).build();
|
||||
|
||||
ELBClient clientWhenDontExist = requestSendsResponse(addZonesToLoadBalancer, getResponse);
|
||||
|
||||
clientWhenDontExist.getAvailabilityZoneClient().addAvailabilityZonesToLoadBalancer(ImmutableSet.of("us-east-1a", "us-east-1b"), "name");
|
||||
}
|
||||
|
||||
|
||||
HttpRequest removeZoneFromLoadBalancer = 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=DisableAvailabilityZonesForLoadBalancer" +
|
||||
"&AvailabilityZones.member.1=us-east-1a" +
|
||||
"&LoadBalancerName=name" +
|
||||
"&Signature=tjzaFDhUghKwTpe%2F9OC8JK%2BJsRMCkF3Kh5YkvPEDPbg%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 testRemoveZoneFromLoadBalancerWhenResponseIs2xx() throws Exception {
|
||||
|
||||
HttpResponse getResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/zones.xml", "text/xml")).build();
|
||||
|
||||
ELBClient clientWhenExist = requestSendsResponse(
|
||||
removeZoneFromLoadBalancer, getResponse);
|
||||
|
||||
assertEquals(clientWhenExist.getAvailabilityZoneClient().removeAvailabilityZoneFromLoadBalancer("us-east-1a", "name").toString(), new AvailabilityZonesResultHandlerTest().expected().toString());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||
public void testRemoveZoneFromLoadBalancerWhenResponseIs404() throws Exception {
|
||||
|
||||
HttpResponse getResponse = HttpResponse.builder().statusCode(404).build();
|
||||
|
||||
ELBClient clientWhenDontExist = requestSendsResponse(
|
||||
removeZoneFromLoadBalancer, getResponse);
|
||||
|
||||
clientWhenDontExist.getAvailabilityZoneClient().removeAvailabilityZoneFromLoadBalancer("us-east-1a", "name");
|
||||
}
|
||||
|
||||
HttpRequest removeZonesFromLoadBalancer = 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=DisableAvailabilityZonesForLoadBalancer" +
|
||||
"&AvailabilityZones.member.1=us-east-1a" +
|
||||
"&AvailabilityZones.member.2=us-east-1b" +
|
||||
"&LoadBalancerName=name" +
|
||||
"&Signature=5yUJQXjfntl0ptL%2BDv3p2jYpDSr%2BmV8hASIS7wtvkOI%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 testRemoveZonesFromLoadBalancerWhenResponseIs2xx() throws Exception {
|
||||
|
||||
HttpResponse getResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/zones.xml", "text/xml")).build();
|
||||
|
||||
ELBClient clientWhenExist = requestSendsResponse(removeZonesFromLoadBalancer, getResponse);
|
||||
|
||||
assertEquals(
|
||||
clientWhenExist.getAvailabilityZoneClient().removeAvailabilityZonesFromLoadBalancer(ImmutableSet.of("us-east-1a", "us-east-1b"), "name")
|
||||
.toString(), new AvailabilityZonesResultHandlerTest().expected().toString());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||
public void testRemoveZonesFromLoadBalancerWhenResponseIs404() throws Exception {
|
||||
|
||||
HttpResponse getResponse = HttpResponse.builder().statusCode(404).build();
|
||||
|
||||
ELBClient clientWhenDontExist = requestSendsResponse(removeZonesFromLoadBalancer, getResponse);
|
||||
|
||||
clientWhenDontExist.getAvailabilityZoneClient().removeAvailabilityZonesFromLoadBalancer(ImmutableSet.of("us-east-1a", "us-east-1b"), "name");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* 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 org.jclouds.elb.internal.BaseELBClientLiveTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", testName = "AvailabilityZoneClientLiveTest")
|
||||
public class AvailabilityZoneClientLiveTest extends BaseELBClientLiveTest {
|
||||
|
||||
protected AvailabilityZoneClient client() {
|
||||
return context.getApi().getAvailabilityZoneClient();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,263 @@
|
|||
/**
|
||||
* 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.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.jclouds.elb.ELBClient;
|
||||
import org.jclouds.elb.internal.BaseELBClientExpectTest;
|
||||
import org.jclouds.elb.parse.DescribeInstanceHealthResponseTest;
|
||||
import org.jclouds.elb.parse.InstancesResultHandlerTest;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "InstanceClientExpectTest")
|
||||
public class InstanceClientExpectTest extends BaseELBClientExpectTest {
|
||||
|
||||
public InstanceClientExpectTest() {
|
||||
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=DescribeInstanceHealth" +
|
||||
"&LoadBalancerName=name" +
|
||||
"&Signature=zIwSuvkooYRNPLyDrPCF8%2BbMLA8t0n9hIlS6K2aahuA%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 testGetHealthOfInstancesOfLoadBalancerIs2xx() throws Exception {
|
||||
|
||||
HttpResponse getResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/describe_instancehealth.xml", "text/xml")).build();
|
||||
|
||||
ELBClient clientWhenExist = requestSendsResponse(
|
||||
get, getResponse);
|
||||
|
||||
assertEquals(clientWhenExist.getInstanceClient().getHealthOfInstancesOfLoadBalancer("name").toString(), new DescribeInstanceHealthResponseTest().expected().toString());
|
||||
}
|
||||
|
||||
public void testGetHealthOfInstancesOfLoadBalancerWhenResponseIs404() throws Exception {
|
||||
|
||||
HttpResponse getResponse = HttpResponse.builder().statusCode(404).build();
|
||||
|
||||
ELBClient clientWhenDontExist = requestSendsResponse(
|
||||
get, getResponse);
|
||||
|
||||
assertEquals(clientWhenDontExist.getInstanceClient().getHealthOfInstancesOfLoadBalancer("name"), ImmutableSet.of());
|
||||
}
|
||||
|
||||
HttpRequest registerInstanceWithLoadBalancer = 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=RegisterInstancesWithLoadBalancer" +
|
||||
"&Instances.member.1.InstanceId=i-6055fa09" +
|
||||
"&LoadBalancerName=name" +
|
||||
"&Signature=YRYjrZGMNoeyghtfKvbMZbRrbIgCuxsCQeYdtai0chY%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 testRegisterInstanceWithLoadBalancerWhenResponseIs2xx() throws Exception {
|
||||
|
||||
HttpResponse getResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/instances.xml", "text/xml")).build();
|
||||
|
||||
ELBClient clientWhenExist = requestSendsResponse(
|
||||
registerInstanceWithLoadBalancer, getResponse);
|
||||
|
||||
assertEquals(clientWhenExist.getInstanceClient().registerInstanceWithLoadBalancer("i-6055fa09", "name").toString(), new InstancesResultHandlerTest().expected().toString());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||
public void testRegisterInstanceWithLoadBalancerWhenResponseIs404() throws Exception {
|
||||
|
||||
HttpResponse getResponse = HttpResponse.builder().statusCode(404).build();
|
||||
|
||||
ELBClient clientWhenDontExist = requestSendsResponse(
|
||||
registerInstanceWithLoadBalancer, getResponse);
|
||||
|
||||
clientWhenDontExist.getInstanceClient().registerInstanceWithLoadBalancer("i-6055fa09", "name");
|
||||
}
|
||||
|
||||
HttpRequest registerInstancesWithLoadBalancer = 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=RegisterInstancesWithLoadBalancer" +
|
||||
"&Instances.member.1.InstanceId=i-6055fa09" +
|
||||
"&Instances.member.2.InstanceId=i-9055fa55" +
|
||||
"&LoadBalancerName=name" +
|
||||
"&Signature=Yfqg8TxL1J1Ug8SimY%2F30rnbt%2FUVygTEa0vhMT5Fz1Y%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 testRegisterInstancesWithLoadBalancerWhenResponseIs2xx() throws Exception {
|
||||
|
||||
HttpResponse getResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/instances.xml", "text/xml")).build();
|
||||
|
||||
ELBClient clientWhenExist = requestSendsResponse(registerInstancesWithLoadBalancer, getResponse);
|
||||
|
||||
assertEquals(
|
||||
clientWhenExist.getInstanceClient().registerInstancesWithLoadBalancer(ImmutableSet.of("i-6055fa09", "i-9055fa55"), "name")
|
||||
.toString(), new InstancesResultHandlerTest().expected().toString());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||
public void testRegisterInstancesWithLoadBalancerWhenResponseIs404() throws Exception {
|
||||
|
||||
HttpResponse getResponse = HttpResponse.builder().statusCode(404).build();
|
||||
|
||||
ELBClient clientWhenDontExist = requestSendsResponse(registerInstancesWithLoadBalancer, getResponse);
|
||||
|
||||
clientWhenDontExist.getInstanceClient().registerInstancesWithLoadBalancer(ImmutableSet.of("i-6055fa09", "i-9055fa55"), "name");
|
||||
}
|
||||
|
||||
|
||||
HttpRequest deregisterInstanceFromLoadBalancer = 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=DeregisterInstancesFromLoadBalancer" +
|
||||
"&Instances.member.1.InstanceId=i-6055fa09" +
|
||||
"&LoadBalancerName=name" +
|
||||
"&Signature=d%2BK6b2ggJLEekW8wLyRnm%2FpcEpZvc8VNI%2FW0bpYBGUk%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 testDeregisterInstanceFromLoadBalancerWhenResponseIs2xx() throws Exception {
|
||||
|
||||
HttpResponse getResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/instances.xml", "text/xml")).build();
|
||||
|
||||
ELBClient clientWhenExist = requestSendsResponse(
|
||||
deregisterInstanceFromLoadBalancer, getResponse);
|
||||
|
||||
assertEquals(clientWhenExist.getInstanceClient().deregisterInstanceFromLoadBalancer("i-6055fa09", "name").toString(), new InstancesResultHandlerTest().expected().toString());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||
public void testDeregisterInstanceFromLoadBalancerWhenResponseIs404() throws Exception {
|
||||
|
||||
HttpResponse getResponse = HttpResponse.builder().statusCode(404).build();
|
||||
|
||||
ELBClient clientWhenDontExist = requestSendsResponse(
|
||||
deregisterInstanceFromLoadBalancer, getResponse);
|
||||
|
||||
clientWhenDontExist.getInstanceClient().deregisterInstanceFromLoadBalancer("i-6055fa09", "name");
|
||||
}
|
||||
|
||||
HttpRequest deregisterInstancesFromLoadBalancer = 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=DeregisterInstancesFromLoadBalancer" +
|
||||
"&Instances.member.1.InstanceId=i-6055fa09" +
|
||||
"&Instances.member.2.InstanceId=i-9055fa55" +
|
||||
"&LoadBalancerName=name" +
|
||||
"&Signature=nqn8iH70979k%2Fu%2FKXEcMlT1Zd%2FPaNK6ZBwFDjvbuMRo%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 testDeregisterInstancesFromLoadBalancerWhenResponseIs2xx() throws Exception {
|
||||
|
||||
HttpResponse getResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/instances.xml", "text/xml")).build();
|
||||
|
||||
ELBClient clientWhenExist = requestSendsResponse(deregisterInstancesFromLoadBalancer, getResponse);
|
||||
|
||||
assertEquals(
|
||||
clientWhenExist.getInstanceClient().deregisterInstancesFromLoadBalancer(ImmutableSet.of("i-6055fa09", "i-9055fa55"), "name")
|
||||
.toString(), new InstancesResultHandlerTest().expected().toString());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||
public void testDeregisterInstancesFromLoadBalancerWhenResponseIs404() throws Exception {
|
||||
|
||||
HttpResponse getResponse = HttpResponse.builder().statusCode(404).build();
|
||||
|
||||
ELBClient clientWhenDontExist = requestSendsResponse(deregisterInstancesFromLoadBalancer, getResponse);
|
||||
|
||||
clientWhenDontExist.getInstanceClient().deregisterInstancesFromLoadBalancer(ImmutableSet.of("i-6055fa09", "i-9055fa55"), "name");
|
||||
}
|
||||
}
|
|
@ -22,7 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.elb.domain.InstanceState;
|
||||
import org.jclouds.elb.domain.InstanceHealth;
|
||||
import org.jclouds.elb.domain.LoadBalancer;
|
||||
import org.jclouds.elb.internal.BaseELBClientLiveTest;
|
||||
import org.testng.Assert;
|
||||
|
@ -36,7 +36,7 @@ import com.google.common.collect.ImmutableSet;
|
|||
@Test(groups = "live", testName = "InstanceClientLiveTest")
|
||||
public class InstanceClientLiveTest extends BaseELBClientLiveTest {
|
||||
|
||||
private void checkInstanceState(InstanceState instanceState) {
|
||||
private void checkInstanceState(InstanceHealth instanceState) {
|
||||
checkNotNull(instanceState.getDescription(), "Description cannot be null for InstanceState");
|
||||
checkNotNull(instanceState.getInstanceId(), "InstanceId cannot be null for InstanceState");
|
||||
checkNotNull(instanceState.getReasonCode(),
|
||||
|
@ -46,24 +46,24 @@ public class InstanceClientLiveTest extends BaseELBClientLiveTest {
|
|||
|
||||
@Test
|
||||
protected void testListInstanceStates() {
|
||||
for (LoadBalancer loadBalancer : context.getApi().getLoadBalancerClientForRegion(null).list()) {
|
||||
Set<InstanceState> response = client().getStateOfInstancesOfLoadBalancer(loadBalancer.getName());
|
||||
for (LoadBalancer loadBalancer : context.getApi().getLoadBalancerClient().list()) {
|
||||
Set<InstanceHealth> response = client().getHealthOfInstancesOfLoadBalancer(loadBalancer.getName());
|
||||
|
||||
for (InstanceState instanceState : response) {
|
||||
for (InstanceHealth instanceState : response) {
|
||||
checkInstanceState(instanceState);
|
||||
}
|
||||
|
||||
if (response.size() > 0) {
|
||||
InstanceState instanceState = response.iterator().next();
|
||||
InstanceHealth instanceState = response.iterator().next();
|
||||
Assert.assertEquals(
|
||||
client().getStateOfInstancesOfLoadBalancer(ImmutableSet.of(instanceState.getInstanceId()),
|
||||
loadBalancer.getName()), instanceState);
|
||||
ImmutableSet.of(client().getHealthOfInstancesOfLoadBalancer(ImmutableSet.of(instanceState.getInstanceId()),
|
||||
loadBalancer.getName())), instanceState);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected InstanceClient client() {
|
||||
return context.getApi().getInstanceClientForRegion(null);
|
||||
return context.getApi().getInstanceClient();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ public class LoadBalancerClientExpectTest extends BaseELBClientExpectTest {
|
|||
ELBClient clientWhenExist = requestSendsResponse(
|
||||
get, getResponse);
|
||||
|
||||
assertEquals(clientWhenExist.getLoadBalancerClientForRegion(null).get("name").toString(), new GetLoadBalancerResponseTest().expected().toString());
|
||||
assertEquals(clientWhenExist.getLoadBalancerClient().get("name").toString(), new GetLoadBalancerResponseTest().expected().toString());
|
||||
}
|
||||
|
||||
public void testGetWhenResponseIs404() throws Exception {
|
||||
|
@ -84,7 +84,7 @@ public class LoadBalancerClientExpectTest extends BaseELBClientExpectTest {
|
|||
ELBClient clientWhenDontExist = requestSendsResponse(
|
||||
get, getResponse);
|
||||
|
||||
assertNull(clientWhenDontExist.getLoadBalancerClientForRegion(null).get("name"));
|
||||
assertNull(clientWhenDontExist.getLoadBalancerClient().get("name"));
|
||||
}
|
||||
|
||||
HttpRequest list = HttpRequest.builder()
|
||||
|
@ -113,7 +113,7 @@ public class LoadBalancerClientExpectTest extends BaseELBClientExpectTest {
|
|||
ELBClient clientWhenExist = requestSendsResponse(
|
||||
list, listResponse);
|
||||
|
||||
assertEquals(clientWhenExist.getLoadBalancerClientForRegion(null).list().toString(), new DescribeLoadBalancersResponseTest().expected().toString());
|
||||
assertEquals(clientWhenExist.getLoadBalancerClient().list().toString(), new DescribeLoadBalancersResponseTest().expected().toString());
|
||||
}
|
||||
|
||||
// TODO: this should really be an empty set
|
||||
|
@ -125,7 +125,7 @@ public class LoadBalancerClientExpectTest extends BaseELBClientExpectTest {
|
|||
ELBClient clientWhenDontExist = requestSendsResponse(
|
||||
list, listResponse);
|
||||
|
||||
clientWhenDontExist.getLoadBalancerClientForRegion(null).list();
|
||||
clientWhenDontExist.getLoadBalancerClient().list();
|
||||
}
|
||||
|
||||
public void testListWithOptionsWhenResponseIs2xx() throws Exception {
|
||||
|
@ -154,7 +154,7 @@ public class LoadBalancerClientExpectTest extends BaseELBClientExpectTest {
|
|||
ELBClient clientWhenWithOptionsExist = requestSendsResponse(listWithOptions,
|
||||
listWithOptionsResponse);
|
||||
|
||||
assertEquals(clientWhenWithOptionsExist.getLoadBalancerClientForRegion(null).list(afterMarker("MARKER")).toString(),
|
||||
assertEquals(clientWhenWithOptionsExist.getLoadBalancerClient().list(afterMarker("MARKER")).toString(),
|
||||
new DescribeLoadBalancersResponseTest().expected().toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,6 +94,6 @@ public class LoadBalancerClientLiveTest extends BaseELBClientLiveTest {
|
|||
}
|
||||
|
||||
protected LoadBalancerClient client() {
|
||||
return context.getApi().getLoadBalancerClientForRegion(null);
|
||||
return context.getApi().getLoadBalancerClient();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ public class PolicyClientExpectTest extends BaseELBClientExpectTest {
|
|||
ELBClient clientWhenExist = requestSendsResponse(
|
||||
get, getResponse);
|
||||
|
||||
assertEquals(clientWhenExist.getPolicyClientForRegion(null).get("name").toString(), new GetPolicyResponseTest().expected().toString());
|
||||
assertEquals(clientWhenExist.getPolicyClient().get("name").toString(), new GetPolicyResponseTest().expected().toString());
|
||||
}
|
||||
|
||||
public void testGetWhenResponseIs404() throws Exception {
|
||||
|
@ -86,7 +86,7 @@ public class PolicyClientExpectTest extends BaseELBClientExpectTest {
|
|||
ELBClient clientWhenDontExist = requestSendsResponse(
|
||||
get, getResponse);
|
||||
|
||||
assertNull(clientWhenDontExist.getPolicyClientForRegion(null).get("name"));
|
||||
assertNull(clientWhenDontExist.getPolicyClient().get("name"));
|
||||
}
|
||||
|
||||
HttpRequest list = HttpRequest.builder()
|
||||
|
@ -115,7 +115,7 @@ public class PolicyClientExpectTest extends BaseELBClientExpectTest {
|
|||
ELBClient clientWhenExist = requestSendsResponse(
|
||||
list, listResponse);
|
||||
|
||||
assertEquals(clientWhenExist.getPolicyClientForRegion(null).list().toString(), new DescribeLoadBalancerPoliciesResponseTest().expected().toString());
|
||||
assertEquals(clientWhenExist.getPolicyClient().list().toString(), new DescribeLoadBalancerPoliciesResponseTest().expected().toString());
|
||||
}
|
||||
|
||||
public void testListWhenResponseIs404() throws Exception {
|
||||
|
@ -125,7 +125,7 @@ public class PolicyClientExpectTest extends BaseELBClientExpectTest {
|
|||
ELBClient clientWhenDontExist = requestSendsResponse(
|
||||
list, listResponse);
|
||||
|
||||
clientWhenDontExist.getPolicyClientForRegion(null).list();
|
||||
clientWhenDontExist.getPolicyClient().list();
|
||||
}
|
||||
|
||||
public void testListWithOptionsWhenResponseIs2xx() throws Exception {
|
||||
|
@ -154,7 +154,7 @@ public class PolicyClientExpectTest extends BaseELBClientExpectTest {
|
|||
ELBClient clientWhenWithOptionsExist = requestSendsResponse(listWithOptions,
|
||||
listWithOptionsResponse);
|
||||
|
||||
assertEquals(clientWhenWithOptionsExist.getPolicyClientForRegion(null).list(loadBalancerName("moo")).toString(),
|
||||
assertEquals(clientWhenWithOptionsExist.getPolicyClient().list(loadBalancerName("moo")).toString(),
|
||||
new DescribeLoadBalancerPoliciesResponseTest().expected().toString());
|
||||
}
|
||||
|
||||
|
@ -187,7 +187,7 @@ public class PolicyClientExpectTest extends BaseELBClientExpectTest {
|
|||
ELBClient clientWhenExist = requestSendsResponse(
|
||||
getType, getResponse);
|
||||
|
||||
assertEquals(clientWhenExist.getPolicyClientForRegion(null).getType("name").toString(), new GetPolicyTypeResponseTest().expected().toString());
|
||||
assertEquals(clientWhenExist.getPolicyClient().getType("name").toString(), new GetPolicyTypeResponseTest().expected().toString());
|
||||
}
|
||||
|
||||
public void testGetTypeWhenResponseIs404() throws Exception {
|
||||
|
@ -197,7 +197,7 @@ public class PolicyClientExpectTest extends BaseELBClientExpectTest {
|
|||
ELBClient clientWhenDontExist = requestSendsResponse(
|
||||
getType, getResponse);
|
||||
|
||||
assertNull(clientWhenDontExist.getPolicyClientForRegion(null).getType("name"));
|
||||
assertNull(clientWhenDontExist.getPolicyClient().getType("name"));
|
||||
}
|
||||
|
||||
HttpRequest listTypes = HttpRequest.builder()
|
||||
|
@ -226,7 +226,7 @@ public class PolicyClientExpectTest extends BaseELBClientExpectTest {
|
|||
ELBClient clientWhenExist = requestSendsResponse(
|
||||
listTypes, listResponse);
|
||||
|
||||
assertEquals(clientWhenExist.getPolicyClientForRegion(null).listTypes().toString(), new DescribeLoadBalancerPolicyTypesResponseTest().expected().toString());
|
||||
assertEquals(clientWhenExist.getPolicyClient().listTypes().toString(), new DescribeLoadBalancerPolicyTypesResponseTest().expected().toString());
|
||||
}
|
||||
|
||||
public void testListTypesWhenResponseIs404() throws Exception {
|
||||
|
@ -236,7 +236,7 @@ public class PolicyClientExpectTest extends BaseELBClientExpectTest {
|
|||
ELBClient clientWhenDontExist = requestSendsResponse(
|
||||
listTypes, listResponse);
|
||||
|
||||
clientWhenDontExist.getPolicyClientForRegion(null).listTypes();
|
||||
clientWhenDontExist.getPolicyClient().listTypes();
|
||||
}
|
||||
|
||||
public void testListTypesByNamesWhenResponseIs2xx() throws Exception {
|
||||
|
@ -265,7 +265,7 @@ public class PolicyClientExpectTest extends BaseELBClientExpectTest {
|
|||
ELBClient clientWhenWithOptionsExist = requestSendsResponse(listWithOptions,
|
||||
listWithOptionsResponse);
|
||||
|
||||
assertEquals(clientWhenWithOptionsExist.getPolicyClientForRegion(null).listTypes(ImmutableSet.of("moo")).toString(),
|
||||
assertEquals(clientWhenWithOptionsExist.getPolicyClient().listTypes(ImmutableSet.of("moo")).toString(),
|
||||
new DescribeLoadBalancerPolicyTypesResponseTest().expected().toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,6 +105,6 @@ public class PolicyClientLiveTest extends BaseELBClientLiveTest {
|
|||
}
|
||||
|
||||
protected PolicyClient client() {
|
||||
return context.getApi().getPolicyClientForRegion(null);
|
||||
return context.getApi().getPolicyClient();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ public class ELBLoadBalancerServiceLiveTest extends BaseLoadBalancerServiceLiveT
|
|||
instanceIds.add(node.getProviderId());
|
||||
}
|
||||
|
||||
PaginatedIterable<LoadBalancer> elbs = elbClient.getLoadBalancerClientForRegion(null).list();
|
||||
PaginatedIterable<LoadBalancer> elbs = elbClient.getLoadBalancerClient().list();
|
||||
for (LoadBalancer elb : elbs) {
|
||||
if (elb.getName().equals(group))
|
||||
assertEquals(elb.getInstanceIds(), instanceIds.build());
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* 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.xml.AvailabilityZonesResultHandler;
|
||||
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 = "ZonesResultHandlerTest")
|
||||
public class AvailabilityZonesResultHandlerTest extends BaseHandlerTest {
|
||||
|
||||
public void test() {
|
||||
InputStream is = getClass().getResourceAsStream("/zones.xml");
|
||||
|
||||
Set<String> expected = expected();
|
||||
|
||||
AvailabilityZonesResultHandler handler = injector.getInstance(AvailabilityZonesResultHandler.class);
|
||||
Set<String> result = factory.create(handler).parse(is);
|
||||
|
||||
assertEquals(result.toString(), expected.toString());
|
||||
|
||||
}
|
||||
|
||||
public Set<String> expected() {
|
||||
return ImmutableSet.of("us-east-1c");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
* 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.InstanceHealth;
|
||||
import org.jclouds.elb.xml.DescribeInstanceHealthResultHandler;
|
||||
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 = "DescribeInstanceHealthResponseTest")
|
||||
public class DescribeInstanceHealthResponseTest extends BaseHandlerTest {
|
||||
|
||||
public void test() {
|
||||
InputStream is = getClass().getResourceAsStream("/describe_instancehealth.xml");
|
||||
|
||||
Set<InstanceHealth> expected = expected();
|
||||
|
||||
DescribeInstanceHealthResultHandler handler = injector.getInstance(DescribeInstanceHealthResultHandler.class);
|
||||
Set<InstanceHealth> result = factory.create(handler).parse(is);
|
||||
|
||||
assertEquals(result.toString(), expected.toString());
|
||||
|
||||
}
|
||||
|
||||
public Set<InstanceHealth> expected() {
|
||||
return ImmutableSet.<InstanceHealth>builder()
|
||||
.add(InstanceHealth.builder()
|
||||
.description("Instance is in terminated state.")
|
||||
.instanceId("i-64bd081c")
|
||||
.state("OutOfService")
|
||||
.reasonCode("Instance")
|
||||
.build()).build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
<DescribeInstanceHealthResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
|
||||
<DescribeInstanceHealthResult>
|
||||
<InstanceStates>
|
||||
<member>
|
||||
<Description>Instance is in terminated state.</Description>
|
||||
<InstanceId>i-64bd081c</InstanceId>
|
||||
<State>OutOfService</State>
|
||||
<ReasonCode>Instance</ReasonCode>
|
||||
</member>
|
||||
</InstanceStates>
|
||||
</DescribeInstanceHealthResult>
|
||||
<ResponseMetadata>
|
||||
<RequestId>6fb803d5-ca15-11e1-ba7e-87298bc8b11d</RequestId>
|
||||
</ResponseMetadata>
|
||||
</DescribeInstanceHealthResponse>
|
|
@ -0,0 +1,10 @@
|
|||
<EnableAvailabilityZonesForLoadBalancerResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
|
||||
<EnableAvailabilityZonesForLoadBalancerResult>
|
||||
<AvailabilityZones>
|
||||
<member>us-east-1c</member>
|
||||
</AvailabilityZones>
|
||||
</EnableAvailabilityZonesForLoadBalancerResult>
|
||||
<ResponseMetadata>
|
||||
<RequestId>04343154-ca27-11e1-b4e4-0b6ac7b9ca3a</RequestId>
|
||||
</ResponseMetadata>
|
||||
</EnableAvailabilityZonesForLoadBalancerResponse>
|
Loading…
Reference in New Issue