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

            ec2CloudWatchMetricNames.put(EC2Constants.MetricName.NETWORK_IN, Unit.BYTES);
            ec2CloudWatchMetricNames.put(EC2Constants.MetricName.NETWORK_OUT, Unit.BYTES);
        }

        try (RestContext<CloudWatchApi, CloudWatchAsyncApi> context = new AWSClient(connection).getCloudWatchServiceContext()) {
            CloudWatchApi cloudWatchClient = context.getApi();
            List<InventoryItem> inventoryItems = getInventoryItems(connection);
            String metricNamespace = Namespaces.EC2;
            Calendar cal = Calendar.getInstance();
            Date endTime = new Date();
            Date startTime;

            cal.add(Calendar.MINUTE, -30);

            startTime = cal.getTime();

            for (InventoryItem inventoryItem : inventoryItems) {
                if (!inventoryItem.getType().equals(Constants.COMPUTE_INSTANCE_TYPE)) {
                    continue;
                }

                Map<String, JSONObject> metrics = new HashMap<>();
                String nodeId = inventoryItem.getExternalId();
                Location region = getLocationByScope(inventoryItem, LocationScope.REGION);

                if (region == null) {
                    continue;
                }

                String regionId = region.getId();
                Dimension dimension = new Dimension(EC2Constants.Dimension.INSTANCE_ID, nodeId);

                for (Map.Entry<String, Unit> ec2MetricEntry : ec2CloudWatchMetricNames.entrySet()) {
                    String metricName = ec2MetricEntry.getKey();
                    Unit metricUnit = ec2MetricEntry.getValue();
                    MetricApi metricClient = cloudWatchClient.getMetricApiForRegion(regionId);
                    GetMetricStatistics requestOptions = GetMetricStatistics.builder()
                            .namespace(metricNamespace)
                            .metricName(metricName)
                            .dimension(dimension)
                            .period(60)
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

Examples of org.jclouds.cloudwatch.CloudWatchApi

                                                        Alarm.State.OK);
   }

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

      // Ensure there is no error returned
      cloudWatchApi.getAlarmApiForRegion(null).save(saveAlarmOptions);
   }
View Full Code Here

Examples of org.jclouds.cloudwatch.CloudWatchApi

   }

   @Test(expectedExceptions = InsufficientResourcesException.class)
   public void testPutMetricAlarmIs400() throws Exception {
      Payload payload = payloadFromResourceWithContentType("/LimitExceededResponse.xml", "text/xml");
      CloudWatchApi cloudWatchApi = requestSendsResponse(putMetricAlarmRequest,
                                                         HttpResponse.builder()
                                                                     .payload(payload)
                                                                     .statusCode(400)
                                                                     .build());

      // Ensure an InsufficientResourcesException is thrown
      cloudWatchApi.getAlarmApiForRegion(null).save(saveAlarmOptions);
   }
View Full Code Here

Examples of org.jclouds.cloudwatch.CloudWatchApi

      // Ensure an InsufficientResourcesException is thrown
      cloudWatchApi.getAlarmApiForRegion(null).save(saveAlarmOptions);
   }

   public void testEnableAlarmActions() throws Exception {
      CloudWatchApi cloudWatchApi = requestSendsResponse(alarmRequest(ImmutableMap.of(
            "Action", "EnableAlarmActions",
            "AlarmNames.member.1", "TestAlarmName1",
            "AlarmNames.member.2", "TestAlarmName2",
            "Signature", "Q1VemnXpc57PKMs9NVCX6R%2B/TSDgsGzQwpOHQ70aJuU%3D"
      )), HttpResponse.builder()
                      .statusCode(200)
                      .payload(payloadFromResourceWithContentType("/VoidResponse.xml", "text/xml"))
                      .build());

      // Ensure there is no error returned
      cloudWatchApi.getAlarmApiForRegion(null).enable(ImmutableSet.of(
            "TestAlarmName1",
            "TestAlarmName2"
      ));
   }
View Full Code Here

Examples of org.jclouds.cloudwatch.CloudWatchApi

            "TestAlarmName2"
      ));
   }

   public void testDisableAlarmActions() throws Exception {
      CloudWatchApi cloudWatchApi = requestSendsResponse(alarmRequest(ImmutableMap.of(
            "Action", "DisableAlarmActions",
            "AlarmNames.member.1", "TestAlarmName1",
            "AlarmNames.member.2", "TestAlarmName2",
            "Signature", "tvSfJ%2BgcrHowwUECSniV0TQP2OObpWCuba0S5dd723Y%3D"
      )), HttpResponse.builder()
                      .statusCode(200)
                      .payload(payloadFromResourceWithContentType("/VoidResponse.xml", "text/xml"))
                      .build());

      // Ensure there is no error returned
      cloudWatchApi.getAlarmApiForRegion(null).disable(ImmutableSet.of(
            "TestAlarmName1",
            "TestAlarmName2"
      ));
   }
View Full Code Here

Examples of org.jclouds.cloudwatch.CloudWatchApi

      String metricName = "TestMetricName";
      String namespace = Namespaces.EC2;
      int period = 60;
      Statistics statistics = Statistics.SAMPLE_COUNT;
      Unit unit = Unit.SECONDS;
      CloudWatchApi cloudWatchApi = requestSendsResponse(
            alarmRequest(ImmutableMap.<String, String>builder()
                                     .put("Action", "DescribeAlarmsForMetric")
                                     .put("Dimensions.member.1.Name", "TestDimensionName1")
                                     .put("Dimensions.member.1.Value", "TestDimensionValue1")
                                     .put("Dimensions.member.2.Name", "TestDimensionName2")
                                     .put("Dimensions.member.2.Value", "TestDimensionValue2")
                                     .put("MetricName", metricName)
                                     .put("Namespace", namespace)
                                     .put("Period", Integer.toString(period))
                                     .put("Statistic", statistics.toString())
                                     .put("Unit", unit.toString())
                                     .put("Signature", "y%2BpU0Lp6AAO2QSrNld1VQY4DhKVHcyn44dIfnrmJhpg%3D")
                                     .build()),
            HttpResponse.builder()
                        .statusCode(200)
                        .payload(payloadFromResourceWithContentType("/DescribeAlarmsForMetricResponse.xml", "text/xml"))
                        .build()
      );

      assertEquals(new ListAlarmsForMetricResponseHandlerTest().expected().toString(),
                   cloudWatchApi.getAlarmApiForRegion(null)
                                .listForMetric(new ListAlarmsForMetric()
                                                     .dimensions(ImmutableSet.of(
                                                           new Dimension("TestDimensionName1",
                                                                         "TestDimensionValue1"),
                                                           new Dimension("TestDimensionName2",
View Full Code Here

Examples of org.jclouds.cloudwatch.CloudWatchApi

      String actionPrefix = "TestActionPrefix";
      String alarmNamePrefix = "TestAlarmNamePrefix";
      Set<String> alarmNames = ImmutableSet.of("TestAlarmName1", "TestAlarmName2");
      int maxRecords = 10;
      Alarm.State state = Alarm.State.ALARM;
      CloudWatchApi cloudWatchApi = requestSendsResponse(
            alarmRequest(ImmutableMap.<String, String>builder()
                                     .put("Action", "DescribeAlarms")
                                     .put("ActionPrefix", actionPrefix)
                                     .put("AlarmNamePrefix", alarmNamePrefix)
                                     .put("AlarmNames.member.1", "TestAlarmName1")
                                     .put("AlarmNames.member.2", "TestAlarmName2")
                                     .put("MaxRecords", Integer.toString(maxRecords))
                                     .put("StateValue", state.toString())
                                     .put("Signature", "jPP1enbHPfOphIZv796W0KN4/EsLdPp6nK1qpbt5Dog%3D")
                                     .build()),
            HttpResponse.builder()
                        .statusCode(200)
                        .payload(payloadFromResourceWithContentType("/DescribeAlarmsResponse.xml", "text/xml"))
                        .build()
            );

      assertEquals(new ListAlarmsResponseHandlerTest().expected().toString(),
                   cloudWatchApi.getAlarmApiForRegion(null)
                                .list(new ListAlarmsOptions()
                                              .actionPrefix(actionPrefix)
                                              .alarmNamePrefix(alarmNamePrefix)
                                              .alarmNames(alarmNames)
                                              .maxRecords(maxRecords)
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.