Skip to content

Commit

Permalink
Updates to enforce stage type population (#1335)
Browse files Browse the repository at this point in the history
* Updates to enforce stage type population

* updating variables and html

* update to tooltip language

---------

Co-authored-by: Rodshell Fleurinord <rfleurinord@packer-mlpuppet.ec2.pin220.com>
  • Loading branch information
rfleur01 and Rodshell Fleurinord authored Nov 16, 2023
1 parent fba404c commit da46927
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ function validName(name) {
return false;
}
return true;
}

function validStageType(stageType) {
// Valid if it is not DEFAULT
if (stageType == "DEFAULT") {
return false;
}
return true;
}
43 changes: 32 additions & 11 deletions deploy-board/deploy_board/templates/configs/env_config.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<div class="col-xs-4">
<input class="form-control" name="group_mention_recipients" required="false"
type="text" value="{{ env.groupMentionRecipients |default_if_none:'' }}"/>
</div>
</div>
</div>
<div class="form-group">
<label for="chatRecipients" class="deployToolTip control-label col-xs-2"
Expand Down Expand Up @@ -249,16 +249,29 @@
Stage Type (Immutable once set off the DEFAULT type)
</label>
<div class ="col-xs-4">
<select class="form-control" name="stageType">
{% get_stage_types as stageTypes %}
{% for stageType in stageTypes %}
{% if env.stageType == stageType %}
<option value="{{ stageType }}" selected="selected">{{ stageType }}</option>
{% else %}
<option value="{{ stageType }}">{{ stageType }}</option>
{% endif %}>
{% endfor %}
</select>
<div class="input-group">
<select class="form-control" name="stageType">
{% get_stage_types as stageTypes %}
{% for stageType in stageTypes %}
{% if env.stageType == stageType %}
<option value="{{ stageType }}" selected="selected">{{ stageType }}</option>
{% else %}
<option value="{{ stageType }}">{{ stageType }}</option>
{% endif %}>
{% endfor %}
</select>
<span class="input-group-btn">
<button class="deployToolTip btn stage-type-btn-default" id="stageTypeBtnId" type="button" data-toggle="tooltip" title="click to see more information">
<span class="glyphicon glyphicon-question-sign"></span>
</button>
</span>
</div>
<div class="col-xs-12" id="stageTypeHelpInfo" hidden="true">
LATEST - Deploy the latest available build</br>
CANARY - Deploy the build after tests</br>
CONTROL - Deploy the build as the production, used with CANARY</br>
PRODUCTION - Deploy the build to production
</div>
</div>
</div>
{% if env.systemPriority != None %}
Expand Down Expand Up @@ -343,6 +356,14 @@
$('#resetEnvConfigBtnId').removeAttr('disabled');
});

$('#stageTypeBtnId').click(function () {
if ($('#stageTypeHelpInfo').is(':visible')){
$('#stageTypeHelpInfo').attr('hidden', 'true');
} else {
$('#stageTypeHelpInfo').removeAttr('hidden');
}
});

$('#saveEnvConfigBtnId').click(function () {
var btn = $(this);
$.ajax({
Expand Down
19 changes: 18 additions & 1 deletion deploy-board/deploy_board/templates/deploys/confirm_deploy.tmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load utils %}
{% load static %}
<div class="modal fade" id="confirmDeployModalId" tabindex="-1" role="dialog"
aria-labelledby="confirmDeployModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
Expand All @@ -22,6 +23,9 @@
<div id="privateBuildDeployMessageId" class="alert alert-warning" role="alert" hidden=true>
<strong>Notice: </strong> This build is private and should only be deployed in testing environments and not production environments
</div>
<div id="defaultStageTypeMessageId" class="alert alert-warning" role="alert" stagetype="{{env.stageType}}" hidden=true>
<strong>Notice: </strong> This stage has a value of DEFAULT for the Stage Type. Please update the Stage Type to a value other than DEFAULT.
</div>
<div class="form-group">
<label for="description"
class="col-md-2 control-label">Description</label>
Expand Down Expand Up @@ -71,8 +75,21 @@
</div>
</div>
</div>

<script src="{% static "js/data-validation-helpers.js" %}"></script>

<script>
$('#deployConfirmFormlId').submit(function () {
var stageType = $('#defaultStageTypeMessageId').attr('stagetype');
$('#deployConfirmFormlId').submit(function (e) {
validateInput(stageType, validStageType, $.noop, function () {
e.preventDefault();
})
if (e.isDefaultPrevented()) {
$('#defaultStageTypeMessageId').show();
return;
} else {
$('#defaultStageTypeMessageId').hide();
}
$(this).find('button[type=submit]').prop('disabled', 'disabled');
$(this).find('button[type=submit]').text('Creating...');
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load utils %}
<div class="modal fade" id="addStageModalId" tabindex="-1" role="dialog"
aria-labelledby="addStageModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
Expand Down Expand Up @@ -25,6 +26,34 @@
title="Letters, numbers, underscores, and hyphens [A-Za-z0-9_-] only.">
</div>
</div>
<div class="form-group">
<label for="stageType" class="deployToolTip control-label col-xs-2"
title="Determines the version of infrastructure services deployed on the hosts in this environment-stage.">
Stage Type
</label>
<div class ="col-xs-6">
<div class="input-group">
<select class="form-control" name="stageType" data-toggle="tooltip" data-placement="left"
data-trigger="manual" title="Select a value that is not DEFAULT" required="required">
{% get_stage_types as stageTypes %}
{% for stageType in stageTypes %}
<option value="{{ stageType }}">{{ stageType }}</option>
{% endfor %}
</select>
<span class="input-group-btn">
<button class="deployToolTip btn stage-type-btn-default" id="newStageTypeBtnId" type="button" data-toggle="tooltip" title="click to see more information">
<span class="glyphicon glyphicon-question-sign"></span>
</button>
</span>
</div>
<div class="col-xs-12" id="newStageTypeHelpInfo" hidden="true">
LATEST - Deploy the latest available build</br>
CANARY - Deploy the build after tests</br>
CONTROL - Deploy the build as the production, used with CANARY</br>
PRODUCTION - Deploy the build to production
</div>
</div>
</div>
<div class="form-group">
<label for="after" class="control-label col-md-2">Clone from</label>

Expand Down Expand Up @@ -71,10 +100,23 @@
$stageNameInput.tooltip("show");
e.preventDefault();
})
var $newStageTypeInput = $(this[name = "stageType"]);
validateInput($newStageTypeInput.val(), validStageType, $.noop, function () {
$newStageTypeInput.tooltip("show");
e.preventDefault();
})
});

$('#addStageModalId').on('hidden.bs.modal', function () {
$('[data-toggle="tooltip"]').tooltip("destroy");
})
});

$('#newStageTypeBtnId').click(function () {
if ($('#newStageTypeHelpInfo').is(':visible')){
$('#newStageTypeHelpInfo').attr('hidden', 'true');
} else {
$('#newStageTypeHelpInfo').removeAttr('hidden');
}
});
});
</script>
8 changes: 4 additions & 4 deletions deploy-board/deploy_board/webapp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def promote(request, name, stage):


def clone_from_stage_name(request, env_name, stage_name, from_env_name, from_stage_name,
description, external_id):
stage_type, description, external_id):
from_stage = environs_helper.get_env_by_stage(request, from_env_name, from_stage_name)
agent_configs = environs_helper.get_env_agent_config(request, from_env_name, from_stage_name)
script_configs = environs_helper.get_env_script_config(request, from_env_name, from_stage_name)
Expand Down Expand Up @@ -187,7 +187,7 @@ def clone_from_stage_name(request, env_name, stage_name, from_env_name, from_sta
new_data['maxDeployNum'] = from_stage['maxDeployNum']
new_data['maxDeployDay'] = from_stage['maxDeployDay']
new_data['overridePolicy'] = from_stage['overridePolicy']
new_data['stageType'] = DEFAULT_STAGE_TYPE
new_data['stageType'] = stage_type
new_data['externalId'] = external_id

new_stage = environs_helper.create_env(request, new_data)
Expand All @@ -209,14 +209,14 @@ def clone_from_stage_name(request, env_name, stage_name, from_env_name, from_sta
return new_stage


def create_simple_stage(request, env_name, stage_name, description, external_id):
def create_simple_stage(request, env_name, stage_name, stage_type, description, external_id):
""" Create a new stage that does not require cloning an existing stage. Here, "simple" means that it does not require cloning."""
data = {}
data['envName'] = env_name
data['stageName'] = stage_name
data['description'] = description
data['externalId'] = external_id
data["stageType"] = DEFAULT_STAGE_TYPE
data["stageType"] = stage_type
return environs_helper.create_env(request, data)


Expand Down
3 changes: 3 additions & 0 deletions deploy-board/deploy_board/webapp/env_config_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,8 @@ def post(self, request, name, stage):
data["stageType"] = query_dict["stageType"]
data["terminationLimit"] = query_dict["terminationLimit"]

if data["stageType"] == "DEFAULT":
raise ValueError("Please update the Stage Type to a value other than DEFAULT")

environs_helper.update_env_basic_config(request, name, stage, data=data)
return self.get(request, name, stage)
8 changes: 6 additions & 2 deletions deploy-board/deploy_board/webapp/env_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ def get(self, request, name, stage=None):
stage_with_external_id = env_stage
break

if env["stageType"] == "DEFAULT":
messages.add_message(request, messages.ERROR, "Please update the Stage Type to a value other than DEFAULT")

if stage_with_external_id is not None and stage_with_external_id['externalId'] is not None:
try:
existing_stage_identifier = environs_helper.get_nimbus_identifier(request, stage_with_external_id['externalId'])
Expand Down Expand Up @@ -919,6 +922,7 @@ def post_add_stage(request, name):
# TODO how to validate stage name
data = request.POST
stage = data.get("stage")
stage_type = data.get("stageType")
from_stage = data.get("from_stage")
description = data.get("description")

Expand All @@ -931,7 +935,7 @@ def post_add_stage(request, name):
if from_stage:
try:
external_id = environs_helper.create_identifier_for_new_stage(request, name, stage)
common.clone_from_stage_name(request, name, stage, name, from_stage, description, external_id)
common.clone_from_stage_name(request, name, stage, name, stage_type, from_stage, description, external_id)
except TeletraanException as detail:
message = 'Failed to create stage {}/{}: {}'.format(name, stage, detail)
log.error(message)
Expand All @@ -946,7 +950,7 @@ def post_add_stage(request, name):
else:
try:
external_id = environs_helper.create_identifier_for_new_stage(request, name, stage)
common.create_simple_stage(request, name, stage, description, external_id)
common.create_simple_stage(request, name, stage, stage_type, description, external_id)
except TeletraanException as detail:
message = 'Failed to create stage {}, Error Message: {}'.format(stage, detail)
log.error(message)
Expand Down

0 comments on commit da46927

Please sign in to comment.