LogsWidget.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*##############################################################################
  2. # Copyright (C) 2011 HPCC Systems.
  3. #
  4. # All rights reserved. This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as
  6. # published by the Free Software Foundation, either version 3 of the
  7. # License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ############################################################################## */
  17. define([
  18. "dojo/_base/declare",
  19. "dojo/_base/lang",
  20. "dojo/i18n",
  21. "dojo/i18n!./nls/common",
  22. "dojo/i18n!./nls/LogsWidget",
  23. "dojo/_base/array",
  24. "dojo/store/Memory",
  25. "dojo/store/Observable",
  26. "dojo/request/iframe",
  27. "dijit/registry",
  28. "dgrid/OnDemandGrid",
  29. "dgrid/Keyboard",
  30. "dgrid/Selection",
  31. "dgrid/selector",
  32. "dgrid/extensions/ColumnResizer",
  33. "dgrid/extensions/DijitRegistry",
  34. "hpcc/_Widget",
  35. "hpcc/ESPUtil",
  36. "hpcc/ESPRequest",
  37. "hpcc/ESPWorkunit",
  38. "dojo/text!../templates/LogsWidget.html",
  39. "dijit/layout/BorderContainer",
  40. "dijit/layout/TabContainer",
  41. "dijit/Toolbar",
  42. "dijit/ToolbarSeparator",
  43. "dijit/form/Button",
  44. "dijit/layout/ContentPane"
  45. ],
  46. function (declare, lang, i18n, nlsCommon, nlsSpecific, array, Memory, Observable, iframe,
  47. registry,
  48. OnDemandGrid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry,
  49. _Widget, ESPUtil, ESPRequest, ESPWorkunit,
  50. template) {
  51. return declare("LogsWidget", [_Widget], {
  52. templateString: template,
  53. baseClass: "LogsWidget",
  54. i18n: lang.mixin(nlsCommon, nlsSpecific),
  55. borderContainer: null,
  56. logsGrid: null,
  57. lastSelection: null,
  58. downloadFrameID: 0,
  59. buildRendering: function (args) {
  60. this.inherited(arguments);
  61. },
  62. postCreate: function (args) {
  63. this.inherited(arguments);
  64. this.borderContainer = registry.byId(this.id + "BorderContainer");
  65. },
  66. startup: function (args) {
  67. this.inherited(arguments);
  68. var store = new Memory({
  69. idProperty: "id",
  70. data: []
  71. });
  72. this.logsStore = Observable(store);
  73. this.logsGrid = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  74. allowSelectAll: true,
  75. columns: {
  76. sel: selector({
  77. width: 27,
  78. selectorType: "checkbox"
  79. }),
  80. Type: {
  81. label: this.i18n.Type,
  82. width: 117
  83. },
  84. Description: {
  85. label: this.i18n.Description
  86. }
  87. },
  88. store: this.logsStore
  89. }, this.id + "LogsGrid");
  90. this.logsGrid.startup();
  91. },
  92. resize: function (args) {
  93. this.inherited(arguments);
  94. this.borderContainer.resize();
  95. },
  96. layout: function (args) {
  97. this.inherited(arguments);
  98. },
  99. _onRefresh: function (evt) {
  100. this.fetchLogs();
  101. },
  102. _doDownload: function (option) {
  103. var selection = this.logsGrid.getSelected();
  104. for (var i = 0; i < selection.length; ++i) {
  105. var downloadPdfIframeName = "downloadIframe_" + this.downloadFrameID++;
  106. var frame = iframe.create(downloadPdfIframeName);
  107. var params = "";
  108. switch (selection[i].Type) {
  109. case "dll":
  110. var parts = selection[i].Orig.Name.split("/");
  111. if (parts.length) {
  112. var leaf = parts[parts.length - 1];
  113. params = "/WUFile/" + leaf + "?Wuid=" + this.wu.Wuid + "&Name=" + selection[i].Orig.Name + "&Type=" + selection[i].Orig.Type;
  114. }
  115. break;
  116. case "res":
  117. params = "/WUFile/res.txt?Wuid=" + this.wu.Wuid + "&Type=" + selection[i].Orig.Type;
  118. break;
  119. case "ThorLog":
  120. case "EclAgentLog":
  121. params = "/WUFile/" + selection[i].Type + "?Wuid=" + this.wu.Wuid + "&Name=" + selection[i].Orig.Name + "&Type=" + selection[i].Orig.Type;
  122. break;
  123. case "ThorSlaveLog":
  124. params = "/WUFile?Wuid=" + this.wu.Wuid + "&Process=" + selection[i].Orig.ProcessName + "&ClusterGroup=" + selection[i].Orig.ProcessName + "&LogDate=" + selection[i].Orig.LogDate + "&SlaveNumber=" + selection[i].Orig.SlaveNumber + "&Type=" + selection[i].Type;
  125. break;
  126. case "Archive Query":
  127. params = "/WUFile/ArchiveQuery?Wuid=" + this.wu.Wuid + "&Name=ArchiveQuery&Type=ArchiveQuery";
  128. break;
  129. }
  130. var url = ESPRequest.getBaseURL() + params + (option ? "&Option=" + option : "&Option=1");
  131. iframe.setSrc(frame, url, true);
  132. }
  133. },
  134. _onDownload: function (args) {
  135. this._doDownload(1);
  136. },
  137. _onDownloadZip: function (args) {
  138. this._doDownload(2);
  139. },
  140. _onDownloadGZip: function (args) {
  141. this._doDownload(3);
  142. },
  143. // Plugin wrapper ---
  144. init: function (params) {
  145. if (this.inherited(arguments))
  146. return;
  147. var context = this;
  148. if (params.Wuid) {
  149. this.wu = ESPWorkunit.Get(params.Wuid);
  150. var monitorCount = 4;
  151. this.wu.monitor(function () {
  152. if (context.wu.isComplete() || ++monitorCount % 5 == 0) {
  153. context.fetchLogs();
  154. }
  155. });
  156. }
  157. },
  158. fetchLogs: function () {
  159. var context = this;
  160. this.wu.getInfo({
  161. onAfterSend: function (response) {
  162. context.logData = [];
  163. if (response.HasArchiveQuery) {
  164. context.logData.push({
  165. id: "A:0",
  166. Type: "Archive Query"
  167. });
  168. }
  169. if (response.Helpers && response.Helpers.ECLHelpFile) {
  170. context.loadHelpers(response.Helpers.ECLHelpFile);
  171. }
  172. if (response.ThorLogList && response.ThorLogList.ThorLogInfo) {
  173. context.loadThorLogInfo(response.ThorLogList.ThorLogInfo);
  174. }
  175. context.logsStore.setData(context.logData);
  176. context.logsGrid.refresh();
  177. }
  178. });
  179. },
  180. loadLogs: function (logs) {
  181. for (var i = 0; i < logs.length; ++i) {
  182. this.logData.push({
  183. id: "L:" + i,
  184. Type: "dfulog",
  185. Description: logs[i],
  186. Orig: logs[i]
  187. });
  188. }
  189. },
  190. loadHelpers: function (helpers) {
  191. for (var i = 0; i < helpers.length; ++i) {
  192. this.logData.push({
  193. id: "H:" + i,
  194. Type: helpers[i].Type,
  195. Description: helpers[i].IPAddress ? "//" + helpers[i].IPAddress + helpers[i].Name : helpers[i].Name,
  196. Orig: helpers[i]
  197. });
  198. }
  199. },
  200. loadThorLogInfo: function (thorLogInfo) {
  201. for (var i = 0; i < thorLogInfo.length; ++i) {
  202. for (var j = 0; j < thorLogInfo[i].NumberSlaves; ++j) {
  203. this.logData.push({
  204. id: "T:" + i + "_" + j,
  205. Type: "ThorSlaveLog",
  206. Description: thorLogInfo[i].ClusterGroup + "." + thorLogInfo[i].LogDate + ".log (slave " + (j + 1) + " of " + thorLogInfo[i].NumberSlaves + ")",
  207. Orig: lang.mixin({
  208. SlaveNumber: j + 1
  209. }, thorLogInfo[i])
  210. });
  211. }
  212. }
  213. }
  214. });
  215. });