Search in sources :

Example 6 with PolicyConfiguration

use of com.netflix.titus.api.appscale.model.PolicyConfiguration in project titus-control-plane by Netflix.

the class CassAppScalePolicyStore method buildAutoScalingPolicyFromRow.

private AutoScalingPolicy buildAutoScalingPolicyFromRow(Row row) {
    String refId = row.getUUID(COLUMN_REF_ID).toString();
    String jobId = row.getString(COLUMN_JOB_ID);
    String policyConfigurationStr = row.getString(COLUMN_VALUE);
    String policyId = row.getString(COLUMN_POLICY_ID);
    String alarmId = row.getString(COLUMN_ALARM_ID);
    String status = row.getString(COLUMN_STATUS);
    String statusMessage = row.getString(COLUMN_STATUS_MESSAGE);
    PolicyConfiguration policyConfiguration = ObjectMappers.readValue(ObjectMappers.appScalePolicyMapper(), policyConfigurationStr, PolicyConfiguration.class);
    return AutoScalingPolicy.newBuilder().withRefId(refId).withJobId(jobId).withPolicyConfiguration(policyConfiguration).withAlarmId(alarmId).withPolicyId(policyId).withStatus(PolicyStatus.valueOf(status)).withStatusMessage(statusMessage).build();
}
Also used : PolicyConfiguration(com.netflix.titus.api.appscale.model.PolicyConfiguration)

Example 7 with PolicyConfiguration

use of com.netflix.titus.api.appscale.model.PolicyConfiguration 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");
}
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) AlarmConfiguration(com.netflix.titus.api.appscale.model.AlarmConfiguration) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) Test(org.junit.Test)

Example 8 with PolicyConfiguration

use of com.netflix.titus.api.appscale.model.PolicyConfiguration 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;
}
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 9 with PolicyConfiguration

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

Example 10 with PolicyConfiguration

use of com.netflix.titus.api.appscale.model.PolicyConfiguration in project titus-control-plane by Netflix.

the class CassAppScalePolicyStoreTest method checkUpdates.

@Test
public void checkUpdates() 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();
    // update policyId
    String policyId = "PolicyARN";
    store.updatePolicyId(refId, policyId).await();
    String getPolicyIdQuery = "SELECT policy_id from app_scale_policy where ref_id = ?;";
    BoundStatement stmt = session.prepare(getPolicyIdQuery).bind(UUID.fromString(refId));
    ResultSet rs = session.execute(stmt);
    List<Row> rows = rs.all();
    Assertions.assertThat(rows.size()).isEqualTo(1);
    String policyIdStored = rows.get(0).getString(CassAppScalePolicyStore.COLUMN_POLICY_ID);
    Assertions.assertThat(policyIdStored).isEqualTo(policyId);
    // update alarmId
    String alarmId = "AlarmARM";
    store.updateAlarmId(refId, alarmId).await();
    String getAlarmIdQuery = "SELECT alarm_id from app_scale_policy where ref_id = ?;";
    stmt = session.prepare(getAlarmIdQuery).bind(UUID.fromString(refId));
    rs = session.execute(stmt);
    rows = rs.all();
    Assertions.assertThat(rows.size()).isEqualTo(1);
    String alarmIdStored = rows.get(0).getString(CassAppScalePolicyStore.COLUMN_ALARM_ID);
    Assertions.assertThat(alarmIdStored).isEqualTo(alarmId);
    // update policy status
    PolicyStatus status = PolicyStatus.Applied;
    store.updatePolicyStatus(refId, status).await();
    String getPolicyStatusQuery = "SELECT status from app_scale_policy where ref_id = ?;";
    stmt = session.prepare(getPolicyStatusQuery).bind(UUID.fromString(refId));
    rs = session.execute(stmt);
    rows = rs.all();
    Assertions.assertThat(rows.size()).isEqualTo(1);
    PolicyStatus updatedStatus = PolicyStatus.valueOf(rows.get(0).getString(CassAppScalePolicyStore.COLUMN_STATUS));
    Assertions.assertThat(updatedStatus).isEqualTo(status);
    String errorStatusMessage = "Got Trumped";
    store.updateStatusMessage(refId, errorStatusMessage).await();
    String getStatusMessageQuery = "SELECT status_message from app_scale_policy where ref_id = ?;";
    stmt = session.prepare(getStatusMessageQuery).bind(UUID.fromString(refId));
    rs = session.execute(stmt);
    rows = rs.all();
    Assertions.assertThat(rows.size()).isEqualTo(1);
    String statusMessage = rows.get(0).getString(CassAppScalePolicyStore.COLUMN_STATUS_MESSAGE);
    Assertions.assertThat(statusMessage).isEqualTo(errorStatusMessage);
    // read policy by refId
    Observable<AutoScalingPolicy> autoScalingPolicyObservable = store.retrievePolicyForRefId(refId);
    AutoScalingPolicy autoScalingPolicy = autoScalingPolicyObservable.toBlocking().first();
    Assertions.assertThat(autoScalingPolicy.getRefId()).isEqualTo(refId);
    Assertions.assertThat(autoScalingPolicy.getStatus()).isEqualTo(status);
    Assertions.assertThat(autoScalingPolicy.getAlarmId()).isEqualTo(alarmId);
    Assertions.assertThat(autoScalingPolicy.getPolicyId()).isEqualTo(policyId);
    // update alarm threshold
    AlarmConfiguration alarmConfiguration = autoScalingPolicy.getPolicyConfiguration().getAlarmConfiguration();
    double currentThreshold = alarmConfiguration.getThreshold();
    int thresholdIncrement = 10;
    AlarmConfiguration newAlarmConfiguration = AlarmConfiguration.newBuilder().withStatistic(alarmConfiguration.getStatistic()).withName(alarmConfiguration.getName()).withMetricNamespace(alarmConfiguration.getMetricNamespace()).withMetricName(alarmConfiguration.getMetricName()).withComparisonOperator(alarmConfiguration.getComparisonOperator()).withThreshold(alarmConfiguration.getThreshold() + thresholdIncrement).withPeriodSec(alarmConfiguration.getPeriodSec()).withEvaluationPeriods(alarmConfiguration.getEvaluationPeriods()).withActionsEnabled(alarmConfiguration.getActionsEnabled().get()).build();
    PolicyConfiguration newPolicyConfig = PolicyConfiguration.newBuilder().withPolicyType(autoScalingPolicy.getPolicyConfiguration().getPolicyType()).withStepScalingPolicyConfiguration(autoScalingPolicy.getPolicyConfiguration().getStepScalingPolicyConfiguration()).withName(autoScalingPolicy.getPolicyConfiguration().getName()).withPolicyType(autoScalingPolicy.getPolicyConfiguration().getPolicyType()).withAlarmConfiguration(newAlarmConfiguration).build();
    AutoScalingPolicy newPolicy = AutoScalingPolicy.newBuilder().withAutoScalingPolicy(autoScalingPolicy).withPolicyConfiguration(newPolicyConfig).build();
    store.updatePolicyConfiguration(newPolicy).await();
    autoScalingPolicyObservable = store.retrievePolicyForRefId(refId);
    AutoScalingPolicy updatedPolicy = autoScalingPolicyObservable.toBlocking().first();
    Assertions.assertThat(updatedPolicy.getPolicyConfiguration().getAlarmConfiguration().getName()).isEqualTo(newAlarmConfiguration.getName());
    Assertions.assertThat(updatedPolicy.getPolicyConfiguration().getAlarmConfiguration().getThreshold()).isEqualTo(currentThreshold + thresholdIncrement);
}
Also used : AlarmConfiguration(com.netflix.titus.api.appscale.model.AlarmConfiguration) AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy) PolicyStatus(com.netflix.titus.api.appscale.model.PolicyStatus) ResultSet(com.datastax.driver.core.ResultSet) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) StepScalingPolicyConfiguration(com.netflix.titus.api.appscale.model.StepScalingPolicyConfiguration) PolicyConfiguration(com.netflix.titus.api.appscale.model.PolicyConfiguration) Row(com.datastax.driver.core.Row) BoundStatement(com.datastax.driver.core.BoundStatement) Session(com.datastax.driver.core.Session) Test(org.junit.Test) IntegrationNotParallelizableTest(com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)

Aggregations

PolicyConfiguration (com.netflix.titus.api.appscale.model.PolicyConfiguration)10 StepScalingPolicyConfiguration (com.netflix.titus.api.appscale.model.StepScalingPolicyConfiguration)7 AutoScalingPolicy (com.netflix.titus.api.appscale.model.AutoScalingPolicy)6 AlarmConfiguration (com.netflix.titus.api.appscale.model.AlarmConfiguration)4 TargetTrackingPolicy (com.netflix.titus.api.appscale.model.TargetTrackingPolicy)3 Test (org.junit.Test)3 StepAdjustment (com.netflix.titus.api.appscale.model.StepAdjustment)2 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)1 AsyncHandler (com.amazonaws.handlers.AsyncHandler)1 AWSApplicationAutoScalingAsync (com.amazonaws.services.applicationautoscaling.AWSApplicationAutoScalingAsync)1 AWSApplicationAutoScalingAsyncClientBuilder (com.amazonaws.services.applicationautoscaling.AWSApplicationAutoScalingAsyncClientBuilder)1 CustomizedMetricSpecification (com.amazonaws.services.applicationautoscaling.model.CustomizedMetricSpecification)1 DeleteScalingPolicyRequest (com.amazonaws.services.applicationautoscaling.model.DeleteScalingPolicyRequest)1 DeleteScalingPolicyResult (com.amazonaws.services.applicationautoscaling.model.DeleteScalingPolicyResult)1 DeregisterScalableTargetRequest (com.amazonaws.services.applicationautoscaling.model.DeregisterScalableTargetRequest)1 DeregisterScalableTargetResult (com.amazonaws.services.applicationautoscaling.model.DeregisterScalableTargetResult)1 DescribeScalableTargetsRequest (com.amazonaws.services.applicationautoscaling.model.DescribeScalableTargetsRequest)1 DescribeScalableTargetsResult (com.amazonaws.services.applicationautoscaling.model.DescribeScalableTargetsResult)1 MetricDimension (com.amazonaws.services.applicationautoscaling.model.MetricDimension)1 ObjectNotFoundException (com.amazonaws.services.applicationautoscaling.model.ObjectNotFoundException)1