jobs.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. var App = require('app');
  18. module.exports = {
  19. /**
  20. * Refreshes the latest information for a given job
  21. *
  22. * @param {App.AbstractJob}
  23. * job
  24. * @param {Function}
  25. * successCallback
  26. */
  27. refreshJobDetails : function(job, successCallback) {
  28. this.refreshHiveJobDetails(job, successCallback);
  29. },
  30. /**
  31. * Refreshes latest information of a Hive Job.
  32. *
  33. * @param {App.HiveJob}
  34. * hiveJob
  35. * @param {Function}
  36. * successCallback
  37. */
  38. refreshHiveJobDetails : function(hiveJob, successCallback) {
  39. var self = this;
  40. // TODO - to be changed to history server when implemented in stack.
  41. var yarnService = App.YARNService.find().objectAt(0);
  42. var historyServerHostName = yarnService.get('resourceManagerNode.hostName');
  43. var ahsWebPort = yarnService.get('ahsWebPort');
  44. var hiveJobId = hiveJob.get('id');
  45. // First refresh query
  46. var hiveQueriesUrl = App.testMode ? "/data/jobs/hive-query-2.json" : "/proxy?url=http://" + historyServerHostName
  47. + ":" + ahsWebPort + "/ws/v1/timeline/HIVE_QUERY_ID/" + hiveJob.get('id') + "?fields=otherinfo";
  48. App.HttpClient.get(hiveQueriesUrl, App.hiveJobMapper, {
  49. complete : function(jqXHR, textStatus) {
  50. // Now get the Tez DAG ID from the DAG name
  51. var hiveRecord = App.HiveJob.find(hiveJobId);
  52. App.router.get('mainHiveJobDetailsController').set('job', hiveRecord);
  53. var tezDagName = hiveRecord.get('tezDag.name');
  54. if (tezDagName != null) {
  55. var sender = {
  56. dagNameToIdSuccess : function(data) {
  57. if (data && data.entities && data.entities.length > 0) {
  58. var dagId = data.entities[0].entity;
  59. App.TezDag.find(tezDagName).set('instanceId', dagId);
  60. self.refreshTezDagDetails(tezDagName, successCallback);
  61. }else{
  62. App.showAlertPopup(Em.I18n.t('jobs.hive.tez.dag.error.noDagId.title'), Em.I18n.t('jobs.hive.tez.dag.error.noDagId.message').format(hiveJobId));
  63. }
  64. },
  65. dagNameToIdError : function(jqXHR, url, method, showStatus) {
  66. App.ajax.defaultErrorHandler(jqXHR, url, method, showStatus);
  67. }
  68. }
  69. App.ajax.send({
  70. name : 'jobs.tezDag.NametoID',
  71. sender : sender,
  72. data : {
  73. historyServerHostName : historyServerHostName,
  74. tezDagName : tezDagName,
  75. ahsWebPort: ahsWebPort
  76. },
  77. success : 'dagNameToIdSuccess',
  78. error : 'dagNameToIdError'
  79. });
  80. } else {
  81. App.showAlertPopup(Em.I18n.t('jobs.hive.tez.dag.error.noDag.title'), Em.I18n.t('jobs.hive.tez.dag.error.noDag.message').format(hiveJobId));
  82. }
  83. }
  84. });
  85. },
  86. /**
  87. * Refreshes runtime information of a Tez DAG based on events generated. The
  88. * instance ID of the Tez DAG should be set.
  89. *
  90. * @param {string}
  91. * tezDagId ID of the Tez DAG. Example: 'HIVE-Q2:1'
  92. * @param {Function}
  93. * successCallback
  94. */
  95. refreshTezDagDetails : function(tezDagId, successCallback) {
  96. var self = this;
  97. var yarnService = App.YARNService.find().objectAt(0);
  98. var ahsWebPort = yarnService.get('ahsWebPort');
  99. var historyServerHostName = yarnService.get('resourceManagerNode.hostName');
  100. var tezDag = App.TezDag.find(tezDagId);
  101. if (tezDag) {
  102. var tezDagInstanceId = tezDag.get('instanceId');
  103. var sender = {
  104. loadTezDagSuccess : function(data) {
  105. if (data && data.relatedentities && data.relatedentities.TEZ_VERTEX_ID != null) {
  106. var count = data.relatedentities.TEZ_VERTEX_ID.length;
  107. data.relatedentities.TEZ_VERTEX_ID.forEach(function(v) {
  108. self.refreshTezDagVertex(tezDagId, v, function() {
  109. if (--count <= 0) {
  110. // all vertices succeeded
  111. successCallback();
  112. }
  113. });
  114. });
  115. }
  116. },
  117. loadTezDagError : function(jqXHR, url, method, showStatus) {
  118. App.ajax.defaultErrorHandler(jqXHR, url, method, showStatus);
  119. }
  120. }
  121. App.ajax.send({
  122. name : 'jobs.tezDag.tezDagId',
  123. sender : sender,
  124. data : {
  125. historyServerHostName : historyServerHostName,
  126. tezDagId : tezDagInstanceId,
  127. ahsWebPort: ahsWebPort
  128. },
  129. success : 'loadTezDagSuccess',
  130. error : 'loadTezDagError'
  131. });
  132. }else{
  133. App.showAlertPopup(Em.I18n.t('jobs.hive.tez.dag.error.noDagForId.title'), Em.I18n.t('jobs.hive.tez.dag.error.noDagForId.message').format(tezDagId));
  134. }
  135. },
  136. /**
  137. * Refreshes runtime information of the given vertex.
  138. *
  139. * @param {string}
  140. * tezDagId ID of the Tez DAG. Exmaple: 'HIVE-Q2:1'
  141. * @param {string}
  142. * tezVertexInstanceID Instance ID of the vertex to refresh. Example
  143. * 'vertex_1390516007863_0001_1_00'
  144. * @param {Function}
  145. * successCallback
  146. */
  147. refreshTezDagVertex : function(tezDagId, tezVertexInstanceId, successCallback) {
  148. var yarnService = App.YARNService.find().objectAt(0);
  149. var ahsWebPort = yarnService.get('ahsWebPort');
  150. var historyServerHostName = yarnService.get('resourceManagerNode.hostName');
  151. var sender = {
  152. loadTezDagVertexSuccess : function(data) {
  153. if (data && data.otherinfo) {
  154. var vertexRecord = App.TezDagVertex.find(tezDagId + "/" + data.otherinfo.vertexName);
  155. if (vertexRecord != null) {
  156. vertexRecord.set('startTime', data.otherinfo.startTime);
  157. vertexRecord.set('endTime', data.otherinfo.endTime);
  158. vertexRecord.set('tasksCount', data.otherinfo.numTasks);
  159. vertexRecord.set('state', data.otherinfo.status);
  160. if (data.otherinfo.counters && data.otherinfo.counters.counterGroups) {
  161. data.otherinfo.counters.counterGroups.forEach(function(cGroup) {
  162. var cNameToPropetyMap = {};
  163. switch (cGroup.counterGroupName) {
  164. case 'org.apache.tez.common.counters.FileSystemCounter':
  165. cNameToPropetyMap = {
  166. 'FILE_BYTES_READ' : 'fileReadBytes',
  167. 'FILE_BYTES_WRITTEN' : 'fileWriteBytes',
  168. 'FILE_READ_OPS' : 'fileReadOps',
  169. 'FILE_WRITE_OPS' : 'fileWriteOps',
  170. 'HDFS_BYTES_READ' : 'hdfsReadBytes',
  171. 'HDFS_BYTES_WRITTEN' : 'hdfsWriteBytes',
  172. 'HDFS_READ_OPS' : 'hdfsReadOps',
  173. 'HDFS_WRITE_OPS' : 'hdfsWriteOps'
  174. };
  175. break;
  176. case 'HIVE':
  177. cNameToPropetyMap = {
  178. 'RECORDS_READ' : 'recordReadCount',
  179. 'RECORDS_WRITE' : 'recordWriteCount'
  180. };
  181. break;
  182. default:
  183. break;
  184. }
  185. if (cGroup.counters) {
  186. cGroup.counters.forEach(function(counter) {
  187. var prop = cNameToPropetyMap[counter.counterName];
  188. if (prop != null) {
  189. vertexRecord.set(prop, counter.counterValue);
  190. }
  191. });
  192. }
  193. });
  194. }
  195. successCallback();
  196. }
  197. }
  198. },
  199. loadTezDagVertexError : function(jqXHR, url, method, showStatus) {
  200. App.ajax.defaultErrorHandler(jqXHR, url, method, showStatus);
  201. }
  202. }
  203. App.ajax.send({
  204. name : 'jobs.tezDag.tezDagVertexId',
  205. sender : sender,
  206. data : {
  207. historyServerHostName : historyServerHostName,
  208. tezDagVertexId : tezVertexInstanceId,
  209. ahsWebPort: ahsWebPort
  210. },
  211. success : 'loadTezDagVertexSuccess',
  212. error : 'loadTezDagVertexError'
  213. });
  214. }
  215. };