Search in sources :

Example 1 with StepScalingPolicyDescriptor

use of com.netflix.titus.grpc.protogen.StepScalingPolicyDescriptor in project titus-control-plane by Netflix.

the class AutoScalingTestUtils method generateStepPolicy.

/**
 * Builds a random scaling policy for use with tests.
 *
 * @return
 */
public static ScalingPolicy generateStepPolicy() {
    // TODO(Andrew L): Add target tracking support
    AlarmConfiguration alarmConfig = AlarmConfiguration.newBuilder().setActionsEnabled(BoolValue.newBuilder().setValue(ThreadLocalRandom.current().nextBoolean()).build()).setComparisonOperator(AlarmConfiguration.ComparisonOperator.GreaterThanThreshold).setEvaluationPeriods(Int32Value.newBuilder().setValue(ThreadLocalRandom.current().nextInt()).build()).setPeriodSec(Int32Value.newBuilder().setValue(ThreadLocalRandom.current().nextInt()).build()).setThreshold(DoubleValue.newBuilder().setValue(ThreadLocalRandom.current().nextDouble()).build()).setMetricNamespace("NFLX/EPIC").setMetricName("Metric-" + ThreadLocalRandom.current().nextInt()).setStatistic(AlarmConfiguration.Statistic.Sum).build();
    StepScalingPolicy stepScalingPolicy = StepScalingPolicy.newBuilder().setAdjustmentType(StepScalingPolicy.AdjustmentType.ChangeInCapacity).setCooldownSec(Int32Value.newBuilder().setValue(ThreadLocalRandom.current().nextInt()).build()).setMinAdjustmentMagnitude(Int64Value.newBuilder().setValue(ThreadLocalRandom.current().nextLong()).build()).setMetricAggregationType(StepScalingPolicy.MetricAggregationType.Maximum).addStepAdjustments(StepAdjustments.newBuilder().setMetricIntervalLowerBound(DoubleValue.newBuilder().setValue(ThreadLocalRandom.current().nextDouble()).build()).setMetricIntervalUpperBound(DoubleValue.newBuilder().setValue(ThreadLocalRandom.current().nextDouble()).build()).setScalingAdjustment(Int32Value.newBuilder().setValue(ThreadLocalRandom.current().nextInt()).build())).build();
    StepScalingPolicyDescriptor stepScalingPolicyDescriptor = StepScalingPolicyDescriptor.newBuilder().setAlarmConfig(alarmConfig).setScalingPolicy(stepScalingPolicy).build();
    return ScalingPolicy.newBuilder().setStepPolicyDescriptor(stepScalingPolicyDescriptor).build();
}
Also used : StepScalingPolicy(com.netflix.titus.grpc.protogen.StepScalingPolicy) StepScalingPolicyDescriptor(com.netflix.titus.grpc.protogen.StepScalingPolicyDescriptor) AlarmConfiguration(com.netflix.titus.grpc.protogen.AlarmConfiguration)

Example 2 with StepScalingPolicyDescriptor

use of com.netflix.titus.grpc.protogen.StepScalingPolicyDescriptor 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();
}
Also used : StepScalingPolicy(com.netflix.titus.grpc.protogen.StepScalingPolicy) ScalingPolicy(com.netflix.titus.grpc.protogen.ScalingPolicy) AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy) StepScalingPolicy(com.netflix.titus.grpc.protogen.StepScalingPolicy) StepScalingPolicyDescriptor(com.netflix.titus.grpc.protogen.StepScalingPolicyDescriptor) AlarmConfiguration(com.netflix.titus.grpc.protogen.AlarmConfiguration) TargetTrackingPolicyDescriptor(com.netflix.titus.grpc.protogen.TargetTrackingPolicyDescriptor)

Example 3 with StepScalingPolicyDescriptor

use of com.netflix.titus.grpc.protogen.StepScalingPolicyDescriptor in project titus-control-plane by Netflix.

the class InternalModelConverters method toPolicyConfiguration.

private static PolicyConfiguration toPolicyConfiguration(ScalingPolicy scalingPolicyGrpc) {
    PolicyConfiguration.Builder policyConfigBuilder = PolicyConfiguration.newBuilder();
    if (scalingPolicyGrpc.getScalingPolicyDescriptorCase() == STEPPOLICYDESCRIPTOR) {
        policyConfigBuilder.withPolicyType(PolicyType.StepScaling);
        StepScalingPolicyDescriptor stepScalingPolicyDesc = scalingPolicyGrpc.getStepPolicyDescriptor();
        // Build alarm
        if (stepScalingPolicyDesc.hasAlarmConfig()) {
            policyConfigBuilder.withAlarmConfiguration(toAlarmConfiguration(stepScalingPolicyDesc.getAlarmConfig()));
        }
        // Build step policy
        if (stepScalingPolicyDesc.hasScalingPolicy()) {
            policyConfigBuilder.withStepScalingPolicyConfiguration(toStepScalingPolicyConfiguration(stepScalingPolicyDesc.getScalingPolicy()));
        }
    } else if (scalingPolicyGrpc.getScalingPolicyDescriptorCase() == TARGETPOLICYDESCRIPTOR) {
        policyConfigBuilder.withPolicyType(PolicyType.TargetTrackingScaling);
        TargetTrackingPolicy targetTrackingPolicy = toTargetTrackingPolicy(scalingPolicyGrpc.getTargetPolicyDescriptor());
        policyConfigBuilder.withTargetTrackingPolicy(targetTrackingPolicy);
    } else {
        throw new IllegalArgumentException("Invalid ScalingPolicy Type provided " + scalingPolicyGrpc.getScalingPolicyDescriptorCase());
    }
    return policyConfigBuilder.build();
}
Also used : TargetTrackingPolicy(com.netflix.titus.api.appscale.model.TargetTrackingPolicy) StepScalingPolicyDescriptor(com.netflix.titus.grpc.protogen.StepScalingPolicyDescriptor) StepScalingPolicyConfiguration(com.netflix.titus.api.appscale.model.StepScalingPolicyConfiguration) PolicyConfiguration(com.netflix.titus.api.appscale.model.PolicyConfiguration)

Example 4 with StepScalingPolicyDescriptor

use of com.netflix.titus.grpc.protogen.StepScalingPolicyDescriptor in project titus-control-plane by Netflix.

the class AutoScalingTestUtils method generateUpdateStepScalingPolicyRequest.

public static UpdatePolicyRequest generateUpdateStepScalingPolicyRequest(String policyRefId, double threshold) {
    ScalingPolicy scalingPolicy = generateStepPolicy();
    AlarmConfiguration alarmConfig = scalingPolicy.getStepPolicyDescriptor().getAlarmConfig().toBuilder().setThreshold(DoubleValue.newBuilder().setValue(threshold).build()).build();
    StepScalingPolicyDescriptor stepScalingPolicyDescriptor = scalingPolicy.getStepPolicyDescriptor().toBuilder().setAlarmConfig(alarmConfig).build();
    ScalingPolicy scalingPolicyToBeUpdated = scalingPolicy.toBuilder().setStepPolicyDescriptor(stepScalingPolicyDescriptor).build();
    UpdatePolicyRequest updatePolicyRequest = UpdatePolicyRequest.newBuilder().setPolicyId(ScalingPolicyID.newBuilder().setId(policyRefId).build()).setScalingPolicy(scalingPolicyToBeUpdated).build();
    return updatePolicyRequest;
}
Also used : ScalingPolicy(com.netflix.titus.grpc.protogen.ScalingPolicy) StepScalingPolicy(com.netflix.titus.grpc.protogen.StepScalingPolicy) StepScalingPolicyDescriptor(com.netflix.titus.grpc.protogen.StepScalingPolicyDescriptor) UpdatePolicyRequest(com.netflix.titus.grpc.protogen.UpdatePolicyRequest) AlarmConfiguration(com.netflix.titus.grpc.protogen.AlarmConfiguration)

Aggregations

StepScalingPolicyDescriptor (com.netflix.titus.grpc.protogen.StepScalingPolicyDescriptor)4 AlarmConfiguration (com.netflix.titus.grpc.protogen.AlarmConfiguration)3 StepScalingPolicy (com.netflix.titus.grpc.protogen.StepScalingPolicy)3 ScalingPolicy (com.netflix.titus.grpc.protogen.ScalingPolicy)2 AutoScalingPolicy (com.netflix.titus.api.appscale.model.AutoScalingPolicy)1 PolicyConfiguration (com.netflix.titus.api.appscale.model.PolicyConfiguration)1 StepScalingPolicyConfiguration (com.netflix.titus.api.appscale.model.StepScalingPolicyConfiguration)1 TargetTrackingPolicy (com.netflix.titus.api.appscale.model.TargetTrackingPolicy)1 TargetTrackingPolicyDescriptor (com.netflix.titus.grpc.protogen.TargetTrackingPolicyDescriptor)1 UpdatePolicyRequest (com.netflix.titus.grpc.protogen.UpdatePolicyRequest)1