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';
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();
@@ -700,5 +700,5 @@ function JobDetailController ($scope, $compile, $routeParams, $log, ClearScope,
JobDetailController.$inject = [ '$scope', '$compile', '$routeParams', '$log', 'ClearScope', 'Breadcrumbs', 'LoadBreadCrumbs', 'GetBasePath', 'Wait',
'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
.factory('PlaybookRun', ['$location','$routeParams', 'LaunchJob', 'PromptForPasswords', 'Rest', 'GetBasePath', 'ProcessErrors', 'Wait', 'Empty', 'PromptForCredential', 'PromptForVars',
function ($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, Alert, ProcessErrors, Wait, Empty, PromptForCredential, PromptForVars) {
return function (params) {
var scope = params.scope,
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/';
Wait('start');
Rest.setUrl(url);
Rest.post(job_template).success(function (data) {
new_job_id = data.id;
launch_url = data.related.start;
prompt_for_vars = data.ask_variables_on_launch;
new_job = data;
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 {
scope.$emit('StartPlaybookRun');
}
}).error(function (data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Failed to create job. POST returned status: ' + status });
});
Rest.post(job_template)
.success(function (data) {
new_job_id = data.id;
launch_url = data.related.start;
prompt_for_vars = data.ask_variables_on_launch;
new_job = data;
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 {
scope.$emit('StartPlaybookRun');
}
})
.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) {