logs.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. import Ember from 'ember';
  19. export default Ember.Controller.extend({
  20. queryParams: ["service"],
  21. service: undefined,
  22. selectedAttemptId: "",
  23. attemptContainerList: null,
  24. selectedContainerId: "",
  25. selectedLogFileName: "",
  26. containerLogFiles: null,
  27. selectedLogFileContent: "",
  28. _isLoadingTopPanel: false,
  29. _isLoadingBottomPanel: false,
  30. initializeSelect: function(selector = ".js-fetch-attempt-containers") {
  31. Ember.run.schedule("afterRender", this, function() {
  32. $(selector).select2({ width: "350px", multiple: false });
  33. });
  34. },
  35. actions: {
  36. showContainersForAttemptId(attemptId) {
  37. this.set("selectedAttemptId", "");
  38. if (attemptId) {
  39. this.set("_isLoadingTopPanel", true);
  40. this.set("selectedAttemptId", attemptId);
  41. this.fetchContainersForAttemptId(attemptId)
  42. .then(hash => {
  43. let containers = null;
  44. let containerIdArr = [];
  45. if (
  46. hash.rmContainers.get("length") > 0 &&
  47. hash.rmContainers.get("content")
  48. ) {
  49. hash.rmContainers.get("content").forEach(function(o) {
  50. containerIdArr.push(o.id);
  51. }.bind(this));
  52. containers = (containers || []).concat(
  53. hash.rmContainers.get("content")
  54. );
  55. }
  56. if (
  57. hash.tsContainers.get("length") > 0 &&
  58. hash.tsContainers.get("content")
  59. ) {
  60. let tscontainer = [];
  61. hash.tsContainers.get("content").forEach(function(o) {
  62. if(!containerIdArr.contains(o.id)) {
  63. tscontainer.push(o);
  64. }
  65. }.bind(this));
  66. containers = (containers || []).concat(
  67. tscontainer);
  68. }
  69. this.set("attemptContainerList", containers);
  70. this.initializeSelect(".js-fetch-logs-containers");
  71. })
  72. .finally(() => {
  73. this.set("_isLoadingTopPanel", false);
  74. });
  75. } else {
  76. this.set("attemptContainerList", null);
  77. this.set("selectedContainerId", "");
  78. this.set("containerLogFiles", null);
  79. this.set("selectedLogFileName", "");
  80. this.set("selectedLogFileContent", "");
  81. }
  82. },
  83. showLogFilesForContainerId(containerId) {
  84. this.set("selectedContainerId", "");
  85. this.set("containerLogFiles", null);
  86. this.set("selectedLogFileName", "");
  87. this.set("selectedLogFileContent", "");
  88. if (containerId) {
  89. this.set("_isLoadingBottomPanel", true);
  90. this.set("selectedContainerId", containerId);
  91. this.fetchLogFilesForContainerId(containerId)
  92. .then(hash => {
  93. if (hash.logs.get("length") > 0) {
  94. this.set("containerLogFiles", hash.logs);
  95. } else {
  96. this.set("containerLogFiles", null);
  97. }
  98. this.initializeSelect(".js-fetch-log-for-container");
  99. })
  100. .finally(() => {
  101. this.set("_isLoadingBottomPanel", false);
  102. });
  103. }
  104. },
  105. showContentForLogFile(logFile) {
  106. this.set("selectedLogFileName", "");
  107. Ember.$("#logContentTextArea1234554321").val("");
  108. this.set("showFullLog", false);
  109. if (logFile) {
  110. this.set("_isLoadingBottomPanel", true);
  111. this.set("selectedLogFileName", logFile);
  112. this.fetchContentForLogFile(this.get("selectedContainerId"), logFile)
  113. .then(
  114. content => {
  115. this.set("selectedLogFileContent", content.trim());
  116. },
  117. () => {
  118. this.set("selectedLogFileContent", "");
  119. }
  120. )
  121. .always(() => {
  122. this.set("_isLoadingBottomPanel", false);
  123. });
  124. } else {
  125. this.set("selectedLogFileContent", "");
  126. }
  127. },
  128. findNextTextInLogContent() {
  129. let searchInputElem = document.getElementById("logSeachInput98765");
  130. this.send("searchTextInLogContent", searchInputElem.value);
  131. },
  132. searchTextInLogContent(searchText) {
  133. Ember.$("body").scrollTop(278);
  134. let textAreaElem = document.getElementById(
  135. "logContentTextArea1234554321"
  136. );
  137. let logContent = textAreaElem.innerText;
  138. let startIndex = this.searchTextStartIndex || 0;
  139. if (startIndex === -1) {
  140. startIndex = this.searchTextStartIndex = 0;
  141. }
  142. if (this.prevSearchText !== searchText) {
  143. startIndex = this.searchTextStartIndex = 0;
  144. }
  145. if (searchText && searchText.trim()) {
  146. searchText = searchText.trim();
  147. this.prevSearchText = searchText;
  148. if (startIndex === 0) {
  149. startIndex = logContent.indexOf(searchText, 0);
  150. }
  151. let endIndex = startIndex + searchText.length;
  152. if (document.createRange && window.getSelection) {
  153. let range = document.createRange();
  154. range.selectNodeContents(textAreaElem);
  155. range.setStart(textAreaElem.childNodes.item(0), startIndex);
  156. range.setEnd(textAreaElem.childNodes.item(0), endIndex);
  157. let selection = window.getSelection();
  158. selection.removeAllRanges();
  159. selection.addRange(range);
  160. }
  161. this.searchTextStartIndex = logContent.indexOf(
  162. searchText,
  163. endIndex + 1
  164. );
  165. } else {
  166. this.searchTextStartIndex = 0;
  167. }
  168. },
  169. showFullLogFileContent() {
  170. this.set("showFullLog", true);
  171. this.notifyPropertyChange("selectedLogFileContent");
  172. }
  173. },
  174. attemptList: Ember.computed("model.attempts", function() {
  175. let attempts = this.get("model.attempts");
  176. let list = null;
  177. if (attempts && attempts.get("length") && attempts.get("content")) {
  178. list = [].concat(attempts.get("content"));
  179. }
  180. return list;
  181. }),
  182. fetchContainersForAttemptId(attemptId) {
  183. return Ember.RSVP.hash({
  184. rmContainers: this.store
  185. .query("yarn-container", {
  186. app_attempt_id: attemptId
  187. })
  188. .catch(function() {
  189. return Ember.A();
  190. }),
  191. tsContainers: this.store
  192. .query("yarn-timeline-container", {
  193. app_attempt_id: attemptId
  194. })
  195. .catch(function() {
  196. return Ember.A();
  197. })
  198. });
  199. },
  200. fetchLogFilesForContainerId(containerId) {
  201. return Ember.RSVP.hash({
  202. logs: this.store
  203. .query("yarn-log", {
  204. containerId: containerId
  205. })
  206. .catch(function() {
  207. return Ember.A();
  208. })
  209. });
  210. },
  211. fetchContentForLogFile(containerId, logFile) {
  212. let logAdapter = this.store.adapterFor("yarn-log");
  213. return logAdapter.fetchLogFileContent(containerId, logFile);
  214. },
  215. resetAfterRefresh() {
  216. this.set("selectedAttemptId", "");
  217. this.set("attemptContainerList", null);
  218. this.set("selectedContainerId", "");
  219. this.set("selectedLogFileName", "");
  220. this.set("containerLogFiles", null);
  221. this.set("selectedLogFileContent", "");
  222. },
  223. showFullLog: false,
  224. showLastFewLinesOfLogContent: Ember.computed(
  225. "selectedLogFileContent",
  226. function() {
  227. let content = this.get("selectedLogFileContent");
  228. let lines = content.split("\n");
  229. if (this.get("showFullLog") || lines.length < 10) {
  230. return content;
  231. }
  232. return lines.slice(lines.length - 10).join("\n");
  233. }
  234. )
  235. });