jobs_mapper.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 fillEmptyValues = function(self, obj) {
  20. $.each(self.config, function(field, value) {
  21. if (obj[value].length == 0) {
  22. obj[value].push({x: 0, y: 0});
  23. };
  24. });
  25. };
  26. App.jobsMapper = App.QuickDataMapper.create({
  27. model:App.Job,
  28. map:function (json) {
  29. if (!this.get('model')) {
  30. return;
  31. }
  32. if (json.jobs) {
  33. var result = [];
  34. json.jobs.forEach(function (item) {
  35. result.push(this.parseIt(item, this.config));
  36. }, this);
  37. var r = Ember.ArrayProxy.create({"content":[]});
  38. result.forEach(function(item){
  39. r.content.push(App.Job2.create(item));
  40. });
  41. this.set('controller.content.jobs', r.content);
  42. }
  43. },
  44. config:{
  45. id:'jobId',
  46. run_id:'workflowId',
  47. job_name:'jobName',
  48. workflow_entity_name:'workflowEntityName',
  49. user_name:'userName',
  50. submit_time:'submitTime',
  51. maps:'maps',
  52. reduces:'reduces',
  53. status:'status',
  54. input:'inputBytes',
  55. output:'outputBytes',
  56. elapsed_time:'elapsedTime'
  57. }
  58. });
  59. App.jobTimeLineMapper = App.QuickDataMapper.create({
  60. model: null, //model will be set outside of mapper
  61. config:{
  62. map:'map',
  63. shuffle:'shuffle',
  64. reduce:'reduce'
  65. },
  66. map:function (json) {
  67. var job = this.get('model'); // @model App.MainAppsItemBarView
  68. var parseResult = this.parseIt(json, this.config);
  69. var self = this;
  70. $.each(parseResult, function (field, value) {
  71. var d = self.coordinatesModify(value);
  72. d.reverse();
  73. d = self.coordinatesModify(d);
  74. d.reverse();
  75. job.set(field, d);
  76. });
  77. fillEmptyValues(this, job);
  78. },
  79. coordinatesModify: function(data) {
  80. var d = this.zeroAdding(data);
  81. d.reverse();
  82. d = this.zeroAdding(d);
  83. d.reverse();
  84. return d;
  85. },
  86. zeroAdding: function(data) {
  87. var d = [];
  88. var last_y = 0;
  89. data.forEach(function(coordinates) {
  90. if (coordinates.y != 0 && last_y == 0) {
  91. d.push({x: coordinates.x, y: 0});
  92. }
  93. d.push(coordinates);
  94. last_y = coordinates.y;
  95. });
  96. return d;
  97. }
  98. });
  99. App.taskTimeLineMapper = App.QuickDataMapper.create({
  100. model: null, //model will be set outside of mapper
  101. config:{
  102. allmap:'map',
  103. allshuffle:'shuffle',
  104. allreduce:'reduce'
  105. },
  106. map:function (json) {
  107. var job = this.get('model'); // @model App.MainAppsItemBarView
  108. var parseResult = this.parseIt(json, this.config);
  109. $.each(parseResult, function (field, value) {
  110. job.set(field, value);
  111. });
  112. fillEmptyValues(this, job);
  113. }
  114. });
  115. App.jobTasksMapper = App.QuickDataMapper.create({
  116. model: null, //model will be set outside of mapper
  117. config:{
  118. mapNodeLocal:'mapNodeLocal',
  119. mapRackLocal:'mapRackLocal',
  120. mapOffSwitch:'mapOffSwitch',
  121. reduceOffSwitch:'reduceOffSwitch',
  122. submit:'submitTime',
  123. finish:'finishTime'
  124. },
  125. map:function (json) {
  126. var job = this.get('model'); // @model App.MainAppsItemBarView
  127. var parseResult = this.parseIt(json, this.config);
  128. $.each(parseResult, function (field, value) {
  129. job.set(field, value);
  130. });
  131. }
  132. });