Search in sources :

Example 1 with ScalingPolicy

use of com.sequenceiq.periscope.domain.ScalingPolicy in project cloudbreak by hortonworks.

the class PrometheusAlertResponseConverter method convert.

@Override
public PrometheusAlert convert(PrometheusAlertResponse source) {
    PrometheusAlert alert = new PrometheusAlert();
    alert.setName(source.getAlertName());
    alert.setDescription(source.getDescription());
    alert.setPeriod(source.getPeriod());
    alert.setAlertState(source.getAlertState() != null ? source.getAlertState() : CRITICAL);
    double threshold = source.getThreshold();
    String alertRuleName = source.getAlertRuleName();
    try {
        AlertOperator alertOperator = source.getAlertOperator() != null ? source.getAlertOperator() : AlertOperator.MORE_THAN;
        String operator = alertOperator.getOperator();
        String alertRule = templateService.createAlert(alertRuleName, alert.getName(), String.valueOf(threshold), alert.getPeriod(), operator);
        alert.setAlertRule(alertRule);
        alert.setParameters(createParametersFrom(threshold, alertOperator));
        if (source.getScalingPolicy() != null) {
            ScalingPolicy scalingPolicy = scalingPolicyRequestConverter.convert(source.getScalingPolicy());
            scalingPolicy.setAlert(alert);
            alert.setScalingPolicy(scalingPolicy);
        }
    } catch (Exception e) {
        throw new ConversionFailedException(TypeDescriptor.valueOf(PrometheusAlertRequest.class), TypeDescriptor.valueOf(PrometheusAlert.class), source.toString(), e);
    }
    return alert;
}
Also used : ScalingPolicy(com.sequenceiq.periscope.domain.ScalingPolicy) ConversionFailedException(org.springframework.core.convert.ConversionFailedException) PrometheusAlert(com.sequenceiq.periscope.domain.PrometheusAlert) AlertOperator(com.sequenceiq.periscope.api.model.AlertOperator) ConversionFailedException(org.springframework.core.convert.ConversionFailedException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with ScalingPolicy

use of com.sequenceiq.periscope.domain.ScalingPolicy in project cloudbreak by hortonworks.

the class ScalingPolicyRequestConverter method convert.

@Override
public ScalingPolicy convert(ScalingPolicyRequest source) {
    ScalingPolicy policy = new ScalingPolicy();
    policy.setAdjustmentType(source.getAdjustmentType());
    policy.setName(source.getName());
    policy.setScalingAdjustment(source.getScalingAdjustment());
    policy.setHostGroup(source.getHostGroup());
    return policy;
}
Also used : ScalingPolicy(com.sequenceiq.periscope.domain.ScalingPolicy)

Example 3 with ScalingPolicy

use of com.sequenceiq.periscope.domain.ScalingPolicy in project cloudbreak by hortonworks.

the class ScalingService method createPolicy.

public ScalingPolicy createPolicy(Long clusterId, Long alertId, ScalingPolicy policy) {
    BaseAlert alert = alertService.getBaseAlert(clusterId, alertId);
    policy.setAlert(alert);
    ScalingPolicy scalingPolicy = policyRepository.save(policy);
    alert.setScalingPolicy(scalingPolicy);
    alertService.save(alert);
    return scalingPolicy;
}
Also used : ScalingPolicy(com.sequenceiq.periscope.domain.ScalingPolicy) BaseAlert(com.sequenceiq.periscope.domain.BaseAlert)

Example 4 with ScalingPolicy

use of com.sequenceiq.periscope.domain.ScalingPolicy in project cloudbreak by hortonworks.

the class ScalingService method updatePolicy.

public ScalingPolicy updatePolicy(Long clusterId, Long policyId, ScalingPolicy scalingPolicy) {
    ScalingPolicy policy = getScalingPolicy(clusterId, policyId);
    policy.setName(scalingPolicy.getName());
    policy.setHostGroup(scalingPolicy.getHostGroup());
    policy.setAdjustmentType(scalingPolicy.getAdjustmentType());
    policy.setScalingAdjustment(scalingPolicy.getScalingAdjustment());
    return policyRepository.save(policy);
}
Also used : ScalingPolicy(com.sequenceiq.periscope.domain.ScalingPolicy)

Example 5 with ScalingPolicy

use of com.sequenceiq.periscope.domain.ScalingPolicy in project cloudbreak by hortonworks.

the class ScalingService method deletePolicy.

public void deletePolicy(Long clusterId, Long policyId) {
    ScalingPolicy policy = getScalingPolicy(clusterId, policyId);
    BaseAlert alert = policy.getAlert();
    alert.setScalingPolicy(null);
    policy.setAlert(null);
    policyRepository.delete(policy);
    alertService.save(alert);
}
Also used : ScalingPolicy(com.sequenceiq.periscope.domain.ScalingPolicy) BaseAlert(com.sequenceiq.periscope.domain.BaseAlert)

Aggregations

ScalingPolicy (com.sequenceiq.periscope.domain.ScalingPolicy)7 BaseAlert (com.sequenceiq.periscope.domain.BaseAlert)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 AlertOperator (com.sequenceiq.periscope.api.model.AlertOperator)1 PrometheusAlert (com.sequenceiq.periscope.domain.PrometheusAlert)1 ConversionFailedException (org.springframework.core.convert.ConversionFailedException)1