run.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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
  7. * "License"); 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. var App = require('app');
  19. var date = require('utils/date');
  20. var misc = require('utils/misc');
  21. App.Run = DS.Model.extend({
  22. runId:DS.attr('string'),
  23. parentRunId:DS.attr('string'),
  24. workflowId:DS.attr('string'),
  25. userName:DS.attr('string'),
  26. startTime:DS.attr('string'),
  27. elapsedTime:DS.attr('string'),
  28. appId:DS.attr('string'),
  29. /**
  30. *
  31. */
  32. /*workflowContext:function() {
  33. var r = '{dag: {';
  34. console.log('entries', this.get('entries'));
  35. this.get('entries').forEach(function(item) {
  36. r += '"' + item.source + '": [';
  37. item.targets.forEach(function(target) {
  38. r += '"' + target + '",';
  39. });
  40. r += '],';
  41. });
  42. r += '}}';
  43. console.log('dag', r);
  44. return r;
  45. }.property('entries'),*/
  46. workflowContext:DS.attr('string'),
  47. /**
  48. * Jobs in the current run
  49. */
  50. jobs: function() {
  51. var self = this;
  52. var r = Array();
  53. App.Job.find().forEach(function(job) {
  54. if (job.get('workflowId') == self.get('workflowId')) {
  55. r.push(job);
  56. }
  57. });
  58. return r;
  59. }.property('workflowId'),
  60. /**
  61. * Number of comleted jobs.
  62. * Field calculates dynamically using <code>jobs</code> property
  63. */
  64. numJobsCompleted: function() {
  65. return this.get('jobs').filterProperty('status', 'RUNNING').length;
  66. }.property('jobs.@each.status'),
  67. /**
  68. * Sum of the child jobs duration
  69. */
  70. duration: function() {
  71. var d = 0;
  72. this.get('jobs').forEach(function(job) {
  73. d += job.get('elapsedTime') / 1000 || 0;
  74. });
  75. return date.dateFormatInterval(parseInt(d));
  76. }.property('lastUpdateTime', 'startTime'),
  77. /**
  78. * Status of running jobs
  79. * Field calculates dynamically using <code>jobs</code> property
  80. */
  81. isRunning: function () {
  82. if (!this.get('isLoaded')) {
  83. return false;
  84. }
  85. return this.get('jobs').someProperty('status', 'RUNNING');
  86. }.property('jobs.@each.status'),
  87. /**
  88. * Sum of input bandwidth for all jobs
  89. * Field calculates dynamically using <code>jobs</code> property
  90. */
  91. input: function () {
  92. var sum = 0;
  93. this.get('jobs').forEach(
  94. function(item) {
  95. sum += item.get('input') || 0;
  96. });
  97. return sum;
  98. }.property('jobs.@each.input'),
  99. /**
  100. * Sum of input bandwidth for all jobs with appropriate measure
  101. * Field calculates dynamically using <code>jobs</code> property
  102. */
  103. inputFormatted: function () {
  104. var input = this.get('input');
  105. input = misc.formatBandwidth(input);
  106. return input;
  107. }.property('input'),
  108. /**
  109. * Sum of output bandwidth for all jobs
  110. * Field calculates dynamically using <code>jobs</code> property
  111. */
  112. output: function () {
  113. var sum = 0;
  114. this.get('jobs').forEach(
  115. function(item){
  116. sum += item.get('output') || 0;
  117. });
  118. return sum;
  119. }.property('jobs.@each.output'),
  120. /**
  121. * Sum of output bandwidth for all jobs with appropriate measure
  122. * Field calculates dynamically using <code>jobs</code> property
  123. */
  124. outputFormatted: function () {
  125. var output = this.get('output');
  126. output = misc.formatBandwidth(output);
  127. return output;
  128. }.property('output'),
  129. /**
  130. * Number of jobs on this run
  131. * Field calculates dynamically using <code>jobs</code> property
  132. */
  133. numJobsTotal: function() {
  134. return this.get('jobs').length;
  135. }.property('jobs'),
  136. /**
  137. *
  138. */
  139. lastUpdateTime: function() {
  140. return parseInt(this.get('startTime')) + parseInt(this.get('elapsedTime'));
  141. }.property('elapsedTime', 'startTime'),
  142. /**
  143. *
  144. */
  145. lastUpdateTimeFormatted: function() {
  146. return date.dateFormat(this.get('lastUpdateTime'));
  147. }.property('lastUpdateTime')
  148. });
  149. App.Run.FIXTURES = [
  150. /*{
  151. id:1,
  152. run_id:'pig_1',
  153. parent_run_id:null,
  154. workflow_context:'{dag: {"1":["2","3"],"2":["3","4"],"4":["2","5"]}}',
  155. user_name:'user3',
  156. start_time:1347539541501,
  157. last_update_time:'1347639541501',
  158. app_id:1,
  159. jobs:[1, 2, 3, 4, 5]
  160. },
  161. {
  162. id:2,
  163. run_id:'pig_3',
  164. parent_run_id:null,
  165. workflow_context:'{dag:{"4":["5","1"],"3":["6"],"6":["4"],"1":["5"]}}',
  166. user_name:'user1',
  167. start_time:1347339951502,
  168. last_update_time:'1347439951502',
  169. app_id:4,
  170. jobs:[4, 5, 1, 3, 6]
  171. },
  172. {
  173. id:3,
  174. run_id:'pig_5',
  175. parent_run_id:null,
  176. workflow_context:'{dag:{"6":["7","8"],"9":["8"],"10":["6"],"9":["7"]}}',
  177. user_name:'user2',
  178. start_time:1341539841503,
  179. last_update_time:'1341639841503',
  180. app_id:1,
  181. jobs:[6, 7, 8, 9, 10]
  182. },
  183. {
  184. id:4,
  185. run_id:'pig_5',
  186. parent_run_id:null,
  187. workflow_context:'{dag:{"8":["9","10"],"9":["10"]}}',
  188. user_name:'user1',
  189. start_time:1347539591504,
  190. last_update_time:'1347639591504',
  191. num_jobs_completed:0,
  192. app_id:2,
  193. jobs:[8, 9, 10]
  194. },
  195. {
  196. id:5,
  197. run_id:'pig_5',
  198. parent_run_id:null,
  199. workflow_context:'{dag:{"8":["9","10"],"8":["10","9"]}}',
  200. user_name:'user5',
  201. start_time:1347531541505,
  202. last_update_time:'1347631541505',
  203. app_id:2,
  204. jobs:[8, 9, 10]
  205. },
  206. {
  207. id:6,
  208. run_id:'pig_5',
  209. parent_run_id:null,
  210. workflow_context:'{dag:{"8":["9","10"],"9":["10","8"]}}',
  211. user_name:'user1',
  212. start_time:1342439541506,
  213. last_update_time:'1342639541506',
  214. app_id:2,
  215. jobs:[8, 9, 10]
  216. },
  217. {
  218. id:7,
  219. run_id:'pig_5',
  220. parent_run_id:null,
  221. workflow_context:'{dag:{"1":["3","5"],"5":["7"],"3":["1"]}}',
  222. user_name:'jsmith',
  223. start_time:1347539541507,
  224. last_update_time:'1347639541507',
  225. app_id:4,
  226. jobs:[1, 3, 5, 7]
  227. },
  228. {
  229. id:8,
  230. run_id:'pig_5',
  231. parent_run_id:null,
  232. workflow_context:'{dag:{"1":["3","5"],"5":["7"],"3":["1"]}}',
  233. user_name:'jsmith',
  234. start_time:1347539541508,
  235. last_update_time:'1347639541508',
  236. app_id:3,
  237. jobs:[1, 3, 5, 7]
  238. },
  239. {
  240. id:9,
  241. run_id:'pig_5',
  242. parent_run_id:null,
  243. workflow_context:'{dag:{"1":["3","5"],"5":["7"],"3":["1"]}}',
  244. user_name:'user1',
  245. start_time:1347539541509,
  246. last_update_time:'1347639541509',
  247. app_id:3,
  248. jobs:[1, 3, 5, 7]
  249. },
  250. {
  251. id:10,
  252. run_id:'pig_5',
  253. parent_run_id:null,
  254. workflow_context:'{dag:{"1":["3","5"],"5":["7"],"3":["1"]}}',
  255. user_name:'user1',
  256. start_time:1347539541510,
  257. last_update_time:'1347639541510',
  258. app_id:3,
  259. jobs:[1, 3, 5, 7]
  260. },
  261. {
  262. id:11,
  263. run_id:'pig_5',
  264. parent_run_id:null,
  265. workflow_context:'{dag:{"1":["3","5"],"5":["7"],"3":["1"]}}',
  266. user_name:'user1',
  267. start_time:1347539541511,
  268. last_update_time:'1347639541511',
  269. app_id:3,
  270. jobs:[1, 3, 5, 7]
  271. }*/
  272. ];