mirror of
https://github.com/ansible/awx.git
synced 2026-03-21 10:57:36 -02:30
figuring out the event_queue flow
This commit is contained in:
committed by
jaredevantabor
parent
c4eb6515b1
commit
9f5bec7767
@@ -4,23 +4,135 @@
|
|||||||
* All Rights Reserved
|
* All Rights Reserved
|
||||||
*************************************************/
|
*************************************************/
|
||||||
|
|
||||||
|
|
||||||
export default [function(){
|
export default [function(){
|
||||||
var val = {
|
var val = {};
|
||||||
|
|
||||||
|
// the playbook_on_stats event returns the count data in a weird format.
|
||||||
|
// format to what we need!
|
||||||
|
var getCountsFromStatsEvent = function(event_data) {
|
||||||
|
var hosts = {},
|
||||||
|
hostsArr;
|
||||||
|
|
||||||
|
// iterate over the event_data and populate an object with hosts
|
||||||
|
// and their status data
|
||||||
|
Object.keys(event_data).forEach(key => {
|
||||||
|
// failed passes boolean not integer
|
||||||
|
if (key === "failed") {
|
||||||
|
// array of hosts from failed type
|
||||||
|
hostsArr = Object.keys(event_data[key]);
|
||||||
|
hostsArr.forEach(host => {
|
||||||
|
if (!hosts[host]) {
|
||||||
|
// host has not been added to hosts object
|
||||||
|
// add now
|
||||||
|
hosts[host] = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
hosts[host][key] = event_data[key][host];
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// array of hosts from each type ("changed", "dark", etc.)
|
||||||
|
hostsArr = Object.keys(event_data[key]);
|
||||||
|
hostsArr.forEach(host => {
|
||||||
|
if (!hosts[host]) {
|
||||||
|
// host has not been added to hosts object
|
||||||
|
// add now
|
||||||
|
hosts[host] = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hosts[host][key]) {
|
||||||
|
// host doesn't have key
|
||||||
|
hosts[host][key] = 0;
|
||||||
|
}
|
||||||
|
hosts[host][key] += event_data[key][host];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// use the hosts data populate above to get the count
|
||||||
|
var count = {
|
||||||
|
ok : _.filter(hosts, function(o){
|
||||||
|
return !o.failures && !o.changed && o.ok > 0;
|
||||||
|
}),
|
||||||
|
skipped : _.filter(hosts, function(o){
|
||||||
|
return o.skipped > 0;
|
||||||
|
}),
|
||||||
|
unreachable : _.filter(hosts, function(o){
|
||||||
|
return o.dark > 0;
|
||||||
|
}),
|
||||||
|
failures : _.filter(hosts, function(o){
|
||||||
|
return o.failed === true;
|
||||||
|
}),
|
||||||
|
changed : _.filter(hosts, function(o){
|
||||||
|
return o.changed > 0;
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
// turn the count into an actual count, rather than a list of host
|
||||||
|
// names
|
||||||
|
Object.keys(count).forEach(key => {
|
||||||
|
count[key] = count[key].length;
|
||||||
|
});
|
||||||
|
|
||||||
|
return count;
|
||||||
|
};
|
||||||
|
|
||||||
|
// munge the raw event from the backend into the event_queue's format
|
||||||
|
var mungeEvent = function(event) {
|
||||||
|
var mungedEvent = {
|
||||||
|
id: event.id,
|
||||||
|
processed: false
|
||||||
|
};
|
||||||
|
if (event.event_name === 'playbook_on_start') {
|
||||||
|
event.count = val.queue.count;
|
||||||
|
mungedEvent.changes = ['count'];
|
||||||
|
} else if (event.event_name === 'runner_on_ok' ||
|
||||||
|
event.event_name === 'runner_on_async_ok') {
|
||||||
|
val.queue.count.ok++;
|
||||||
|
event.count = val.queue.count;
|
||||||
|
mungedEvent.changes = ['count'];
|
||||||
|
} else if (event.event_name === 'runner_on_skipped') {
|
||||||
|
val.queue.count.skipped++;
|
||||||
|
event.count = val.queue.count;
|
||||||
|
mungedEvent.changes = ['count'];
|
||||||
|
} else if (event.event_name === 'runner_on_unreachable') {
|
||||||
|
val.queue.count.unreachable++;
|
||||||
|
event.count = val.queue.count;
|
||||||
|
mungedEvent.changes = ['count'];
|
||||||
|
} else if (event.event_name === 'runner_on_error' ||
|
||||||
|
event.event_name === 'runner_on_async_failed') {
|
||||||
|
val.queue.count.failed++;
|
||||||
|
event.count = val.queue.count;
|
||||||
|
mungedEvent.changes = ['count'];
|
||||||
|
} else if (event.event_name === 'playbook_on_stats') {
|
||||||
|
// get the data for populating the host status bar
|
||||||
|
val.queue.count = getCountsFromStatsEvent(event.event_data);
|
||||||
|
event.count = val.queue.count;
|
||||||
|
mungedEvent.changes = ['count'];
|
||||||
|
}
|
||||||
|
return mungedEvent;
|
||||||
|
};
|
||||||
|
|
||||||
|
val = {
|
||||||
queue: {},
|
queue: {},
|
||||||
// munge the raw event from the backend into the event_queue's format
|
|
||||||
mungeEvent: function(event) {
|
|
||||||
event.processed = false;
|
|
||||||
return event;
|
|
||||||
},
|
|
||||||
// reinitializes the event queue value for the job results page
|
// reinitializes the event queue value for the job results page
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
val.queue = {};
|
val.queue = {};
|
||||||
|
|
||||||
|
// initialize the host status counts
|
||||||
|
val.queue.count = {
|
||||||
|
ok: 0,
|
||||||
|
skipped: 0,
|
||||||
|
unreachable: 0,
|
||||||
|
failures: 0,
|
||||||
|
changed: 0
|
||||||
|
};
|
||||||
},
|
},
|
||||||
// populates the event queue
|
// populates the event queue
|
||||||
populate: function(event) {
|
populate: function(event) {
|
||||||
var mungedEvent = val.mungeEvent(event);
|
var mungedEvent = mungeEvent(event);
|
||||||
val.queue[event.id] = mungedEvent;
|
val.queue[event.id] = mungedEvent;
|
||||||
|
|
||||||
|
return mungedEvent;
|
||||||
},
|
},
|
||||||
// the event has been processed in the view and should be marked as
|
// the event has been processed in the view and should be marked as
|
||||||
// completed in the queue
|
// completed in the queue
|
||||||
@@ -28,5 +140,6 @@ export default [function(){
|
|||||||
val.queue[event.id].processed = true;
|
val.queue[event.id].processed = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}];
|
}];
|
||||||
|
|||||||
@@ -1,22 +1,4 @@
|
|||||||
export default ['jobData', 'jobDataOptions', 'jobLabels', '$scope', 'ParseTypeChange', 'ParseVariableString', 'jobResultsService', '$rootScope', 'eventQueue', function(jobData, jobDataOptions, jobLabels, $scope, ParseTypeChange, ParseVariableString, jobResultsService, $rootScope, eventQueue) {
|
export default ['jobData', 'jobDataOptions', 'jobLabels', '$scope', 'ParseTypeChange', 'ParseVariableString', 'jobResultsService', '$rootScope', 'eventQueue', function(jobData, jobDataOptions, jobLabels, $scope, ParseTypeChange, ParseVariableString, jobResultsService, $rootScope, eventQueue) {
|
||||||
// just putting the event queue on scope so it can be inspected in the
|
|
||||||
// console
|
|
||||||
$scope.event_queue = eventQueue.queue;
|
|
||||||
|
|
||||||
var processEvent = function(event) {
|
|
||||||
// put the event in the queue
|
|
||||||
eventQueue.populate(event);
|
|
||||||
|
|
||||||
if(event.event_name === "playbook_on_stats"){
|
|
||||||
// get the data for populating the host status bar
|
|
||||||
$scope.count = jobResultsService
|
|
||||||
.getHostStatusBarCounts(event.event_data);
|
|
||||||
|
|
||||||
// mark the event as processed in the queue;
|
|
||||||
eventQueue.markProcessed(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var getTowerLinks = function() {
|
var getTowerLinks = function() {
|
||||||
var getTowerLink = function(key) {
|
var getTowerLink = function(key) {
|
||||||
if ($scope.job.related[key]) {
|
if ($scope.job.related[key]) {
|
||||||
@@ -76,9 +58,6 @@ export default ['jobData', 'jobDataOptions', 'jobLabels', '$scope', 'ParseTypeCh
|
|||||||
$scope.stdoutFullScreen = !$scope.stdoutFullScreen;
|
$scope.stdoutFullScreen = !$scope.stdoutFullScreen;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initially set the count data to have no hosts as finsihed
|
|
||||||
$scope.count = {ok: 0, skipped: 0, unreachable: 0, failures: 0, changed: 0};
|
|
||||||
|
|
||||||
$scope.deleteJob = function() {
|
$scope.deleteJob = function() {
|
||||||
jobResultsService.deleteJob($scope.job);
|
jobResultsService.deleteJob($scope.job);
|
||||||
};
|
};
|
||||||
@@ -87,6 +66,27 @@ export default ['jobData', 'jobDataOptions', 'jobLabels', '$scope', 'ParseTypeCh
|
|||||||
jobResultsService.cancelJob($scope.job);
|
jobResultsService.cancelJob($scope.job);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// EVENT STUFF BELOW
|
||||||
|
|
||||||
|
// just putting the event queue on scope so it can be inspected in the
|
||||||
|
// console
|
||||||
|
$scope.event_queue = eventQueue.queue;
|
||||||
|
|
||||||
|
var processEvent = function(event) {
|
||||||
|
// put the event in the queue
|
||||||
|
var mungedEvent = eventQueue.populate(event);
|
||||||
|
|
||||||
|
// make changes to ui based on the event returned from the queue
|
||||||
|
mungedEvent.changes.forEach(change => {
|
||||||
|
if (change === 'count') {
|
||||||
|
$scope.count = mungedEvent.count;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// the changes have been processed in the ui, mark it in the queue
|
||||||
|
eventQueue.markProcessed(event);
|
||||||
|
};
|
||||||
|
|
||||||
// grab completed event data and process each event
|
// grab completed event data and process each event
|
||||||
jobResultsService.getEvents($scope.job)
|
jobResultsService.getEvents($scope.job)
|
||||||
.then(events => {
|
.then(events => {
|
||||||
@@ -96,12 +96,11 @@ export default ['jobData', 'jobDataOptions', 'jobLabels', '$scope', 'ParseTypeCh
|
|||||||
event.event_name = event.event;
|
event.event_name = event.event;
|
||||||
processEvent(event);
|
processEvent(event);
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
// process incoming job events
|
// process incoming job events
|
||||||
$rootScope.event_socket.on("job_events-" + $scope.job.id, function(data) {
|
$rootScope.event_socket.on("job_events-" + $scope.job.id, function(data) {
|
||||||
processEvent(data);
|
processEvent(data);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// process incoming job status changes
|
// process incoming job status changes
|
||||||
|
|||||||
@@ -7,72 +7,6 @@
|
|||||||
|
|
||||||
export default ['$q', 'Prompt', '$filter', 'Wait', 'Rest', '$state', 'ProcessErrors', function ($q, Prompt, $filter, Wait, Rest, $state, ProcessErrors) {
|
export default ['$q', 'Prompt', '$filter', 'Wait', 'Rest', '$state', 'ProcessErrors', function ($q, Prompt, $filter, Wait, Rest, $state, ProcessErrors) {
|
||||||
var val = {
|
var val = {
|
||||||
getHostStatusBarCounts: function(event_data) {
|
|
||||||
var hosts = {},
|
|
||||||
hostsArr;
|
|
||||||
|
|
||||||
// iterate over the event_data and populate an object with hosts
|
|
||||||
// and their status data
|
|
||||||
Object.keys(event_data).forEach(key => {
|
|
||||||
// failed passes boolean not integer
|
|
||||||
if (key === "failed") {
|
|
||||||
// array of hosts from failed type
|
|
||||||
hostsArr = Object.keys(event_data[key]);
|
|
||||||
hostsArr.forEach(host => {
|
|
||||||
if (!hosts[host]) {
|
|
||||||
// host has not been added to hosts object
|
|
||||||
// add now
|
|
||||||
hosts[host] = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
hosts[host][key] = event_data[key][host];
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// array of hosts from each type ("changed", "dark", etc.)
|
|
||||||
hostsArr = Object.keys(event_data[key]);
|
|
||||||
hostsArr.forEach(host => {
|
|
||||||
if (!hosts[host]) {
|
|
||||||
// host has not been added to hosts object
|
|
||||||
// add now
|
|
||||||
hosts[host] = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hosts[host][key]) {
|
|
||||||
// host doesn't have key
|
|
||||||
hosts[host][key] = 0;
|
|
||||||
}
|
|
||||||
hosts[host][key] += event_data[key][host];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// use the hosts data populate above to get the count
|
|
||||||
var count = {
|
|
||||||
ok : _.filter(hosts, function(o){
|
|
||||||
return !o.failures && !o.changed && o.ok > 0;
|
|
||||||
}),
|
|
||||||
skipped : _.filter(hosts, function(o){
|
|
||||||
return o.skipped > 0;
|
|
||||||
}),
|
|
||||||
unreachable : _.filter(hosts, function(o){
|
|
||||||
return o.dark > 0;
|
|
||||||
}),
|
|
||||||
failures : _.filter(hosts, function(o){
|
|
||||||
return o.failed === true;
|
|
||||||
}),
|
|
||||||
changed : _.filter(hosts, function(o){
|
|
||||||
return o.changed > 0;
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
// turn the count into an actual count, rather than a list of host
|
|
||||||
// names
|
|
||||||
Object.keys(count).forEach(key => {
|
|
||||||
count[key] = count[key].length;
|
|
||||||
});
|
|
||||||
|
|
||||||
return count;
|
|
||||||
},
|
|
||||||
getEvents: function(job) {
|
getEvents: function(job) {
|
||||||
var val = $q.defer();
|
var val = $q.defer();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user