Search in sources :

Example 1 with AutoScalePolicyException

use of com.netflix.titus.api.appscale.service.AutoScalePolicyException in project titus-control-plane by Netflix.

the class DefaultAppScaleManager method saveStatusOnError.

private Completable saveStatusOnError(Throwable e) {
    Optional<AutoScalePolicyException> autoScalePolicyExceptionOpt = extractAutoScalePolicyException(e);
    if (!autoScalePolicyExceptionOpt.isPresent()) {
        return Completable.complete();
    }
    logger.info("Saving AutoScalePolicyException", autoScalePolicyExceptionOpt.get());
    AutoScalePolicyException autoScalePolicyException = autoScalePolicyExceptionOpt.get();
    if (autoScalePolicyException.getPolicyRefId() != null && !autoScalePolicyException.getPolicyRefId().isEmpty()) {
        metrics.reportErrorForException(autoScalePolicyException);
        String statusMessage = String.format("%s - %s", autoScalePolicyException.getErrorCode(), autoScalePolicyException.getMessage());
        AutoScalingPolicy autoScalingPolicy = AutoScalingPolicy.newBuilder().withRefId(autoScalePolicyException.getPolicyRefId()).build();
        if (autoScalePolicyException.getErrorCode() == AutoScalePolicyException.ErrorCode.UnknownScalingPolicy) {
            metrics.reportPolicyStatusTransition(autoScalingPolicy, PolicyStatus.Deleted);
            return appScalePolicyStore.updateStatusMessage(autoScalePolicyException.getPolicyRefId(), statusMessage).andThen(appScalePolicyStore.updatePolicyStatus(autoScalePolicyException.getPolicyRefId(), PolicyStatus.Deleted));
        } else if (isPolicyCreationError(autoScalePolicyException)) {
            metrics.reportPolicyStatusTransition(autoScalingPolicy, PolicyStatus.Error);
            return appScalePolicyStore.updateStatusMessage(autoScalePolicyException.getPolicyRefId(), statusMessage).andThen(appScalePolicyStore.updatePolicyStatus(autoScalePolicyException.getPolicyRefId(), PolicyStatus.Error));
        } else {
            return appScalePolicyStore.updateStatusMessage(autoScalePolicyException.getPolicyRefId(), statusMessage);
        }
    } else {
        return Completable.complete();
    }
}
Also used : AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy) AutoScalePolicyException(com.netflix.titus.api.appscale.service.AutoScalePolicyException)

Aggregations

AutoScalingPolicy (com.netflix.titus.api.appscale.model.AutoScalingPolicy)1 AutoScalePolicyException (com.netflix.titus.api.appscale.service.AutoScalePolicyException)1