mirror of
https://github.com/ansible/awx.git
synced 2026-05-12 03:47:36 -02:30
Job submission error handling
If playbook submission fails, check for a 400 status and parse the key/value pairs returned by the API. This occurs on an attempt to submit a job template that is no longer valid. Fixed JS compile errors from prior commit.
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function JobDetailController ($scope, $compile, $routeParams, $log, ClearScope, Breadcrumbs, LoadBreadCrumbs, GetBasePath, Wait, Rest, ProcessErrors, DigestEvents,
|
function JobDetailController ($scope, $compile, $routeParams, $log, ClearScope, Breadcrumbs, LoadBreadCrumbs, GetBasePath, Wait, Rest, ProcessErrors, DigestEvents,
|
||||||
SelectPlay, SelectTask, Socket, GetElapsed, SelectHost, FilterAllByHostName, DrawGraph, LoadHostSummary) {
|
SelectPlay, SelectTask, Socket, GetElapsed, SelectHost, FilterAllByHostName, DrawGraph, LoadHostSummary, ReloadHostSummaryList) {
|
||||||
|
|
||||||
ClearScope();
|
ClearScope();
|
||||||
|
|
||||||
@@ -700,5 +700,5 @@ function JobDetailController ($scope, $compile, $routeParams, $log, ClearScope,
|
|||||||
|
|
||||||
JobDetailController.$inject = [ '$scope', '$compile', '$routeParams', '$log', 'ClearScope', 'Breadcrumbs', 'LoadBreadCrumbs', 'GetBasePath', 'Wait',
|
JobDetailController.$inject = [ '$scope', '$compile', '$routeParams', '$log', 'ClearScope', 'Breadcrumbs', 'LoadBreadCrumbs', 'GetBasePath', 'Wait',
|
||||||
'Rest', 'ProcessErrors', 'DigestEvents', 'SelectPlay', 'SelectTask', 'Socket', 'GetElapsed', 'SelectHost', 'FilterAllByHostName', 'DrawGraph',
|
'Rest', 'ProcessErrors', 'DigestEvents', 'SelectPlay', 'SelectTask', 'Socket', 'GetElapsed', 'SelectHost', 'FilterAllByHostName', 'DrawGraph',
|
||||||
'LoadHostSummary'
|
'LoadHostSummary', 'ReloadHostSummaryList'
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ angular.module('JobSubmissionHelper', [ 'RestServices', 'Utilities', 'Credential
|
|||||||
passwords = params.passwords || {},
|
passwords = params.passwords || {},
|
||||||
callback = params.callback || 'JobLaunched',
|
callback = params.callback || 'JobLaunched',
|
||||||
url = params.url;
|
url = params.url;
|
||||||
|
|
||||||
Wait('start');
|
Wait('start');
|
||||||
Rest.setUrl(url);
|
Rest.setUrl(url);
|
||||||
Rest.post(passwords)
|
Rest.post(passwords)
|
||||||
@@ -33,11 +33,11 @@ angular.module('JobSubmissionHelper', [ 'RestServices', 'Utilities', 'Credential
|
|||||||
.factory('PromptForCredential', ['$location', 'Wait', 'GetBasePath', 'LookUpInit', 'JobTemplateForm', 'CredentialList', 'Rest', 'Prompt', 'ProcessErrors',
|
.factory('PromptForCredential', ['$location', 'Wait', 'GetBasePath', 'LookUpInit', 'JobTemplateForm', 'CredentialList', 'Rest', 'Prompt', 'ProcessErrors',
|
||||||
function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialList, Rest, Prompt, ProcessErrors) {
|
function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialList, Rest, Prompt, ProcessErrors) {
|
||||||
return function(params) {
|
return function(params) {
|
||||||
|
|
||||||
var scope = params.scope,
|
var scope = params.scope,
|
||||||
callback = params.callback || 'CredentialReady',
|
callback = params.callback || 'CredentialReady',
|
||||||
selectionMade;
|
selectionMade;
|
||||||
|
|
||||||
Wait('stop');
|
Wait('stop');
|
||||||
scope.credential = '';
|
scope.credential = '';
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
|
|||||||
selectionMade = function () {
|
selectionMade = function () {
|
||||||
scope.$emit(callback, scope.credential);
|
scope.$emit(callback, scope.credential);
|
||||||
};
|
};
|
||||||
|
|
||||||
LookUpInit({
|
LookUpInit({
|
||||||
url: GetBasePath('credentials') + '?kind=ssh',
|
url: GetBasePath('credentials') + '?kind=ssh',
|
||||||
scope: scope,
|
scope: scope,
|
||||||
@@ -107,15 +107,15 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
|
|||||||
acceptedPasswords = {},
|
acceptedPasswords = {},
|
||||||
scope = parent_scope.$new(),
|
scope = parent_scope.$new(),
|
||||||
e, buttons;
|
e, buttons;
|
||||||
|
|
||||||
Wait('stop');
|
Wait('stop');
|
||||||
|
|
||||||
function buildHtml() {
|
function buildHtml() {
|
||||||
var fld, field, html;
|
var fld, field, html;
|
||||||
html = "";
|
html = "";
|
||||||
html += "<div class=\"alert alert-info\">Launching this job requires the passwords listed below. Enter and confirm each password before continuing.</div>\n";
|
html += "<div class=\"alert alert-info\">Launching this job requires the passwords listed below. Enter and confirm each password before continuing.</div>\n";
|
||||||
html += "<form name=\"password_form\" novalidate>\n";
|
html += "<form name=\"password_form\" novalidate>\n";
|
||||||
|
|
||||||
passwords.forEach(function(password) {
|
passwords.forEach(function(password) {
|
||||||
// Prompt for password
|
// Prompt for password
|
||||||
field = form.fields[password];
|
field = form.fields[password];
|
||||||
@@ -204,7 +204,7 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
|
|||||||
$('#password-modal').dialog('open');
|
$('#password-modal').dialog('open');
|
||||||
$('#password-accept-button').attr({ "disabled": "disabled" });
|
$('#password-accept-button').attr({ "disabled": "disabled" });
|
||||||
});
|
});
|
||||||
|
|
||||||
scope.passwordAccept = function() {
|
scope.passwordAccept = function() {
|
||||||
if (!scope.password_form.$invalid) {
|
if (!scope.password_form.$invalid) {
|
||||||
passwords.forEach(function(password) {
|
passwords.forEach(function(password) {
|
||||||
@@ -258,7 +258,7 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
|
|||||||
"<a href=\"\" id=\"awp-promote\" href=\"\" aw-pop-over=\"{{ helpText }}\" aw-tool-tip=\"Click for help\" aw-pop-over-watch=\"helpText\" " +
|
"<a href=\"\" id=\"awp-promote\" href=\"\" aw-pop-over=\"{{ helpText }}\" aw-tool-tip=\"Click for help\" aw-pop-over-watch=\"helpText\" " +
|
||||||
"aw-tip-placement=\"top\" data-placement=\"bottom\" data-container=\"body\" data-title=\"Help\" class=\"help-link\"><i class=\"fa fa-question-circle\">" +
|
"aw-tip-placement=\"top\" data-placement=\"bottom\" data-container=\"body\" data-title=\"Help\" class=\"help-link\"><i class=\"fa fa-question-circle\">" +
|
||||||
"</i> click for help</a></div>\n";
|
"</i> click for help</a></div>\n";
|
||||||
|
|
||||||
scope.helpText = "<p>After defining any extra variables, click Continue to start the job. Otherwise, click cancel to abort.</p>" +
|
scope.helpText = "<p>After defining any extra variables, click Continue to start the job. Otherwise, click cancel to abort.</p>" +
|
||||||
"<p>Extra variables are passed as command line variables to the playbook run. It is equivalent to the -e or --extra-vars " +
|
"<p>Extra variables are passed as command line variables to the playbook run. It is equivalent to the -e or --extra-vars " +
|
||||||
"command line parameter for ansible-playbook. Provide key/value pairs using either YAML or JSON.</p>" +
|
"command line parameter for ansible-playbook. Provide key/value pairs using either YAML or JSON.</p>" +
|
||||||
@@ -368,8 +368,8 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
|
|||||||
}])
|
}])
|
||||||
|
|
||||||
// Submit request to run a playbook
|
// Submit request to run a playbook
|
||||||
.factory('PlaybookRun', ['$location','$routeParams', 'LaunchJob', 'PromptForPasswords', 'Rest', 'GetBasePath', 'ProcessErrors', 'Wait', 'Empty', 'PromptForCredential', 'PromptForVars',
|
.factory('PlaybookRun', ['$location','$routeParams', 'LaunchJob', 'PromptForPasswords', 'Rest', 'GetBasePath', 'Alert', 'ProcessErrors', 'Wait', 'Empty', 'PromptForCredential', 'PromptForVars',
|
||||||
function ($location, $routeParams, LaunchJob, PromptForPasswords, Rest, GetBasePath, ProcessErrors, Wait, Empty, PromptForCredential, PromptForVars) {
|
function ($location, $routeParams, LaunchJob, PromptForPasswords, Rest, GetBasePath, Alert, ProcessErrors, Wait, Empty, PromptForCredential, PromptForVars) {
|
||||||
return function (params) {
|
return function (params) {
|
||||||
var scope = params.scope,
|
var scope = params.scope,
|
||||||
id = params.id,
|
id = params.id,
|
||||||
@@ -397,24 +397,39 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
|
|||||||
var url = (job_template.related.jobs) ? job_template.related.jobs : job_template.related.job_template + 'jobs/';
|
var url = (job_template.related.jobs) ? job_template.related.jobs : job_template.related.job_template + 'jobs/';
|
||||||
Wait('start');
|
Wait('start');
|
||||||
Rest.setUrl(url);
|
Rest.setUrl(url);
|
||||||
Rest.post(job_template).success(function (data) {
|
Rest.post(job_template)
|
||||||
new_job_id = data.id;
|
.success(function (data) {
|
||||||
launch_url = data.related.start;
|
new_job_id = data.id;
|
||||||
prompt_for_vars = data.ask_variables_on_launch;
|
launch_url = data.related.start;
|
||||||
new_job = data;
|
prompt_for_vars = data.ask_variables_on_launch;
|
||||||
if (data.passwords_needed_to_start.length > 0) {
|
new_job = data;
|
||||||
scope.$emit('PromptForPasswords', data.passwords_needed_to_start);
|
if (data.passwords_needed_to_start.length > 0) {
|
||||||
}
|
scope.$emit('PromptForPasswords', data.passwords_needed_to_start);
|
||||||
else if (data.ask_variables_on_launch) {
|
}
|
||||||
scope.$emit('PromptForVars');
|
else if (data.ask_variables_on_launch) {
|
||||||
}
|
scope.$emit('PromptForVars');
|
||||||
else {
|
}
|
||||||
scope.$emit('StartPlaybookRun');
|
else {
|
||||||
}
|
scope.$emit('StartPlaybookRun');
|
||||||
}).error(function (data, status) {
|
}
|
||||||
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
|
})
|
||||||
msg: 'Failed to create job. POST returned status: ' + status });
|
.error(function (data, status) {
|
||||||
});
|
var key, html;
|
||||||
|
if (status === 400) {
|
||||||
|
// there's a data problem with the job template
|
||||||
|
html = "<ul style=\"list-style-type: none; margin: 15px 0;\">\n";
|
||||||
|
for (key in data) {
|
||||||
|
html += "<li><strong>" + key + "</strong>: " + data[key][0] + "</li>\n";
|
||||||
|
}
|
||||||
|
html += "</ul>\n";
|
||||||
|
Wait('stop');
|
||||||
|
Alert('Job Template Error', "<p>Fix the following issues before using the template:</p>" + html, 'alert-danger');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
|
||||||
|
msg: 'Failed to create job. POST returned status: ' + status });
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (scope.removeCancelJob) {
|
if (scope.removeCancelJob) {
|
||||||
|
|||||||
Reference in New Issue
Block a user