Search in sources :

Example 1 with ThresholdRangeCondition

use of io.gravitee.alert.api.condition.ThresholdRangeCondition in project gravitee-management-rest-api by gravitee-io.

the class AlertMapperTest method convertAlertInputToUpdateAlertTriggerEntityStatus2xx.

@Test
public void convertAlertInputToUpdateAlertTriggerEntityStatus2xx() {
    final AlertInput alertInput = new AlertInput();
    alertInput.setEnabled(true);
    alertInput.setStatusCode("2xx");
    alertInput.setStatusPercent(20);
    alertInput.setDuration(10);
    alertInput.setTimeUnit(AlertTimeUnit.MINUTES);
    alertInput.setType(AlertType.STATUS);
    final UpdateAlertTriggerEntity actual = alertMapper.convertToUpdate(alertInput);
    assertThat(actual.isEnabled()).isEqualTo(alertInput.getEnabled());
    final RateCondition rateCondition = (RateCondition) actual.getConditions().get(0);
    assertThat(rateCondition.getDuration()).isEqualTo(alertInput.getDuration().longValue());
    assertThat(rateCondition.getTimeUnit()).isEqualTo(TimeUnit.MINUTES);
    assertThat(rateCondition.getThreshold()).isEqualTo(alertInput.getStatusPercent().doubleValue());
    final ThresholdRangeCondition condition = (ThresholdRangeCondition) rateCondition.getComparison();
    assertThat(condition.getProperty()).isEqualTo("response.status");
    assertThat(condition.getThresholdLow()).isEqualTo(200D);
    assertThat(condition.getThresholdHigh()).isEqualTo(299D);
}
Also used : UpdateAlertTriggerEntity(io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity) AlertInput(io.gravitee.rest.api.portal.rest.model.AlertInput) RateCondition(io.gravitee.alert.api.condition.RateCondition) ThresholdRangeCondition(io.gravitee.alert.api.condition.ThresholdRangeCondition) Test(org.junit.Test)

Example 2 with ThresholdRangeCondition

use of io.gravitee.alert.api.condition.ThresholdRangeCondition in project gravitee-management-rest-api by gravitee-io.

the class AlertMapperTest method convertAlertInputToUpdateAlertTriggerEntityStatus200.

@Test
public void convertAlertInputToUpdateAlertTriggerEntityStatus200() {
    final AlertInput alertInput = new AlertInput();
    alertInput.setEnabled(true);
    alertInput.setStatusCode("200");
    alertInput.setStatusPercent(20);
    alertInput.setDuration(10);
    alertInput.setTimeUnit(AlertTimeUnit.MINUTES);
    alertInput.setType(AlertType.STATUS);
    final UpdateAlertTriggerEntity actual = alertMapper.convertToUpdate(alertInput);
    assertThat(actual.isEnabled()).isEqualTo(alertInput.getEnabled());
    final RateCondition rateCondition = (RateCondition) actual.getConditions().get(0);
    assertThat(rateCondition.getDuration()).isEqualTo(alertInput.getDuration().longValue());
    assertThat(rateCondition.getTimeUnit()).isEqualTo(TimeUnit.MINUTES);
    assertThat(rateCondition.getThreshold()).isEqualTo(alertInput.getStatusPercent().doubleValue());
    final ThresholdRangeCondition condition = (ThresholdRangeCondition) rateCondition.getComparison();
    assertThat(condition.getProperty()).isEqualTo("response.status");
    assertThat(condition.getThresholdLow()).isEqualTo(200D);
    assertThat(condition.getThresholdHigh()).isEqualTo(200D);
}
Also used : UpdateAlertTriggerEntity(io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity) AlertInput(io.gravitee.rest.api.portal.rest.model.AlertInput) RateCondition(io.gravitee.alert.api.condition.RateCondition) ThresholdRangeCondition(io.gravitee.alert.api.condition.ThresholdRangeCondition) Test(org.junit.Test)

Example 3 with ThresholdRangeCondition

use of io.gravitee.alert.api.condition.ThresholdRangeCondition in project gravitee-management-rest-api by gravitee-io.

the class AlertMapperTest method convertAlertTriggerEntityToAlertStatus200.

@Test
public void convertAlertTriggerEntityToAlertStatus200() {
    AlertTriggerEntity alertTriggerEntity = mock(AlertTriggerEntity.class);
    when(alertTriggerEntity.getType()).thenReturn(AlertMapper.STATUS_ALERT);
    final RateCondition rateCondition = mock(RateCondition.class);
    when(alertTriggerEntity.getConditions()).thenReturn(Collections.singletonList(rateCondition));
    when(rateCondition.getTimeUnit()).thenReturn(TimeUnit.MINUTES);
    when(rateCondition.getDuration()).thenReturn(10L);
    when(rateCondition.getThreshold()).thenReturn(20D);
    final ThresholdRangeCondition thresholdRangeCondition = mock(ThresholdRangeCondition.class);
    when(rateCondition.getComparison()).thenReturn(thresholdRangeCondition);
    when(thresholdRangeCondition.getThresholdLow()).thenReturn(200D);
    when(thresholdRangeCondition.getThresholdHigh()).thenReturn(200D);
    final Alert actual = alertMapper.convert(alertTriggerEntity);
    assertThat(actual.getType()).isEqualTo(AlertType.STATUS);
    assertThat(actual.getStatusCode()).isEqualTo("200");
    assertThat(actual.getStatusPercent()).isEqualTo(20);
    assertThat(actual.getDuration()).isEqualTo(10);
    assertThat(actual.getTimeUnit()).isEqualTo(AlertTimeUnit.MINUTES);
}
Also used : RateCondition(io.gravitee.alert.api.condition.RateCondition) ThresholdRangeCondition(io.gravitee.alert.api.condition.ThresholdRangeCondition) Alert(io.gravitee.rest.api.portal.rest.model.Alert) UpdateAlertTriggerEntity(io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity) AlertTriggerEntity(io.gravitee.rest.api.model.alert.AlertTriggerEntity) NewAlertTriggerEntity(io.gravitee.rest.api.model.alert.NewAlertTriggerEntity) Test(org.junit.Test)

Example 4 with ThresholdRangeCondition

use of io.gravitee.alert.api.condition.ThresholdRangeCondition in project gravitee-management-rest-api by gravitee-io.

the class AlertMapper method convert.

public Alert convert(AlertTriggerEntity alertTriggerEntity) {
    final Alert alert = new Alert();
    alert.setId(alertTriggerEntity.getId());
    alert.setEnabled(alertTriggerEntity.isEnabled());
    if (RESPONSE_TIME_ALERT.equals(alertTriggerEntity.getType())) {
        alert.setType(AlertType.RESPONSE_TIME);
        final AggregationCondition condition = (AggregationCondition) alertTriggerEntity.getConditions().get(0);
        alert.setDuration((int) condition.getDuration());
        alert.setTimeUnit(convert(condition.getTimeUnit()));
        alert.setResponseTime(condition.getThreshold().intValue());
    } else if (STATUS_ALERT.equals(alertTriggerEntity.getType())) {
        alert.setType(AlertType.STATUS);
        final RateCondition condition = (RateCondition) alertTriggerEntity.getConditions().get(0);
        alert.setDuration((int) condition.getDuration());
        alert.setTimeUnit(convert(condition.getTimeUnit()));
        final ThresholdRangeCondition comparison = (ThresholdRangeCondition) condition.getComparison();
        alert.setStatusCode(convertStatusCode(comparison.getThresholdLow(), comparison.getThresholdHigh()));
        alert.setStatusPercent((int) condition.getThreshold());
    }
    return alert;
}
Also used : AggregationCondition(io.gravitee.alert.api.condition.AggregationCondition) RateCondition(io.gravitee.alert.api.condition.RateCondition) Alert(io.gravitee.rest.api.portal.rest.model.Alert) ThresholdRangeCondition(io.gravitee.alert.api.condition.ThresholdRangeCondition)

Example 5 with ThresholdRangeCondition

use of io.gravitee.alert.api.condition.ThresholdRangeCondition in project gravitee-management-rest-api by gravitee-io.

the class AlertMapperTest method convertAlertTriggerEntityToAlertStatus2xx.

@Test
public void convertAlertTriggerEntityToAlertStatus2xx() {
    AlertTriggerEntity alertTriggerEntity = mock(AlertTriggerEntity.class);
    when(alertTriggerEntity.getType()).thenReturn(AlertMapper.STATUS_ALERT);
    final RateCondition rateCondition = mock(RateCondition.class);
    when(alertTriggerEntity.getConditions()).thenReturn(Collections.singletonList(rateCondition));
    when(rateCondition.getTimeUnit()).thenReturn(TimeUnit.MINUTES);
    when(rateCondition.getDuration()).thenReturn(10L);
    when(rateCondition.getThreshold()).thenReturn(20D);
    final ThresholdRangeCondition thresholdRangeCondition = mock(ThresholdRangeCondition.class);
    when(rateCondition.getComparison()).thenReturn(thresholdRangeCondition);
    when(thresholdRangeCondition.getThresholdLow()).thenReturn(200D);
    when(thresholdRangeCondition.getThresholdHigh()).thenReturn(299D);
    final Alert actual = alertMapper.convert(alertTriggerEntity);
    assertThat(actual.getType()).isEqualTo(AlertType.STATUS);
    assertThat(actual.getStatusCode()).isEqualTo("2xx");
    assertThat(actual.getStatusPercent()).isEqualTo(20);
    assertThat(actual.getDuration()).isEqualTo(10);
    assertThat(actual.getTimeUnit()).isEqualTo(AlertTimeUnit.MINUTES);
}
Also used : RateCondition(io.gravitee.alert.api.condition.RateCondition) ThresholdRangeCondition(io.gravitee.alert.api.condition.ThresholdRangeCondition) Alert(io.gravitee.rest.api.portal.rest.model.Alert) UpdateAlertTriggerEntity(io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity) AlertTriggerEntity(io.gravitee.rest.api.model.alert.AlertTriggerEntity) NewAlertTriggerEntity(io.gravitee.rest.api.model.alert.NewAlertTriggerEntity) Test(org.junit.Test)

Aggregations

RateCondition (io.gravitee.alert.api.condition.RateCondition)7 ThresholdRangeCondition (io.gravitee.alert.api.condition.ThresholdRangeCondition)7 Test (org.junit.Test)6 NewAlertTriggerEntity (io.gravitee.rest.api.model.alert.NewAlertTriggerEntity)4 UpdateAlertTriggerEntity (io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity)4 AlertInput (io.gravitee.rest.api.portal.rest.model.AlertInput)4 Alert (io.gravitee.rest.api.portal.rest.model.Alert)3 AlertTriggerEntity (io.gravitee.rest.api.model.alert.AlertTriggerEntity)2 AggregationCondition (io.gravitee.alert.api.condition.AggregationCondition)1