Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to support other cluster/group name formats #1544

Merged
merged 15 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</a>
</div>
<div class="row">
<a href="/groups/{{ env_name }}-{{ env_stage }}/scaling_activities/" target="_blank"
<a href="/groups/{{ cluster_name }}/scaling_activities/" target="_blank"
type="button" class="btn btn-default btn-block">
<span class="glyphicon glyphicon-list"></span> Show Replacement Activities
</a>
Expand Down Expand Up @@ -122,7 +122,7 @@
<span style="color:red;"><b>may need to be refreshed</b></span>
<span class="glyphicon glyphicon-warning-sign"></span>
<span>(This <i>suggestion</i> is based on the last time cluster configuration was changed/updated vs. the last time cluster refresh was started and its status. It may be <i>inaccurate</i>
in case where the last configuration change was <i>not</i> related to host/instance configurations. In this case, if the cluster is indeed up to date, refreshing (skip matching) it
in case where the last configuration change was <i>not</i> related to host/instance configurations. In this case, if the cluster is indeed up to date, refreshing (skip matching) it
will result in a no-op, and it will complete after few seconds. And the cluster will be up to date.)
</span>
{% endif %}
Expand Down Expand Up @@ -162,7 +162,7 @@
else {
checkpointPercentagesElement.setCustomValidity('');
}

const checkpointPercentages = checkpointPercentagesElement.value.split(',').reduce( (acc, p) => acc.concat(+p), []);

for (let i = 0; i < checkpointPercentages.length - 1; i++) {
Expand Down Expand Up @@ -212,21 +212,21 @@
<span class="fa fa-bell"></span> Checkpoint percentages:
</label>
<input type="text" id="checkpointPercentages" name="checkpointPercentages" maxlength="200" value={% if auto_refresh_config.config.checkpointPercentages %}{{ auto_refresh_config.config.checkpointPercentages|join:"," }}{% endif %}>

<label for="checkpointDelay" data-toggle="tooltip" title="Delay in seconds between checkpoints">
<span class="fa fa-clock-o"></span> Checkpoint delay (seconds):
</label>
<input type="number" id="checkpointDelay" name="checkpointDelay" min="0" value={% if auto_refresh_config.config.checkpointDelay %}{{ auto_refresh_config.config.checkpointDelay }}{% endif %}>
</div>

<div style="padding-top: 20px;">
<label class="switch" data-toggle="tooltip" title="Skip replacing instances that already use the latest launch template." >
Skip matching launch template
<input type="checkbox" id="skipMatching" name="skipMatching" {% if auto_refresh_config.config.skipMatching %} checked {% endif %}>
<div class="slider round"></div>
</label>
</div>

<div style="padding-top: 20px;">
<label class="switch" data-toggle="tooltip" title="Whether to replace instances that are protected from autoscaling.">
Replace protected instances
Expand Down Expand Up @@ -267,7 +267,7 @@
Update
</button>
</div>

{% csrf_token %}
</form>

Expand All @@ -283,7 +283,7 @@
else {
updateClusterAutoRefreshConfigBtnElement.disabled = false
}
</script>
</script>
</div>
{% else %}
<div class="container-fluid">
Expand All @@ -300,37 +300,37 @@
<span class="fa fa-bell"></span> Checkpoint percentages:
</label>
<input type="text" id="checkpointPercentages" name="checkpointPercentages" maxlength="200" placeholder="e.g. 25, 50, 100">

<label for="checkpointDelay" data-toggle="tooltip" title="Delay in seconds between checkpoints">
<span class="fa fa-clock-o"></span> Checkpoint delay (seconds):
</label>
<input type="number" id="checkpointDelay" name="checkpointDelay" min="0" value="3600">
</div>

<div style="padding-top: 20px;">
<label class="switch" data-toggle="tooltip" title="Skip replacing instances that already use the latest launch template." >
Skip matching launch template
<input type="checkbox" id="skipMatching" name="skipMatching" checked>
<div class="slider round"></div>
</label>
</div>

<div style="padding-top: 20px;">
<label class="switch" data-toggle="tooltip" title="Whether to replace instances that are protected from autoscaling.">
Replace protected instances
<input type="checkbox" id="replaceProtectedInstances" name="replaceProtectedInstances">
<div class="slider round"></div>
</label>
</div>

<div class="pull-left" style="padding-top: 20px;">
<button type="submit" id="startReplacementBtnId" class="btn"
data-toggle="modal"
title="Start cluster replacement">
<span class="glyphicon glyphicon-refresh"></span> Start
</button>
</div>

{% csrf_token %}
</form>

Expand Down Expand Up @@ -430,7 +430,7 @@
</table>
</div>
</div>
</div>
</div>
{% endif %}

{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h4 class="panel-title pull-left">Capacity</h4>
<side-button styleclass="fa fa-gears" text="Cluster Configuration" href="/env/{{ env.envName }}/{{ env.stageName }}/config/cluster/config/" title="Go to the cluster configuration page"></side-button>
</div>
<div v-if="!noCluster" class="row">
<side-button styleclass="fa fa-cloud" text="Autoscaling Settings" href="/groups/{{ env.envName }}-{{ env.stageName }}/config" title="Advanced auto scaling configuration page"></side-button>
<side-button styleclass="fa fa-cloud" text="Autoscaling Settings" href="/groups/{{ env.clusterName }}/config" title="Advanced auto scaling configuration page"></side-button>
</div>
<div v-if="showAddExistingCapacity" class="row">
<side-button styleclass="fa fa-plus" text="Add Existing Capacity" href="/env/{{ env.envName }}/{{ env.stageName }}/config/capacity?addexisting" title="Add Existing Capacity"></side-button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
var groups = rootVue.$refs.groupsinput.tags;
var image = info.basic_cluster_info ? info.basic_cluster_info.base_image_info : null;
if(hasCMPCluster && image && image.abstract_name && image.abstract_name.startsWith('cmp_base')) {
var defaultClusterASGGroupName = '{{ env.envName }}-{{ env.stageName }}';
var defaultClusterASGGroupName = '{{ cluster_name }}';
if(groups.indexOf(defaultClusterASGGroupName) < 0) {
groups.push(defaultClusterASGGroupName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ <h4 class="panel-title pull-left">{{title}}</h4>
</div>
{% if hasGroups %}
<div v-if="showCluster" class="row">
<side-button styleclass="fa fa-expand" v-bind:text="autoScalingSettingsText" href="/groups/{{ env.envName }}-{{ env.stageName }}/config" title="Configure autoscaling group"></side-button>
<side-button styleclass="fa fa-expand" v-bind:text="autoScalingSettingsText" href="/groups/{{ env.clusterName }}/config" title="Configure autoscaling group"></side-button>
</div>
{% endif %}
{% if hasCluster %}
Expand Down Expand Up @@ -313,7 +313,7 @@ <h4 class="modal-title">Resume Confirm</h4>
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<strong>Info!</strong> {{ cluster_refresh_suggestion_for_golden_ami }}
Click <a href="/env/{{ env.envName }}/{{ env.stageName }}/base_images/" target="_blank">here</a> for image update history.
Click <a href="/groups/{{ env.envName }}-{{ env.stageName }}/host-ami-dist/" target="_blank">here</a> to see AMI(s) used by hosts.
Click <a href="/groups/{{ env.clusterName }}/host-ami-dist/" target="_blank">here</a> to see AMI(s) used by hosts.
Click <a href="/env/{{ env.envName }}/{{ env.stageName }}/cluster_replacements/" target="_blank">here</a> to replace the cluster.
</div>
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions deploy-board/deploy_board/templates/host_side_panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h4 class="modal-title">Host Termination Confirm</h4>
try {
result = await $.ajax({
type: 'GET',
url: `/groups/{{env_name}}-{{stage_name}}/hosts`,
url: `/groups/{{ group_name }}/hosts`,
dataType: "json",
beforeSend: function(xhr, settings) {
var csrftoken = getCookie('csrftoken');
Expand All @@ -72,7 +72,7 @@ <h4 class="modal-title">Host Termination Confirm</h4>
terminatingHostCount = data;
if (terminatingHostCount >= `{{termination_limit}}`) {
$('#terminationWarning').show();
}
}
});
}
});
Expand Down
40 changes: 29 additions & 11 deletions deploy-board/deploy_board/webapp/cluster_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ def post(self, request, name, stage):
class ClusterConfigurationView(View):
def get(self, request, name, stage):

cluster_name = '{}-{}'.format(name, stage)
current_cluster = clusters_helper.get_cluster(request, cluster_name)
current_cluster = get_current_cluster(request, name, stage)
host_types = hosttypes_helper.get_by_arch(
request, current_cluster['archName'])
current_image = baseimages_helper.get_by_id(
Expand Down Expand Up @@ -306,8 +305,7 @@ def post(self, request, name, stage):
cluster_info = json.loads(request.body)
log.info("Update Cluster Configuration with {}", cluster_info)

cluster_name = '{}-{}'.format(name, stage)
current_cluster = clusters_helper.get_cluster(request, cluster_name)
current_cluster = get_current_cluster(request, name, stage, env=env)
log.info("getting current Cluster Configuration is {}", current_cluster)
if 'configs' in current_cluster and 'configs' in cluster_info:
for field in TELETRAAN_CLUSTER_READONLY_FIELDS:
Expand Down Expand Up @@ -336,7 +334,7 @@ def post(self, request, name, stage):
log.info("Update Cluster Capacity with data {}".format(request.body))
try:
settings = json.loads(request.body)
cluster_name = '{}-{}'.format(name, stage)
cluster_name = get_cluster_name(request, name, stage)
log.info("Update cluster {0} with {1}".format(
cluster_name, settings))
minSize = int(settings['minsize'])
Expand Down Expand Up @@ -905,7 +903,7 @@ def clone_cluster(request, src_name, src_stage):
dest_name = params.get('new_environment', src_name)
dest_stage = params.get('new_stage', src_stage + '_clone')

src_cluster_name = '{}-{}'.format(src_name, src_stage)
src_cluster_name = get_cluster_name(request, src_name, src_stage)
dest_cluster_name = '{}-{}'.format(dest_name, dest_stage)

# 0. teletraan service get src env buildName
Expand Down Expand Up @@ -1078,7 +1076,7 @@ def enable_cluster_replacement(request, name, stage):

def gen_cluster_replacement_view(request, name, stage):
env = environs_helper.get_env_by_stage(request, name, stage)
cluster_name = '{}-{}'.format(name, stage)
cluster_name = get_cluster_name(request, name, stage, env=env)
get_cluster_replacement_body = {
"clusterName": cluster_name
}
Expand All @@ -1105,7 +1103,7 @@ def gen_cluster_replacement_view(request, name, stage):

def gen_auto_cluster_refresh_view(request, name, stage):
env = environs_helper.get_env_by_stage(request, name, stage)
cluster_name = '{}-{}'.format(name, stage)
cluster_name = get_cluster_name(request, name, stage, env=env)
get_cluster_replacement_body = {
"clusterName": cluster_name
}
Expand Down Expand Up @@ -1176,7 +1174,7 @@ def sanitize_slack_email_input(input):

def get_cluster_replacement_details(request, name, stage, replacement_id):
env = environs_helper.get_env_by_stage(request, name, stage)
cluster_name = '{}-{}'.format(name, stage)
cluster_name = get_cluster_name(request, name, stage, env=env)
get_cluster_replacement_details_body = {
"clusterName": cluster_name,
"replacementIds": [replacement_id]
Expand Down Expand Up @@ -1403,7 +1401,7 @@ class ClusterHistoriesView(View):
def get(self, request, name, stage):
env = environs_helper.get_env_by_stage(request, name, stage)

cluster_name = '{}-{}'.format(name, stage)
cluster_name = get_cluster_name(request, name, stage, env=env)
page_index = request.GET.get('index')
page_size = request.GET.get('size')
histories = clusters_helper.get_cluster_replacement_histories(
Expand All @@ -1430,7 +1428,7 @@ class ClusterBaseImageHistoryView(View):

def get(self, request, name, stage):
env = environs_helper.get_env_by_stage(request, name, stage)
cluster_name = '{}-{}'.format(name, stage)
cluster_name = get_cluster_name(request, name, stage, env=env)
current_cluster = clusters_helper.get_cluster(request, cluster_name)
current_image = baseimages_helper.get_by_id(request, current_cluster['baseImageId'])
golden_image = baseimages_helper.get_current_golden_image(
Expand All @@ -1448,3 +1446,23 @@ def get(self, request, name, stage):
}

return render(request, 'clusters/base_image_history.html', data)

def get_cluster_name(request, name, stage, env=None):
cluster_name = '{}-{}'.format(name, stage)
current_cluster = clusters_helper.get_cluster(request, cluster_name)
if current_cluster is None:
if env is None:
env = environs_helper.get_env_by_stage(request, name, stage)
cluster_name = env.get("clusterName")
return cluster_name

def get_current_cluster(request, name, stage, env=None):
cluster_name = '{}-{}'.format(name, stage)
current_cluster = clusters_helper.get_cluster(request, cluster_name)
if current_cluster is None:
if env is None:
env = environs_helper.get_env_by_stage(request, name, stage)
cluster_name = env.get("clusterName")
current_cluster = clusters_helper.get_cluster(request, cluster_name)
return current_cluster

27 changes: 23 additions & 4 deletions deploy-board/deploy_board/webapp/env_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from collections import Counter
from .helpers import builds_helper, environs_helper, agents_helper, ratings_helper, deploys_helper, \
systems_helper, environ_hosts_helper, clusters_helper, tags_helper, baseimages_helper, schedules_helper, placements_helper, hosttypes_helper, \
accounts_helper
accounts_helper, autoscaling_groups_helper
from .templatetags import utils
from .helpers.exceptions import TeletraanException
import math
Expand Down Expand Up @@ -581,7 +581,7 @@ def get(self, request, name, stage=None):

def _gen_message_for_refreshing_cluster(request, last_cluster_refresh_status, latest_succeeded_base_image_update_event, env):
try:
group_name = '{}-{}'.format(env["envName"], env["stageName"])
group_name = get_group_name(request, env.get('envName'), env.get('stageName'), env=env)
host_ami_dist = requests.post(url = CMDB_API_HOST+"/v2/query", json={
"query": "tags.Autoscaling:{} AND state:running".format(group_name),
"fields": "cloud.aws.imageId"
Expand Down Expand Up @@ -610,8 +610,9 @@ def _gen_message_for_refreshing_cluster(request, last_cluster_refresh_status, la

def _getLastClusterRefreshStatus(request, env):
try:
cluster_name = get_cluster_name(request, env.get('envName'), env.get('stageName'), env=env)
replace_summaries = clusters_helper.get_cluster_replacement_status(
request, data={"clusterName": '{}-{}'.format(env["envName"], env["stageName"])})
request, data={"clusterName": cluster_name})

if len(replace_summaries["clusterRollingUpdateStatuses"]) == 0:
return None
Expand Down Expand Up @@ -779,7 +780,7 @@ def _gen_deploy_summary(request, deploys, for_env=None):
deploy_accounts = [create_legacy_ui_account(account) for account in get_accounts(report)]
elif account:
deploy_accounts = [account]

summary = {}
summary['deploy'] = deploy
summary['env'] = env
Expand Down Expand Up @@ -1952,3 +1953,21 @@ def override_session(request, name, stage):
session_num = request.GET.get('session_num')
schedules_helper.override_session(request, name, stage, session_num)
return HttpResponse(json.dumps(''))

def get_cluster_name(request, name, stage, env=None):
cluster_name = '{}-{}'.format(name, stage)
current_cluster = clusters_helper.get_cluster(request, cluster_name)
if current_cluster is None:
if env is None:
env = environs_helper.get_env_by_stage(request, name, stage)
cluster_name = env.get("clusterName")
return cluster_name

def get_group_name(request, name, stage, env=None):
group_name = '{}-{}'.format(name, stage)
current_group = autoscaling_groups_helper.get_group_info(request, group_name)
if current_group is None:
if env is None:
env = environs_helper.get_env_by_stage(request, name, stage)
group_name = env.get("groupName")
return group_name
Loading