Examples of CloudWatchApi


Examples of org.jclouds.cloudwatch.CloudWatchApi

         Thread.sleep(TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES));

         // stop the spinner
         future.cancel(true);

         CloudWatchApi monitoringApi = ContextBuilder.newBuilder(new AWSCloudWatchProviderMetadata())
                                                     .credentials(identity, credential)
                                                     .modules(setupModules())
                                                     .buildApi(CloudWatchApi.class);

         try {
            GetMetricStatisticsResponse datapoints = monitoringApi.getMetricApiForRegion(instance.getRegion())
                     .getMetricStatistics(GetMetricStatistics.builder()
                                                             .dimension(new Dimension(EC2Constants.Dimension.INSTANCE_ID, instance.getId()))
                                                             .unit(Unit.PERCENT)
                                                             .namespace("AWS/EC2")
                                                             .metricName("CPUUtilization")
                                                             .startTime(before)
                                                             .endTime(new Date())
                                                             .period(60)
                                                             .statistic(Statistics.AVERAGE)
                                                             .build());
            assert datapoints.size() > 0 : instance;
         } finally {
            monitoringApi.close();
         }

         // make sure we made our dummy group and also let in the user's group
         assertEquals(newTreeSet(instance.getGroupNames()), ImmutableSortedSet.<String> of("jclouds#" + group, group));
View Full Code Here

Examples of org.jclouds.cloudwatch.CloudWatchApi

   public void testListMetricsWhenResponseIs2xx() throws Exception {

      HttpResponse listMetricsResponse = HttpResponse.builder().statusCode(200)
            .payload(payloadFromResourceWithContentType("/list_metrics.xml", "text/xml")).build();

      CloudWatchApi apiWhenMetricsExist = requestSendsResponse(
            listMetrics, listMetricsResponse);

      assertEquals(apiWhenMetricsExist.getMetricApiForRegion(null).list().get(0).toString(),
            "[Metric{namespace=AWS/EC2, metricName=CPUUtilization, dimension=[Dimension{name=InstanceId, value=i-689fcf0f}]}]");
   }
View Full Code Here

Examples of org.jclouds.cloudwatch.CloudWatchApi

   public void testListMetricsWhenResponseIs404() throws Exception {

      HttpResponse listMetricsResponse = HttpResponse.builder().statusCode(404).build();

      CloudWatchApi apiWhenMetricsDontExist = requestSendsResponse(
            listMetrics, listMetricsResponse);

      assertEquals(apiWhenMetricsDontExist.getMetricApiForRegion(null).list().get(0).toSet(), ImmutableSet.of());
   }
View Full Code Here

Examples of org.jclouds.cloudwatch.CloudWatchApi

               .build();

      HttpResponse listMetrics2Response = HttpResponse.builder().statusCode(200)
               .payload(payloadFromResourceWithContentType("/list_metrics.xml", "text/xml")).build();

      CloudWatchApi apiWhenMetricsExist = requestsSendResponses(
            listMetrics, listMetricsResponse, listMetrics2, listMetrics2Response);

      assertEquals(apiWhenMetricsExist.getMetricApiForRegion(null).list().concat().toString(),
            "[Metric{namespace=AWS/EC2, metricName=CPUUtilization, dimension=[Dimension{name=InstanceId, value=i-689fcf0f}]}, Metric{namespace=AWS/EC2, metricName=CPUUtilization, dimension=[Dimension{name=InstanceId, value=i-689fcf0f}]}]");
   }
View Full Code Here

Examples of org.jclouds.cloudwatch.CloudWatchApi

                       .build();
     
      HttpResponse listMetricsWithOptionsResponse = HttpResponse.builder().statusCode(200)
               .payload(payloadFromResourceWithContentType("/list_metrics.xml", "text/xml")).build();

      CloudWatchApi apiWhenMetricsWithOptionsExist = requestSendsResponse(listMetricsWithOptions,
               listMetricsWithOptionsResponse);

      assertEquals(
               apiWhenMetricsWithOptionsExist.getMetricApiForRegion(null).list(
                        ListMetricsOptions.Builder
                                          .dimension(new Dimension(EC2Constants.Dimension.INSTANCE_ID,
                                                                   "SOMEINSTANCEID"))
                                          .metricName(EC2Constants.MetricName.CPU_UTILIZATION)
                                          .namespace("SOMENEXTTOKEN")
View Full Code Here

Examples of org.jclouds.cloudwatch.CloudWatchApi

   public void testGetMetricStatisticsWhenResponseIs2xx() throws Exception {

      HttpResponse getMetricStatisticsResponse = HttpResponse.builder().statusCode(200).payload(
               payloadFromResourceWithContentType("/get_metric_statistics.xml", "text/xml")).build();

      CloudWatchApi apiWhenMetricsExist = requestSendsResponse(getMetricStatistics, getMetricStatisticsResponse);

      assertEquals(
               apiWhenMetricsExist.getMetricApiForRegion(null).getMetricStatistics(stats).toString(),
               // TODO: make an object for this
               "GetMetricStatisticsResponse{label=CPUUtilization, " +
                     "datapoints=[Datapoint{timestamp=Thu Jan 15 16:00:00 PST 2009, customUnit=null, maximum=null, " +
                     "minimum=null, average=0.17777777777777778, sum=null, samples=9.0, unit=Percent}, " +
                     "Datapoint{timestamp=Thu Jan 15 16:01:00 PST 2009, customUnit=null, maximum=null, minimum=null, " +
View Full Code Here

Examples of org.jclouds.cloudwatch.CloudWatchApi

   @Test(expectedExceptions = ResourceNotFoundException.class)
   public void testGetMetricStatisticsWhenResponseIs404() throws Exception {

      HttpResponse getMetricStatisticsResponse = HttpResponse.builder().statusCode(404).build();

      CloudWatchApi apiWhenMetricsDontExist = requestSendsResponse(getMetricStatistics, getMetricStatisticsResponse);

      apiWhenMetricsDontExist.getMetricApiForRegion(null).getMetricStatistics(stats);
   }
View Full Code Here

Examples of org.jclouds.cloudwatch.CloudWatchApi

                       .build();

      HttpResponse getMetricStatisticsResponse = HttpResponse.builder().statusCode(200).payload(
               payloadFromResourceWithContentType("/get_metric_statistics.xml", "text/xml")).build();

      CloudWatchApi apiWhenMetricsExist = requestSendsResponse(getMetricStatistics, getMetricStatisticsResponse);

      Dimension dimension1 = new Dimension(EC2Constants.Dimension.INSTANCE_ID, "SOMEINSTANCEID");
      Dimension dimension2 = new Dimension(EC2Constants.Dimension.INSTANCE_TYPE, "t1.micro");

      assertEquals(
               apiWhenMetricsExist.getMetricApiForRegion(null).getMetricStatistics(stats,
                        GetMetricStatisticsOptions.Builder.dimension(dimension1).dimension(dimension2)).toString(),
               // TODO: make an object for this
               "GetMetricStatisticsResponse{label=CPUUtilization, " +
                     "datapoints=[Datapoint{timestamp=Thu Jan 15 16:00:00 PST 2009, customUnit=null, maximum=null, " +
                     "minimum=null, average=0.17777777777777778, sum=null, samples=9.0, unit=Percent}, " +
View Full Code Here

Examples of org.jclouds.cloudwatch.CloudWatchApi

      TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
   }

   public void testSetAlarmStateIs2xx() throws Exception {
      Payload payload = payloadFromResourceWithContentType("/VoidResponse.xml", "text/xml");
      CloudWatchApi cloudWatchApi = requestSendsResponse(setAlarmStateRequest,
                                                         HttpResponse.builder()
                                                                     .payload(payload)
                                                                     .statusCode(200)
                                                                     .build());

      // Ensure there is no error returned
      cloudWatchApi.getAlarmApiForRegion(null).setState("TestAlarmName", "TestStateReason",
                                                        "{\"reason\": \"Some reason\"}",
                                                        Alarm.State.OK);
   }
View Full Code Here

Examples of org.jclouds.cloudwatch.CloudWatchApi

   }

   @Test(expectedExceptions = IllegalArgumentException.class)
   public void testSetAlarmStateIs400() throws Exception {
      Payload payload = payloadFromResourceWithContentType("/InvalidFormatResponse.xml", "text/xml");
      CloudWatchApi cloudWatchApi = requestSendsResponse(setAlarmStateRequest,
                                                         HttpResponse.builder()
                                                                     .payload(payload)
                                                                     .statusCode(400)
                                                                     .build());

      // Ensure an IllegalArgumentException is thrown
      cloudWatchApi.getAlarmApiForRegion(null).setState("TestAlarmName", "TestStateReason",
                                                        "{\"reason\": \"Some reason\"}",
                                                        Alarm.State.OK);
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.