LogsWidget.js 9.0 KB

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