use of com.netflix.titus.api.appscale.model.AutoScalingPolicy in project titus-control-plane by Netflix.
the class GrpcModelConverters method toScalingPolicy.
private static ScalingPolicy toScalingPolicy(AutoScalingPolicy autoScalingPolicy) {
ScalingPolicy.Builder scalingPolicyBuilder = ScalingPolicy.newBuilder();
if (autoScalingPolicy.getPolicyConfiguration().getPolicyType() == StepScaling) {
AlarmConfiguration alarmConfiguration = toAlarmConfiguration(autoScalingPolicy.getPolicyConfiguration().getAlarmConfiguration());
StepScalingPolicy stepScalingPolicy = toStepScalingPolicy(autoScalingPolicy.getPolicyConfiguration().getStepScalingPolicyConfiguration());
StepScalingPolicyDescriptor stepScalingPolicyDescriptor = StepScalingPolicyDescriptor.newBuilder().setAlarmConfig(alarmConfiguration).setScalingPolicy(stepScalingPolicy).build();
scalingPolicyBuilder.setStepPolicyDescriptor(stepScalingPolicyDescriptor);
} else if (autoScalingPolicy.getPolicyConfiguration().getPolicyType() == TargetTrackingScaling) {
TargetTrackingPolicyDescriptor targetTrackingPolicyDesc = toTargetTrackingPolicyDescriptor(autoScalingPolicy.getPolicyConfiguration().getTargetTrackingPolicy());
scalingPolicyBuilder.setTargetPolicyDescriptor(targetTrackingPolicyDesc);
} else {
throw new IllegalArgumentException("Invalid AutoScalingPolicyType value " + autoScalingPolicy.getPolicyConfiguration().getPolicyType());
}
return scalingPolicyBuilder.build();
}
use of com.netflix.titus.api.appscale.model.AutoScalingPolicy in project titus-control-plane by Netflix.
the class GrpcModelConverters method toScalingPolicyResult.
public static ScalingPolicyResult toScalingPolicyResult(AutoScalingPolicy autoScalingPolicy) {
ScalingPolicy scalingPolicy = toScalingPolicy(autoScalingPolicy);
ScalingPolicyStatus scalingPolicyStatus = toScalingPolicyStatus(autoScalingPolicy.getStatus(), autoScalingPolicy.getStatusMessage());
return ScalingPolicyResult.newBuilder().setJobId(autoScalingPolicy.getJobId()).setId(ScalingPolicyID.newBuilder().setId(autoScalingPolicy.getRefId()).build()).setPolicyState(scalingPolicyStatus).setScalingPolicy(scalingPolicy).build();
}
use of com.netflix.titus.api.appscale.model.AutoScalingPolicy in project titus-control-plane by Netflix.
the class ScalingPolicyModelSanitizationTest method testInvalidScalingConfigurationWithBothPolicies.
@Test
public void testInvalidScalingConfigurationWithBothPolicies() {
PolicyConfiguration policyConfiguration = PolicyConfiguration.newBuilder().withStepScalingPolicyConfiguration(mock(StepScalingPolicyConfiguration.class)).withAlarmConfiguration(mock(AlarmConfiguration.class)).withTargetTrackingPolicy(mock(TargetTrackingPolicy.class)).build();
AutoScalingPolicy autoScalingPolicy = AutoScalingPolicy.newBuilder().withPolicyConfiguration(policyConfiguration).build();
Set<ValidationError> validationErrors = newScalingPolicySanitizer().validate(autoScalingPolicy);
assertThat(validationErrors).hasSize(1);
assertThat(CollectionsExt.first(validationErrors).getDescription()).isEqualTo("exactly one scaling policy should be set");
}
use of com.netflix.titus.api.appscale.model.AutoScalingPolicy in project titus-control-plane by Netflix.
the class AutoScalingPolicyTests method buildStepScalingPolicy.
public static AutoScalingPolicy buildStepScalingPolicy(String jobId) {
AlarmConfiguration alarmConfiguration = AlarmConfiguration.newBuilder().withActionsEnabled(true).withComparisonOperator(ComparisonOperator.GreaterThanThreshold).withEvaluationPeriods(1).withPeriodSec(60).withMetricName("CPUUtilization").withMetricNamespace("AWS/EC2").withName(jobId).withStatistic(Statistic.Average).build();
StepAdjustment stepAdjustment = StepAdjustment.newBuilder().withMetricIntervalLowerBound(0).withScalingAdjustment(1).build();
StepScalingPolicyConfiguration stepScalingPolicyConfiguration = StepScalingPolicyConfiguration.newBuilder().withAdjustmentType(StepAdjustmentType.ChangeInCapacity).withCoolDownSec(60).withMetricAggregatorType(MetricAggregationType.Average).withMinAdjustmentMagnitude(1).withSteps(Arrays.asList(stepAdjustment)).build();
PolicyConfiguration policyConfiguration = PolicyConfiguration.newBuilder().withAlarmConfiguration(alarmConfiguration).withStepScalingPolicyConfiguration(stepScalingPolicyConfiguration).withPolicyType(PolicyType.StepScaling).withName(jobId).build();
AutoScalingPolicy autoScalingPolicy = AutoScalingPolicy.newBuilder().withPolicyConfiguration(policyConfiguration).withStatus(PolicyStatus.Pending).withStatusMessage("ICE-ed by AWS").withJobId(jobId).build();
return autoScalingPolicy;
}
use of com.netflix.titus.api.appscale.model.AutoScalingPolicy in project titus-control-plane by Netflix.
the class AutoScalingPolicyTests method buildTargetTrackingPolicy.
public static AutoScalingPolicy buildTargetTrackingPolicy(String jobId) {
CustomizedMetricSpecification customizedMetricSpec = CustomizedMetricSpecification.newBuilder().withNamespace("foobar").withNamespace("NFLX/EPIC").withStatistic(Statistic.Sum).withUnit("Seconds").build();
TargetTrackingPolicy targetTrackingPolicy = TargetTrackingPolicy.newBuilder().withDisableScaleIn(false).withScaleInCooldownSec(10).withScaleOutCooldownSec(5).withCustomizedMetricSpecification(customizedMetricSpec).build();
PolicyConfiguration policyConfiguration = PolicyConfiguration.newBuilder().withTargetTrackingPolicy(targetTrackingPolicy).withPolicyType(PolicyType.TargetTrackingScaling).build();
AutoScalingPolicy autoScalingPolicy = AutoScalingPolicy.newBuilder().withPolicyConfiguration(policyConfiguration).withStatus(PolicyStatus.Pending).withStatusMessage("ICE-ed by AWS").withJobId(jobId).build();
return autoScalingPolicy;
}
Aggregations