LogsWidget.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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/data/ObjectStore",
  23. "dojo/request/iframe",
  24. "dijit/registry",
  25. "dijit/layout/_LayoutWidget",
  26. "dijit/_TemplatedMixin",
  27. "dijit/_WidgetsInTemplateMixin",
  28. "dojox/grid/EnhancedGrid",
  29. "dojox/grid/enhanced/plugins/IndirectSelection",
  30. "hpcc/ESPWorkunit",
  31. "dojo/text!../templates/LogsWidget.html"
  32. ],
  33. function (declare, array, lang, Memory, ObjectStore, iframe,
  34. registry, _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin,
  35. EnhancedGrid, IndirectSelection,
  36. ESPWorkunit,
  37. template) {
  38. return declare("LogsWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  39. templateString: template,
  40. baseClass: "LogsWidget",
  41. borderContainer: null,
  42. logsGrid: null,
  43. dataStore: null,
  44. lastSelection: null,
  45. buildRendering: function (args) {
  46. this.inherited(arguments);
  47. },
  48. postCreate: function (args) {
  49. this.inherited(arguments);
  50. this.borderContainer = registry.byId(this.id + "BorderContainer");
  51. this.logsGrid = new dojox.grid.EnhancedGrid({
  52. id: this.id + "LogsGrid",
  53. structure: [
  54. { name: "Type", field: "Type", width: 8 },
  55. { name: "Description", field: "Description", width: "100%" }
  56. ],
  57. plugins: {
  58. indirectSelection: {
  59. headerSelector: true, width: "40px", styles: "text-align: center;"
  60. }
  61. }
  62. });
  63. this.logsGrid.placeAt(this.id + 'CenterPane');
  64. this.logsGrid.startup();
  65. var context = this;
  66. this.logsGrid.on("RowClick", function (evt) {
  67. });
  68. this.logsGrid.on("RowDblClick", function (evt) {
  69. });
  70. },
  71. startup: function (args) {
  72. this.inherited(arguments);
  73. },
  74. resize: function (args) {
  75. this.inherited(arguments);
  76. this.borderContainer.resize();
  77. },
  78. layout: function (args) {
  79. this.inherited(arguments);
  80. },
  81. _doDownload: function (option) {
  82. var selection = this.logsGrid.selection.getSelected();
  83. for (var i = 0; i < selection.length; ++i) {
  84. var downloadPdfIframeName = "downloadIframe_" + i;
  85. var frame = iframe.create(downloadPdfIframeName);
  86. var params = "";
  87. switch (selection[i].Type) {
  88. case "dll":
  89. var parts = selection[i].Orig.Name.split("/");
  90. if (parts.length) {
  91. var leaf = parts[parts.length - 1];
  92. params = "/WUFile/" + leaf + "?Wuid=" + this.wu.Wuid + "&Name=" + selection[i].Orig.Name + "&Type=" + selection[i].Orig.Type;
  93. }
  94. break;
  95. case "res":
  96. params = "/WUFile/res.txt?Wuid=" + this.wu.Wuid + "&Type=" + selection[i].Orig.Type;
  97. break;
  98. case "ThorLog":
  99. case "EclAgentLog":
  100. params = "/WUFile/" + selection[i].Type + "?Wuid=" + this.wu.Wuid + "&Process=" + selection[i].Orig.Description + "&Type=" + selection[i].Orig.Type;
  101. break;
  102. case "ThorSlaveLog":
  103. 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;
  104. break;
  105. case "Archive Query":
  106. params = "/WUFile/ArchiveQuery?Wuid=" + this.wu.Wuid + "&Name=ArchiveQuery&Type=ArchiveQuery";
  107. break;
  108. }
  109. var url = this.wu.getBaseURL() + params + (option ? "&Option=" + option : "&Option=1");
  110. iframe.setSrc(frame, url, true);
  111. }
  112. },
  113. _onDownload: function (args) {
  114. this._doDownload(1);
  115. },
  116. _onDownloadZip: function (args) {
  117. this._doDownload(2);
  118. },
  119. _onDownloadGZip: function (args) {
  120. this._doDownload(3);
  121. },
  122. // Plugin wrapper ---
  123. init: function (params) {
  124. if (this.initalized)
  125. return;
  126. this.initalized = true;
  127. this.wu = ESPWorkunit.Get(params.Wuid);
  128. var context = this;
  129. this.wu.monitor(function () {
  130. context.wu.getInfo({
  131. onAfterSend: function (response) {
  132. context.logData = [];
  133. if (response.HasArchiveQuery) {
  134. context.logData.push({
  135. Type: "Archive Query"
  136. });
  137. }
  138. if (response.Helpers && response.Helpers.ECLHelpFile) {
  139. context.loadHelpers(response.Helpers.ECLHelpFile);
  140. }
  141. if (response.ThorLogList && response.ThorLogList.ThorLogInfo) {
  142. context.loadThorLogInfo(response.ThorLogList.ThorLogInfo);
  143. }
  144. var memory = new Memory({ data: context.logData });
  145. var store = new ObjectStore({ objectStore: memory });
  146. context.logsGrid.setStore(store);
  147. context.logsGrid.setQuery({
  148. Type: "*"
  149. });
  150. }
  151. });
  152. });
  153. },
  154. loadHelpers: function (helpers) {
  155. for (var i = 0; i < helpers.length; ++i) {
  156. this.logData.push({
  157. Type: helpers[i].Type,
  158. Description: helpers[i].IPAddress ? "//" + helpers[i].IPAddress + helpers[i].Name : helpers[i].Name,
  159. Orig: helpers[i]
  160. });
  161. }
  162. },
  163. loadThorLogInfo: function (thorLogInfo) {
  164. for (var i = 0; i < thorLogInfo.length; ++i) {
  165. for (var j = 0; j < thorLogInfo[i].NumberSlaves; ++j) {
  166. this.logData.push({
  167. Type: "ThorSlaveLog",
  168. Description: thorLogInfo[i].ClusterGroup + "." + thorLogInfo[i].LogDate + ".log (slave " + (j + 1) + " of " + thorLogInfo[i].NumberSlaves + ")",
  169. Orig: lang.mixin({
  170. SlaveNumber: j + 1
  171. }, thorLogInfo[i])
  172. });
  173. }
  174. }
  175. }
  176. });
  177. });