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:
Chris Houseknecht
2014-06-11 18:43:56 -04:00
parent e01b34ee38
commit eccfe128dd
2 changed files with 46 additions and 31 deletions

View File

@@ -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'
]; ];

View File

@@ -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) {