import type { Application , IJob , IMetricAlarmDimension , IServerGroup , ITask } from '@spinnaker/core' ; import { TaskExecutor } from '@spinnaker/core' ; import type { AlarmComparisonOperator , AlarmStatisticType , IScalingPolicy , IStepAdjustment , ITargetTrackingConfiguration , MetricAggregationType , ScalingPolicyAdjustmentType , StandardUnitType , } from '../../../domain' ; export interface IUpsertScalingPolicyCommand extends IJob { type ? : string ; cloudProvider : string ; credentials : string ; region : string ; serverGroupName : string ; adjustmentType : ScalingPolicyAdjustmentType ; name ? : string ; minAdjustmentMagnitude ? : number ; alarm ? : IUpsertAlarmDescription ; simple ? : ISimplePolicyDescription ; step ? : IStepPolicyDescription ; } export interface ITargetTrackingPolicyCommand extends IUpsertScalingPolicyCommand { estimatedInstanceWarmup : number ; targetTrackingConfiguration : ITargetTrackingConfiguration ; } export interface ISimplePolicyDescription { cooldown : number ; scalingAdjustment : number ; } export interface IStepPolicyDescription { cooldown ? : number ; stepAdjustments : IStepAdjustment [ ] ; estimatedInstanceWarmup : number ; metricAggregationType : MetricAggregationType ; } export interface IConfigurableMetric { namespace : string ; metricName : string ; dimensions : IMetricAlarmDimension [ ] ; } export interface IUpsertAlarmDescription extends IConfigurableMetric { name : string ; asgName : string ; region : string ; alarmDescription : string ; comparisonOperator : AlarmComparisonOperator ; evaluationPeriods : number ; period : number ; threshold : number ; statistic : AlarmStatisticType ; unit : StandardUnitType ; disableEditingDimensions ? : boolean ; actionsEnabled ? : boolean ; alarmActionArns : string [ ] ; insufficientDataActionArns : string [ ] ; okActionArns : string [ ] ; } export class ScalingPolicyWriter { public static upsertScalingPolicy ( application , command ) { command . type = command . type || 'upsertScalingPolicy' ; return TaskExecutor . executeTask ( { application , description : 'Upsert scaling policy ' + ( command . name || command . serverGroupName ) , job : [ command ] , } ) ; } public static deleteScalingPolicy ( application , serverGroup , scalingPolicy ) { return TaskExecutor . executeTask ( { application , description : 'Delete scaling policy ' + scalingPolicy . policyName , job : [ { type : 'deleteScalingPolicy' , cloudProvider : 'aws' , credentials : serverGroup . account , region : serverGroup . region , policyName : scalingPolicy . policyName , serverGroupName : serverGroup . name , } , ] , } ) ; } }