Search in sources :

Example 1 with AggregationCondition

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

the class AlertMapperTest method convertAlertInputToUpdateAlertTriggerEntityResponseTime.

@Test
public void convertAlertInputToUpdateAlertTriggerEntityResponseTime() {
    final AlertInput alertInput = new AlertInput();
    alertInput.setEnabled(true);
    alertInput.setResponseTime(35);
    alertInput.setDuration(10);
    alertInput.setTimeUnit(AlertTimeUnit.MINUTES);
    alertInput.setType(AlertType.RESPONSE_TIME);
    final UpdateAlertTriggerEntity actual = alertMapper.convertToUpdate(alertInput);
    assertThat(actual.isEnabled()).isEqualTo(alertInput.getEnabled());
    final AggregationCondition aggregationCondition = (AggregationCondition) actual.getConditions().get(0);
    assertThat(aggregationCondition.getDuration()).isEqualTo(alertInput.getDuration().longValue());
    assertThat(aggregationCondition.getTimeUnit()).isEqualTo(TimeUnit.MINUTES);
    assertThat(aggregationCondition.getThreshold()).isEqualTo(alertInput.getResponseTime().doubleValue());
}
Also used : UpdateAlertTriggerEntity(io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity) AggregationCondition(io.gravitee.alert.api.condition.AggregationCondition) AlertInput(io.gravitee.rest.api.portal.rest.model.AlertInput) Test(org.junit.Test)

Example 2 with AggregationCondition

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

the class AlertMapperTest method convertAlertTriggerEntityToAlertResponseTime.

@Test
public void convertAlertTriggerEntityToAlertResponseTime() {
    AlertTriggerEntity alertTriggerEntity = mock(AlertTriggerEntity.class);
    when(alertTriggerEntity.getType()).thenReturn(AlertMapper.RESPONSE_TIME_ALERT);
    final AggregationCondition aggregationCondition = mock(AggregationCondition.class);
    when(alertTriggerEntity.getConditions()).thenReturn(Collections.singletonList(aggregationCondition));
    when(aggregationCondition.getTimeUnit()).thenReturn(TimeUnit.MINUTES);
    when(aggregationCondition.getDuration()).thenReturn(10L);
    when(aggregationCondition.getThreshold()).thenReturn(200D);
    final Alert actual = alertMapper.convert(alertTriggerEntity);
    assertThat(actual.getType()).isEqualTo(AlertType.RESPONSE_TIME);
    assertThat(actual.getResponseTime()).isEqualTo(200);
    assertThat(actual.getDuration()).isEqualTo(10);
    assertThat(actual.getTimeUnit()).isEqualTo(AlertTimeUnit.MINUTES);
}
Also used : AggregationCondition(io.gravitee.alert.api.condition.AggregationCondition) 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 3 with AggregationCondition

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

the class AlertMapperTest method convertAlertInputToNewAlertTriggerEntityResponseTime.

@Test
public void convertAlertInputToNewAlertTriggerEntityResponseTime() {
    final AlertInput alertInput = new AlertInput();
    alertInput.setEnabled(true);
    alertInput.setResponseTime(35);
    alertInput.setDuration(10);
    alertInput.setTimeUnit(AlertTimeUnit.MINUTES);
    alertInput.setType(AlertType.RESPONSE_TIME);
    final NewAlertTriggerEntity actual = alertMapper.convert(alertInput);
    assertThat(actual.isEnabled()).isEqualTo(alertInput.getEnabled());
    assertThat(actual.getType()).isEqualTo(AlertMapper.RESPONSE_TIME_ALERT);
    final AggregationCondition aggregationCondition = (AggregationCondition) actual.getConditions().get(0);
    assertThat(aggregationCondition.getDuration()).isEqualTo(alertInput.getDuration().longValue());
    assertThat(aggregationCondition.getTimeUnit()).isEqualTo(TimeUnit.MINUTES);
    assertThat(aggregationCondition.getThreshold()).isEqualTo(alertInput.getResponseTime().doubleValue());
}
Also used : AggregationCondition(io.gravitee.alert.api.condition.AggregationCondition) AlertInput(io.gravitee.rest.api.portal.rest.model.AlertInput) NewAlertTriggerEntity(io.gravitee.rest.api.model.alert.NewAlertTriggerEntity) Test(org.junit.Test)

Example 4 with AggregationCondition

use of io.gravitee.alert.api.condition.AggregationCondition 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)

Aggregations

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