Skip to content

Commit

Permalink
add validation for step scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
knguyen100000010 committed Feb 12, 2024
1 parent a1b56b7 commit 3e6132a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
8 changes: 8 additions & 0 deletions deploy-board/deploy_board/templates/groups/asg_config.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@

{% block main %}

{% if storage %}
{% for message in storage %}
<div class="alert alert-warning" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<strong>Warning!</strong> {{ message | safe}}
</div>
{% endfor %}
{% endif %}


{% if not is_cmp %}
Expand Down
57 changes: 57 additions & 0 deletions deploy-board/deploy_board/webapp/group_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from django.template.loader import render_to_string
from django.http import HttpResponse
from django.contrib import messages
from django.contrib.messages import get_messages
import json
import logging
import traceback
Expand Down Expand Up @@ -581,7 +582,31 @@ def update_policy(request, group_name):

if (params['scaleUpSteps']):
scaleUpSteps = [float(x) for x in params["scaleUpSteps"].split(',')]

if len(scaleUpSteps) == 0:
messages.add_message(request, messages.ERROR, 'Invalid scale up steps: {}'.format(params["scaleUpSteps"]))
return redirect("/groups/{}/config/".format(group_name))

if scaleUpSteps[0] != 0:
messages.add_message(request, messages.ERROR, 'Invalid steps: {}. Must start with 0'.format(params["scaleUpSteps"]))
return redirect("/groups/{}/config/".format(group_name))

for i in range(len(scaleUpSteps) - 1):
if scaleUpSteps[i] >= scaleUpSteps[i + 1]:
messages.add_message(request, messages.ERROR, 'Steps must be a strictly increasing sequence: {}'.format(params["scaleUpSteps"]))
return redirect("/groups/{}/config/".format(group_name))

scaleUpAdjustments = [int(x) for x in params["scaleUpAdjustments"].split(',')]

if len(scaleUpSteps) != len(scaleUpAdjustments):
messages.add_message(request, messages.ERROR, 'Each step must have an adjustment: {}/{}'.format(params["scaleUpSteps"], params["scaleUpAdjustments"]))
return redirect("/groups/{}/config/".format(group_name))

for adjustment in scaleUpAdjustments:
if adjustment < 0:
messages.add_message(request, messages.ERROR, 'Scale up adjustments must be positive numbers: {}'.format(params["scaleUpAdjustments"]))
return redirect("/groups/{}/config/".format(group_name))

for i in range(len(scaleUpSteps)):
step = {}
step["metricIntervalLowerBound"] = scaleUpSteps[i]
Expand All @@ -592,8 +617,39 @@ def update_policy(request, group_name):

if (params['scaleDownSteps']):
scaleDownSteps = [float(x) for x in params["scaleDownSteps"].split(',')]

if len(scaleDownSteps) == 0:
messages.add_message(request, messages.ERROR, 'Invalid scale down steps: {}'.format(params["scaleDownSteps"]))
return redirect("/groups/{}/config/".format(group_name))

if scaleDownSteps[-1] != 0:
messages.add_message(request, messages.ERROR, 'Last step must end with 0: {}'.format(params["scaleDownSteps"]))
return redirect("/groups/{}/config/".format(group_name))

for i in range(len(scaleDownSteps) - 1):
if scaleDownSteps[i] >= scaleDownSteps[i + 1]:
messages.add_message(request, messages.ERROR, 'Steps must be a strictly increasing sequence: {}'.format(params["scaleDownSteps"]))
return redirect("/groups/{}/config/".format(group_name))

scaleDownAdjustments = [int(x) for x in params["scaleDownAdjustments"].split(',')]

if len(scaleDownSteps) != len(scaleDownAdjustments):
messages.add_message(request, messages.ERROR, 'Each step must have an adjustment: {}/{}'.format(params["scaleDownSteps"], params["scaleDownAdjustments"]))
return redirect("/groups/{}/config/".format(group_name))

for adjustment in scaleDownAdjustments:
if adjustment > 0:
messages.add_message(request, messages.ERROR, 'Scale down adjustments must be negative numbers: {}'.format(params["scaleDownAdjustments"]))
return redirect("/groups/{}/config/".format(group_name))

for i in range(len(scaleUpSteps)):
step = {}
step["metricIntervalLowerBound"] = scaleUpSteps[i]
if i < len(scaleUpSteps) - 1:
step["metricIntervalUpperBound"] = scaleUpSteps[i + 1]
step["scalingAdjustment"] = scaleUpAdjustments[i]
step_scaling_policy["stepAdjustments"].append(step)

for i in range(len(scaleDownSteps)):
step = {}
step["metricIntervalUpperBound"] = scaleDownSteps[i]
Expand Down Expand Up @@ -1180,6 +1236,7 @@ def get(self, request, group_name):
"pas_config": pas_config,
"is_cmp": is_cmp,
"disallow_autoscaling": _disallow_autoscaling(curr_image),
"storage": get_messages(request)
})


Expand Down

0 comments on commit 3e6132a

Please sign in to comment.