2017-07-13 18:57:28 +00:00
|
|
|
/* laminar.js
|
|
|
|
* frontend application for Laminar Continuous Integration
|
|
|
|
* https://laminar.ohwg.net
|
|
|
|
*/
|
2018-06-01 07:14:59 +00:00
|
|
|
|
2018-09-08 15:16:23 +00:00
|
|
|
String.prototype.hashCode = function() {
|
|
|
|
for(var r=0, i=0; i<this.length; i++)
|
|
|
|
r=(r<<5)-r+this.charCodeAt(i),r&=r;
|
|
|
|
return r;
|
|
|
|
};
|
|
|
|
|
2018-06-01 07:14:59 +00:00
|
|
|
Vue.filter('iecFileSize', function(bytes) {
|
|
|
|
var exp = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
|
|
return (bytes / Math.pow(1024, exp)).toFixed(1) + ' ' +
|
|
|
|
['B', 'KiB', 'MiB', 'GiB', 'TiB'][exp];
|
|
|
|
});
|
|
|
|
|
2018-09-30 10:00:23 +00:00
|
|
|
const timeScale = function(max){
|
|
|
|
return max > 3600
|
|
|
|
? { scale:function(v){return Math.round(v/360)/10}, label:'Hours' }
|
|
|
|
: max > 60
|
|
|
|
? { scale:function(v){return Math.round(v/60)/10}, label:'Minutes' }
|
|
|
|
: { scale:function(v){return v;}, label:'Seconds' };
|
|
|
|
}
|
2019-10-05 17:06:35 +00:00
|
|
|
const ServerEventHandler = function() {
|
|
|
|
function setupEventSource(path, query, next) {
|
|
|
|
const es = new EventSource(document.head.baseURI + path.substr(1) + query);
|
|
|
|
es.path = path; // save for later in case we need to add query params
|
|
|
|
es.onmessage = function(msg) {
|
2017-07-13 18:57:28 +00:00
|
|
|
msg = JSON.parse(msg.data);
|
2019-10-05 17:06:35 +00:00
|
|
|
// "status" is the first message the server always delivers.
|
2017-07-13 18:57:28 +00:00
|
|
|
// Use this to confirm the navigation. The component is not
|
|
|
|
// created until next() is called, so creating a reference
|
2018-06-30 17:19:41 +00:00
|
|
|
// for other message types must be deferred. There are some extra
|
2019-10-05 17:06:35 +00:00
|
|
|
// subtle checks here. If this eventsource already has a component,
|
2018-06-30 17:19:41 +00:00
|
|
|
// then this is not the first time the status message has been
|
|
|
|
// received. If the frontend requests an update, the status message
|
|
|
|
// should not be handled here, but treated the same as any other
|
|
|
|
// message. An exception is if the connection has been lost - in
|
|
|
|
// that case we should treat this as a "first-time" status message.
|
2019-10-05 17:06:35 +00:00
|
|
|
// this.comp.es is used as a proxy for this.
|
|
|
|
if (msg.type === 'status' && (!this.comp || !this.comp.es)) {
|
2017-07-13 18:57:28 +00:00
|
|
|
next(comp => {
|
|
|
|
// Set up bidirectional reference
|
|
|
|
// 1. needed to reference the component for other msg types
|
|
|
|
this.comp = comp;
|
|
|
|
// 2. needed to close the ws on navigation away
|
2019-10-05 17:06:35 +00:00
|
|
|
comp.es = this;
|
2017-07-13 18:57:28 +00:00
|
|
|
// Update html and nav titles
|
|
|
|
document.title = comp.$root.title = msg.title;
|
2018-02-03 14:52:46 +00:00
|
|
|
// Calculate clock offset (used by ProgressUpdater)
|
|
|
|
comp.$root.clockSkew = msg.time - Math.floor((new Date()).getTime()/1000);
|
2017-12-23 15:15:48 +00:00
|
|
|
comp.$root.connected = true;
|
2017-07-13 18:57:28 +00:00
|
|
|
// Component-specific callback handler
|
|
|
|
comp[msg.type](msg.data);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// at this point, the component must be defined
|
|
|
|
if (!this.comp)
|
|
|
|
return console.error("Page component was undefined");
|
2017-12-29 15:18:43 +00:00
|
|
|
else {
|
2019-10-05 17:06:35 +00:00
|
|
|
this.comp.$root.connected = true;
|
2017-12-29 15:18:43 +00:00
|
|
|
this.comp.$root.showNotify(msg.type, msg.data);
|
|
|
|
if(typeof this.comp[msg.type] === 'function')
|
|
|
|
this.comp[msg.type](msg.data);
|
|
|
|
}
|
2017-07-13 18:57:28 +00:00
|
|
|
}
|
2017-12-23 15:15:48 +00:00
|
|
|
}
|
2019-10-05 17:06:35 +00:00
|
|
|
es.onerror = function() {
|
|
|
|
this.comp.$root.connected = false;
|
|
|
|
}
|
|
|
|
return es;
|
|
|
|
}
|
2017-07-13 18:57:28 +00:00
|
|
|
return {
|
|
|
|
beforeRouteEnter(to, from, next) {
|
2019-10-05 17:06:35 +00:00
|
|
|
setupEventSource(to.path, '', (fn) => { next(fn); });
|
2017-07-13 18:57:28 +00:00
|
|
|
},
|
|
|
|
beforeRouteUpdate(to, from, next) {
|
2019-10-05 17:06:35 +00:00
|
|
|
this.es.close();
|
|
|
|
setupEventSource(to.path, '', (fn) => { fn(this); next(); });
|
2017-07-13 18:57:28 +00:00
|
|
|
},
|
|
|
|
beforeRouteLeave(to, from, next) {
|
2019-10-05 17:06:35 +00:00
|
|
|
this.es.close();
|
2017-07-13 18:57:28 +00:00
|
|
|
next();
|
2019-10-05 17:06:35 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
query(q) {
|
|
|
|
this.es.close();
|
|
|
|
setupEventSource(this.es.path, '?' + Object.entries(q).map(([k,v])=>`${k}=${v}`).join('&'), (fn) => { fn(this); });
|
|
|
|
}
|
2017-12-23 15:15:48 +00:00
|
|
|
}
|
2017-07-13 18:57:28 +00:00
|
|
|
};
|
|
|
|
}();
|
2015-09-26 20:54:27 +00:00
|
|
|
|
2017-07-13 18:57:28 +00:00
|
|
|
const Utils = {
|
|
|
|
methods: {
|
|
|
|
runIcon(result) {
|
2017-12-28 14:57:57 +00:00
|
|
|
var marker = '⚙';
|
|
|
|
var classname = result;
|
|
|
|
if (result === 'success')
|
|
|
|
marker = '✔';
|
|
|
|
else if (result === 'failed' || result === 'aborted')
|
|
|
|
marker = '✘';
|
|
|
|
else
|
|
|
|
classname = 'spin';
|
|
|
|
return '<span title="' + result + '" class="status ' + classname + '">' + marker + '︎</span>';
|
2017-07-13 18:57:28 +00:00
|
|
|
},
|
|
|
|
formatDate: function(unix) {
|
|
|
|
// TODO: reimplement when toLocaleDateString() accepts formatting options on most browsers
|
|
|
|
var d = new Date(1000 * unix);
|
|
|
|
var m = d.getMinutes();
|
|
|
|
if (m < 10) m = '0' + m;
|
|
|
|
return d.getHours() + ':' + m + ' on ' + ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][d.getDay()] + ' ' +
|
|
|
|
d.getDate() + '. ' + ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
|
|
|
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
|
|
|
|
][d.getMonth()] + ' ' +
|
|
|
|
d.getFullYear();
|
|
|
|
},
|
2017-11-03 14:47:30 +00:00
|
|
|
formatDuration: function(start, end) {
|
|
|
|
if(!end)
|
2018-02-03 14:52:46 +00:00
|
|
|
end = Math.floor(Date.now()/1000) + this.$root.clockSkew;
|
2017-11-03 14:47:30 +00:00
|
|
|
if(end - start > 3600)
|
2017-12-01 10:22:39 +00:00
|
|
|
return Math.floor((end-start)/3600) + ' hours, ' + Math.floor(((end-start)%3600)/60) + ' minutes';
|
2017-11-03 14:47:30 +00:00
|
|
|
else if(end - start > 60)
|
2017-12-01 10:22:39 +00:00
|
|
|
return Math.floor((end-start)/60) + ' minutes, ' + ((end-start)%60) + ' seconds';
|
2017-11-03 14:47:30 +00:00
|
|
|
else
|
|
|
|
return (end-start) + ' seconds';
|
|
|
|
}
|
2017-07-13 18:57:28 +00:00
|
|
|
}
|
|
|
|
};
|
2015-09-13 20:25:26 +00:00
|
|
|
|
2017-07-13 18:57:28 +00:00
|
|
|
const ProgressUpdater = {
|
|
|
|
data() { return { jobsRunning: [] }; },
|
|
|
|
methods: {
|
|
|
|
updateProgress(o) {
|
|
|
|
if (o.etc) {
|
2018-02-03 14:52:46 +00:00
|
|
|
var p = (Math.floor(Date.now()/1000) + this.$root.clockSkew - o.started) / (o.etc - o.started);
|
2017-07-13 18:57:28 +00:00
|
|
|
if (p > 1.2) {
|
|
|
|
o.overtime = true;
|
|
|
|
} else if (p >= 1) {
|
|
|
|
o.progress = 99;
|
|
|
|
} else {
|
|
|
|
o.progress = 100 * p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
clearInterval(this.updateTimer);
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
jobsRunning(val) {
|
|
|
|
// this function handles several cases:
|
|
|
|
// - the route has changed to a different run of the same job
|
|
|
|
// - the current job has ended
|
|
|
|
// - the current job has started (practically hard to reach)
|
|
|
|
clearInterval(this.updateTimer);
|
|
|
|
if (val.length) {
|
|
|
|
// TODO: first, a non-animated progress update
|
|
|
|
this.updateTimer = setInterval(() => {
|
|
|
|
this.jobsRunning.forEach(this.updateProgress);
|
|
|
|
this.$forceUpdate();
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-09-26 20:54:27 +00:00
|
|
|
|
2017-07-13 18:57:28 +00:00
|
|
|
const Home = function() {
|
|
|
|
var state = {
|
|
|
|
jobsQueued: [],
|
2018-09-08 15:16:23 +00:00
|
|
|
jobsRecent: [],
|
|
|
|
resultChanged: []
|
2017-07-13 18:57:28 +00:00
|
|
|
};
|
2015-09-26 20:54:27 +00:00
|
|
|
|
2017-07-13 18:57:28 +00:00
|
|
|
var chtUtilization, chtBuildsPerDay, chtBuildsPerJob, chtTimePerJob;
|
2015-09-26 20:54:27 +00:00
|
|
|
|
2017-07-13 18:57:28 +00:00
|
|
|
var updateUtilization = function(busy) {
|
2018-07-06 14:47:48 +00:00
|
|
|
chtUtilization.data.datasets[0].data[0] += busy ? 1 : -1;
|
|
|
|
chtUtilization.data.datasets[0].data[1] -= busy ? 1 : -1;
|
2017-07-13 18:57:28 +00:00
|
|
|
chtUtilization.update();
|
|
|
|
}
|
2015-09-26 20:54:27 +00:00
|
|
|
|
2017-07-13 18:57:28 +00:00
|
|
|
return {
|
|
|
|
template: '#home',
|
2019-10-05 17:06:35 +00:00
|
|
|
mixins: [ServerEventHandler, Utils, ProgressUpdater],
|
2017-07-13 18:57:28 +00:00
|
|
|
data: function() {
|
|
|
|
return state;
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
status: function(msg) {
|
|
|
|
state.jobsQueued = msg.queued;
|
|
|
|
state.jobsRunning = msg.running;
|
|
|
|
state.jobsRecent = msg.recent;
|
2018-09-08 15:16:23 +00:00
|
|
|
state.resultChanged = msg.resultChanged;
|
2017-07-13 18:57:28 +00:00
|
|
|
this.$forceUpdate();
|
2015-09-26 20:54:27 +00:00
|
|
|
|
2017-07-13 18:57:28 +00:00
|
|
|
// setup charts
|
2018-07-06 14:47:48 +00:00
|
|
|
chtUtilization = new Chart(document.getElementById("chartUtil"), {
|
|
|
|
type: 'pie',
|
|
|
|
data: {
|
|
|
|
labels: ["Busy", "Idle"],
|
|
|
|
datasets: [{
|
|
|
|
data: [ msg.executorsBusy, msg.executorsTotal - msg.executorsBusy ],
|
2018-09-08 15:16:23 +00:00
|
|
|
backgroundColor: ["darkgoldenrod", "forestgreen"]
|
2018-07-06 14:47:48 +00:00
|
|
|
}]
|
|
|
|
}
|
|
|
|
});
|
2018-09-28 12:37:39 +00:00
|
|
|
var buildsPerDayDates = function(){
|
|
|
|
res = [];
|
|
|
|
var now = new Date();
|
|
|
|
for (var i = 6; i >= 0; --i) {
|
|
|
|
var then = new Date(now.getTime() - i * 86400000);
|
|
|
|
res.push({
|
|
|
|
short: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][then.getDay()],
|
|
|
|
long: then.toLocaleDateString()}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}();
|
2018-07-06 14:47:48 +00:00
|
|
|
chtBuildsPerDay = new Chart(document.getElementById("chartBpd"), {
|
|
|
|
type: 'line',
|
|
|
|
data: {
|
2018-09-28 12:37:39 +00:00
|
|
|
labels: buildsPerDayDates.map((e)=>{ return e.short; }),
|
2018-07-06 14:47:48 +00:00
|
|
|
datasets: [{
|
|
|
|
label: 'Successful Builds',
|
2018-09-08 15:16:23 +00:00
|
|
|
backgroundColor: "rgba(34,139,34,0.65)", //forestgreen at 0.65
|
2018-07-06 14:47:48 +00:00
|
|
|
borderColor: "forestgreen",
|
|
|
|
data: msg.buildsPerDay.map((e)=>{ return e.success || 0; })
|
|
|
|
}, {
|
|
|
|
label: 'Failed Builds',
|
2018-09-08 15:16:23 +00:00
|
|
|
backgroundColor: "rgba(178,34,34,0.65)", //firebrick at 0.65
|
|
|
|
borderColor: "firebrick",
|
2018-07-06 14:47:48 +00:00
|
|
|
data: msg.buildsPerDay.map((e)=>{ return e.failed || 0; })
|
|
|
|
}]
|
2018-09-28 12:37:39 +00:00
|
|
|
},
|
|
|
|
options:{
|
|
|
|
tooltips:{callbacks:{title: function(tip, data) {
|
|
|
|
return buildsPerDayDates[tip[0].index].long;
|
|
|
|
}}},
|
|
|
|
scales:{yAxes:[{ticks:{userCallback: (label, index, labels)=>{
|
|
|
|
if(Number.isInteger(label))
|
|
|
|
return label;
|
|
|
|
}}}]}
|
2018-07-06 14:47:48 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
chtBuildsPerJob = new Chart(document.getElementById("chartBpj"), {
|
|
|
|
type: 'horizontalBar',
|
|
|
|
data: {
|
|
|
|
labels: Object.keys(msg.buildsPerJob),
|
|
|
|
datasets: [{
|
2018-09-28 12:37:39 +00:00
|
|
|
label: 'Runs in last 24 hours',
|
2018-09-08 15:16:23 +00:00
|
|
|
backgroundColor: "steelblue",
|
2018-07-06 14:47:48 +00:00
|
|
|
data: Object.keys(msg.buildsPerJob).map((e)=>{ return msg.buildsPerJob[e]; })
|
|
|
|
}]
|
2018-09-28 12:37:39 +00:00
|
|
|
},
|
|
|
|
options:{
|
|
|
|
scales:{xAxes:[{ticks:{userCallback: (label, index, labels)=>{
|
|
|
|
if(Number.isInteger(label))
|
|
|
|
return label;
|
|
|
|
}}}]}
|
2018-07-06 14:47:48 +00:00
|
|
|
}
|
|
|
|
});
|
2018-09-30 10:00:23 +00:00
|
|
|
var tpjScale = timeScale(Math.max(Object.values(msg.timePerJob)));
|
2018-07-06 14:47:48 +00:00
|
|
|
chtTimePerJob = new Chart(document.getElementById("chartTpj"), {
|
|
|
|
type: 'horizontalBar',
|
|
|
|
data: {
|
|
|
|
labels: Object.keys(msg.timePerJob),
|
|
|
|
datasets: [{
|
2018-09-28 12:37:39 +00:00
|
|
|
label: 'Mean run time this week',
|
2018-09-08 15:16:23 +00:00
|
|
|
backgroundColor: "steelblue",
|
2018-07-06 14:47:48 +00:00
|
|
|
data: Object.keys(msg.timePerJob).map((e)=>{ return msg.timePerJob[e]; })
|
|
|
|
}]
|
2018-09-28 12:37:39 +00:00
|
|
|
},
|
|
|
|
options:{
|
|
|
|
scales:{xAxes:[{
|
2018-09-30 10:00:23 +00:00
|
|
|
ticks:{userCallback: tpjScale.scale},
|
2018-09-28 12:37:39 +00:00
|
|
|
scaleLabel: {
|
|
|
|
display: true,
|
2018-09-30 10:00:23 +00:00
|
|
|
labelString: tpjScale.label
|
2018-09-28 12:37:39 +00:00
|
|
|
}
|
|
|
|
}]},
|
|
|
|
tooltips:{callbacks:{label:(tip, data)=>{
|
2018-09-30 10:00:23 +00:00
|
|
|
return data.datasets[tip.datasetIndex].label + ': ' + tip.xLabel + ' ' + tpjScale.label.toLowerCase();
|
2018-09-28 12:37:39 +00:00
|
|
|
}}}
|
2017-07-13 18:57:28 +00:00
|
|
|
}
|
|
|
|
});
|
2018-09-08 15:16:23 +00:00
|
|
|
var chtResultChanges = new Chart(document.getElementById("chartResultChanges"), {
|
|
|
|
type: 'horizontalBar',
|
|
|
|
data: {
|
|
|
|
labels: msg.resultChanged.map((e)=>{ return e.name; }),
|
|
|
|
datasets: [{
|
|
|
|
//label: '% Passed',
|
|
|
|
backgroundColor: msg.resultChanged.map((e)=>{return e.lastFailure > e.lastSuccess ? 'firebrick' : 'forestgreen';}),
|
|
|
|
data: msg.resultChanged.map((e)=>{ return e.lastSuccess - e.lastFailure; }),
|
|
|
|
itemid: msg.resultChanged.map((e)=> { return 'rcd_' + e.name; })
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
options:{
|
|
|
|
scales:{
|
|
|
|
xAxes:[{ticks:{display: false}}],
|
|
|
|
yAxes:[{ticks:{display: false}}]
|
|
|
|
},
|
|
|
|
tooltips:{
|
|
|
|
enabled:false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
var chtPassRates = new Chart(document.getElementById("chartPassRates"), {
|
|
|
|
type: 'horizontalBar',
|
|
|
|
data: {
|
|
|
|
labels: msg.lowPassRates.map((e)=>{ return e.name }),
|
|
|
|
datasets: [{
|
|
|
|
stack: 'passrate',
|
|
|
|
label: '% Passed',
|
|
|
|
backgroundColor: "forestgreen",
|
|
|
|
data: msg.lowPassRates.map((e)=>{ return e.passRate*100; })
|
|
|
|
},{
|
|
|
|
stack:'passrate',
|
|
|
|
label: '% Failed',
|
|
|
|
backgroundColor: "firebrick",
|
|
|
|
data: msg.lowPassRates.map((e)=>{ return (1-e.passRate)*100; })
|
|
|
|
}],
|
2018-09-28 12:37:39 +00:00
|
|
|
},
|
|
|
|
options:{
|
|
|
|
scales:{xAxes:[{ticks:{callback:(val,idx,values)=>{
|
|
|
|
return val + '%';
|
|
|
|
}}}]},
|
|
|
|
tooltips:{
|
|
|
|
enabled:false
|
|
|
|
}
|
2018-09-08 15:16:23 +00:00
|
|
|
}
|
|
|
|
});
|
2018-09-30 10:00:23 +00:00
|
|
|
var btcScale = timeScale(Math.max(msg.buildTimeChanges.map((e)=>{return Math.max(e.durations)})));
|
2018-09-08 15:16:23 +00:00
|
|
|
var chtBuildTimeChanges = new Chart(document.getElementById("chartBuildTimeChanges"), {
|
|
|
|
type: 'line',
|
|
|
|
data: {
|
|
|
|
labels: [...Array(10).keys()],
|
|
|
|
datasets: msg.buildTimeChanges.map((e)=>{return {
|
|
|
|
label: e.name,
|
|
|
|
data: e.durations,
|
|
|
|
borderColor: 'hsl('+(e.name.hashCode() % 360)+', 61%, 34%)',
|
|
|
|
backgroundColor: 'transparent'
|
|
|
|
}})
|
|
|
|
},
|
2018-09-28 12:37:39 +00:00
|
|
|
options:{
|
|
|
|
legend:{display:true},
|
|
|
|
scales:{
|
|
|
|
xAxes:[{ticks:{display: false}}],
|
|
|
|
yAxes:[{
|
2018-09-30 10:00:23 +00:00
|
|
|
ticks:{userCallback: btcScale.scale},
|
2018-09-28 12:37:39 +00:00
|
|
|
scaleLabel: {
|
|
|
|
display: true,
|
2018-09-30 10:00:23 +00:00
|
|
|
labelString: btcScale.label
|
2018-09-28 12:37:39 +00:00
|
|
|
}
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
tooltips:{
|
|
|
|
enabled:false
|
|
|
|
}
|
|
|
|
}
|
2018-09-08 15:16:23 +00:00
|
|
|
});
|
|
|
|
var chtBuildTimeDist = new Chart(document.getElementById("chartBuildTimeDist"), {
|
|
|
|
type: 'line',
|
|
|
|
data: {
|
|
|
|
labels: ['<30s','30s-1m','1m-5m','5m-10m','10m-20m','20m-40m','40m-60m','>60m'],
|
|
|
|
datasets: [{
|
|
|
|
label: 'Number jobs with average build time in range',
|
|
|
|
data: msg.buildTimeDist,
|
|
|
|
backgroundColor: "steelblue",
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
});
|
2017-07-13 18:57:28 +00:00
|
|
|
},
|
|
|
|
job_queued: function(data) {
|
|
|
|
state.jobsQueued.splice(0, 0, data);
|
|
|
|
this.$forceUpdate();
|
|
|
|
},
|
|
|
|
job_started: function(data) {
|
|
|
|
state.jobsQueued.splice(state.jobsQueued.length - data.queueIndex - 1, 1);
|
|
|
|
state.jobsRunning.splice(0, 0, data);
|
|
|
|
this.$forceUpdate();
|
|
|
|
updateUtilization(true);
|
|
|
|
},
|
|
|
|
job_completed: function(data) {
|
|
|
|
if (data.result === "success")
|
2018-07-06 14:47:48 +00:00
|
|
|
chtBuildsPerDay.data.datasets[0].data[6]++;
|
2017-07-13 18:57:28 +00:00
|
|
|
else
|
2018-07-06 14:47:48 +00:00
|
|
|
chtBuildsPerDay.data.datasets[1].data[6]++;
|
2017-07-13 18:57:28 +00:00
|
|
|
chtBuildsPerDay.update();
|
|
|
|
|
|
|
|
for (var i = 0; i < state.jobsRunning.length; ++i) {
|
|
|
|
var job = state.jobsRunning[i];
|
|
|
|
if (job.name == data.name && job.number == data.number) {
|
|
|
|
state.jobsRunning.splice(i, 1);
|
|
|
|
state.jobsRecent.splice(0, 0, data);
|
|
|
|
this.$forceUpdate();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateUtilization(false);
|
2018-07-06 14:47:48 +00:00
|
|
|
for (var j = 0; j < chtBuildsPerJob.data.datasets[0].data.length; ++j) {
|
|
|
|
if (chtBuildsPerJob.data.labels[j] == job.name) {
|
|
|
|
chtBuildsPerJob.data.datasets[0].data[j]++;
|
2017-07-13 18:57:28 +00:00
|
|
|
chtBuildsPerJob.update();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}();
|
|
|
|
|
|
|
|
const Jobs = function() {
|
|
|
|
var state = {
|
|
|
|
jobs: [],
|
|
|
|
search: '',
|
2019-12-13 08:42:22 +00:00
|
|
|
groups: {},
|
|
|
|
group: null,
|
|
|
|
ungrouped: []
|
2017-07-13 18:57:28 +00:00
|
|
|
};
|
|
|
|
return {
|
|
|
|
template: '#jobs',
|
2019-10-05 17:06:35 +00:00
|
|
|
mixins: [ServerEventHandler, Utils, ProgressUpdater],
|
2017-07-13 18:57:28 +00:00
|
|
|
data: function() { return state; },
|
|
|
|
methods: {
|
|
|
|
status: function(msg) {
|
|
|
|
state.jobs = msg.jobs;
|
2017-11-07 06:21:01 +00:00
|
|
|
state.jobsRunning = msg.running;
|
|
|
|
// mix running and completed jobs
|
|
|
|
for (var i in msg.running) {
|
|
|
|
var idx = state.jobs.findIndex(job => job.name === msg.running[i].name);
|
|
|
|
if (idx > -1)
|
|
|
|
state.jobs[idx] = msg.running[i];
|
2017-12-02 15:55:21 +00:00
|
|
|
else {
|
|
|
|
// special case: first run of a job.
|
|
|
|
state.jobs.unshift(msg.running[i]);
|
|
|
|
state.jobs.sort(function(a, b){return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;});
|
|
|
|
}
|
2017-11-07 06:21:01 +00:00
|
|
|
}
|
2019-12-13 08:42:22 +00:00
|
|
|
state.groups = {};
|
|
|
|
Object.keys(msg.groups).map(k => state.groups[k] = new RegExp(msg.groups[k]));
|
|
|
|
state.ungrouped = state.jobs.filter(j => !Object.values(state.groups).some(r => r.test(j.name))).map(j => j.name);
|
|
|
|
state.group = state.ungrouped.length ? null : Object.keys(state.groups)[0];
|
2017-07-13 18:57:28 +00:00
|
|
|
},
|
2017-11-07 06:21:01 +00:00
|
|
|
job_started: function(data) {
|
|
|
|
var updAt = null;
|
2018-08-24 10:10:00 +00:00
|
|
|
// jobsRunning must be maintained for ProgressUpdater
|
2017-11-07 06:21:01 +00:00
|
|
|
for (var i in state.jobsRunning) {
|
|
|
|
if (state.jobsRunning[i].name === data.name) {
|
|
|
|
updAt = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (updAt === null) {
|
|
|
|
state.jobsRunning.unshift(data);
|
|
|
|
} else {
|
|
|
|
state.jobsRunning[updAt] = data;
|
|
|
|
}
|
2017-12-02 15:55:21 +00:00
|
|
|
updAt = null;
|
2017-11-07 06:21:01 +00:00
|
|
|
for (var i in state.jobs) {
|
|
|
|
if (state.jobs[i].name === data.name) {
|
2017-12-02 15:55:21 +00:00
|
|
|
updAt = i;
|
2017-11-07 06:21:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-12-02 15:55:21 +00:00
|
|
|
if (updAt === null) {
|
|
|
|
// first execution of new job. TODO insert without resort
|
|
|
|
state.jobs.unshift(data);
|
|
|
|
state.jobs.sort(function(a, b){return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;});
|
2019-12-13 08:42:22 +00:00
|
|
|
if(!Object.values(state.groups).some(r => r.test(data.name)))
|
|
|
|
state.ungrouped.push(data.name);
|
2017-12-02 15:55:21 +00:00
|
|
|
} else {
|
|
|
|
state.jobs[updAt] = data;
|
|
|
|
}
|
|
|
|
this.$forceUpdate();
|
2017-11-07 06:21:01 +00:00
|
|
|
},
|
2017-07-13 18:57:28 +00:00
|
|
|
job_completed: function(data) {
|
|
|
|
for (var i in state.jobs) {
|
|
|
|
if (state.jobs[i].name === data.name) {
|
|
|
|
state.jobs[i] = data;
|
2017-11-07 06:21:01 +00:00
|
|
|
// forceUpdate in second loop
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (var i in state.jobsRunning) {
|
|
|
|
if (state.jobsRunning[i].name === data.name) {
|
|
|
|
state.jobsRunning.splice(i, 1);
|
2017-07-13 18:57:28 +00:00
|
|
|
this.$forceUpdate();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-08-24 10:10:00 +00:00
|
|
|
},
|
|
|
|
filteredJobs: function() {
|
2019-12-13 08:42:22 +00:00
|
|
|
let ret = [];
|
|
|
|
if (state.group)
|
|
|
|
ret = state.jobs.filter(job => state.groups[state.group].test(job.name));
|
|
|
|
else
|
|
|
|
ret = state.jobs.filter(job => state.ungrouped.includes(job.name));
|
|
|
|
if (this.search)
|
|
|
|
ret = ret.filter(job => job.name.indexOf(this.search) > -1);
|
2018-08-24 10:10:00 +00:00
|
|
|
return ret;
|
|
|
|
},
|
2017-07-13 18:57:28 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}();
|
|
|
|
|
|
|
|
var Job = function() {
|
|
|
|
var state = {
|
2019-12-24 20:10:16 +00:00
|
|
|
description: '',
|
2017-07-13 18:57:28 +00:00
|
|
|
jobsRunning: [],
|
|
|
|
jobsRecent: [],
|
|
|
|
lastSuccess: null,
|
|
|
|
lastFailed: null,
|
|
|
|
nQueued: 0,
|
2018-06-01 11:51:34 +00:00
|
|
|
pages: 0,
|
2018-08-24 09:15:40 +00:00
|
|
|
sort: {}
|
2017-07-13 18:57:28 +00:00
|
|
|
};
|
2018-08-24 10:32:07 +00:00
|
|
|
var chtBt = null;
|
2017-07-13 18:57:28 +00:00
|
|
|
return Vue.extend({
|
|
|
|
template: '#job',
|
2019-10-05 17:06:35 +00:00
|
|
|
mixins: [ServerEventHandler, Utils, ProgressUpdater],
|
2017-07-13 18:57:28 +00:00
|
|
|
data: function() {
|
|
|
|
return state;
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
status: function(msg) {
|
2019-12-24 20:10:16 +00:00
|
|
|
state.description = msg.description;
|
2017-07-13 18:57:28 +00:00
|
|
|
state.jobsRunning = msg.running;
|
|
|
|
state.jobsRecent = msg.recent;
|
|
|
|
state.lastSuccess = msg.lastSuccess;
|
|
|
|
state.lastFailed = msg.lastFailed;
|
2017-12-02 17:06:54 +00:00
|
|
|
state.nQueued = msg.nQueued;
|
2018-06-01 11:51:34 +00:00
|
|
|
state.pages = msg.pages;
|
2018-08-24 09:15:40 +00:00
|
|
|
state.sort = msg.sort;
|
2017-07-13 18:57:28 +00:00
|
|
|
|
2018-08-24 10:32:07 +00:00
|
|
|
// "status" comes again if we change page/sorting. Delete the
|
|
|
|
// old chart and recreate it to prevent flickering of old data
|
|
|
|
if(chtBt)
|
|
|
|
chtBt.destroy();
|
2018-09-30 10:00:23 +00:00
|
|
|
var btScale = timeScale(Math.max(msg.recent.map(v=>{v.completed-v.started})));
|
2018-08-24 10:32:07 +00:00
|
|
|
chtBt = new Chart(document.getElementById("chartBt"), {
|
2018-07-06 14:47:48 +00:00
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
labels: msg.recent.map(function(e) {
|
|
|
|
return '#' + e.number;
|
|
|
|
}).reverse(),
|
|
|
|
datasets: [{
|
2018-09-08 18:02:58 +00:00
|
|
|
label: 'Average',
|
|
|
|
type: 'line',
|
|
|
|
data: [{x:0,y:msg.averageRuntime},{x:1,y:msg.averageRuntime}],
|
|
|
|
borderColor: 'steelblue',
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
xAxisID: 'avg',
|
|
|
|
pointRadius: 0,
|
|
|
|
pointHitRadius: 0,
|
|
|
|
pointHoverRadius: 0,
|
|
|
|
},{
|
2018-07-06 14:47:48 +00:00
|
|
|
label: 'Build time',
|
|
|
|
backgroundColor: (new Array(msg.recent.length)).fill('darkseagreen'),
|
|
|
|
borderColor: (new Array(msg.recent.length)).fill('forestgreen'),
|
|
|
|
data: msg.recent.map(function(e) {
|
|
|
|
return e.completed - e.started;
|
|
|
|
}).reverse()
|
|
|
|
}]
|
2018-09-08 18:02:58 +00:00
|
|
|
},
|
|
|
|
options: {
|
|
|
|
scales:{
|
|
|
|
xAxes:[{},{
|
|
|
|
id: 'avg',
|
|
|
|
type: 'linear',
|
|
|
|
ticks: {
|
|
|
|
display: false
|
|
|
|
},
|
|
|
|
gridLines: {
|
|
|
|
display: false,
|
|
|
|
drawBorder: false
|
|
|
|
}
|
2018-09-30 10:00:23 +00:00
|
|
|
}],
|
|
|
|
yAxes:[{
|
|
|
|
ticks:{userCallback: btScale.scale},
|
|
|
|
scaleLabel:{display: true, labelString: btScale.label}
|
2018-09-08 18:02:58 +00:00
|
|
|
}]
|
2018-09-30 10:00:23 +00:00
|
|
|
},
|
|
|
|
tooltips:{callbacks:{label:(tip, data)=>{
|
|
|
|
return data.datasets[tip.datasetIndex].label + ': ' + tip.yLabel + ' ' + btScale.label.toLowerCase();
|
|
|
|
}}}
|
2018-07-06 14:47:48 +00:00
|
|
|
}
|
2017-07-13 18:57:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
for (var i = 0, n = msg.recent.length; i < n; ++i) {
|
|
|
|
if (msg.recent[i].result != "success") {
|
2018-07-06 14:47:48 +00:00
|
|
|
chtBt.data.datasets[0].backgroundColor[n - i - 1] = "darksalmon";
|
|
|
|
chtBt.data.datasets[0].borderColor[n - i - 1] = "crimson";
|
2017-07-13 18:57:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
chtBt.update();
|
|
|
|
},
|
|
|
|
job_queued: function() {
|
|
|
|
state.nQueued++;
|
|
|
|
},
|
|
|
|
job_started: function(data) {
|
|
|
|
state.nQueued--;
|
|
|
|
state.jobsRunning.splice(0, 0, data);
|
|
|
|
this.$forceUpdate();
|
|
|
|
},
|
|
|
|
job_completed: function(data) {
|
|
|
|
for (var i = 0; i < state.jobsRunning.length; ++i) {
|
|
|
|
var job = state.jobsRunning[i];
|
|
|
|
if (job.number === data.number) {
|
|
|
|
state.jobsRunning.splice(i, 1);
|
|
|
|
state.jobsRecent.splice(0, 0, data);
|
|
|
|
this.$forceUpdate();
|
|
|
|
// TODO: update the chart
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-06-01 11:51:34 +00:00
|
|
|
},
|
|
|
|
page_next: function() {
|
2018-08-24 09:15:40 +00:00
|
|
|
state.sort.page++;
|
2019-10-05 17:06:35 +00:00
|
|
|
this.query(state.sort)
|
2018-06-01 11:51:34 +00:00
|
|
|
},
|
|
|
|
page_prev: function() {
|
2018-08-24 09:15:40 +00:00
|
|
|
state.sort.page--;
|
2019-10-05 17:06:35 +00:00
|
|
|
this.query(state.sort)
|
2018-08-24 09:15:40 +00:00
|
|
|
},
|
|
|
|
do_sort: function(field) {
|
|
|
|
if(state.sort.field == field) {
|
|
|
|
state.sort.order = state.sort.order == 'asc' ? 'dsc' : 'asc';
|
|
|
|
} else {
|
|
|
|
state.sort.order = 'dsc';
|
|
|
|
state.sort.field = field;
|
|
|
|
}
|
2019-10-05 17:06:35 +00:00
|
|
|
this.query(state.sort)
|
2017-07-13 18:57:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}();
|
|
|
|
|
|
|
|
const Run = function() {
|
2019-02-18 20:06:37 +00:00
|
|
|
const utf8decoder = new TextDecoder('utf-8');
|
2017-07-13 18:57:28 +00:00
|
|
|
var state = {
|
2018-09-30 06:04:17 +00:00
|
|
|
job: { artifacts: [], upstream: {} },
|
2017-07-13 18:57:28 +00:00
|
|
|
latestNum: null,
|
|
|
|
log: '',
|
|
|
|
autoscroll: false
|
|
|
|
};
|
|
|
|
var firstLog = false;
|
2019-02-15 17:05:44 +00:00
|
|
|
const logFetcher = (vm, name, num) => {
|
|
|
|
const abort = new AbortController();
|
2019-03-29 19:43:16 +00:00
|
|
|
fetch('log/'+name+'/'+num, {signal:abort.signal}).then(res => {
|
2019-02-18 20:06:37 +00:00
|
|
|
// ATOW pipeThrough not supported in Firefox
|
|
|
|
//const reader = res.body.pipeThrough(new TextDecoderStream).getReader();
|
|
|
|
const reader = res.body.getReader();
|
2019-02-15 17:05:44 +00:00
|
|
|
let total = 0;
|
|
|
|
return function pump() {
|
|
|
|
return reader.read().then(({done, value}) => {
|
2019-02-18 20:06:37 +00:00
|
|
|
value = utf8decoder.decode(value);
|
2019-02-15 17:05:44 +00:00
|
|
|
if (done)
|
|
|
|
return;
|
2019-03-29 19:43:16 +00:00
|
|
|
state.log += ansi_up.ansi_to_html(value.replace(/</g,'<').replace(/>/g,'>').replace(/\033\[\{([^:]+):(\d+)\033\\/g, (m,$1,$2)=>{return '<a href="jobs/'+$1+'" onclick="return vroute(this);">'+$1+'</a>:<a href="jobs/'+$1+'/'+$2+'" onclick="return vroute(this);">#'+$2+'</a>';}));
|
2019-02-15 17:05:44 +00:00
|
|
|
vm.$forceUpdate();
|
|
|
|
if (!firstLog) {
|
|
|
|
firstLog = true;
|
|
|
|
} else if (state.autoscroll) {
|
|
|
|
window.scrollTo(0, document.body.scrollHeight);
|
|
|
|
}
|
|
|
|
return pump();
|
|
|
|
});
|
2019-02-18 20:06:37 +00:00
|
|
|
}();
|
2019-02-15 17:05:44 +00:00
|
|
|
}).catch(e => {});
|
|
|
|
return abort;
|
|
|
|
}
|
|
|
|
|
2017-07-13 18:57:28 +00:00
|
|
|
return {
|
|
|
|
template: '#run',
|
2019-10-05 17:06:35 +00:00
|
|
|
mixins: [ServerEventHandler, Utils, ProgressUpdater],
|
2017-07-13 18:57:28 +00:00
|
|
|
data: function() {
|
|
|
|
return state;
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
status: function(data) {
|
2019-02-18 21:06:11 +00:00
|
|
|
// Check for the /latest endpoint. An intuitive check might be
|
|
|
|
// if(this.$route.params.number == 'latest'), but unfortunately
|
|
|
|
// after calling $router.replace, we re-enter status() before
|
|
|
|
// $route.params is updated. Instead, assume that if there is
|
|
|
|
// no 'started' field, we should redirect to the latest number
|
|
|
|
if(!('started' in data) && 'latestNum' in data)
|
|
|
|
return this.$router.replace('/jobs/' + this.$route.params.name + '/' + data.latestNum);
|
|
|
|
|
2017-08-14 05:45:28 +00:00
|
|
|
state.jobsRunning = [];
|
2017-07-13 18:57:28 +00:00
|
|
|
state.job = data;
|
|
|
|
state.latestNum = data.latestNum;
|
2017-11-18 09:26:04 +00:00
|
|
|
state.jobsRunning = [data];
|
2017-07-13 18:57:28 +00:00
|
|
|
},
|
|
|
|
job_started: function(data) {
|
|
|
|
state.latestNum++;
|
|
|
|
this.$forceUpdate();
|
|
|
|
},
|
|
|
|
job_completed: function(data) {
|
2018-10-05 14:53:37 +00:00
|
|
|
state.job = Object.assign(state.job, data);
|
2017-07-13 18:57:28 +00:00
|
|
|
state.jobsRunning = [];
|
|
|
|
this.$forceUpdate();
|
|
|
|
},
|
|
|
|
runComplete: function(run) {
|
|
|
|
return !!run && (run.result === 'aborted' || run.result === 'failed' || run.result === 'success');
|
|
|
|
},
|
|
|
|
},
|
|
|
|
beforeRouteEnter(to, from, next) {
|
|
|
|
next(vm => {
|
2017-12-23 15:15:48 +00:00
|
|
|
state.log = '';
|
2019-02-15 17:05:44 +00:00
|
|
|
vm.logstream = logFetcher(vm, to.params.name, to.params.number);
|
2017-07-13 18:57:28 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
beforeRouteUpdate(to, from, next) {
|
|
|
|
var vm = this;
|
2019-02-15 17:05:44 +00:00
|
|
|
vm.logstream.abort();
|
2017-12-23 15:15:48 +00:00
|
|
|
state.log = '';
|
2019-02-15 17:05:44 +00:00
|
|
|
vm.logstream = logFetcher(vm, to.params.name, to.params.number);
|
2017-07-13 18:57:28 +00:00
|
|
|
next();
|
|
|
|
},
|
|
|
|
beforeRouteLeave(to, from, next) {
|
2019-02-18 20:06:37 +00:00
|
|
|
this.logstream.abort();
|
2017-07-13 18:57:28 +00:00
|
|
|
next();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}();
|
|
|
|
|
2018-08-24 10:31:29 +00:00
|
|
|
// For all charts, set miniumum Y to 0
|
|
|
|
Chart.scaleService.updateScaleDefaults('linear', {
|
2018-09-08 15:16:23 +00:00
|
|
|
ticks: { suggestedMin: 0 }
|
|
|
|
});
|
|
|
|
// Don't display legend by default
|
|
|
|
Chart.defaults.global.legend.display = false;
|
|
|
|
// Plugin to move a DOM item on top of a chart element
|
|
|
|
Chart.plugins.register({
|
|
|
|
afterDatasetsDraw: (chart) => {
|
|
|
|
chart.data.datasets.forEach((dataset, i) => {
|
|
|
|
var meta = chart.getDatasetMeta(i);
|
|
|
|
if(dataset.itemid)
|
|
|
|
meta.data.forEach((e,j) => {
|
|
|
|
var pos = e.getCenterPoint();
|
|
|
|
var node = document.getElementById(dataset.itemid[j]);
|
|
|
|
node.style.top = (pos.y - node.clientHeight/2) + 'px';
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2018-08-24 10:31:29 +00:00
|
|
|
});
|
|
|
|
|
2017-07-13 18:57:28 +00:00
|
|
|
new Vue({
|
|
|
|
el: '#app',
|
|
|
|
data: {
|
2017-12-23 15:15:48 +00:00
|
|
|
title: '', // populated by status ws message
|
2018-02-03 14:52:46 +00:00
|
|
|
clockSkew: 0,
|
2017-12-29 15:18:43 +00:00
|
|
|
connected: false,
|
|
|
|
notify: 'localStorage' in window && localStorage.getItem('showNotifications') == 1
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
supportsNotifications() {
|
|
|
|
return 'Notification' in window && Notification.permission !== 'denied';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
toggleNotifications(en) {
|
|
|
|
if(Notification.permission !== 'granted')
|
|
|
|
Notification.requestPermission(p => this.notify = (p === 'granted'))
|
|
|
|
else
|
|
|
|
this.notify = en;
|
|
|
|
},
|
|
|
|
showNotify(msg, data) {
|
|
|
|
if(this.notify && msg === 'job_completed')
|
2018-01-05 08:50:50 +00:00
|
|
|
new Notification('Job ' + data.result, {
|
|
|
|
body: data.name + ' ' + '#' + data.number + ': ' + data.result
|
|
|
|
});
|
2017-12-29 15:18:43 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
notify(e) { localStorage.setItem('showNotifications', e ? 1 : 0); }
|
2017-07-13 18:57:28 +00:00
|
|
|
},
|
|
|
|
router: new VueRouter({
|
|
|
|
mode: 'history',
|
2019-03-29 19:43:16 +00:00
|
|
|
base: document.head.baseURI.substr(location.origin.length),
|
2017-07-13 18:57:28 +00:00
|
|
|
routes: [
|
|
|
|
{ path: '/', component: Home },
|
|
|
|
{ path: '/jobs', component: Jobs },
|
|
|
|
{ path: '/jobs/:name', component: Job },
|
|
|
|
{ path: '/jobs/:name/:number', component: Run }
|
|
|
|
],
|
|
|
|
}),
|
2015-09-26 20:54:27 +00:00
|
|
|
});
|