1
0

metrics.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. import Ember from 'ember';
  19. import ColumnDef from 'em-table/utils/column-definition';
  20. function _createColumns() {
  21. var columns = [];
  22. columns.push({
  23. id: 'name',
  24. headerTitle: 'Name',
  25. contentPath: 'name',
  26. observePath: true,
  27. cellComponentName: 'em-table-html-cell',
  28. getCellContent: function(row) {
  29. var plainName = row.name;
  30. if (plainName.indexOf('MAP:') > -1 || plainName.indexOf('REDUCE:') > -1) {
  31. plainName = plainName.substring(plainName.indexOf(':') + 1);
  32. }
  33. return `<span>${plainName}</span>`;
  34. }
  35. }, {
  36. id: 'value',
  37. headerTitle: 'Value',
  38. contentPath: 'value',
  39. observePath: true
  40. });
  41. return ColumnDef.make(columns);
  42. }
  43. export default Ember.Controller.extend({
  44. mapMetrics: null,
  45. reduceMetrics: null,
  46. generalMetrics: null,
  47. columns: Ember.computed(function() {
  48. return _createColumns(this.get('model.flowrun_uid'));
  49. }),
  50. metricsObserver: Ember.observer('model.flowrun', function() {
  51. var metrics = this.get('model.flowrun.metrics');
  52. var mapConfigs = [],
  53. reduceConfigs = [],
  54. generalConfigs = [];
  55. metrics.forEach(function(metric) {
  56. let id = metric.id;
  57. if (id.startsWith('MAP:')) {
  58. mapConfigs.push(metric);
  59. } else if (id.startsWith('REDUCE:')) {
  60. reduceConfigs.push(metric);
  61. } else {
  62. generalConfigs.push(metric);
  63. }
  64. }, this);
  65. this.set('mapMetrics', mapConfigs);
  66. this.set('reduceMetrics', reduceConfigs);
  67. this.set('generalMetrics', generalConfigs);
  68. }),
  69. mapConfigRows: Ember.computed('mapMetrics', function() {
  70. var row = null,
  71. data = [];
  72. this.get('mapMetrics').forEach(function(map) {
  73. let value = map.values[Object.keys(map.values)[0]];
  74. row = Ember.Object.create({
  75. name: map.id,
  76. value: value
  77. });
  78. data.push(row);
  79. }, this);
  80. return Ember.A(data);
  81. }),
  82. reduceConfigRows: Ember.computed('reduceMetrics', function() {
  83. var row = null,
  84. data = [];
  85. this.get('reduceMetrics').forEach(function(map) {
  86. let value = map.values[Object.keys(map.values)[0]];
  87. row = Ember.Object.create({
  88. name: map.id,
  89. value: value
  90. });
  91. data.push(row);
  92. }, this);
  93. return Ember.A(data);
  94. }),
  95. generalConfigRows: Ember.computed('generalMetrics', function() {
  96. var row = null,
  97. data = [];
  98. this.get('generalMetrics').forEach(function(map) {
  99. let value = map.values[Object.keys(map.values)[0]];
  100. row = Ember.Object.create({
  101. name: map.id,
  102. value: value
  103. });
  104. data.push(row);
  105. }, this);
  106. return Ember.A(data);
  107. })
  108. });