LogsWidget.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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/array",
  20. "dojo/_base/lang",
  21. "dojo/store/Memory",
  22. "dojo/store/Observable",
  23. "dojo/request/iframe",
  24. "dijit/registry",
  25. "dijit/layout/_LayoutWidget",
  26. "dijit/_TemplatedMixin",
  27. "dijit/_WidgetsInTemplateMixin",
  28. "dgrid/OnDemandGrid",
  29. "dgrid/Keyboard",
  30. "dgrid/Selection",
  31. "dgrid/selector",
  32. "dgrid/extensions/ColumnResizer",
  33. "dgrid/extensions/DijitRegistry",
  34. "hpcc/ESPUtil",
  35. "hpcc/ESPRequest",
  36. "hpcc/ESPWorkunit",
  37. "dojo/text!../templates/LogsWidget.html"
  38. ],
  39. function (declare, array, lang, Memory, Observable, iframe,
  40. registry, _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin,
  41. OnDemandGrid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry,
  42. ESPUtil, ESPRequest, ESPWorkunit,
  43. template) {
  44. return declare("LogsWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  45. templateString: template,
  46. baseClass: "LogsWidget",
  47. borderContainer: null,
  48. logsGrid: null,
  49. lastSelection: null,
  50. downloadFrameID: 0,
  51. buildRendering: function (args) {
  52. this.inherited(arguments);
  53. },
  54. postCreate: function (args) {
  55. this.inherited(arguments);
  56. this.borderContainer = registry.byId(this.id + "BorderContainer");
  57. },
  58. startup: function (args) {
  59. this.inherited(arguments);
  60. var store = new Memory({
  61. idProperty: "id",
  62. data: []
  63. });
  64. this.logsStore = Observable(store);
  65. this.logsGrid = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  66. allowSelectAll: true,
  67. columns: {
  68. sel: selector({
  69. width: 27,
  70. selectorType: 'checkbox'
  71. }),
  72. Type: {
  73. field: "Type",
  74. width: 117
  75. },
  76. Description: {
  77. field: "Description"
  78. }
  79. },
  80. store: this.logsStore
  81. }, this.id + "LogsGrid");
  82. this.logsGrid.startup();
  83. },
  84. resize: function (args) {
  85. this.inherited(arguments);
  86. this.borderContainer.resize();
  87. },
  88. layout: function (args) {
  89. this.inherited(arguments);
  90. },
  91. _doDownload: function (option) {
  92. var selection = this.logsGrid.getSelected();
  93. for (var i = 0; i < selection.length; ++i) {
  94. var downloadPdfIframeName = "downloadIframe_" + this.downloadFrameID++;
  95. var frame = iframe.create(downloadPdfIframeName);
  96. var params = "";
  97. switch (selection[i].Type) {
  98. case "dll":
  99. var parts = selection[i].Orig.Name.split("/");
  100. if (parts.length) {
  101. var leaf = parts[parts.length - 1];
  102. params = "/WUFile/" + leaf + "?Wuid=" + this.wu.Wuid + "&Name=" + selection[i].Orig.Name + "&Type=" + selection[i].Orig.Type;
  103. }
  104. break;
  105. case "res":
  106. params = "/WUFile/res.txt?Wuid=" + this.wu.Wuid + "&Type=" + selection[i].Orig.Type;
  107. break;
  108. case "ThorLog":
  109. case "EclAgentLog":
  110. params = "/WUFile/" + selection[i].Type + "?Wuid=" + this.wu.Wuid + "&Name=" + selection[i].Orig.Name + "&Type=" + selection[i].Orig.Type;
  111. break;
  112. case "ThorSlaveLog":
  113. 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;
  114. break;
  115. case "Archive Query":
  116. params = "/WUFile/ArchiveQuery?Wuid=" + this.wu.Wuid + "&Name=ArchiveQuery&Type=ArchiveQuery";
  117. break;
  118. }
  119. var url = ESPRequest.getBaseURL() + params + (option ? "&Option=" + option : "&Option=1");
  120. iframe.setSrc(frame, url, true);
  121. }
  122. },
  123. _onDownload: function (args) {
  124. this._doDownload(1);
  125. },
  126. _onDownloadZip: function (args) {
  127. this._doDownload(2);
  128. },
  129. _onDownloadGZip: function (args) {
  130. this._doDownload(3);
  131. },
  132. // Plugin wrapper ---
  133. init: function (params) {
  134. if (this.initalized)
  135. return;
  136. this.initalized = true;
  137. this.logData = [];
  138. var context = this;
  139. if (params.wu) {
  140. this.wu = params.wu;
  141. this.wu.fetchLogs(function (logs) {
  142. context.loadLogs(logs);
  143. context.logsStore.setData(context.logData);
  144. context.logsGrid.refresh();
  145. });
  146. } else {
  147. this.wu = ESPWorkunit.Get(params.Wuid);
  148. this.wu.monitor(function () {
  149. context.wu.getInfo({
  150. onAfterSend: function (response) {
  151. if (response.HasArchiveQuery) {
  152. context.logData.push({
  153. id: "A:0",
  154. Type: "Archive Query"
  155. });
  156. }
  157. if (response.Helpers && response.Helpers.ECLHelpFile) {
  158. context.loadHelpers(response.Helpers.ECLHelpFile);
  159. }
  160. if (response.ThorLogList && response.ThorLogList.ThorLogInfo) {
  161. context.loadThorLogInfo(response.ThorLogList.ThorLogInfo);
  162. }
  163. context.logsStore.setData(context.logData);
  164. context.logsGrid.refresh();
  165. }
  166. });
  167. });
  168. }
  169. },
  170. loadLogs: function (logs) {
  171. for (var i = 0; i < logs.length; ++i) {
  172. this.logData.push({
  173. id: "L:" + i,
  174. Type: "dfulog",
  175. Description: logs[i],
  176. Orig: logs[i]
  177. });
  178. }
  179. },
  180. loadHelpers: function (helpers) {
  181. for (var i = 0; i < helpers.length; ++i) {
  182. this.logData.push({
  183. id: "H:" + i,
  184. Type: helpers[i].Type,
  185. Description: helpers[i].IPAddress ? "//" + helpers[i].IPAddress + helpers[i].Name : helpers[i].Name,
  186. Orig: helpers[i]
  187. });
  188. }
  189. },
  190. loadThorLogInfo: function (thorLogInfo) {
  191. for (var i = 0; i < thorLogInfo.length; ++i) {
  192. for (var j = 0; j < thorLogInfo[i].NumberSlaves; ++j) {
  193. this.logData.push({
  194. id: "T:" + i + "_" + j,
  195. Type: "ThorSlaveLog",
  196. Description: thorLogInfo[i].ClusterGroup + "." + thorLogInfo[i].LogDate + ".log (slave " + (j + 1) + " of " + thorLogInfo[i].NumberSlaves + ")",
  197. Orig: lang.mixin({
  198. SlaveNumber: j + 1
  199. }, thorLogInfo[i])
  200. });
  201. }
  202. }
  203. }
  204. });
  205. });