diff --git a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersApi.java b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersApi.java index 71924ba0a4..9f93d688ae 100644 --- a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersApi.java +++ b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersApi.java @@ -27,6 +27,7 @@ import org.jclouds.location.Zone; import org.jclouds.location.functions.ZoneToEndpoint; import org.jclouds.rackspace.cloudloadbalancers.features.AccessRuleApi; import org.jclouds.rackspace.cloudloadbalancers.features.ConnectionApi; +import org.jclouds.rackspace.cloudloadbalancers.features.ContentCachingApi; import org.jclouds.rackspace.cloudloadbalancers.features.HealthMonitorApi; import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerApi; import org.jclouds.rackspace.cloudloadbalancers.features.NodeApi; @@ -106,4 +107,12 @@ public interface CloudLoadBalancersApi { @Path("/loadbalancers/{lbId}") SessionPersistenceApi getSessionPersistenceApiForZoneAndLoadBalancer( @EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone, @PathParam("lbId") int lbId); + + /** + * Provides synchronous access to Content Caching features. + */ + @Delegate + @Path("/loadbalancers/{lbId}") + ContentCachingApi getContentCachingApiForZoneAndLoadBalancer( + @EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone, @PathParam("lbId") int lbId); } diff --git a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersAsyncApi.java b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersAsyncApi.java index 48bd7f9a44..6a11704833 100644 --- a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersAsyncApi.java +++ b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/CloudLoadBalancersAsyncApi.java @@ -28,6 +28,7 @@ import org.jclouds.location.Zone; import org.jclouds.location.functions.ZoneToEndpoint; import org.jclouds.rackspace.cloudloadbalancers.features.AccessRuleAsyncApi; import org.jclouds.rackspace.cloudloadbalancers.features.ConnectionAsyncApi; +import org.jclouds.rackspace.cloudloadbalancers.features.ContentCachingAsyncApi; import org.jclouds.rackspace.cloudloadbalancers.features.HealthMonitorAsyncApi; import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerAsyncApi; import org.jclouds.rackspace.cloudloadbalancers.features.NodeAsyncApi; @@ -107,4 +108,12 @@ public interface CloudLoadBalancersAsyncApi { @Path("/loadbalancers/{lbId}") SessionPersistenceAsyncApi getSessionPersistenceApiForZoneAndLoadBalancer( @EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone, @PathParam("lbId") int lbId); + + /** + * Provides asynchronous access to Content Caching features. + */ + @Delegate + @Path("/loadbalancers/{lbId}") + ContentCachingAsyncApi getContentCachingApiForZoneAndLoadBalancer( + @EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone, @PathParam("lbId") int lbId); } diff --git a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/config/CloudLoadBalancersRestClientModule.java b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/config/CloudLoadBalancersRestClientModule.java index e946c2e926..2f283213fc 100644 --- a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/config/CloudLoadBalancersRestClientModule.java +++ b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/config/CloudLoadBalancersRestClientModule.java @@ -32,6 +32,8 @@ import org.jclouds.rackspace.cloudloadbalancers.features.AccessRuleApi; import org.jclouds.rackspace.cloudloadbalancers.features.AccessRuleAsyncApi; import org.jclouds.rackspace.cloudloadbalancers.features.ConnectionApi; import org.jclouds.rackspace.cloudloadbalancers.features.ConnectionAsyncApi; +import org.jclouds.rackspace.cloudloadbalancers.features.ContentCachingApi; +import org.jclouds.rackspace.cloudloadbalancers.features.ContentCachingAsyncApi; import org.jclouds.rackspace.cloudloadbalancers.features.HealthMonitorApi; import org.jclouds.rackspace.cloudloadbalancers.features.HealthMonitorAsyncApi; import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerAsyncApi; @@ -67,6 +69,7 @@ public class CloudLoadBalancersRestClientModule extends .put(ConnectionApi.class, ConnectionAsyncApi.class) .put(HealthMonitorApi.class, HealthMonitorAsyncApi.class) .put(SessionPersistenceApi.class, SessionPersistenceAsyncApi.class) + .put(ContentCachingApi.class, ContentCachingAsyncApi.class) .build(); public CloudLoadBalancersRestClientModule() { diff --git a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/domain/HealthMonitor.java b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/domain/HealthMonitor.java index 8da0c3287c..d42a94bc90 100644 --- a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/domain/HealthMonitor.java +++ b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/domain/HealthMonitor.java @@ -143,8 +143,8 @@ public class HealthMonitor { protected ToStringHelper string() { return Objects.toStringHelper(this).omitNullValues().add("type", type).add("delay", delay) .add("timeout", timeout).add("attemptsBeforeDeactivation", attemptsBeforeDeactivation) - .add("bodyRegex", bodyRegex).add("statusRegex", statusRegex).add("path", path) - .add("hostHeader", hostHeader); + .add("bodyRegex", bodyRegex.orNull()).add("statusRegex", statusRegex.orNull()).add("path", path.orNull()) + .add("hostHeader", hostHeader.orNull()); } @Override diff --git a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/features/ContentCachingApi.java b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/features/ContentCachingApi.java new file mode 100644 index 0000000000..b7072b39c4 --- /dev/null +++ b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/features/ContentCachingApi.java @@ -0,0 +1,47 @@ +/** + * 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; + +/** + * When content caching is enabled, recently-accessed files are stored on the load balancer for easy retrieval by web + * clients. Content caching improves the performance of high traffic web sites by temporarily storing data that was + * recently accessed. While it's cached, requests for that data will be served by the load balancer, which in turn + * reduces load off the back end nodes. The result is improved response times for those requests and less load on the + * web server. + *

+ * + * @see ContentCachingAsyncApi + * @author Everett Toews + */ +public interface ContentCachingApi { + /** + * Determine if the load balancer is content caching. + */ + boolean isContentCaching(); + + /** + * Enable content caching. + */ + void enable(); + + /** + * Disable content caching. + */ + void disable(); +} \ No newline at end of file diff --git a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/features/ContentCachingAsyncApi.java b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/features/ContentCachingAsyncApi.java new file mode 100644 index 0000000000..5e1087fc4a --- /dev/null +++ b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/features/ContentCachingAsyncApi.java @@ -0,0 +1,84 @@ +/** + * 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.inject.Named; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.jclouds.Fallbacks.FalseOnNotFoundOr404; +import org.jclouds.Fallbacks.VoidOnNotFoundOr404; +import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; +import org.jclouds.rackspace.cloudloadbalancers.functions.ParseNestedBoolean; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.Payload; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides asynchronous access to Rackspace Cloud Load Balancers via their REST API. + *

+ * + * @see ContentCachingAsyncApi + * @author Everett Toews + */ +@RequestFilters(AuthenticateRequest.class) +public interface ContentCachingAsyncApi { + + /** + * @see ContentCachingApi#isContentCaching() + */ + @Named("contentcaching:state") + @GET + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(ParseNestedBoolean.class) + @Fallback(FalseOnNotFoundOr404.class) + @Path("/contentcaching") + ListenableFuture isContentCaching(); + + /** + * @see ContentCachingApi#enable() + */ + @Named("contentcaching:state") + @PUT + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @Fallback(VoidOnNotFoundOr404.class) + @Payload("{\"contentCaching\":{\"enabled\":true}}") + @Path("/contentcaching") + ListenableFuture enable(); + + /** + * @see ContentCachingApi#disableConnectionLogging() + */ + @Named("contentcaching:state") + @PUT + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @Fallback(VoidOnNotFoundOr404.class) + @Payload("{\"contentCaching\":{\"enabled\":false}}") + @Path("/contentcaching") + ListenableFuture disable(); +} diff --git a/apis/rackspace-cloudloadbalancers/src/test/java/org/jclouds/rackspace/cloudloadbalancers/features/ContentCachingApiExpectTest.java b/apis/rackspace-cloudloadbalancers/src/test/java/org/jclouds/rackspace/cloudloadbalancers/features/ContentCachingApiExpectTest.java new file mode 100644 index 0000000000..8e380ac239 --- /dev/null +++ b/apis/rackspace-cloudloadbalancers/src/test/java/org/jclouds/rackspace/cloudloadbalancers/features/ContentCachingApiExpectTest.java @@ -0,0 +1,70 @@ +/** + * 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.assertTrue; + +import java.net.URI; + +import org.jclouds.http.HttpResponse; +import org.jclouds.rackspace.cloudloadbalancers.CloudLoadBalancersApi; +import org.jclouds.rackspace.cloudloadbalancers.internal.BaseCloudLoadBalancerApiExpectTest; +import org.testng.annotations.Test; + +/** + * @author Everett Toews + */ +@Test(groups = "unit") +public class ContentCachingApiExpectTest extends BaseCloudLoadBalancerApiExpectTest { + public void testIsContentCaching() { + URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/contentcaching"); + ContentCachingApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().endpoint(endpoint).build(), + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/contentcaching-enable.json")).build() + ).getContentCachingApiForZoneAndLoadBalancer("DFW", 2000); + + assertTrue(api.isContentCaching()); + } + + public void testEnableContentCaching() { + URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/contentcaching"); + ContentCachingApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().method("PUT").endpoint(endpoint).payload(payloadFromResource("/contentcaching-enable.json")).build(), + HttpResponse.builder().statusCode(200).build() + ).getContentCachingApiForZoneAndLoadBalancer("DFW", 2000); + + api.enable(); + } + + public void testDisableContentCaching() { + URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/contentcaching"); + ContentCachingApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().method("PUT").endpoint(endpoint).payload(payloadFromResource("/contentcaching-disable.json")).build(), + HttpResponse.builder().statusCode(200).build() + ).getContentCachingApiForZoneAndLoadBalancer("DFW", 2000); + + api.disable(); + } +} diff --git a/apis/rackspace-cloudloadbalancers/src/test/java/org/jclouds/rackspace/cloudloadbalancers/features/ContentCachingApiLiveTest.java b/apis/rackspace-cloudloadbalancers/src/test/java/org/jclouds/rackspace/cloudloadbalancers/features/ContentCachingApiLiveTest.java new file mode 100644 index 0000000000..be1923eaaf --- /dev/null +++ b/apis/rackspace-cloudloadbalancers/src/test/java/org/jclouds/rackspace/cloudloadbalancers/features/ContentCachingApiLiveTest.java @@ -0,0 +1,85 @@ +/** + * 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.assertFalse; +import static org.testng.Assert.assertTrue; + +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.Type; +import org.jclouds.rackspace.cloudloadbalancers.internal.BaseCloudLoadBalancersApiLiveTest; +import org.testng.annotations.AfterGroups; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; + +/** + * @author Everett Toews + */ +@Test(groups = "live", singleThreaded = true, testName = "ContentCachingApiLiveTest") +public class ContentCachingApiLiveTest extends BaseCloudLoadBalancersApiLiveTest { + private LoadBalancer lb; + private String zone; + + 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 testEnableAndIsContentCaching() throws Exception { + clbApi.getContentCachingApiForZoneAndLoadBalancer(zone, lb.getId()).enable(); + assertTrue(awaitAvailable(clbApi.getLoadBalancerApiForZone(zone)).apply(lb)); + + boolean isContentCaching = + clbApi.getContentCachingApiForZoneAndLoadBalancer(zone, lb.getId()).isContentCaching(); + + assertTrue(isContentCaching); + } + + @Test(dependsOnMethods = "testEnableAndIsContentCaching") + public void testDisableAndIsContentCaching() throws Exception { + clbApi.getContentCachingApiForZoneAndLoadBalancer(zone, lb.getId()).disable(); + assertTrue(awaitAvailable(clbApi.getLoadBalancerApiForZone(zone)).apply(lb)); + + boolean isContentCaching = + clbApi.getContentCachingApiForZoneAndLoadBalancer(zone, lb.getId()).isContentCaching(); + + assertFalse(isContentCaching); + } + + @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(); + } +} diff --git a/apis/rackspace-cloudloadbalancers/src/test/resources/contentcaching-disable.json b/apis/rackspace-cloudloadbalancers/src/test/resources/contentcaching-disable.json new file mode 100644 index 0000000000..ef37f80917 --- /dev/null +++ b/apis/rackspace-cloudloadbalancers/src/test/resources/contentcaching-disable.json @@ -0,0 +1 @@ +{"contentCaching":{"enabled":false}} \ No newline at end of file diff --git a/apis/rackspace-cloudloadbalancers/src/test/resources/contentcaching-enable.json b/apis/rackspace-cloudloadbalancers/src/test/resources/contentcaching-enable.json new file mode 100644 index 0000000000..dafdba5802 --- /dev/null +++ b/apis/rackspace-cloudloadbalancers/src/test/resources/contentcaching-enable.json @@ -0,0 +1 @@ +{"contentCaching":{"enabled":true}} \ No newline at end of file