jobs.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. if (job) {
  29. switch (job.get('jobType')) {
  30. case App.JobType.HIVE:
  31. this.refreshHiveJobDetails(job, successCallback);
  32. break;
  33. default:
  34. break;
  35. }
  36. }
  37. },
  38. /**
  39. * Refreshes latest information of a Hive Job.
  40. *
  41. * @param {App.HiveJob}
  42. * hiveJob
  43. * @param {Function}
  44. * successCallback
  45. */
  46. refreshHiveJobDetails : function(hiveJob, successCallback) {
  47. var self = this;
  48. // TODO - to be changed to history server when implemented in stack.
  49. var historyServerHostName = App.YARNService.find().objectAt(0).get('resourceManagerNode.hostName')
  50. var hiveJobId = hiveJob.get('id');
  51. // First refresh query
  52. var hiveQueriesUrl = App.testMode ? "/data/jobs/hive-query-2.json" : "/proxy?url=http://" + historyServerHostName
  53. + ":8188/ws/v1/apptimeline/HIVE_QUERY_ID/" + hiveJob.get('id') + "?fields=otherinfo";
  54. App.HttpClient.get(hiveQueriesUrl, App.hiveJobMapper, {
  55. complete : function(jqXHR, textStatus) {
  56. // Now get the Tez DAG ID from the DAG name
  57. var hiveRecord = App.HiveJob.find(hiveJobId);
  58. var tezDagName = hiveRecord.get('tezDag.name');
  59. if (tezDagName != null) {
  60. var sender = {
  61. dagNameToIdSuccess : function(data) {
  62. if (data && data.entities && data.entities.length > 0) {
  63. var dagId = data.entities[0].entity;
  64. App.TezDag.find(tezDagName).set('instanceId', dagId);
  65. self.refreshTezDagDetails(tezDagName, successCallback);
  66. }else{
  67. App.showAlertPopup(Em.I18n.t('jobs.hive.tez.dag.error.noDagId.title'), Em.I18n.t('jobs.hive.tez.dag.error.noDagId.message').format(hiveJobId));
  68. }
  69. },
  70. dagNameToIdError : function(jqXHR, url, method, showStatus) {
  71. App.ajax.defaultErrorHandler(jqXHR, url, method, showStatus);
  72. }
  73. }
  74. App.ajax.send({
  75. name : 'jobs.tezDag.NametoID',
  76. sender : sender,
  77. data : {
  78. historyServerHostName : historyServerHostName,
  79. tezDagName : tezDagName
  80. },
  81. success : 'dagNameToIdSuccess',
  82. error : 'dagNameToIdError'
  83. });
  84. } else {
  85. App.showAlertPopup(Em.I18n.t('jobs.hive.tez.dag.error.noDag.title'), Em.I18n.t('jobs.hive.tez.dag.error.noDag.message').format(hiveJobId));
  86. }
  87. }
  88. });
  89. },
  90. /**
  91. * Refreshes runtime information of a Tez DAG based on events generated. The
  92. * instance ID of the Tez DAG should be set.
  93. *
  94. * @param {string}
  95. * tezDagId ID of the Tez DAG. Example: 'HIVE-Q2:1'
  96. * @param {Function}
  97. * successCallback
  98. */
  99. refreshTezDagDetails : function(tezDagId, successCallback) {
  100. var self = this;
  101. var historyServerHostName = App.YARNService.find().objectAt(0).get('resourceManagerNode.hostName');
  102. var tezDag = App.TezDag.find(tezDagId);
  103. if (tezDag) {
  104. var tezDagInstanceId = tezDag.get('instanceId');
  105. var sender = {
  106. loadTezDagSuccess : function(data) {
  107. if (data && data.relatedentities && data.relatedentities.TEZ_VERTEX_ID != null) {
  108. var count = data.relatedentities.TEZ_VERTEX_ID.length;
  109. data.relatedentities.TEZ_VERTEX_ID.forEach(function(v) {
  110. self.refreshTezDagVertex(tezDagId, v, function() {
  111. if (--count <= 0) {
  112. // all vertices succeeded
  113. successCallback();
  114. }
  115. });
  116. });
  117. }
  118. },
  119. loadTezDagError : function(jqXHR, url, method, showStatus) {
  120. App.ajax.defaultErrorHandler(jqXHR, url, method, showStatus);
  121. }
  122. }
  123. App.ajax.send({
  124. name : 'jobs.tezDag.tezDagId',
  125. sender : sender,
  126. data : {
  127. historyServerHostName : historyServerHostName,
  128. tezDagId : tezDagInstanceId
  129. },
  130. success : 'loadTezDagSuccess',
  131. error : 'loadTezDagError'
  132. });
  133. }else{
  134. App.showAlertPopup(Em.I18n.t('jobs.hive.tez.dag.error.noDagForId.title'), Em.I18n.t('jobs.hive.tez.dag.error.noDagForId.message').format(tezDagId));
  135. }
  136. },
  137. /**
  138. * Refreshes runtime information of the given vertex.
  139. *
  140. * @param {string}
  141. * tezDagId ID of the Tez DAG. Exmaple: 'HIVE-Q2:1'
  142. * @param {string}
  143. * tezVertexInstanceID Instance ID of the vertex to refresh. Example
  144. * 'vertex_1390516007863_0001_1_00'
  145. * @param {Function}
  146. * successCallback
  147. */
  148. refreshTezDagVertex : function(tezDagId, tezVertexInstanceId, successCallback) {
  149. var historyServerHostName = App.YARNService.find().objectAt(0).get('resourceManagerNode.hostName');
  150. var sender = {
  151. loadTezDagVertexSuccess : function(data) {
  152. if (data && data.otherinfo) {
  153. var vertexRecord = App.TezDagVertex.find(tezDagId + "/" + data.otherinfo.vertexName);
  154. if (vertexRecord != null) {
  155. vertexRecord.set('startTime', data.otherinfo.startTime);
  156. vertexRecord.set('endTime', data.otherinfo.startTime + +data.otherinfo.timeTaken);
  157. vertexRecord.set('tasksCount', data.otherinfo.numTasks);
  158. vertexRecord.set('state', data.otherinfo.status);
  159. // TODO Need additional vertex metrics
  160. vertexRecord.set('fileReadBytes', 0);
  161. vertexRecord.set('fileReadOps', 0);
  162. vertexRecord.set('fileWriteOps', 0);
  163. vertexRecord.set('fileWriteBytes', 0);
  164. vertexRecord.set('hdfsReadOps', 0);
  165. vertexRecord.set('hdfsReadBytes', 0);
  166. vertexRecord.set('hdfsWriteOps', 0);
  167. vertexRecord.set('hdfsWriteBytes', 0);
  168. vertexRecord.set('recordReadCount', 0);
  169. vertexRecord.set('recordWriteCount', 0);
  170. successCallback();
  171. }
  172. }
  173. },
  174. loadTezDagVertexError : function(jqXHR, url, method, showStatus) {
  175. App.ajax.defaultErrorHandler(jqXHR, url, method, showStatus);
  176. }
  177. }
  178. App.ajax.send({
  179. name : 'jobs.tezDag.tezDagVertexId',
  180. sender : sender,
  181. data : {
  182. historyServerHostName : historyServerHostName,
  183. tezDagVertexId : tezVertexInstanceId
  184. },
  185. success : 'loadTezDagVertexSuccess',
  186. error : 'loadTezDagVertexError'
  187. });
  188. }
  189. };