Package org.jclouds.rackspace.autoscale.v1.features

Examples of org.jclouds.rackspace.autoscale.v1.features.PolicyApi


         Group g = created.get(zone).get(0);
         WebhookApi webhookApi = api.getWebhookApiForGroupAndPolicyInZone(g.getId(), g.getScalingPolicies().iterator().next().getId(), zone);
         String webhookId = webhookApi.list().first().get().getId();
         assertTrue( webhookApi.update(webhookId, "updated_name", ImmutableMap.<String, Object>of()) );

         WebhookResponse webhook= webhookApi.get(webhookId);
         assertEquals(webhook.getName(), "updated_name");
         assertTrue( webhook.getMetadata().isEmpty() );
      }
   }
View Full Code Here


   @Test
   public void testGetWebhook() {
      for (String zone : api.getConfiguredZones()) {
         Group g = created.get(zone).get(0);
         WebhookApi webhookApi = api.getWebhookApiForGroupAndPolicyInZone(g.getId(), g.getScalingPolicies().iterator().next().getId(), zone);
         WebhookResponse webhookList = webhookApi.list().first().get();
         WebhookResponse webhookGet = webhookApi.get(webhookList.getId());
         assertNotNull(webhookList);
         assertNotNull(webhookGet);
         assertEquals(webhookList, webhookGet);
      }
   }
View Full Code Here

   @Test
   public void testDeleteWebhook() {
      for (String zone : api.getConfiguredZones()) {
         Group g = created.get(zone).get(0);
         WebhookApi webhookApi = api.getWebhookApiForGroupAndPolicyInZone(g.getId(), g.getScalingPolicies().iterator().next().getId(), zone);
         WebhookResponse webhook = webhookApi.create("test1", ImmutableMap.<String, Object>of("notes", "test metadata")).first().get();

         assertEquals(webhook.getName(), "test1");
         assertEquals(webhook.getMetadata().get("notes"), "test metadata");
        
         assertTrue( webhookApi.delete(webhook.getId()) );
         assertNull( webhookApi.get(webhook.getId()) );
      }
   }
View Full Code Here

   @Test
   public void testExecuteWebhook() throws IOException {
      for (String zone : api.getConfiguredZones()) {
         Group g = created.get(zone).get(0);
         WebhookApi webhookApi = api.getWebhookApiForGroupAndPolicyInZone(g.getId(), g.getScalingPolicies().iterator().next().getId(), zone);
         WebhookResponse webhook = webhookApi.create("test_execute", ImmutableMap.<String, Object>of("notes", "test metadata")).first().get();
        
         assertTrue( AutoscaleUtils.execute(webhook.getAnonymousExecutionURI().get()) , " for " + webhook + " in " + zone);
      }
   }
View Full Code Here

   @Test
   public void testExecuteWebhookFail() throws IOException, URISyntaxException {
      for (String zone : api.getConfiguredZones()) {
         Group g = created.get(zone).get(0);
         WebhookApi webhookApi = api.getWebhookApiForGroupAndPolicyInZone(g.getId(), g.getScalingPolicies().iterator().next().getId(), zone);
         WebhookResponse webhook = webhookApi.create("test_execute_fail", ImmutableMap.<String, Object>of("notes", "test metadata")).first().get();
        
         URI uri = new URI(webhook.getAnonymousExecutionURI().toString() + "123");
         assertFalse( AutoscaleUtils.execute(uri) );
      }
   }
View Full Code Here

            responseWithKeystoneAccess,
            authenticatedGET().endpoint(endpoint).build(),
            HttpResponse.builder().statusCode(201).payload(payloadFromResource("/autoscale_webhook_get_response.json")).build()
            ).getWebhookApiForGroupAndPolicyInZone("1234567890", "321456", "DFW");

      WebhookResponse webhook = api.get("5555");
      assertEquals(webhook.getName(), "alice");
      assertEquals(webhook.getLinks().size(), 2);
   }
View Full Code Here

            responseWithKeystoneAccess,
            authenticatedGET().endpoint(endpoint).build(),
            HttpResponse.builder().statusCode(404).payload(payloadFromResource("/autoscale_webhook_get_response.json")).build()
            ).getWebhookApiForGroupAndPolicyInZone("1234567890", "321456", "DFW");

      WebhookResponse webhook = api.get("5555");
      assertNull(webhook);
   }
View Full Code Here

            responseWithKeystoneAccess,
            authenticatedGET().endpoint(endpoint).build(),
            HttpResponse.builder().statusCode(201).payload(payloadFromResource("/autoscale_webhook_get_response.json")).build()
            ).getWebhookApiForZoneAndGroupAndPolicy("DFW", "1234567890", "321456");

      WebhookResponse webhook = api.get("5555");
      assertEquals(webhook.getName(), "alice");
      assertEquals(webhook.getLinks().size(), 2);
   }
View Full Code Here

            responseWithKeystoneAccess,
            authenticatedGET().endpoint(endpoint).build(),
            HttpResponse.builder().statusCode(404).payload(payloadFromResource("/autoscale_webhook_get_response.json")).build()
            ).getWebhookApiForZoneAndGroupAndPolicy("DFW", "1234567890", "321456");

      WebhookResponse webhook = api.get("5555");
      assertNull(webhook);
   }
View Full Code Here

   private void autoscaleCleanup() {
      System.out.format("Cleanup autoscale %n");

      // Remove ALL policies and groups with that name
      for (GroupState g : groupApi.listGroupStates()) {
         PolicyApi pa = autoscaleApi.getPolicyApiForZoneAndGroup(ZONE, g.getId());
         for(ScalingPolicy p : pa.list()) {
            if(p.getName().equals(NAME)) {
               System.out.format("Found matching policy: %s with cooldown %s%n", p.getId(), p.getCooldown());
               String policyId = p.getId();

               if (!(p.getTarget().equals("0") && p.getTargetType().equals(ScalingPolicyTargetType.DESIRED_CAPACITY))) {
                  System.out.format("Removing servers %n");

                  // Update policy to 0 servers
                  CreateScalingPolicy scalingPolicy = CreateScalingPolicy.builder()
                        .cooldown(3)
                        .type(ScalingPolicyType.WEBHOOK)
                        .name(NAME)
                        .targetType(ScalingPolicyTargetType.DESIRED_CAPACITY)
                        .target("0")
                        .build();

                  pa.update(policyId, scalingPolicy);
                  Uninterruptibles.sleepUninterruptibly(5, TimeUnit.SECONDS);

                  try {
                     pa.execute(policyId);
                  } catch (Exception e) {
                     // This will fail to execute when the number of servers is already zero (no change).
                  }
               }
               Uninterruptibles.sleepUninterruptibly(5, TimeUnit.SECONDS);
               pa.delete(policyId);
               groupApi.delete(g.getId());
            } else {
               System.out.format("Found another policy: %s - %s with cooldown %s%n", p.getName(), p.getId(), p.getCooldown());
            }
         }
View Full Code Here

TOP

Related Classes of org.jclouds.rackspace.autoscale.v1.features.PolicyApi

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.