use of com.netflix.titus.api.appscale.model.AutoScalingPolicy in project titus-control-plane by Netflix.
the class ScalingPolicyModelSanitizationTest method testInvalidStepScalingPolicyNoAlarmConfiguration.
@Test
public void testInvalidStepScalingPolicyNoAlarmConfiguration() {
PolicyConfiguration policyConfiguration = PolicyConfiguration.newBuilder().withStepScalingPolicyConfiguration(mock(StepScalingPolicyConfiguration.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("alarmConfiguration must be specified for a step scaling policy");
}
use of com.netflix.titus.api.appscale.model.AutoScalingPolicy in project titus-control-plane by Netflix.
the class CassAppScalePolicyStoreTest method checkStoreAndRetrieve.
@Test
public void checkStoreAndRetrieve() throws Exception {
Session session = cassandraCQLUnit.getSession();
CassAppScalePolicyStore store = new CassAppScalePolicyStore(session, configuration, new DefaultRegistry());
String jobId = UUID.randomUUID().toString();
Observable<String> respRefId = store.storePolicy(buildAutoScalingPolicy(jobId));
String refId = respRefId.toBlocking().first();
Assertions.assertThat(refId).isNotNull().isNotEmpty();
Observable<AutoScalingPolicy> autoScalingPolicyObservable = store.retrievePolicyForRefId(refId);
AutoScalingPolicy autoScalingPolicy = autoScalingPolicyObservable.toBlocking().first();
Assertions.assertThat(autoScalingPolicy.getRefId()).isEqualTo(refId);
Assertions.assertThat(autoScalingPolicy.getStatus()).isEqualTo(PolicyStatus.Pending);
Observable<String> respRefIdTwo = store.storePolicy(buildAutoScalingPolicy(jobId));
String refIdTwo = respRefIdTwo.toBlocking().first();
Assertions.assertThat(refIdTwo).isNotNull().isNotEmpty();
autoScalingPolicyObservable = store.retrievePoliciesForJob(jobId);
List<AutoScalingPolicy> autoScalingPolicies = autoScalingPolicyObservable.toList().toBlocking().first();
Assertions.assertThat(autoScalingPolicies.size()).isEqualTo(2);
List<String> refIdList = autoScalingPolicies.stream().map(ap -> ap.getRefId()).collect(Collectors.toList());
Assertions.assertThat(refIdList).isEqualTo(Arrays.asList(refId, refIdTwo));
Assertions.assertThat(autoScalingPolicies.get(1).getStatus()).isEqualTo(PolicyStatus.Pending);
autoScalingPolicyObservable = store.retrievePoliciesForJob("invalidJobId");
List<AutoScalingPolicy> emptyPolicies = autoScalingPolicyObservable.toList().toBlocking().first();
Assertions.assertThat(emptyPolicies.size()).isEqualTo(0);
}
use of com.netflix.titus.api.appscale.model.AutoScalingPolicy in project titus-control-plane by Netflix.
the class CassAppScalePolicyStoreTest method buildAutoScalingPolicy.
private AutoScalingPolicy buildAutoScalingPolicy(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 InMemoryPolicyStore method updateAlarmId.
@Override
public Completable updateAlarmId(String policyRefId, String alarmId) {
return Completable.fromCallable(() -> {
AutoScalingPolicy autoScalingPolicy = policyMap.get(policyRefId);
AutoScalingPolicy policySaved = AutoScalingPolicy.newBuilder().withAutoScalingPolicy(autoScalingPolicy).withAlarmId(alarmId).build();
return policyMap.put(policyRefId, policySaved);
});
}
use of com.netflix.titus.api.appscale.model.AutoScalingPolicy in project titus-control-plane by Netflix.
the class InMemoryPolicyStore method updatePolicyConfiguration.
@Override
public Completable updatePolicyConfiguration(AutoScalingPolicy autoScalingPolicy) {
return Completable.fromCallable(() -> {
log.info("Updating policy configuration for refID {}", autoScalingPolicy.getRefId());
AutoScalingPolicy existingPolicy = policyMap.get(autoScalingPolicy.getRefId());
AutoScalingPolicy policySaved = AutoScalingPolicy.newBuilder().withAutoScalingPolicy(existingPolicy).withPolicyConfiguration(autoScalingPolicy.getPolicyConfiguration()).build();
return policyMap.put(policySaved.getRefId(), policySaved);
});
}
Aggregations