use of com.netflix.titus.api.appscale.model.TargetTrackingPolicy 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();
}
use of com.netflix.titus.api.appscale.model.TargetTrackingPolicy in project titus-control-plane by Netflix.
the class AWSAppAutoScalingClient method createOrUpdateScalingPolicy.
@Override
public Observable<String> createOrUpdateScalingPolicy(String policyRefId, String jobId, PolicyConfiguration policyConfiguration) {
PutScalingPolicyRequest putScalingPolicyRequest = new PutScalingPolicyRequest();
putScalingPolicyRequest.setPolicyName(buildScalingPolicyName(policyRefId, jobId));
putScalingPolicyRequest.setPolicyType(policyConfiguration.getPolicyType().name());
putScalingPolicyRequest.setResourceId(AWSAppAutoScalingUtil.buildGatewayResourceId(jobId, awsAppScalingConfig.getAWSGatewayEndpointPrefix(), awsAppScalingConfig.getRegion(), awsAppScalingConfig.getAWSGatewayEndpointTargetStage()));
putScalingPolicyRequest.setServiceNamespace(SERVICE_NAMESPACE);
putScalingPolicyRequest.setScalableDimension(SCALABLE_DIMENSION);
if (policyConfiguration.getPolicyType() == PolicyType.StepScaling) {
StepScalingPolicyConfiguration stepScalingPolicyConfiguration = new StepScalingPolicyConfiguration();
if (policyConfiguration.getStepScalingPolicyConfiguration().getMetricAggregationType().isPresent()) {
stepScalingPolicyConfiguration.setMetricAggregationType(policyConfiguration.getStepScalingPolicyConfiguration().getMetricAggregationType().get().name());
}
if (policyConfiguration.getStepScalingPolicyConfiguration().getCoolDownSec().isPresent()) {
stepScalingPolicyConfiguration.setCooldown(policyConfiguration.getStepScalingPolicyConfiguration().getCoolDownSec().get());
}
List<com.netflix.titus.api.appscale.model.StepAdjustment> steps = policyConfiguration.getStepScalingPolicyConfiguration().getSteps();
List<StepAdjustment> stepAdjustments = steps.stream().map(step -> {
StepAdjustment stepAdjustment = new StepAdjustment();
if (step.getMetricIntervalUpperBound() != null && step.getMetricIntervalUpperBound().isPresent()) {
stepAdjustment.setMetricIntervalUpperBound(step.getMetricIntervalUpperBound().get());
}
if (step.getMetricIntervalLowerBound() != null && step.getMetricIntervalLowerBound().isPresent()) {
stepAdjustment.setMetricIntervalLowerBound(step.getMetricIntervalLowerBound().get());
}
stepAdjustment.setScalingAdjustment(step.getScalingAdjustment());
return stepAdjustment;
}).collect(Collectors.toList());
stepScalingPolicyConfiguration.setStepAdjustments(stepAdjustments);
if (policyConfiguration.getStepScalingPolicyConfiguration().getAdjustmentType().isPresent()) {
stepScalingPolicyConfiguration.setAdjustmentType(policyConfiguration.getStepScalingPolicyConfiguration().getAdjustmentType().get().name());
}
putScalingPolicyRequest.setStepScalingPolicyConfiguration(stepScalingPolicyConfiguration);
} else if (policyConfiguration.getPolicyType() == PolicyType.TargetTrackingScaling) {
TargetTrackingScalingPolicyConfiguration targetTrackingConfigAws = new TargetTrackingScalingPolicyConfiguration();
TargetTrackingPolicy targetTrackingPolicyInt = policyConfiguration.getTargetTrackingPolicy();
targetTrackingConfigAws.setTargetValue(targetTrackingPolicyInt.getTargetValue());
if (targetTrackingPolicyInt.getDisableScaleIn().isPresent()) {
targetTrackingConfigAws.setDisableScaleIn(targetTrackingPolicyInt.getDisableScaleIn().get());
}
if (targetTrackingPolicyInt.getScaleInCooldownSec().isPresent()) {
targetTrackingConfigAws.setScaleInCooldown(targetTrackingPolicyInt.getScaleInCooldownSec().get());
}
if (targetTrackingPolicyInt.getScaleOutCooldownSec().isPresent()) {
targetTrackingConfigAws.setScaleOutCooldown(targetTrackingPolicyInt.getScaleOutCooldownSec().get());
}
if (targetTrackingPolicyInt.getCustomizedMetricSpecification().isPresent()) {
com.netflix.titus.api.appscale.model.CustomizedMetricSpecification customizedMetricSpecInt = targetTrackingPolicyInt.getCustomizedMetricSpecification().get();
CustomizedMetricSpecification customizedMetricSpecAws = new CustomizedMetricSpecification();
customizedMetricSpecAws.setDimensions(customizedMetricSpecInt.getMetricDimensionList().stream().map(metricDimensionInt -> {
MetricDimension metricDimensionAws = new MetricDimension().withName(metricDimensionInt.getName()).withValue(metricDimensionInt.getValue());
return metricDimensionAws;
}).collect(Collectors.toList()));
customizedMetricSpecAws.setMetricName(customizedMetricSpecInt.getMetricName());
customizedMetricSpecAws.setNamespace(customizedMetricSpecInt.getNamespace());
customizedMetricSpecAws.setStatistic(customizedMetricSpecInt.getStatistic().name());
if (customizedMetricSpecInt.getUnit().isPresent()) {
customizedMetricSpecAws.setUnit(customizedMetricSpecInt.getUnit().get());
}
targetTrackingConfigAws.setCustomizedMetricSpecification(customizedMetricSpecAws);
}
putScalingPolicyRequest.setTargetTrackingScalingPolicyConfiguration(targetTrackingConfigAws);
} else {
return Observable.error(new UnsupportedOperationException(String.format("Scaling policy type not supported: jobId=%s, policyRefId=%s, type=%s", jobId, policyRefId, policyConfiguration.getPolicyType().name())));
}
return RetryWrapper.wrapWithExponentialRetry(String.format("createOrUpdateScalingPolicy %s for job %s", policyRefId, jobId), Observable.create(emitter -> awsAppAutoScalingClientAsync.putScalingPolicyAsync(putScalingPolicyRequest, new AsyncHandler<PutScalingPolicyRequest, PutScalingPolicyResult>() {
@Override
public void onError(Exception exception) {
logger.error("Exception creating scaling policy: jobId={}, policyRefId={}", jobId, policyRefId, exception);
awsAppAutoScalingMetrics.registerAwsCreatePolicyError(exception);
if (exception instanceof ValidationException) {
emitter.onError(AutoScalePolicyException.invalidScalingPolicy(policyRefId, exception.getMessage()));
} else {
emitter.onError(AutoScalePolicyException.errorCreatingPolicy(policyRefId, exception.getMessage()));
}
}
@Override
public void onSuccess(PutScalingPolicyRequest request, PutScalingPolicyResult putScalingPolicyResult) {
String policyARN = putScalingPolicyResult.getPolicyARN();
logger.info("New Scaling policy {} created {} for Job {}", request, policyARN, jobId);
awsAppAutoScalingMetrics.registerAwsCreatePolicySuccess();
emitter.onNext(policyARN);
emitter.onCompleted();
}
}), Emitter.BackpressureMode.NONE));
}
use of com.netflix.titus.api.appscale.model.TargetTrackingPolicy 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