LogsWidget.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. }
  106. var url = this.wu.getBaseURL() + params + (option ? "&Option=" + option : "&Option=1");
  107. iframe.setSrc(frame, url, true);
  108. }
  109. },
  110. _onDownload: function (args) {
  111. this._doDownload(1);
  112. },
  113. _onDownloadZip: function (args) {
  114. this._doDownload(2);
  115. },
  116. _onDownloadGZip: function (args) {
  117. this._doDownload(3);
  118. },
  119. // Plugin wrapper ---
  120. init: function (params) {
  121. this.wu = new ESPWorkunit({
  122. wuid: params.Wuid
  123. });
  124. var context = this;
  125. this.wu.monitor(function () {
  126. context.wu.getInfo({
  127. onGetAll: function (response) {
  128. context.logData = [];
  129. if (response.Helpers && response.Helpers.ECLHelpFile) {
  130. context.loadHelpers(response.Helpers.ECLHelpFile);
  131. }
  132. if (response.ThorLogList && response.ThorLogList.ThorLogInfo) {
  133. context.loadThorLogInfo(response.ThorLogList.ThorLogInfo);
  134. }
  135. var memory = new Memory({ data: context.logData });
  136. var store = new ObjectStore({ objectStore: memory });
  137. context.logsGrid.setStore(store);
  138. context.logsGrid.setQuery({
  139. Type: "*"
  140. });
  141. }
  142. });
  143. });
  144. },
  145. loadHelpers: function (helpers) {
  146. for (var i = 0; i < helpers.length; ++i) {
  147. this.logData.push({
  148. Type: helpers[i].Type,
  149. Description: helpers[i].IPAddress ? "//" + helpers[i].IPAddress + helpers[i].Name : helpers[i].Name,
  150. Orig: helpers[i]
  151. });
  152. }
  153. },
  154. loadThorLogInfo: function (thorLogInfo) {
  155. for (var i = 0; i < thorLogInfo.length; ++i) {
  156. for (var j = 0; j < thorLogInfo[i].NumberSlaves; ++j) {
  157. this.logData.push({
  158. Type: "ThorSlaveLog",
  159. Description: thorLogInfo[i].ClusterGroup + "." + thorLogInfo[i].LogDate + ".log (slave " + (j + 1) + " of " + thorLogInfo[i].NumberSlaves + ")",
  160. Orig: lang.mixin({
  161. SlaveNumber: j + 1
  162. }, thorLogInfo[i])
  163. });
  164. }
  165. }
  166. }
  167. });
  168. });