Search in sources :

Example 1 with AutoScalingPolicy

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");
}
Also used : AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy) StepScalingPolicyConfiguration(com.netflix.titus.api.appscale.model.StepScalingPolicyConfiguration) PolicyConfiguration(com.netflix.titus.api.appscale.model.PolicyConfiguration) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) Test(org.junit.Test)

Example 2 with AutoScalingPolicy

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);
}
Also used : Arrays(java.util.Arrays) StepAdjustmentType(com.netflix.titus.api.appscale.model.StepAdjustmentType) Row(com.datastax.driver.core.Row) LoggerFactory(org.slf4j.LoggerFactory) ComparisonOperator(com.netflix.titus.api.appscale.model.ComparisonOperator) CassandraCQLUnit(org.cassandraunit.CassandraCQLUnit) Observable(rx.Observable) PreparedStatement(com.datastax.driver.core.PreparedStatement) ResultSet(com.datastax.driver.core.ResultSet) BoundStatement(com.datastax.driver.core.BoundStatement) AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy) Session(com.datastax.driver.core.Session) ClassPathCQLDataSet(org.cassandraunit.dataset.cql.ClassPathCQLDataSet) Assertions(org.assertj.core.api.Assertions) PolicyStatus(com.netflix.titus.api.appscale.model.PolicyStatus) Before(org.junit.Before) AlarmConfiguration(com.netflix.titus.api.appscale.model.AlarmConfiguration) MetricAggregationType(com.netflix.titus.api.appscale.model.MetricAggregationType) Logger(org.slf4j.Logger) Test(org.junit.Test) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) PolicyType(com.netflix.titus.api.appscale.model.PolicyType) StepScalingPolicyConfiguration(com.netflix.titus.api.appscale.model.StepScalingPolicyConfiguration) Statistic(com.netflix.titus.api.appscale.model.Statistic) List(java.util.List) StepAdjustment(com.netflix.titus.api.appscale.model.StepAdjustment) ObjectMappers(com.netflix.titus.api.json.ObjectMappers) Rule(org.junit.Rule) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Optional(java.util.Optional) PolicyConfiguration(com.netflix.titus.api.appscale.model.PolicyConfiguration) IntegrationNotParallelizableTest(com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest) Mockito.mock(org.mockito.Mockito.mock) AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Session(com.datastax.driver.core.Session) Test(org.junit.Test) IntegrationNotParallelizableTest(com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)

Example 3 with AutoScalingPolicy

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;
}
Also used : AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy) AlarmConfiguration(com.netflix.titus.api.appscale.model.AlarmConfiguration) StepScalingPolicyConfiguration(com.netflix.titus.api.appscale.model.StepScalingPolicyConfiguration) PolicyConfiguration(com.netflix.titus.api.appscale.model.PolicyConfiguration) StepAdjustment(com.netflix.titus.api.appscale.model.StepAdjustment) StepScalingPolicyConfiguration(com.netflix.titus.api.appscale.model.StepScalingPolicyConfiguration)

Example 4 with 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);
    });
}
Also used : AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy)

Example 5 with AutoScalingPolicy

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);
    });
}
Also used : AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy)

Aggregations

AutoScalingPolicy (com.netflix.titus.api.appscale.model.AutoScalingPolicy)21 PolicyConfiguration (com.netflix.titus.api.appscale.model.PolicyConfiguration)8 StepScalingPolicyConfiguration (com.netflix.titus.api.appscale.model.StepScalingPolicyConfiguration)8 Test (org.junit.Test)7 DefaultRegistry (com.netflix.spectator.api.DefaultRegistry)6 AlarmConfiguration (com.netflix.titus.api.appscale.model.AlarmConfiguration)6 StepAdjustment (com.netflix.titus.api.appscale.model.StepAdjustment)4 BoundStatement (com.datastax.driver.core.BoundStatement)3 ResultSet (com.datastax.driver.core.ResultSet)3 Row (com.datastax.driver.core.Row)3 Session (com.datastax.driver.core.Session)3 PolicyStatus (com.netflix.titus.api.appscale.model.PolicyStatus)3 PolicyType (com.netflix.titus.api.appscale.model.PolicyType)3 V3JobOperations (com.netflix.titus.api.jobmanager.service.V3JobOperations)3 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)3 InMemoryPolicyStore (com.netflix.titus.runtime.store.v3.memory.InMemoryPolicyStore)3 IntegrationNotParallelizableTest (com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)3 List (java.util.List)3 Optional (java.util.Optional)3 UUID (java.util.UUID)3