Merge pull request #1191 from rackspace/rax-clb-virtual-ips

The Virtual IP API for Rackspace Cloud Load Balancers.
This commit is contained in:
Adrian Cole 2013-01-17 13:54:18 -08:00
commit fed4cf5a4c
18 changed files with 539 additions and 88 deletions

View File

@ -28,6 +28,7 @@ import org.jclouds.location.functions.ZoneToEndpoint;
import org.jclouds.rackspace.cloudloadbalancers.features.AccessRuleApi;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerApi;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeApi;
import org.jclouds.rackspace.cloudloadbalancers.features.VirtualIPApi;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam;
@ -70,4 +71,12 @@ public interface CloudLoadBalancersApi {
@Path("/loadbalancers/{lbId}")
AccessRuleApi getAccessRuleApiForZoneAndLoadBalancer(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone, @PathParam("lbId") int lbId);
/**
* Provides synchronous access to Virtual IP features.
*/
@Delegate
@Path("/loadbalancers/{lbId}")
VirtualIPApi getVirtualIPApiForZoneAndLoadBalancer(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone, @PathParam("lbId") int lbId);
}

View File

@ -26,9 +26,10 @@ import javax.ws.rs.PathParam;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.Zone;
import org.jclouds.location.functions.ZoneToEndpoint;
import org.jclouds.rackspace.cloudloadbalancers.features.AccessRuleApi;
import org.jclouds.rackspace.cloudloadbalancers.features.AccessRuleAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.features.VirtualIPAsyncApi;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam;
@ -69,6 +70,14 @@ public interface CloudLoadBalancersAsyncApi {
*/
@Delegate
@Path("/loadbalancers/{lbId}")
AccessRuleApi getAccessRuleApiForZoneAndLoadBalancer(
AccessRuleAsyncApi getAccessRuleApiForZoneAndLoadBalancer(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone, @PathParam("lbId") int lbId);
/**
* Provides synchronous access to Virtual IP features.
*/
@Delegate
@Path("/loadbalancers/{lbId}")
VirtualIPAsyncApi getVirtualIPApiForZoneAndLoadBalancer(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone, @PathParam("lbId") int lbId);
}

View File

@ -34,6 +34,8 @@ import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerApi;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeApi;
import org.jclouds.rackspace.cloudloadbalancers.features.VirtualIPApi;
import org.jclouds.rackspace.cloudloadbalancers.features.VirtualIPAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.functions.ConvertLB;
import org.jclouds.rackspace.cloudloadbalancers.handlers.ParseCloudLoadBalancersErrorFromHttpResponse;
import org.jclouds.rest.ConfiguresRestClient;
@ -55,6 +57,7 @@ public class CloudLoadBalancersRestClientModule extends
.put(LoadBalancerApi.class, LoadBalancerAsyncApi.class)
.put(NodeApi.class, NodeAsyncApi.class)
.put(AccessRuleApi.class, AccessRuleAsyncApi.class)
.put(VirtualIPApi.class, VirtualIPAsyncApi.class)
.build();
public CloudLoadBalancersRestClientModule() {

View File

@ -41,7 +41,7 @@ public class LoadBalancer extends BaseLoadBalancer<Node, LoadBalancer> {
private final String region;
private final int id;
private final Status status;
private final Set<VirtualIP> virtualIPs;
private final Set<VirtualIPWithId> virtualIPs;
private final String clusterName;
private final Date created;
private final Date updated;
@ -53,7 +53,7 @@ public class LoadBalancer extends BaseLoadBalancer<Node, LoadBalancer> {
public LoadBalancer(String region, int id, String name, String protocol, @Nullable Integer port, Set<Node> nodes,
@Nullable Integer timeout, @Nullable Boolean halfClosed, @Nullable Algorithm algorithm, Status status,
Set<VirtualIP> virtualIPs, @Nullable Map<String, SessionPersistenceType> sessionPersistenceType,
Set<VirtualIPWithId> virtualIPs, @Nullable Map<String, SessionPersistenceType> sessionPersistenceType,
String clusterName, Date created, Date updated, @Nullable Map<String, Boolean> connectionLogging,
@Nullable ConnectionThrottle connectionThrottle, boolean contentCaching, int nodeCount,
@Nullable HealthMonitor healthMonitor, @Nullable SSLTermination sslTermination,
@ -94,7 +94,7 @@ public class LoadBalancer extends BaseLoadBalancer<Node, LoadBalancer> {
/**
* @see VirtualIP
*/
public Set<VirtualIP> getVirtualIPs() {
public Set<VirtualIPWithId> getVirtualIPs() {
return virtualIPs;
}
@ -251,7 +251,7 @@ public class LoadBalancer extends BaseLoadBalancer<Node, LoadBalancer> {
private String region;
private int id = -1;
private Status status;
private Set<VirtualIP> virtualIPs = ImmutableSet.<VirtualIP> of();
private Set<VirtualIPWithId> virtualIPs = ImmutableSet.<VirtualIPWithId> of();
private String clusterName;
private Date created;
private Date updated;
@ -276,8 +276,8 @@ public class LoadBalancer extends BaseLoadBalancer<Node, LoadBalancer> {
return this;
}
public Builder virtualIPs(Iterable<VirtualIP> virtualIPs) {
this.virtualIPs = ImmutableSet.<VirtualIP> copyOf(checkNotNull(virtualIPs, "virtualIPs"));
public Builder virtualIPs(Iterable<VirtualIPWithId> virtualIPs) {
this.virtualIPs = ImmutableSet.<VirtualIPWithId> copyOf(checkNotNull(virtualIPs, "virtualIPs"));
return this;
}

View File

@ -18,7 +18,6 @@
*/
package org.jclouds.rackspace.cloudloadbalancers.domain;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Objects;
@ -26,38 +25,28 @@ import com.google.common.base.Objects.ToStringHelper;
/**
* A virtual IP (VIP) makes a load balancer accessible by clients. The load balancing service
* supports either a public VIP, routable on the public Internet, or a ServiceNet address, routable
* supports either a public virtual IP, routable on the public Internet, or a ServiceNet address, routable
* only within the region in which the load balancer resides.
*
* @author Adrian Cole
* @author Everett Toews
*/
public class VirtualIP implements Comparable<VirtualIP> {
public class VirtualIP {
private int id;
private String address;
private Type type;
private IPVersion ipVersion;
// for serialization only
VirtualIP() {
/**
* Use this method to easily create virtual IPs. Only public IPv6 virtual IPs can be created.
*/
public static VirtualIP publicIPv6() {
return new VirtualIP(Type.PUBLIC, IPVersion.IPV6);
}
public VirtualIP(int id, String address, Type type, IPVersion ipVersion) {
checkArgument(id != -1, "id must be specified");
this.id = id;
this.address = checkNotNull(address, "address");
protected VirtualIP(Type type, IPVersion ipVersion) {
this.type = checkNotNull(type, "type");
this.ipVersion = checkNotNull(ipVersion, "ipVersion");
}
public int getId() {
return id;
}
public String getAddress() {
return address;
}
public Type getType() {
return type;
}
@ -66,14 +55,9 @@ public class VirtualIP implements Comparable<VirtualIP> {
return ipVersion;
}
@Override
public int compareTo(VirtualIP arg0) {
return address.compareTo(arg0.address);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this).omitNullValues()
.add("id", id).add("address", address).add("ipVersion", ipVersion).add("type", type);
.add("ipVersion", ipVersion).add("type", type);
}
@Override
@ -83,7 +67,7 @@ public class VirtualIP implements Comparable<VirtualIP> {
@Override
public int hashCode() {
return Objects.hashCode(id);
return Objects.hashCode(ipVersion, type);
}
@Override
@ -92,7 +76,8 @@ public class VirtualIP implements Comparable<VirtualIP> {
if (obj == null || getClass() != obj.getClass()) return false;
VirtualIP that = VirtualIP.class.cast(obj);
return Objects.equal(this.id, that.id);
return Objects.equal(this.ipVersion, that.ipVersion)
&& Objects.equal(this.type, that.type);
}
/**
@ -104,7 +89,7 @@ public class VirtualIP implements Comparable<VirtualIP> {
*/
PUBLIC,
/**
* An address that is routable only on ServiceNet.
* An address that is routable only on the Rackspace ServiceNet.
*/
SERVICENET, UNRECOGNIZED;
@ -132,41 +117,5 @@ public class VirtualIP implements Comparable<VirtualIP> {
return UNRECOGNIZED;
}
}
}
public static class Builder {
private int id = -1;
private String address;
private Type type;
private IPVersion ipVersion = IPVersion.IPV4;
public Builder id(int id) {
this.id = id;
return this;
}
public Builder address(String address) {
this.address = address;
return this;
}
public Builder type(Type type) {
this.type = type;
return this;
}
public Builder ipVersion(IPVersion ipVersion) {
this.ipVersion = ipVersion;
return this;
}
public VirtualIP build() {
return new VirtualIP(id, address, type, ipVersion);
}
}
public static Builder builder() {
return new Builder();
}
}

View File

@ -0,0 +1,73 @@
/**
* 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.rackspace.cloudloadbalancers.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/**
* @see VirtualIP
*
* @author Everett Toews
*/
public class VirtualIPWithId extends VirtualIP {
private int id;
private String address;
public VirtualIPWithId(Type type, IPVersion ipVersion, int id, String address) {
super(type, ipVersion);
this.id = id;
this.address = checkNotNull(address, "address");
}
public int getId() {
return id;
}
public String getAddress() {
return address;
}
protected ToStringHelper string() {
return Objects.toStringHelper(this).omitNullValues()
.add("id", id).add("address", address).add("ipVersion", getIpVersion()).add("type", getType());
}
@Override
public String toString() {
return string().toString();
}
@Override
public int hashCode() {
return Objects.hashCode(id);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
VirtualIPWithId that = VirtualIPWithId.class.cast(obj);
return Objects.equal(this.id, that.id);
}
}

View File

@ -0,0 +1,65 @@
/**
* 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.rackspace.cloudloadbalancers.features;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIPWithId;
/**
* A virtual IP makes a load balancer accessible by clients. The load balancing service supports either a public VIP,
* routable on the public Internet, or a ServiceNet address, routable only within the region in which the load balancer
* resides.
* <p/>
*
* @see VirtualIPAsyncApi
* @author Everett Toews
*/
public interface VirtualIPApi {
/**
* Create a new virtual IP.
*/
VirtualIPWithId create(VirtualIP virtualIP);
/**
* List the virtual IPs.
*/
Iterable<VirtualIPWithId> list();
/**
* Remove a virtual IP.
*
* @see VirtualIPApi#remove(Iterable)
*
* @return true on a successful removal, false if the virtual IP was not found
*/
boolean remove(int id);
/**
* Batch delete virtual IPs given the specified ids.
*
* All load balancers must have at least one virtual IP associated with them at all times. Attempting to delete the
* last virtual IP will result in an exception. The current default limit is ten ids per request. Any
* and all configuration data is immediately purged and is not recoverable. If one or more of the items in the list
* cannot be removed due to its current status, an exception is thrown along with the ids of the ones the
* system identified as potential failures for this request.
*
* @return true on a successful removal, false if the virtual IP was not found
*/
boolean remove(Iterable<Integer> ids);
}

View File

@ -0,0 +1,90 @@
/**
* 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.rackspace.cloudloadbalancers.features;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.FalseOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIPWithId;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.binders.BindToJsonPayload;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides asynchronous access to Rackspace Cloud Load Balancers via their REST API.
* <p/>
*
* @see VirtualIPApi
* @author Everett Toews
*/
@RequestFilters(AuthenticateRequest.class)
public interface VirtualIPAsyncApi {
/**
* @see VirtualIPApi#create(VirtualIP)
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(NullOnNotFoundOr404.class)
@Path("/virtualips")
ListenableFuture<VirtualIPWithId> create(@BinderParam(BindToJsonPayload.class) VirtualIP virtualIP);
/**
* @see VirtualIPApi#list()
*/
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
@SelectJson("virtualIps")
@Path("/virtualips")
ListenableFuture<Iterable<VirtualIPWithId>> list();
/**
* @see VirtualIPApi#remove(int)
*/
@DELETE
@Fallback(FalseOnNotFoundOr404.class)
@Path("/virtualips/{id}")
@Consumes("*/*")
ListenableFuture<Boolean> remove(@PathParam("id") int id);
/**
* @see VirtualIPApi#remove(Iterable)
*/
@DELETE
@Fallback(FalseOnNotFoundOr404.class)
@Path("/virtualips")
@Consumes("*/*")
ListenableFuture<Boolean> remove(@QueryParam("id") Iterable<Integer> ids);
}

View File

@ -24,6 +24,7 @@ import javax.inject.Inject;
import org.jclouds.logging.Logger;
import org.jclouds.rackspace.cloudloadbalancers.domain.AccessRuleWithId;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIPWithId;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer.Builder;
import com.google.common.base.Function;
@ -58,7 +59,7 @@ public class ConvertLB implements Function<LB, LoadBalancer> {
.timeout(lb.getTimeout()).algorithm(lb.getAlgorithm()).halfClosed(lb.isHalfClosed())
.sessionPersistenceType(lb.getSessionPersistenceType()).connectionLogging(lb.isConnectionLogging())
.connectionThrottle(lb.getConnectionThrottle()).healthMonitor(lb.getHealthMonitor())
.metadata(lb.getMetadata()).virtualIPs(lb.virtualIps);
.metadata(lb.getMetadata());
if (lb.cluster.size() == 1)
builder.clusterName(Iterables.get(lb.cluster.values(), 0));
@ -76,6 +77,10 @@ public class ConvertLB implements Function<LB, LoadBalancer> {
builder.accessRules(ImmutableSet.<AccessRuleWithId> of());
else
builder.accessRules(lb.accessList);
if (lb.virtualIps == null)
builder.virtualIPs(ImmutableSet.<VirtualIPWithId> of());
else
builder.virtualIPs(lb.virtualIps);
return builder.build();
}

View File

@ -22,12 +22,12 @@ import java.util.Date;
import java.util.Map;
import java.util.Set;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer.Status;
import org.jclouds.rackspace.cloudloadbalancers.domain.AccessRuleWithId;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer.Status;
import org.jclouds.rackspace.cloudloadbalancers.domain.Node;
import org.jclouds.rackspace.cloudloadbalancers.domain.SSLTermination;
import org.jclouds.rackspace.cloudloadbalancers.domain.SourceAddresses;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIPWithId;
import org.jclouds.rackspace.cloudloadbalancers.domain.internal.BaseLoadBalancer;
import com.google.common.base.Objects;
@ -41,7 +41,7 @@ class LB extends BaseLoadBalancer<Node, LB> {
int id;
int nodeCount;
Status status;
Set<VirtualIP> virtualIps = Sets.newLinkedHashSet();
Set<VirtualIPWithId> virtualIps = Sets.newLinkedHashSet();
Map<String, String> cluster = Maps.newLinkedHashMap();
Map<String, Date> created = Maps.newLinkedHashMap();
Map<String, Date> updated = Maps.newLinkedHashMap();

View File

@ -30,7 +30,7 @@ import org.jclouds.loadbalancer.domain.LoadBalancerType;
import org.jclouds.loadbalancer.domain.internal.LoadBalancerMetadataImpl;
import org.jclouds.location.predicates.LocationPredicates;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIPWithId;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
@ -62,10 +62,10 @@ public class LoadBalancerToLoadBalancerMetadata implements Function<LoadBalancer
// TODO Builder
return new LoadBalancerMetadataImpl(LoadBalancerType.LB, String.valueOf(input.getId()), input.getName(), id, location, null,
ImmutableMap.<String, String> of(), Iterables.transform(input.getVirtualIPs(),
new Function<VirtualIP, String>() {
new Function<VirtualIPWithId, String>() {
@Override
public String apply(VirtualIP arg0) {
public String apply(VirtualIPWithId arg0) {
return arg0.getAddress();
}

View File

@ -0,0 +1,99 @@
/**
* 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.rackspace.cloudloadbalancers.features;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import java.util.List;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.HttpResponse;
import org.jclouds.rackspace.cloudloadbalancers.CloudLoadBalancersApi;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIPWithId;
import org.jclouds.rackspace.cloudloadbalancers.internal.BaseCloudLoadBalancerApiExpectTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
/**
* @author Everett Toews
*/
@Test(groups = "unit")
public class VirtualIPApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<CloudLoadBalancersApi> {
public void testListVirtualIPs() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/virtualips");
VirtualIPApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/virtualips-list.json")).build()
).getVirtualIPApiForZoneAndLoadBalancer("DFW", 2000);
Iterable<VirtualIPWithId> virtualIPs = api.list();
assertEquals(virtualIPs, getVirtualIPs());
}
public void testCreateVirtualIPs() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/virtualips");
VirtualIPApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("POST").endpoint(endpoint).payload(payloadFromResource("/virtualips-create.json")).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/virtualips-create-response.json")).build()
).getVirtualIPApiForZoneAndLoadBalancer("DFW", 2000);
api.create(VirtualIP.publicIPv6());
}
public void testRemoveSingleVirtualIP() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/virtualips/23");
VirtualIPApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("DELETE").endpoint(endpoint).replaceHeader("Accept", MediaType.WILDCARD).build(),
HttpResponse.builder().statusCode(200).build()
).getVirtualIPApiForZoneAndLoadBalancer("DFW", 2000);
api.remove(23);
}
public void testRemoveManyVirtualIPs() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/virtualips?id=23&id=24");
VirtualIPApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("DELETE").endpoint(endpoint).replaceHeader("Accept", MediaType.WILDCARD).build(),
HttpResponse.builder().statusCode(200).build()
).getVirtualIPApiForZoneAndLoadBalancer("DFW", 2000);
List<Integer> virtualIPIds = ImmutableList.<Integer> of(23, 24);
api.remove(virtualIPIds);
}
private Iterable<VirtualIPWithId> getVirtualIPs() {
VirtualIPWithId virtualIP1 = new VirtualIPWithId(VirtualIP.Type.PUBLIC, VirtualIP.IPVersion.IPV4, 5557, "166.78.34.87");
VirtualIPWithId virtualIP2 = new VirtualIPWithId(VirtualIP.Type.PUBLIC, VirtualIP.IPVersion.IPV6, 9076419, "2001:4800:7901:0000:9a32:3c2a:0000:0001");
VirtualIPWithId virtualIP3 = new VirtualIPWithId(VirtualIP.Type.PUBLIC, VirtualIP.IPVersion.IPV6, 9079727, "2001:4800:7901:0000:9a32:3c2a:0000:0002");
return ImmutableList.<VirtualIPWithId> of(virtualIP1, virtualIP2, virtualIP3);
}
}

View File

@ -0,0 +1,121 @@
/**
* 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.rackspace.cloudloadbalancers.features;
import static org.jclouds.rackspace.cloudloadbalancers.predicates.LoadBalancerPredicates.awaitAvailable;
import static org.jclouds.rackspace.cloudloadbalancers.predicates.LoadBalancerPredicates.awaitDeleted;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.util.List;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancerRequest;
import org.jclouds.rackspace.cloudloadbalancers.domain.NodeRequest;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP.Type;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIPWithId;
import org.jclouds.rackspace.cloudloadbalancers.internal.BaseCloudLoadBalancersApiLiveTest;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
/**
* @author Everett Toews
*/
@Test(groups = "live", singleThreaded = true, testName = "VirtualIPApiLiveTest")
public class VirtualIPApiLiveTest extends BaseCloudLoadBalancersApiLiveTest {
private LoadBalancer lb;
private String zone;
@Override
@BeforeGroups(groups = { "live" })
public void setupContext() {
super.setupContext();
new VirtualIPWithId(VirtualIP.Type.PUBLIC, VirtualIP.IPVersion.IPV4, 1000, "206.10.10.210");
new VirtualIPWithId(VirtualIP.Type.PUBLIC, VirtualIP.IPVersion.IPV6, 1001, "2001:4800:7901:0000:9a32:3c2a:0000:0001");
}
public void testCreateLoadBalancer() {
NodeRequest nodeRequest = NodeRequest.builder().address("192.168.1.1").port(8080).build();
LoadBalancerRequest lbRequest = LoadBalancerRequest.builder()
.name(prefix+"-jclouds").protocol("HTTP").port(80).virtualIPType(Type.PUBLIC).node(nodeRequest).build();
zone = Iterables.getFirst(clbApi.getConfiguredZones(), null);
lb = clbApi.getLoadBalancerApiForZone(zone).create(lbRequest);
assertTrue(awaitAvailable(clbApi.getLoadBalancerApiForZone(zone)).apply(lb));
}
@Test(dependsOnMethods = "testCreateLoadBalancer")
public void testCreateVirtualIPs() throws Exception {
clbApi.getVirtualIPApiForZoneAndLoadBalancer(zone, lb.getId()).create(VirtualIP.publicIPv6());
assertTrue(awaitAvailable(clbApi.getLoadBalancerApiForZone(zone)).apply(lb));
clbApi.getVirtualIPApiForZoneAndLoadBalancer(zone, lb.getId()).create(VirtualIP.publicIPv6());
assertTrue(awaitAvailable(clbApi.getLoadBalancerApiForZone(zone)).apply(lb));
clbApi.getVirtualIPApiForZoneAndLoadBalancer(zone, lb.getId()).create(VirtualIP.publicIPv6());
assertTrue(awaitAvailable(clbApi.getLoadBalancerApiForZone(zone)).apply(lb));
Iterable<VirtualIPWithId> actualVirtualIPs = clbApi.getVirtualIPApiForZoneAndLoadBalancer(zone, lb.getId()).list();
assertEquals(Iterators.size(actualVirtualIPs.iterator()), 5);
}
@Test(dependsOnMethods = "testCreateVirtualIPs")
public void testRemoveSingleVirtualIP() throws Exception {
Iterable<VirtualIPWithId> actualVirtualIPs = clbApi.getVirtualIPApiForZoneAndLoadBalancer(zone, lb.getId()).list();
VirtualIPWithId removedVirtualIP = Iterables.getFirst(actualVirtualIPs, null);
assertTrue(clbApi.getVirtualIPApiForZoneAndLoadBalancer(zone, lb.getId()).remove(removedVirtualIP.getId()));
assertTrue(awaitAvailable(clbApi.getLoadBalancerApiForZone(zone)).apply(lb));
actualVirtualIPs = clbApi.getVirtualIPApiForZoneAndLoadBalancer(zone, lb.getId()).list();
assertEquals(Iterators.size(actualVirtualIPs.iterator()), 4);
}
@Test(dependsOnMethods = "testRemoveSingleVirtualIP")
public void testRemoveManyVirtualIPs() throws Exception {
Iterable<VirtualIPWithId> actualVirtualIPs = clbApi.getVirtualIPApiForZoneAndLoadBalancer(zone, lb.getId()).list();
VirtualIPWithId removedVirtualIP1 = Iterables.getFirst(actualVirtualIPs, null);
VirtualIPWithId removedVirtualIP2 = Iterables.getLast(actualVirtualIPs);
List<Integer> removedVirtualIPIds = ImmutableList.<Integer> of(removedVirtualIP1.getId(), removedVirtualIP2.getId());
assertTrue(clbApi.getVirtualIPApiForZoneAndLoadBalancer(zone, lb.getId()).remove(removedVirtualIPIds));
assertTrue(awaitAvailable(clbApi.getLoadBalancerApiForZone(zone)).apply(lb));
actualVirtualIPs = clbApi.getVirtualIPApiForZoneAndLoadBalancer(zone, lb.getId()).list();
assertEquals(Iterators.size(actualVirtualIPs.iterator()), 2);
}
@Override
@AfterGroups(groups = "live")
protected void tearDownContext() {
assertTrue(awaitAvailable(clbApi.getLoadBalancerApiForZone(zone)).apply(lb));
clbApi.getLoadBalancerApiForZone(zone).remove(lb.getId());
assertTrue(awaitDeleted(clbApi.getLoadBalancerApiForZone(zone)).apply(lb));
super.tearDownContext();
}
}

View File

@ -33,7 +33,7 @@ import org.jclouds.rackspace.cloudloadbalancers.domain.Node;
import org.jclouds.rackspace.cloudloadbalancers.domain.SSLTermination;
import org.jclouds.rackspace.cloudloadbalancers.domain.SourceAddresses;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP.IPVersion;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIPWithId;
import org.jclouds.rackspace.cloudloadbalancers.domain.internal.BaseLoadBalancer.Algorithm;
import org.jclouds.rackspace.cloudloadbalancers.domain.internal.BaseLoadBalancer.SessionPersistenceType;
import org.testng.annotations.Test;
@ -79,8 +79,8 @@ public class ParseLoadBalancerTest extends BaseItemParserTest<LoadBalancer> {
new AccessRuleWithId(22215, "1.2.3.4/32", AccessRule.Type.DENY),
new AccessRuleWithId(22217, "12.0.0.0/8", AccessRule.Type.ALLOW)))
.virtualIPs(ImmutableSet.of(
VirtualIP.builder().id(1000).address("206.10.10.210").type(VirtualIP.Type.PUBLIC).ipVersion(IPVersion.IPV4).build(),
VirtualIP.builder().id(1001).address("2001:4800:7901:0000:9a32:3c2a:0000:0001").type(VirtualIP.Type.PUBLIC).ipVersion(IPVersion.IPV6).build()))
new VirtualIPWithId(VirtualIP.Type.PUBLIC, VirtualIP.IPVersion.IPV4, 1000, "206.10.10.210"),
new VirtualIPWithId(VirtualIP.Type.PUBLIC, VirtualIP.IPVersion.IPV6, 1001, "2001:4800:7901:0000:9a32:3c2a:0000:0001")))
.nodes(ImmutableSet.of(
Node.builder().id(1041).address("10.1.1.1").port(80).condition(Node.Condition.ENABLED).status(Node.Status.ONLINE).build(),
Node.builder().id(1411).address("10.1.1.2").port(80).condition(Node.Condition.ENABLED).status(Node.Status.ONLINE).build()))

View File

@ -27,6 +27,7 @@ import org.jclouds.http.HttpResponse;
import org.jclouds.json.BaseIterableWithMarkerParserTest;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer.Status;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIPWithId;
import org.jclouds.rackspace.cloudloadbalancers.domain.internal.BaseLoadBalancer.Algorithm;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP;
import org.testng.annotations.Test;
@ -57,8 +58,7 @@ public class ParseLoadBalancersTest extends BaseIterableWithMarkerParserTest<Loa
.status(Status.ACTIVE)
.nodeCount(1)
.virtualIPs(ImmutableSet.of(
VirtualIP.builder().id(403).address("206.55.130.1")
.type(VirtualIP.Type.PUBLIC).ipVersion(VirtualIP.IPVersion.IPV4).build()))
new VirtualIPWithId(VirtualIP.Type.PUBLIC, VirtualIP.IPVersion.IPV4, 403, "206.55.130.1")))
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2010-11-30T03:23:42Z"))
.updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2010-11-30T03:23:44Z")).build(),
LoadBalancer
@ -72,8 +72,7 @@ public class ParseLoadBalancersTest extends BaseIterableWithMarkerParserTest<Loa
.status(Status.ACTIVE)
.nodeCount(1)
.virtualIPs(ImmutableSet.of(
VirtualIP.builder().id(401).address("206.55.130.2")
.type(VirtualIP.Type.PUBLIC).ipVersion(VirtualIP.IPVersion.IPV4).build()))
new VirtualIPWithId(VirtualIP.Type.PUBLIC, VirtualIP.IPVersion.IPV4, 401, "206.55.130.2")))
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2010-11-30T03:23:42Z"))
.updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2010-11-30T03:23:44Z")).build());
}

View File

@ -0,0 +1,6 @@
{
"address": "fd24:f480:ce44:91bc:1af2:15ff:0000:0002",
"id": 9000134,
"type": "PUBLIC",
"ipVersion": "IPV6"
}

View File

@ -0,0 +1 @@
{"type":"PUBLIC","ipVersion":"IPV6"}

View File

@ -0,0 +1,22 @@
{
"virtualIps": [
{
"address": "166.78.34.87",
"id": 5557,
"type": "PUBLIC",
"ipVersion": "IPV4"
},
{
"address": "2001:4800:7901:0000:9a32:3c2a:0000:0001",
"id": 9076419,
"type": "PUBLIC",
"ipVersion": "IPV6"
},
{
"address": "2001:4800:7901:0000:9a32:3c2a:0000:0002",
"id": 9079727,
"type": "PUBLIC",
"ipVersion": "IPV6"
}
]
}