-
Notifications
You must be signed in to change notification settings - Fork 202
/
job-tracker-parser.js
171 lines (157 loc) · 4.36 KB
/
job-tracker-parser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
var DataURL = {};
DataURL.jobTrackerURL = "http://localhost:50030/jobtracker.jsp";
DataURL.proxyURL = "http://localhost:8080/__ajaxproxy/";
DataURL.jobDetailsURL = "http://localhost:50030/jobdetails.jsp?jobid=";
function JobTrackerParser() {
this.retrieveDataFromJobTracker = function(callback) {
if (!callback && typeof(callback) !== "function") {
return;
}
d3.html(DataURL.proxyURL + DataURL.jobTrackerURL, function(document) {
{
if (!document) {
return;
}
var allA = document.querySelectorAll("a");
for ( var i = 0; i < allA.length; i++) {
var href = allA[i].href;
if (href.indexOf("jobid") !== -1) {
var newURL = swapURL(DataURL.jobTrackerURL, href);
d3.html(DataURL.proxyURL + newURL, function(document) {
if (!document) {
return;
}
var task = jobTrackerParser.parseRunningAndCompleted(document);
var tasks = new Array();
tasks.push(task);
callback(tasks);
});
}
}
var tasks = jobTrackerParser.parseRetired(document);
callback(tasks);
}
});
};
this.parseRetired = function(document) {
if (!document) {
return;
}
var tasks = new Array();
var sortable = document.querySelectorAll(".sortable");
if (sortable.length > 1) {
var trList = sortable[1].querySelectorAll("tr");
for ( var j = 0; j < trList.length; j++) {
var allTD = trList[j].querySelectorAll("td");
if (allTD[0].id.indexOf("job") !== -1) {
task = {
"taskUID" : allTD[0].textContent.trim(),
"taskLink" : DataURL.jobDetailsURL + allTD[0].textContent.trim(),
"date" : allTD[5].textContent.trim(),
"endDate" : allTD[6].textContent.trim(),
"taskName" : allTD[3].textContent.trim(),
"taskStatus" : allTD[4].textContent.trim()
};
tasks.push(task);
}
}
}
return tasks;
};
this.parseRunningAndCompleted = function(document) {
if (!document) {
return;
}
var lines = document.textContent.split('\n');
var filterLines = lines.filter(function(n, i) {
if (n.split(':').length > 1) {
return n;
}
});
var user = "";
var taskName = "";
var taskStatus = "";
var date = "";
var endDate = nowDate;
var taskUID = "";
var taskUIDFilteredLines = lines.filter(function(n, i) {
if (n.indexOf('job_') > -1 && n.split(' ').length > 1) {
return n;
}
});
var taskUIDLine = taskUIDFilteredLines[0];
taskUID = taskUIDLine.slice(taskUIDLine.indexOf('job_'), taskUIDLine.length).split(' ')[0].trim();
for ( var i = 0; i < filterLines.length; i++) {
var lineArray = filterLines[i].split(/:(.+)?/);
var name = lineArray[0].trim();
var value = lineArray[1].trim();
switch (name) {
case "User":
user = value;
break;
case "JobName":
taskName = value;
case "Job Name":
taskName = value;
break;
case "Status":
taskStatus = value.toUpperCase();
break;
case "Launched At":
date = value.split('(')[0];
break;
case "Started at":
date = value;
break;
case "Finished At":
endDate = value.split('(')[0];
break;
case "Finished at":
endDate = value.split('(')[0];
break;
}
}
task = {
"taskUID" : taskUID,
"taskLink" : DataURL.jobDetailsURL + taskUID,
"date" : date,
"endDate" : endDate,
"taskName" : taskName,
"taskStatus" : taskStatus
};
return task;
};
function swapURL(src, dest) {
return src.split(parseURL(src).path)[0] + parseURL(dest).relative;
};
//This function creates a new anchor element and uses location
//properties (inherent) to get the desired URL data. Some String
//operations are used (to normalize results across browsers).
function parseURL(url) {
var a = document.createElement('a');
a.href = url;
return {
source : url,
protocol : a.protocol.replace(':', ''),
host : a.hostname,
port : a.port,
query : a.search,
params : (function() {
var ret = {}, seg = a.search.replace(/^\?/, '').split('&'), len = seg.length, i = 0, s;
for (; i < len; i++) {
if (!seg[i]) {
continue;
}
s = seg[i].split('=');
ret[s[0]] = s[1];
}
return ret;
})(),
file : (a.pathname.match(/\/([^\/?#]+)$/i) || [ , '' ])[1],
hash : a.hash.replace('#', ''),
path : a.pathname.replace(/^([^\/])/, '/$1'),
relative : (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [ , '' ])[1],
segments : a.pathname.replace(/^\//, '').split('/')
};
};
};