com.amazonaws.services.cloudwatch.model.DeleteAlarmsRequest Java Examples
The following examples show how to use
com.amazonaws.services.cloudwatch.model.DeleteAlarmsRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DeleteAlarm.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
public static void main(String[] args) { final String USAGE = "To run this example, supply an alarm name\n" + "Ex: DeleteAlarm <alarm-name>\n"; if (args.length != 1) { System.out.println(USAGE); System.exit(1); } String alarm_name = args[0]; final AmazonCloudWatch cw = AmazonCloudWatchClientBuilder.defaultClient(); DeleteAlarmsRequest request = new DeleteAlarmsRequest() .withAlarmNames(alarm_name); DeleteAlarmsResult response = cw.deleteAlarms(request); System.out.printf("Successfully deleted alarm %s", alarm_name); }
Example #2
Source File: CloudWatchClient.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Override public Completable deleteAlarm(String policyRefId, String jobId) { DeleteAlarmsRequest deleteAlarmsRequest = new DeleteAlarmsRequest(); deleteAlarmsRequest.setAlarmNames(Arrays.asList(buildCloudWatchName(policyRefId, jobId))); return wrapWithExponentialRetry(String.format("deleteAlarm in policy %s for job %s", policyRefId, jobId), Observable.create(emitter -> awsCloudWatch.deleteAlarmsAsync(deleteAlarmsRequest, new AsyncHandler<DeleteAlarmsRequest, DeleteAlarmsResult>() { @Override public void onError(Exception exception) { deleteErrorCounter.increment(); if (exception instanceof ResourceNotFoundException) { emitter.onError(AutoScalePolicyException.unknownScalingPolicy(policyRefId, exception.getMessage())); } else { emitter.onError(AutoScalePolicyException.errorDeletingAlarm(policyRefId, exception.getMessage())); } } @Override public void onSuccess(DeleteAlarmsRequest request, DeleteAlarmsResult deleteAlarmsResult) { int httpStatusCode = deleteAlarmsResult.getSdkHttpMetadata().getHttpStatusCode(); log.info("Deleted cloud watch alarm for job-id {}, status {}", jobId, httpStatusCode); deleteAlarmCounter.increment(); emitter.onCompleted(); } }), Emitter.BackpressureMode.NONE)).toCompletable(); }
Example #3
Source File: AwsCloudWatchService.java From cloudbreak with Apache License 2.0 | 5 votes |
private void deleteCloudWatchAlarms(String regionName, AwsCredentialView credentialView, List<String> alarmNames) { try { DeleteAlarmsRequest deleteAlarmsRequest = new DeleteAlarmsRequest().withAlarmNames(alarmNames); AmazonCloudWatchClient amazonCloudWatchClient = awsClient.createCloudWatchClient(credentialView, regionName); amazonCloudWatchClient.deleteAlarms(deleteAlarmsRequest); LOGGER.debug("Deleted cloudwatch alarms [{}]", alarmNames); } catch (AmazonCloudWatchException acwe) { LOGGER.error("Unable to delete cloudwatch alarms [{}]: {}", alarmNames, acwe.getLocalizedMessage()); throw new CloudConnectorException("unable to delete cloud watch alarms", acwe); } }
Example #4
Source File: NoopCloudWatch.java From dynamodb-cross-region-library with Apache License 2.0 | 4 votes |
@Override public DeleteAlarmsResult deleteAlarms(DeleteAlarmsRequest deleteAlarmsRequest) { return null; }
Example #5
Source File: AwsCloudWatchServiceTest.java From cloudbreak with Apache License 2.0 | 4 votes |
@Test void testDeleteCloudWatchAlarmsForSystemFailuresWhenOneAlarmHasAlreadyBeenDeleted() { String alarm1Name = "i-1-Status-Check-Failed-System"; String alarm2Name = "i-2-Status-Check-Failed-System"; String alarm3Name = "i-3-Status-Check-Failed-System"; String instanceId1 = "i-1"; String instanceId2 = "i-2"; String instanceId3 = "i-3"; MetricAlarm alarm1 = mock(MetricAlarm.class); MetricAlarm alarm2 = mock(MetricAlarm.class); DescribeAlarmsResult describeAlarmsResult = mock(DescribeAlarmsResult.class); AmazonCloudWatchClient cloudWatchClient = mock(AmazonCloudWatchClient.class); AwsCredentialView credentialView = mock(AwsCredentialView.class); CloudStack stack = mock(CloudStack.class); Group group = mock(Group.class); CloudInstance instance1 = mock(CloudInstance.class); CloudInstance instance2 = mock(CloudInstance.class); CloudInstance instance3 = mock(CloudInstance.class); List<Group> groups = List.of(group); when(stack.getParameters()).thenReturn(PARAMETERS); when(stack.getGroups()).thenReturn(groups); when(group.getInstances()).thenReturn(List.of(instance1, instance2, instance3)); when(instance1.getInstanceId()).thenReturn(instanceId1); when(instance2.getInstanceId()).thenReturn(instanceId2); when(instance3.getInstanceId()).thenReturn(instanceId3); when(awsClient.createCloudWatchClient(eq(credentialView), eq(REGION))).thenReturn(cloudWatchClient); when(cloudWatchClient.describeAlarms(any())).thenReturn(describeAlarmsResult); // alarm 3 was already deleted when(describeAlarmsResult.getMetricAlarms()).thenReturn(List.of(alarm1, alarm2)); when(alarm1.getAlarmName()).thenReturn(alarm1Name); when(alarm2.getAlarmName()).thenReturn(alarm2Name); underTest.deleteCloudWatchAlarmsForSystemFailures(stack, REGION, credentialView); ArgumentCaptor<DescribeAlarmsRequest> captorDescribe = ArgumentCaptor.forClass(DescribeAlarmsRequest.class); ArgumentCaptor<DeleteAlarmsRequest> captorDelete = ArgumentCaptor.forClass(DeleteAlarmsRequest.class); verify(cloudWatchClient, times(1)).describeAlarms(captorDescribe.capture()); verify(cloudWatchClient, times(1)).deleteAlarms(captorDelete.capture()); assertEquals(List.of(alarm1Name, alarm2Name, alarm3Name), captorDescribe.getValue().getAlarmNames()); // only delete alarms that were not already deleted assertEquals(List.of(alarm1Name, alarm2Name), captorDelete.getValue().getAlarmNames()); }