4314 |
20 Jan 17 |
nicklas |
var Remote = function() |
4314 |
20 Jan 17 |
nicklas |
2 |
{ |
4314 |
20 Jan 17 |
nicklas |
var remote = {}; |
6842 |
09 Sep 22 |
nicklas |
var debug = 0; |
4314 |
20 Jan 17 |
nicklas |
5 |
|
4314 |
20 Jan 17 |
nicklas |
remote.initPage = function() |
4314 |
20 Jan 17 |
nicklas |
7 |
{ |
4314 |
20 Jan 17 |
nicklas |
remote.getHostInfo(false); |
4314 |
20 Jan 17 |
nicklas |
Buttons.addClickHandler('btnReload', remote.reloadConfiguration); |
4314 |
20 Jan 17 |
nicklas |
10 |
} |
4314 |
20 Jan 17 |
nicklas |
11 |
|
4314 |
20 Jan 17 |
nicklas |
remote.reloadConfiguration = function() |
4314 |
20 Jan 17 |
nicklas |
13 |
{ |
4314 |
20 Jan 17 |
nicklas |
remote.getHostInfo(true); |
4314 |
20 Jan 17 |
nicklas |
15 |
} |
4314 |
20 Jan 17 |
nicklas |
16 |
|
4314 |
20 Jan 17 |
nicklas |
remote.getHostInfo = function(reload) |
4314 |
20 Jan 17 |
nicklas |
18 |
{ |
4314 |
20 Jan 17 |
nicklas |
var rows = Doc.element('all-rows'); |
4314 |
20 Jan 17 |
nicklas |
while (rows.lastChild) |
4314 |
20 Jan 17 |
nicklas |
21 |
{ |
4314 |
20 Jan 17 |
nicklas |
rows.removeChild(rows.lastChild); |
4314 |
20 Jan 17 |
nicklas |
23 |
} |
4314 |
20 Jan 17 |
nicklas |
var template = Doc.element('row-template'); |
4314 |
20 Jan 17 |
nicklas |
var cols = template.getElementsByTagName('th'); |
4314 |
20 Jan 17 |
nicklas |
26 |
|
4314 |
20 Jan 17 |
nicklas |
var wait = document.createElement('tr'); |
5988 |
18 Aug 20 |
nicklas |
wait.innerHTML = '<td colspan="'+cols.length+'"><div class="messagecontainer note">Loading information about clusters. Please wait...</div></td>'; |
4314 |
20 Jan 17 |
nicklas |
rows.appendChild(wait); |
4314 |
20 Jan 17 |
nicklas |
30 |
|
4314 |
20 Jan 17 |
nicklas |
var url = 'OpenGrid.servlet?ID='+App.getSessionId(); |
4317 |
23 Jan 17 |
nicklas |
url += '&cmd=GetHostInfo&jobAgentDetails=1'; |
4314 |
20 Jan 17 |
nicklas |
if (reload) url += '&reload=1'; |
4314 |
20 Jan 17 |
nicklas |
var request = Ajax.getXmlHttpRequest(); |
4314 |
20 Jan 17 |
nicklas |
request.open("GET", url, true); |
4314 |
20 Jan 17 |
nicklas |
Ajax.setReadyStateHandler(request, remote.onHostInfoLoaded, remote.onHostInfoLoaded); |
4314 |
20 Jan 17 |
nicklas |
request.send(null); |
4314 |
20 Jan 17 |
nicklas |
38 |
} |
4314 |
20 Jan 17 |
nicklas |
39 |
|
4314 |
20 Jan 17 |
nicklas |
remote.onHostInfoLoaded = function(request) |
4314 |
20 Jan 17 |
nicklas |
41 |
{ |
4314 |
20 Jan 17 |
nicklas |
if (debug) App.debug(Strings.encodeTags(request.responseText)); |
4314 |
20 Jan 17 |
nicklas |
var response; |
4314 |
20 Jan 17 |
nicklas |
var error = false; |
4314 |
20 Jan 17 |
nicklas |
try |
4314 |
20 Jan 17 |
nicklas |
46 |
{ |
4314 |
20 Jan 17 |
nicklas |
response = JSON.parse(request.responseText); |
4314 |
20 Jan 17 |
nicklas |
if (response.status != 'ok') |
4314 |
20 Jan 17 |
nicklas |
49 |
{ |
4314 |
20 Jan 17 |
nicklas |
error = response.message || response.stacktrace || 'Unexpected error'; |
4314 |
20 Jan 17 |
nicklas |
51 |
} |
4314 |
20 Jan 17 |
nicklas |
52 |
} |
4314 |
20 Jan 17 |
nicklas |
catch (ex) |
4314 |
20 Jan 17 |
nicklas |
54 |
{ |
4314 |
20 Jan 17 |
nicklas |
error = ex; |
4314 |
20 Jan 17 |
nicklas |
56 |
} |
4314 |
20 Jan 17 |
nicklas |
57 |
|
4314 |
20 Jan 17 |
nicklas |
var template = Doc.element('row-template'); |
4314 |
20 Jan 17 |
nicklas |
var cols = template.getElementsByTagName('th'); |
4314 |
20 Jan 17 |
nicklas |
60 |
|
4314 |
20 Jan 17 |
nicklas |
var rows = Doc.element('all-rows'); |
4314 |
20 Jan 17 |
nicklas |
while (rows.lastChild) |
4314 |
20 Jan 17 |
nicklas |
63 |
{ |
4314 |
20 Jan 17 |
nicklas |
rows.removeChild(rows.lastChild); |
4314 |
20 Jan 17 |
nicklas |
65 |
} |
4314 |
20 Jan 17 |
nicklas |
66 |
|
4314 |
20 Jan 17 |
nicklas |
if (error) |
4314 |
20 Jan 17 |
nicklas |
68 |
{ |
4314 |
20 Jan 17 |
nicklas |
var wait = document.createElement('tr'); |
4314 |
20 Jan 17 |
nicklas |
wait.innerHTML = '<td colspan="'+cols.length+'"><div class="messagecontainer error">'+Strings.encodeTags(error)+'</div></td>'; |
4314 |
20 Jan 17 |
nicklas |
rows.appendChild(wait); |
4314 |
20 Jan 17 |
nicklas |
return; |
4314 |
20 Jan 17 |
nicklas |
73 |
} |
4314 |
20 Jan 17 |
nicklas |
74 |
|
4314 |
20 Jan 17 |
nicklas |
var hosts = response.hosts; |
4314 |
20 Jan 17 |
nicklas |
for (var hostNo = 0; hostNo < hosts.length; hostNo++) |
4314 |
20 Jan 17 |
nicklas |
77 |
{ |
4314 |
20 Jan 17 |
nicklas |
var host = hosts[hostNo]; |
4314 |
20 Jan 17 |
nicklas |
var connectionInfo = host.connection; |
4314 |
20 Jan 17 |
nicklas |
var hostInfo = host.clusterInfo.hostInfo; |
4314 |
20 Jan 17 |
nicklas |
var openGridInfo = host.clusterInfo.openGridInfo; |
4317 |
23 Jan 17 |
nicklas |
var jobAgent = host.config.jobAgent; |
4314 |
20 Jan 17 |
nicklas |
83 |
|
4314 |
20 Jan 17 |
nicklas |
var row = document.createElement('tr'); |
4314 |
20 Jan 17 |
nicklas |
row.className = hostNo % 2 == 0 ? 'evenrow highlight' : 'oddrow highlight'; |
4314 |
20 Jan 17 |
nicklas |
86 |
|
4314 |
20 Jan 17 |
nicklas |
for (var colNo = 0; colNo < cols.length; colNo++) |
4314 |
20 Jan 17 |
nicklas |
88 |
{ |
4314 |
20 Jan 17 |
nicklas |
var cell = document.createElement('td'); |
4314 |
20 Jan 17 |
nicklas |
cell.className = 'cell'; |
4314 |
20 Jan 17 |
nicklas |
var colId = cols[colNo].id; |
4314 |
20 Jan 17 |
nicklas |
if (colId == 'hosts.name') |
4314 |
20 Jan 17 |
nicklas |
93 |
{ |
4314 |
20 Jan 17 |
nicklas |
cell.innerHTML = '<span class="link">'+Strings.encodeTags(connectionInfo.name)+'<span>'; |
4314 |
20 Jan 17 |
nicklas |
Data.set(cell, 'host-id', host.id) |
4314 |
20 Jan 17 |
nicklas |
Events.addEventHandler(cell, 'click', remote.hostOnClick); |
4314 |
20 Jan 17 |
nicklas |
97 |
} |
4314 |
20 Jan 17 |
nicklas |
else if (colId == 'hosts.server') |
4314 |
20 Jan 17 |
nicklas |
99 |
{ |
4314 |
20 Jan 17 |
nicklas |
cell.innerHTML = Strings.encodeTags(connectionInfo.user + '@' + connectionInfo.address + ':' + connectionInfo.port); |
4314 |
20 Jan 17 |
nicklas |
101 |
} |
4314 |
20 Jan 17 |
nicklas |
else if (colId == 'hosts.timeDiff') |
4314 |
20 Jan 17 |
nicklas |
103 |
{ |
4314 |
20 Jan 17 |
nicklas |
cell.innerHTML = host.clusterInfo.timeAdjustment + ' seconds'; |
4314 |
20 Jan 17 |
nicklas |
105 |
} |
5986 |
10 Jul 20 |
nicklas |
else if (colId == 'hosts.type') |
5986 |
10 Jul 20 |
nicklas |
107 |
{ |
5986 |
10 Jul 20 |
nicklas |
cell.innerHTML = Strings.encodeTags(host.config.type); |
5986 |
10 Jul 20 |
nicklas |
109 |
} |
4314 |
20 Jan 17 |
nicklas |
else if (colId == 'hosts.ogs') |
4314 |
20 Jan 17 |
nicklas |
111 |
{ |
4314 |
20 Jan 17 |
nicklas |
var html; |
4314 |
20 Jan 17 |
nicklas |
if (openGridInfo.exitStatus == 0) |
4314 |
20 Jan 17 |
nicklas |
114 |
{ |
4314 |
20 Jan 17 |
nicklas |
html = Strings.encodeTags(openGridInfo.stdout); |
4314 |
20 Jan 17 |
nicklas |
116 |
} |
4314 |
20 Jan 17 |
nicklas |
else |
4314 |
20 Jan 17 |
nicklas |
118 |
{ |
4314 |
20 Jan 17 |
nicklas |
html = '<div class="messagecontainer error">['+openGridInfo.exitStatus+'] '+Strings.encodeTags(openGridInfo.stderr)+'</div>'; |
4314 |
20 Jan 17 |
nicklas |
120 |
} |
4314 |
20 Jan 17 |
nicklas |
cell.innerHTML = html; |
4314 |
20 Jan 17 |
nicklas |
122 |
} |
4314 |
20 Jan 17 |
nicklas |
else if (colId == 'hosts.info') |
4314 |
20 Jan 17 |
nicklas |
124 |
{ |
4314 |
20 Jan 17 |
nicklas |
var html; |
4314 |
20 Jan 17 |
nicklas |
if (hostInfo.exitStatus == 0) |
4314 |
20 Jan 17 |
nicklas |
127 |
{ |
4314 |
20 Jan 17 |
nicklas |
html = Strings.encodeTags(hostInfo.stdout); |
4314 |
20 Jan 17 |
nicklas |
129 |
} |
4314 |
20 Jan 17 |
nicklas |
else |
4314 |
20 Jan 17 |
nicklas |
131 |
{ |
4314 |
20 Jan 17 |
nicklas |
html = '<div class="messagecontainer error">['+hostInfo.exitStatus+'] '+Strings.encodeTags(hostInfo.stderr)+'</div>'; |
4314 |
20 Jan 17 |
nicklas |
133 |
} |
4314 |
20 Jan 17 |
nicklas |
cell.innerHTML = html; |
4314 |
20 Jan 17 |
nicklas |
135 |
} |
4314 |
20 Jan 17 |
nicklas |
else if (colId == 'hosts.status') |
4314 |
20 Jan 17 |
nicklas |
137 |
{ |
4314 |
20 Jan 17 |
nicklas |
var img = 'ok.png'; |
4314 |
20 Jan 17 |
nicklas |
if (host.clusterInfo.error) |
4314 |
20 Jan 17 |
nicklas |
140 |
{ |
4314 |
20 Jan 17 |
nicklas |
img = 'error.png'; |
4314 |
20 Jan 17 |
nicklas |
142 |
} |
4314 |
20 Jan 17 |
nicklas |
cell.className = 'host-status'; |
4314 |
20 Jan 17 |
nicklas |
cell.innerHTML = '<img src="../../images/'+img + '">'; |
4314 |
20 Jan 17 |
nicklas |
145 |
} |
4315 |
23 Jan 17 |
nicklas |
else if (colId == 'hosts.jobAgent') |
4315 |
23 Jan 17 |
nicklas |
147 |
{ |
4317 |
23 Jan 17 |
nicklas |
var html = ''; |
4317 |
23 Jan 17 |
nicklas |
if (!jobAgent) |
4317 |
23 Jan 17 |
nicklas |
150 |
{ |
4317 |
23 Jan 17 |
nicklas |
html = '<i>Not connected</i>'; |
4317 |
23 Jan 17 |
nicklas |
152 |
} |
4317 |
23 Jan 17 |
nicklas |
else if (jobAgent.exception) |
4317 |
23 Jan 17 |
nicklas |
154 |
{ |
4317 |
23 Jan 17 |
nicklas |
html = Strings.encodeTags(jobAgent.externalId + ' [' + jobAgent.exception + ']'); |
4317 |
23 Jan 17 |
nicklas |
156 |
} |
4317 |
23 Jan 17 |
nicklas |
else |
4317 |
23 Jan 17 |
nicklas |
158 |
{ |
4317 |
23 Jan 17 |
nicklas |
if (jobAgent.isShared) |
4317 |
23 Jan 17 |
nicklas |
160 |
{ |
4317 |
23 Jan 17 |
nicklas |
html += '<span class="icon link shared-item" title="Set access permissions" data-item-type="JOBAGENT" data-item-id="'+jobAgent.id+'">'; |
4317 |
23 Jan 17 |
nicklas |
html += '<img src="../../images/shared.png"></span> '; |
4317 |
23 Jan 17 |
nicklas |
163 |
} |
4317 |
23 Jan 17 |
nicklas |
html += '<span class="link linked-item" title="View/edit this job agent" data-item-type="JOBAGENT" data-item-id="'+jobAgent.id+'">'; |
4317 |
23 Jan 17 |
nicklas |
html += Strings.encodeTags(jobAgent.externalId)+'</span>'; |
4317 |
23 Jan 17 |
nicklas |
166 |
} |
4317 |
23 Jan 17 |
nicklas |
cell.innerHTML = html; |
4315 |
23 Jan 17 |
nicklas |
168 |
} |
4314 |
20 Jan 17 |
nicklas |
row.appendChild(cell); |
4314 |
20 Jan 17 |
nicklas |
170 |
} |
4314 |
20 Jan 17 |
nicklas |
171 |
|
4314 |
20 Jan 17 |
nicklas |
rows.appendChild(row); |
4314 |
20 Jan 17 |
nicklas |
173 |
} |
4314 |
20 Jan 17 |
nicklas |
174 |
|
4317 |
23 Jan 17 |
nicklas |
var linkedItems = document.getElementsByClassName('linked-item'); |
4317 |
23 Jan 17 |
nicklas |
for (var itemNo = 0; itemNo < linkedItems.length; itemNo++) |
4317 |
23 Jan 17 |
nicklas |
177 |
{ |
4317 |
23 Jan 17 |
nicklas |
Events.addEventHandler(linkedItems[itemNo], 'click', Items.itemOnClick); |
4317 |
23 Jan 17 |
nicklas |
179 |
} |
4317 |
23 Jan 17 |
nicklas |
180 |
|
4317 |
23 Jan 17 |
nicklas |
var sharedItems = document.getElementsByClassName('shared-item'); |
4317 |
23 Jan 17 |
nicklas |
for (var itemNo = 0; itemNo < sharedItems.length; itemNo++) |
4317 |
23 Jan 17 |
nicklas |
183 |
{ |
4317 |
23 Jan 17 |
nicklas |
Events.addEventHandler(sharedItems[itemNo], 'click', Buttons.shareItem); |
4317 |
23 Jan 17 |
nicklas |
185 |
} |
4317 |
23 Jan 17 |
nicklas |
186 |
|
4314 |
20 Jan 17 |
nicklas |
187 |
} |
4314 |
20 Jan 17 |
nicklas |
188 |
|
4314 |
20 Jan 17 |
nicklas |
remote.hostOnClick = function(event) |
4314 |
20 Jan 17 |
nicklas |
190 |
{ |
4314 |
20 Jan 17 |
nicklas |
var hostId = Data.get(event.currentTarget, 'host-id'); |
4314 |
20 Jan 17 |
nicklas |
var url = 'view-host.jsp?ID='+App.getSessionId(); |
4314 |
20 Jan 17 |
nicklas |
url += '&hostId='+encodeURIComponent(hostId); |
4314 |
20 Jan 17 |
nicklas |
location.href = url; |
4314 |
20 Jan 17 |
nicklas |
195 |
} |
4314 |
20 Jan 17 |
nicklas |
196 |
|
4314 |
20 Jan 17 |
nicklas |
return remote; |
4314 |
20 Jan 17 |
nicklas |
198 |
}(); |
4314 |
20 Jan 17 |
nicklas |
199 |
|
4314 |
20 Jan 17 |
nicklas |
Doc.onLoad(Remote.initPage); |