You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by za...@apache.org on 2013/11/12 00:10:27 UTC
[4/8] JCLOUDS-215 - Adds Group configuration, Group launch,
Scaling policy functionality
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/92fa9cf7/rackspace-autoscale/src/test/java/org/jclouds/rackspace/autoscale/v1/features/ScalingPolicyApiExpectTest.java
----------------------------------------------------------------------
diff --git a/rackspace-autoscale/src/test/java/org/jclouds/rackspace/autoscale/v1/features/ScalingPolicyApiExpectTest.java b/rackspace-autoscale/src/test/java/org/jclouds/rackspace/autoscale/v1/features/ScalingPolicyApiExpectTest.java
new file mode 100644
index 0000000..8bb310c
--- /dev/null
+++ b/rackspace-autoscale/src/test/java/org/jclouds/rackspace/autoscale/v1/features/ScalingPolicyApiExpectTest.java
@@ -0,0 +1,265 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.autoscale.v1.features;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import java.net.URI;
+import java.util.List;
+
+import javax.ws.rs.core.MediaType;
+
+import org.jclouds.http.HttpResponse;
+import org.jclouds.rackspace.autoscale.v1.domain.ScalingPolicy;
+import org.jclouds.rackspace.autoscale.v1.domain.ScalingPolicy.ScalingPolicyTargetType;
+import org.jclouds.rackspace.autoscale.v1.domain.ScalingPolicy.ScalingPolicyType;
+import org.jclouds.rackspace.autoscale.v1.domain.ScalingPolicyResponse;
+import org.jclouds.rackspace.autoscale.v1.internal.BaseAutoscaleApiExpectTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.Lists;
+
+/**
+ * Tests Scaling Policy Api Guice wiring and parsing
+ *
+ * @author Zack Shoylev
+ */
+@Test(groups = "unit", testName = "GroupApiExpectTest")
+public class ScalingPolicyApiExpectTest extends BaseAutoscaleApiExpectTest {
+
+ public void testCreateScalingPolicy() {
+ URI endpoint = URI.create("https://dfw.autoscale.api.rackspacecloud.com/v1.0/888888/groups/groupId1/policies");
+ PolicyApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess,
+ authenticatedGET().method("POST").endpoint(endpoint).payload(payloadFromResourceWithContentType("/autoscale_policy_create_request.json", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(201).payload(payloadFromResource("/autoscale_policy_create_response.json")).build()
+ ).getPolicyApiForGroupInZone("groupId1", "DFW");
+
+ List<ScalingPolicy> scalingPolicies = Lists.newArrayList();
+
+ ScalingPolicy scalingPolicy = ScalingPolicy.builder()
+ .cooldown(1800)
+ .type(ScalingPolicyType.WEBHOOK)
+ .name("scale up by one server")
+ .targetType(ScalingPolicyTargetType.INCREMENTAL)
+ .target("1")
+ .build();
+ scalingPolicies.add(scalingPolicy);
+
+ FluentIterable<ScalingPolicyResponse> scalingPolicyResponse = api.create(scalingPolicies);
+
+ assertNotNull(scalingPolicyResponse);
+ assertEquals(scalingPolicyResponse.size(), 1);
+ assertEquals(scalingPolicyResponse.get(0).getCooldown(), 1800);
+ assertEquals(scalingPolicyResponse.get(0).getId(), "dceb14ac-b2b3-4f06-aac9-a5b6cd5d40e1");
+ assertEquals(scalingPolicyResponse.get(0).getName(), "scale up by one server");
+ assertEquals(scalingPolicyResponse.get(0).getTarget(), "1");
+ assertEquals(scalingPolicyResponse.get(0).getLinks().size(), 1);
+ }
+
+ public void testCreateScalingPolicyFail() {
+ URI endpoint = URI.create("https://dfw.autoscale.api.rackspacecloud.com/v1.0/888888/groups/groupId1/policies");
+ PolicyApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess,
+ authenticatedGET().method("POST").endpoint(endpoint).payload(payloadFromResourceWithContentType("/autoscale_policy_create_request.json", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(404).payload(payloadFromResource("/autoscale_policy_create_response.json")).build()
+ ).getPolicyApiForGroupInZone("groupId1", "DFW");
+
+ List<ScalingPolicy> scalingPolicies = Lists.newArrayList();
+
+ ScalingPolicy scalingPolicy = ScalingPolicy.builder()
+ .cooldown(1800)
+ .type(ScalingPolicyType.WEBHOOK)
+ .name("scale up by one server")
+ .targetType(ScalingPolicyTargetType.INCREMENTAL)
+ .target("1")
+ .build();
+ scalingPolicies.add(scalingPolicy);
+
+ FluentIterable<ScalingPolicyResponse> scalingPolicyResponse = api.create(scalingPolicies);
+
+ assertTrue(scalingPolicyResponse.size() == 0);
+ }
+
+ public void testListScalingPolicies() {
+ URI endpoint = URI.create("https://dfw.autoscale.api.rackspacecloud.com/v1.0/888888/groups/groupId1/policies");
+ PolicyApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess,
+ authenticatedGET().method("GET").endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(201).payload(payloadFromResource("/autoscale_policy_list_response.json")).build()
+ ).getPolicyApiForGroupInZone("groupId1", "DFW");
+
+ FluentIterable<ScalingPolicyResponse> scalingPolicyResponse = api.list();
+
+ assertNotNull(scalingPolicyResponse);
+ assertEquals(scalingPolicyResponse.size(), 2);
+ assertEquals(scalingPolicyResponse.get(0).getCooldown(), 150);
+ assertEquals(scalingPolicyResponse.get(0).getId(), "policyId1");
+ assertEquals(scalingPolicyResponse.get(0).getName(), "scale up by one server");
+ assertEquals(scalingPolicyResponse.get(0).getTarget(), "1");
+ assertEquals(scalingPolicyResponse.get(0).getLinks().size(), 1);
+ }
+
+ public void testListScalingPoliciesFail() {
+ URI endpoint = URI.create("https://dfw.autoscale.api.rackspacecloud.com/v1.0/888888/groups/groupId1/policies");
+ PolicyApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess,
+ authenticatedGET().method("GET").endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).payload(payloadFromResource("/autoscale_policy_list_response.json")).build()
+ ).getPolicyApiForGroupInZone("groupId1", "DFW");
+
+ FluentIterable<ScalingPolicyResponse> scalingPolicyResponse = api.list();
+
+ assertEquals(scalingPolicyResponse.size(), 0);
+ }
+
+ public void testGetScalingPolicies() {
+ URI endpoint = URI.create("https://dfw.autoscale.api.rackspacecloud.com/v1.0/888888/groups/groupId1/policies/policyId");
+ PolicyApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess,
+ authenticatedGET().method("GET").endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(201).payload(payloadFromResource("/autoscale_policy_get_response.json")).build()
+ ).getPolicyApiForGroupInZone("groupId1", "DFW");
+
+ ScalingPolicyResponse scalingPolicyResponse = api.get("policyId");
+
+ assertNotNull(scalingPolicyResponse);
+ assertEquals(scalingPolicyResponse.getCooldown(), 150);
+ assertEquals(scalingPolicyResponse.getId(), "policyId");
+ assertEquals(scalingPolicyResponse.getName(), "scale up by one server");
+ assertEquals(scalingPolicyResponse.getTarget(), "1");
+ assertEquals(scalingPolicyResponse.getLinks().size(), 1);
+ }
+
+ public void testGetScalingPoliciesFail() {
+ URI endpoint = URI.create("https://dfw.autoscale.api.rackspacecloud.com/v1.0/888888/groups/groupId1/policies/policyId");
+ PolicyApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess,
+ authenticatedGET().method("GET").endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).payload(payloadFromResource("/autoscale_policy_get_response.json")).build()
+ ).getPolicyApiForGroupInZone("groupId1", "DFW");
+
+ ScalingPolicyResponse scalingPolicyResponse = api.get("policyId");
+
+ assertNull(scalingPolicyResponse);
+ }
+
+ public void testUpdateScalingPolicy() {
+ URI endpoint = URI.create("https://dfw.autoscale.api.rackspacecloud.com/v1.0/888888/groups/groupId1/policies/policyId");
+ PolicyApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess,
+ authenticatedGET().method("PUT").endpoint(endpoint).payload(payloadFromResourceWithContentType("/autoscale_policy_update_request.json", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(201).build()
+ ).getPolicyApiForGroupInZone("groupId1", "DFW");
+
+ ScalingPolicy scalingPolicy = ScalingPolicy.builder()
+ .cooldown(6)
+ .type(ScalingPolicyType.WEBHOOK)
+ .name("scale down by 5 percent")
+ .targetType(ScalingPolicyTargetType.PERCENT_CHANGE)
+ .target("-5")
+ .build();
+
+ boolean result = api.update("policyId", scalingPolicy);
+ assertTrue(result);
+ }
+
+ public void testUpdateScalingPolicyFail() {
+ URI endpoint = URI.create("https://dfw.autoscale.api.rackspacecloud.com/v1.0/888888/groups/groupId1/policies/policyId");
+ PolicyApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess,
+ authenticatedGET().method("PUT").endpoint(endpoint).payload(payloadFromResourceWithContentType("/autoscale_policy_update_request.json", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getPolicyApiForGroupInZone("groupId1", "DFW");
+
+ ScalingPolicy scalingPolicy = ScalingPolicy.builder()
+ .cooldown(6)
+ .type(ScalingPolicyType.WEBHOOK)
+ .name("scale down by 5 percent")
+ .targetType(ScalingPolicyTargetType.PERCENT_CHANGE)
+ .target("-5")
+ .build();
+
+ boolean result = api.update("policyId", scalingPolicy);
+ assertFalse(result);
+ }
+
+ public void testDeleteScalingPolicy() {
+ URI endpoint = URI.create("https://dfw.autoscale.api.rackspacecloud.com/v1.0/888888/groups/groupId1/policies/policyId");
+ PolicyApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess,
+ authenticatedGET().method("DELETE").endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(201).build()
+ ).getPolicyApiForGroupInZone("groupId1", "DFW");
+
+ boolean result = api.delete("policyId");
+ assertTrue(result);
+ }
+
+ public void testDeleteScalingPolicyFail() {
+ URI endpoint = URI.create("https://dfw.autoscale.api.rackspacecloud.com/v1.0/888888/groups/groupId1/policies/policyId");
+ PolicyApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess,
+ authenticatedGET().method("DELETE").endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getPolicyApiForGroupInZone("groupId1", "DFW");
+
+ boolean result = api.delete("policyId");
+ assertFalse(result);
+ }
+
+ public void testExecuteScalingPolicy() {
+ URI endpoint = URI.create("https://dfw.autoscale.api.rackspacecloud.com/v1.0/888888/groups/groupId1/policies/policyId/execute");
+ PolicyApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess,
+ authenticatedGET().method("POST").endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(201).build()
+ ).getPolicyApiForGroupInZone("groupId1", "DFW");
+
+ boolean result = api.execute("policyId");
+ assertTrue(result);
+ }
+
+ public void testExecuteScalingPolicyFail() {
+ URI endpoint = URI.create("https://dfw.autoscale.api.rackspacecloud.com/v1.0/888888/groups/groupId1/policies/policyId/execute");
+ PolicyApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess,
+ authenticatedGET().method("POST").endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getPolicyApiForGroupInZone("groupId1", "DFW");
+
+ boolean result = api.execute("policyId");
+ assertFalse(result);
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/92fa9cf7/rackspace-autoscale/src/test/java/org/jclouds/rackspace/autoscale/v1/features/ScalingPolicyApiLiveTest.java
----------------------------------------------------------------------
diff --git a/rackspace-autoscale/src/test/java/org/jclouds/rackspace/autoscale/v1/features/ScalingPolicyApiLiveTest.java b/rackspace-autoscale/src/test/java/org/jclouds/rackspace/autoscale/v1/features/ScalingPolicyApiLiveTest.java
new file mode 100644
index 0000000..ab2e257
--- /dev/null
+++ b/rackspace-autoscale/src/test/java/org/jclouds/rackspace/autoscale/v1/features/ScalingPolicyApiLiveTest.java
@@ -0,0 +1,338 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.autoscale.v1.features;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import org.jclouds.openstack.v2_0.domain.Link;
+import org.jclouds.rackspace.autoscale.v1.domain.Group;
+import org.jclouds.rackspace.autoscale.v1.domain.GroupConfiguration;
+import org.jclouds.rackspace.autoscale.v1.domain.LaunchConfiguration;
+import org.jclouds.rackspace.autoscale.v1.domain.LaunchConfiguration.LaunchConfigurationType;
+import org.jclouds.rackspace.autoscale.v1.domain.LoadBalancer;
+import org.jclouds.rackspace.autoscale.v1.domain.Personality;
+import org.jclouds.rackspace.autoscale.v1.domain.ScalingPolicy;
+import org.jclouds.rackspace.autoscale.v1.domain.ScalingPolicy.ScalingPolicyTargetType;
+import org.jclouds.rackspace.autoscale.v1.domain.ScalingPolicy.ScalingPolicyType;
+import org.jclouds.rackspace.autoscale.v1.domain.ScalingPolicyResponse;
+import org.jclouds.rackspace.autoscale.v1.internal.BaseAutoscaleApiLiveTest;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.util.concurrent.Uninterruptibles;
+
+/**
+ * Scaling Policy live test
+ *
+ * @author Zack Shoylev
+ */
+@Test(groups = "unit", testName = "ScalingPolicyApiLiveTest", singleThreaded = true)
+public class ScalingPolicyApiLiveTest extends BaseAutoscaleApiLiveTest {
+
+ private static Map<String, List<Group>> created = Maps.newHashMap();
+
+ @Override
+ @BeforeClass(groups = { "integration", "live" })
+ public void setup() {
+ super.setup();
+ for (String zone : api.getConfiguredZones()) {
+ List<Group> createdGroupList = Lists.newArrayList();
+ created.put(zone, createdGroupList);
+ GroupApi groupApi = api.getGroupApiForZone(zone);
+
+ GroupConfiguration groupConfiguration = GroupConfiguration.builder().maxEntities(10).cooldown(360)
+ .name("testscalinggroup198547").minEntities(0)
+ .metadata(ImmutableMap.of("gc_meta_key_2", "gc_meta_value_2", "gc_meta_key_1", "gc_meta_value_1"))
+ .build();
+
+ LaunchConfiguration launchConfiguration = LaunchConfiguration
+ .builder()
+ .loadBalancers(ImmutableList.of(LoadBalancer.builder().port(8080).id(9099).build()))
+ .serverName("autoscale_server")
+ .serverImageRef("c52a0ca6-c1f2-4cd1-b7d6-afbcd1ebda22")
+ .serverFlavorRef("2")
+ .serverDiskConfig("AUTO")
+ .serverMetadata(
+ ImmutableMap
+ .of("build_config", "core", "meta_key_1", "meta_value_1", "meta_key_2", "meta_value_2"))
+ .networks(
+ ImmutableList.of("11111111-1111-1111-1111-111111111111", "00000000-0000-0000-0000-000000000000"))
+ .personalities(
+ ImmutableList.of(Personality.builder().path("/root/.csivh")
+ .contents("VGhpcyBpcyBhIHRlc3QgZmlsZS4=").build()))
+ .type(LaunchConfigurationType.LAUNCH_SERVER).build();
+
+ List<ScalingPolicy> scalingPolicies = Lists.newArrayList();
+
+ ScalingPolicy scalingPolicy = ScalingPolicy.builder().cooldown(0).type(ScalingPolicyType.WEBHOOK)
+ .name("scale up by 1").targetType(ScalingPolicyTargetType.INCREMENTAL).target("1").build();
+ scalingPolicies.add(scalingPolicy);
+
+ Group g = groupApi.create(groupConfiguration, launchConfiguration, scalingPolicies);
+ createdGroupList.add(g);
+
+ assertNotNull(g);
+ assertNotNull(g.getId());
+ assertEquals(g.getLinks().size(), 1);
+ assertEquals(g.getLinks().get(0).getHref().toString(),
+ "https://" + zone.toLowerCase() + ".autoscale.api.rackspacecloud.com/v1.0/" + api.getCurrentTenantId().get().getId() + "/groups/" + g.getId() + "/");
+ assertEquals(g.getLinks().get(0).getRelation(), Link.Relation.SELF);
+
+ assertNotNull(g.getScalingPolicies().get(0).getId());
+ assertEquals(g.getScalingPolicies().get(0).getLinks().size(), 1);
+ assertEquals(
+ g.getScalingPolicies().get(0).getLinks().get(0).getHref().toString(),
+ "https://" + zone.toLowerCase() + ".autoscale.api.rackspacecloud.com/v1.0/" + api.getCurrentTenantId().get().getId() + "/groups/" + g.getId() + "/policies/" + g.getScalingPolicies().get(0).getId() +"/");
+ assertEquals(g.getScalingPolicies().get(0).getLinks().get(0).getRelation(), Link.Relation.SELF);
+ assertEquals(g.getScalingPolicies().get(0).getCooldown(), 0);
+ assertEquals(g.getScalingPolicies().get(0).getTarget(), "1");
+ assertEquals(g.getScalingPolicies().get(0).getTargetType(), ScalingPolicyTargetType.INCREMENTAL);
+ assertEquals(g.getScalingPolicies().get(0).getType(), ScalingPolicyType.WEBHOOK);
+ assertEquals(g.getScalingPolicies().get(0).getName(), "scale up by 1");
+
+ assertEquals(g.getLaunchConfiguration().getLoadBalancers().size(), 1);
+ assertEquals(g.getLaunchConfiguration().getLoadBalancers().get(0).getId(), 9099);
+ assertEquals(g.getLaunchConfiguration().getLoadBalancers().get(0).getPort(), 8080);
+ assertEquals(g.getLaunchConfiguration().getServerName(), "autoscale_server");
+ assertNotNull(g.getLaunchConfiguration().getServerImageRef());
+ assertEquals(g.getLaunchConfiguration().getServerFlavorRef(), "2");
+ assertEquals(g.getLaunchConfiguration().getServerDiskConfig(), "AUTO");
+ assertEquals(g.getLaunchConfiguration().getPersonalities().size(), 1);
+ assertEquals(g.getLaunchConfiguration().getPersonalities().get(0).getPath(), "/root/.csivh");
+ assertEquals(g.getLaunchConfiguration().getPersonalities().get(0).getContents(),
+ "VGhpcyBpcyBhIHRlc3QgZmlsZS4=");
+ assertEquals(g.getLaunchConfiguration().getNetworks().size(), 2);
+ assertEquals(g.getLaunchConfiguration().getNetworks().get(0), "11111111-1111-1111-1111-111111111111");
+ assertEquals(g.getLaunchConfiguration().getNetworks().get(1), "00000000-0000-0000-0000-000000000000");
+ assertEquals(g.getLaunchConfiguration().getServerMetadata().size(), 3);
+ assertTrue(g.getLaunchConfiguration().getServerMetadata().containsKey("build_config"));
+ assertTrue(g.getLaunchConfiguration().getServerMetadata().containsValue("core"));
+ assertEquals(g.getLaunchConfiguration().getType(), LaunchConfigurationType.LAUNCH_SERVER);
+
+ assertEquals(g.getGroupConfiguration().getMaxEntities(), 10);
+ assertEquals(g.getGroupConfiguration().getCooldown(), 360);
+ assertEquals(g.getGroupConfiguration().getName(), "testscalinggroup198547");
+ assertEquals(g.getGroupConfiguration().getMinEntities(), 0);
+ assertEquals(g.getGroupConfiguration().getMetadata().size(), 2);
+ assertTrue(g.getGroupConfiguration().getMetadata().containsKey("gc_meta_key_2"));
+ assertTrue(g.getGroupConfiguration().getMetadata().containsValue("gc_meta_value_2"));
+ }
+ }
+
+ @Test
+ public void testCreatePolicy() {
+ for (String zone : api.getConfiguredZones()) {
+
+ PolicyApi policyApi = api.getPolicyApiForGroupInZone(created.get(zone).get(0).getId(), zone);
+
+ List<ScalingPolicy> scalingPolicies = Lists.newArrayList();
+
+ ScalingPolicy scalingPolicy = ScalingPolicy.builder()
+ .cooldown(1800)
+ .type(ScalingPolicyType.WEBHOOK)
+ .name("scale up by one server")
+ .targetType(ScalingPolicyTargetType.INCREMENTAL)
+ .target("1")
+ .build();
+ scalingPolicies.add(scalingPolicy);
+
+ FluentIterable<ScalingPolicyResponse> scalingPolicyResponse = policyApi.create(scalingPolicies);
+ assertNotNull(scalingPolicyResponse.iterator().next().getId());
+ assertEquals(scalingPolicyResponse.iterator().next().getCooldown(), 1800);
+ assertEquals(scalingPolicyResponse.iterator().next().getTarget(), "1");
+ }
+ }
+
+ @Test
+ public void testListPolicy() {
+ for (String zone : api.getConfiguredZones()) {
+
+ PolicyApi policyApi = api.getPolicyApiForGroupInZone(created.get(zone).get(0).getId(), zone);
+
+ FluentIterable<ScalingPolicyResponse> scalingPolicyResponse = policyApi.list();
+ assertNotNull(scalingPolicyResponse.iterator().next().getId());
+ }
+ }
+
+ @Test
+ public void testGetPolicy() {
+ for (String zone : api.getConfiguredZones()) {
+
+ PolicyApi policyApi = api.getPolicyApiForGroupInZone(created.get(zone).get(0).getId(), zone);
+
+ assertNotNull(policyApi);
+ ScalingPolicyResponse listResponse = policyApi.list().iterator().next();
+ ScalingPolicyResponse getResponse = policyApi.get(listResponse.getId());
+ assertEquals(listResponse.getId(), getResponse.getId());
+ assertEquals(listResponse.getName(), getResponse.getName());
+ assertEquals(listResponse.getCooldown(), getResponse.getCooldown());
+ assertEquals(listResponse.getLinks(), getResponse.getLinks());
+ assertEquals(listResponse.getTarget(), getResponse.getTarget());
+ assertEquals(listResponse.getTargetType(), getResponse.getTargetType());
+ assertEquals(listResponse.getType(), getResponse.getType());
+ }
+ }
+
+ @Test
+ public void testUpdatePolicy() {
+ for (String zone : api.getConfiguredZones()) {
+
+ PolicyApi policyApi = api.getPolicyApiForGroupInZone(created.get(zone).get(0).getId(), zone);
+
+ List<ScalingPolicy> scalingPolicies = Lists.newArrayList();
+
+ ScalingPolicy scalingPolicy = ScalingPolicy.builder()
+ .cooldown(1800)
+ .type(ScalingPolicyType.WEBHOOK)
+ .name("scale up by one server")
+ .targetType(ScalingPolicyTargetType.INCREMENTAL)
+ .target("1")
+ .build();
+ scalingPolicies.add(scalingPolicy);
+
+ ScalingPolicy updated = ScalingPolicy.builder()
+ .cooldown(2000)
+ .type(ScalingPolicyType.WEBHOOK)
+ .name("scale up by 2 PERCENT server")
+ .targetType(ScalingPolicyTargetType.PERCENT_CHANGE)
+ .target("2")
+ .build();
+
+
+ FluentIterable<ScalingPolicyResponse> scalingPolicyResponse = policyApi.create(scalingPolicies);
+ String policyId = scalingPolicyResponse.iterator().next().getId();
+ assertNotNull(policyId);
+
+ boolean result = policyApi.update(policyId, updated);
+ assertTrue(result);
+
+ ScalingPolicyResponse updatedResponse = policyApi.get(policyId);
+
+ assertNotNull(updatedResponse.getId());
+ assertEquals(updatedResponse.getCooldown(), 2000);
+ assertEquals(updatedResponse.getTarget(), "2");
+ assertEquals(updatedResponse.getTargetType(), ScalingPolicyTargetType.PERCENT_CHANGE);
+ assertEquals(updatedResponse.getType(), ScalingPolicyType.WEBHOOK);
+ assertEquals(updatedResponse.getName(), "scale up by 2 PERCENT server");
+ }
+ }
+
+ @Test
+ public void testDeletePolicy() {
+ for (String zone : api.getConfiguredZones()) {
+
+ PolicyApi policyApi = api.getPolicyApiForGroupInZone(created.get(zone).get(0).getId(), zone);
+
+ List<ScalingPolicy> scalingPolicies = Lists.newArrayList();
+
+ ScalingPolicy scalingPolicy = ScalingPolicy.builder()
+ .cooldown(1800)
+ .type(ScalingPolicyType.WEBHOOK)
+ .name("scale up by one server")
+ .targetType(ScalingPolicyTargetType.INCREMENTAL)
+ .target("1")
+ .build();
+ scalingPolicies.add(scalingPolicy);
+
+ FluentIterable<ScalingPolicyResponse> scalingPolicyResponse = policyApi.create(scalingPolicies);
+ String policyId = scalingPolicyResponse.iterator().next().getId();
+ assertNotNull(policyId);
+
+ boolean result = policyApi.delete(policyId);
+ assertTrue(result);
+ }
+ }
+
+ @Test
+ public void testExecutePolicy() {
+ for (String zone : api.getConfiguredZones()) {
+
+ PolicyApi policyApi = api.getPolicyApiForGroupInZone(created.get(zone).get(0).getId(), zone);
+
+ List<ScalingPolicy> scalingPolicies = Lists.newArrayList();
+
+ ScalingPolicy scalingPolicy = ScalingPolicy.builder()
+ .cooldown(1800)
+ .type(ScalingPolicyType.WEBHOOK)
+ .name("scale up by 0 server")
+ .targetType(ScalingPolicyTargetType.INCREMENTAL)
+ .target("1")
+ .build();
+ scalingPolicies.add(scalingPolicy);
+
+ FluentIterable<ScalingPolicyResponse> scalingPolicyResponse = policyApi.create(scalingPolicies);
+ String policyId = scalingPolicyResponse.iterator().next().getId();
+ assertNotNull(policyId);
+
+ boolean result = policyApi.execute(policyId);
+ assertTrue(result);
+ }
+ }
+
+ @Override
+ @AfterClass(groups = { "integration", "live" })
+ public void tearDown() {
+ for (String zone : api.getConfiguredZones()) {
+ GroupApi groupApi = api.getGroupApiForZone(zone);
+ for (Group group : created.get(zone)) {
+ PolicyApi policyApi = api.getPolicyApiForGroupInZone(group.getId(), zone);
+ if(policyApi == null)continue;
+ for(ScalingPolicyResponse sgr : policyApi.list()) {
+ if(!policyApi.delete(sgr.getId())) {
+ System.out.println("Could not delete an autoscale policy after tests!");
+ }
+ }
+
+ List<ScalingPolicy> scalingPolicies = Lists.newArrayList();
+
+ ScalingPolicy scalingPolicy = ScalingPolicy.builder()
+ .cooldown(1)
+ .type(ScalingPolicyType.WEBHOOK)
+ .name("0 machines")
+ .targetType(ScalingPolicyTargetType.DESIRED_CAPACITY)
+ .target("0")
+ .build();
+ scalingPolicies.add(scalingPolicy);
+
+ FluentIterable<ScalingPolicyResponse> scalingPolicyResponse = policyApi.create(scalingPolicies);
+ String policyId = scalingPolicyResponse.iterator().next().getId();
+
+ Uninterruptibles.sleepUninterruptibly(3, TimeUnit.SECONDS);
+
+ policyApi.execute(policyId);
+
+ Uninterruptibles.sleepUninterruptibly(3, TimeUnit.SECONDS);
+
+ if (!groupApi.delete(group.getId()))
+ System.out.println("Could not delete an autoscale group after tests!");
+ }
+ }
+ super.tearDown();
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/92fa9cf7/rackspace-autoscale/src/test/resources/autoscale_groups_configuration_get_response.json
----------------------------------------------------------------------
diff --git a/rackspace-autoscale/src/test/resources/autoscale_groups_configuration_get_response.json b/rackspace-autoscale/src/test/resources/autoscale_groups_configuration_get_response.json
new file mode 100644
index 0000000..d8799c3
--- /dev/null
+++ b/rackspace-autoscale/src/test/resources/autoscale_groups_configuration_get_response.json
@@ -0,0 +1,12 @@
+{
+ "groupConfiguration": {
+ "name": "workers",
+ "cooldown": 60,
+ "minEntities": 5,
+ "maxEntities": 100,
+ "metadata": {
+ "firstkey": "this is a string",
+ "secondkey": "1"
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/92fa9cf7/rackspace-autoscale/src/test/resources/autoscale_groups_launch_configuration_get_response.json
----------------------------------------------------------------------
diff --git a/rackspace-autoscale/src/test/resources/autoscale_groups_launch_configuration_get_response.json b/rackspace-autoscale/src/test/resources/autoscale_groups_launch_configuration_get_response.json
new file mode 100644
index 0000000..c80e6ea
--- /dev/null
+++ b/rackspace-autoscale/src/test/resources/autoscale_groups_launch_configuration_get_response.json
@@ -0,0 +1,33 @@
+{
+ "launchConfiguration": {
+ "type": "launch_server",
+ "args": {
+ "server": {
+ "flavorRef": "3",
+ "name": "webhead",
+ "imageRef": "0d589460-f177-4b0f-81c1-8ab8903ac7d8",
+ "OS-DCF:diskConfig": "AUTO",
+ "metadata": {
+ "mykey": "myvalue"
+ },
+ "personality": [
+ {
+ "path": "/root/.ssh/authorized_keys",
+ "contents": "ssh-rsa AAAAB3Nza...LiPk== user@example.net"
+ }
+ ],
+ "networks": [
+ {
+ "uuid": "11111111-1111-1111-1111-111111111111"
+ }
+ ]
+ },
+ "loadBalancers": [
+ {
+ "loadBalancerId": 2200,
+ "port": 8081
+ }
+ ]
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/92fa9cf7/rackspace-autoscale/src/test/resources/autoscale_groups_update_configuration_request.json
----------------------------------------------------------------------
diff --git a/rackspace-autoscale/src/test/resources/autoscale_groups_update_configuration_request.json b/rackspace-autoscale/src/test/resources/autoscale_groups_update_configuration_request.json
new file mode 100644
index 0000000..70704cd
--- /dev/null
+++ b/rackspace-autoscale/src/test/resources/autoscale_groups_update_configuration_request.json
@@ -0,0 +1,10 @@
+{
+ "name": "workers",
+ "cooldown": 60,
+ "minEntities": 5,
+ "maxEntities": 100,
+ "metadata": {
+ "firstkey": "this is a string",
+ "secondkey": "1"
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/92fa9cf7/rackspace-autoscale/src/test/resources/autoscale_groups_update_launch_configuration_request.json
----------------------------------------------------------------------
diff --git a/rackspace-autoscale/src/test/resources/autoscale_groups_update_launch_configuration_request.json b/rackspace-autoscale/src/test/resources/autoscale_groups_update_launch_configuration_request.json
new file mode 100644
index 0000000..9ab0d78
--- /dev/null
+++ b/rackspace-autoscale/src/test/resources/autoscale_groups_update_launch_configuration_request.json
@@ -0,0 +1,36 @@
+{
+ "args":{
+ "loadBalancers":[
+ {
+ "port":8080,
+ "loadBalancerId":9099
+ }
+ ],
+ "server":{
+ "name":"autoscale_server",
+ "imageRef":"0d589460-f177-4b0f-81c1-8ab8903ac7d8",
+ "flavorRef":"2",
+ "OS-DCF:diskConfig":"AUTO",
+ "metadata":{
+ "build_config":"core",
+ "meta_key_1":"meta_value_1",
+ "meta_key_2":"meta_value_2"
+ },
+ "networks":[
+ {
+ "uuid":"11111111-1111-1111-1111-111111111111"
+ },
+ {
+ "uuid":"00000000-0000-0000-0000-000000000000"
+ }
+ ],
+ "personality":[
+ {
+ "path":"/root/.csivh",
+ "contents":"VGhpcyBpcyBhIHRlc3QgZmlsZS4="
+ }
+ ]
+ }
+ },
+ "type":"launch_server"
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/92fa9cf7/rackspace-autoscale/src/test/resources/autoscale_policy_create_request.json
----------------------------------------------------------------------
diff --git a/rackspace-autoscale/src/test/resources/autoscale_policy_create_request.json b/rackspace-autoscale/src/test/resources/autoscale_policy_create_request.json
new file mode 100644
index 0000000..b0918a8
--- /dev/null
+++ b/rackspace-autoscale/src/test/resources/autoscale_policy_create_request.json
@@ -0,0 +1,8 @@
+[
+ {
+ "name": "scale up by one server",
+ "change": 1,
+ "cooldown": 1800,
+ "type": "webhook"
+ }
+]
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/92fa9cf7/rackspace-autoscale/src/test/resources/autoscale_policy_create_response.json
----------------------------------------------------------------------
diff --git a/rackspace-autoscale/src/test/resources/autoscale_policy_create_response.json b/rackspace-autoscale/src/test/resources/autoscale_policy_create_response.json
new file mode 100644
index 0000000..62d333c
--- /dev/null
+++ b/rackspace-autoscale/src/test/resources/autoscale_policy_create_response.json
@@ -0,0 +1,18 @@
+{
+"policies":
+[
+ {
+ "cooldown": 1800,
+ "type": "webhook",
+ "name": "scale up by one server",
+ "change": 1,
+ "links": [
+ {
+ "href": "https://ord.autoscale.api.rackspacecloud.com/v1.0/829409/groups/6791761b-821a-4d07-820d-0b2afc7dd7f6/policies/dceb14ac-b2b3-4f06-aac9-a5b6cd5d40e1/",
+ "rel": "self"
+ }
+ ],
+ "id": "dceb14ac-b2b3-4f06-aac9-a5b6cd5d40e1"
+ }
+]
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/92fa9cf7/rackspace-autoscale/src/test/resources/autoscale_policy_get_response.json
----------------------------------------------------------------------
diff --git a/rackspace-autoscale/src/test/resources/autoscale_policy_get_response.json b/rackspace-autoscale/src/test/resources/autoscale_policy_get_response.json
new file mode 100644
index 0000000..aa241b4
--- /dev/null
+++ b/rackspace-autoscale/src/test/resources/autoscale_policy_get_response.json
@@ -0,0 +1,15 @@
+{
+ "policy": {
+ "id": "policyId",
+ "links": [
+ {
+ "href": "urlRoot/v1.0/010101/groups/groupId/policy/policyId",
+ "rel": "self"
+ }
+ ],
+ "name": "scale up by one server",
+ "change": 1,
+ "cooldown": 150,
+ "type": "webhook"
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/92fa9cf7/rackspace-autoscale/src/test/resources/autoscale_policy_list_response.json
----------------------------------------------------------------------
diff --git a/rackspace-autoscale/src/test/resources/autoscale_policy_list_response.json b/rackspace-autoscale/src/test/resources/autoscale_policy_list_response.json
new file mode 100644
index 0000000..843370c
--- /dev/null
+++ b/rackspace-autoscale/src/test/resources/autoscale_policy_list_response.json
@@ -0,0 +1,30 @@
+{
+ "policies": [
+ {
+ "id":"policyId1",
+ "name": "scale up by one server",
+ "change": 1,
+ "cooldown": 150,
+ "type": "webhook",
+ "links": [
+ {
+ "href": "urlRoot/v1.0/010101/groups/groupId1/policy/policyId1",
+ "rel": "self"
+ }
+ ]
+ },
+ {
+ "id": "policyId2",
+ "name": "scale up ten percent",
+ "changePercent": 10,
+ "cooldown": 150,
+ "type": "webhook",
+ "links": [
+ {
+ "href": "urlRoot/v1.0/010101/groups/groupId1/policy/policyId2",
+ "rel": "self"
+ }
+ ]
+ }
+ ]
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/92fa9cf7/rackspace-autoscale/src/test/resources/autoscale_policy_update_request.json
----------------------------------------------------------------------
diff --git a/rackspace-autoscale/src/test/resources/autoscale_policy_update_request.json b/rackspace-autoscale/src/test/resources/autoscale_policy_update_request.json
new file mode 100644
index 0000000..e0438bd
--- /dev/null
+++ b/rackspace-autoscale/src/test/resources/autoscale_policy_update_request.json
@@ -0,0 +1,6 @@
+{
+ "name": "scale down by 5 percent",
+ "changePercent": -5,
+ "cooldown": 6,
+ "type": "webhook"
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/92fa9cf7/rackspace-autoscale/src/test/resources/autoscale_webhook_get_response.json
----------------------------------------------------------------------
diff --git a/rackspace-autoscale/src/test/resources/autoscale_webhook_get_response.json b/rackspace-autoscale/src/test/resources/autoscale_webhook_get_response.json
new file mode 100644
index 0000000..fa1d859
--- /dev/null
+++ b/rackspace-autoscale/src/test/resources/autoscale_webhook_get_response.json
@@ -0,0 +1,17 @@
+{
+ "webhook": {
+ "id":"{webhookId}",
+ "name": "webhook name",
+ "metadata": {},
+ "links": [
+ {
+ "href": ".../{groupId1}/policies/{policyId1}/webhooks/{webhookId}/",
+ "rel": "self"
+ },
+ {
+ "href": ".../execute/1/{capabilityHash2}",
+ "rel": "capability"
+ }
+ ]
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/92fa9cf7/rackspace-autoscale/src/test/resources/autoscale_webhook_update_request.json
----------------------------------------------------------------------
diff --git a/rackspace-autoscale/src/test/resources/autoscale_webhook_update_request.json b/rackspace-autoscale/src/test/resources/autoscale_webhook_update_request.json
new file mode 100644
index 0000000..5b74d4d
--- /dev/null
+++ b/rackspace-autoscale/src/test/resources/autoscale_webhook_update_request.json
@@ -0,0 +1,6 @@
+{
+ "name": "alice",
+ "metadata": {
+ "notes": "this is for Alice"
+ }
+}