info.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. import Converter from 'yarn-ui/utils/converter';
  21. function createColumn() {
  22. var columns = [];
  23. // Generate columns
  24. columns.push({
  25. id: 'appId',
  26. headerTitle: 'Application ID',
  27. contentPath: 'appId',
  28. cellComponentName: 'em-table-linked-cell',
  29. minWidth: "300px",
  30. getCellContent: function (row) {
  31. return {
  32. routeName: 'yarn-app.attempts',
  33. id: row.get('appId'),
  34. displayText: row.get('appId')
  35. };
  36. }
  37. });
  38. columns.push({
  39. id: 'appType',
  40. headerTitle: 'Application Type',
  41. contentPath: 'type'
  42. });
  43. columns.push({
  44. id: 'state',
  45. headerTitle: 'State',
  46. contentPath: 'state',
  47. cellComponentName: 'em-table-status-cell',
  48. });
  49. columns.push({
  50. id: 'elapsedTs',
  51. headerTitle: 'Elapsed Time',
  52. contentPath: 'elapsedTs',
  53. getCellContent: function(row) {
  54. return Converter.msToElapsedTimeUnit(row.get('elapsedTs'));
  55. }
  56. });
  57. columns.push({
  58. id: 'cpuVCores',
  59. headerTitle: 'CPU VCores',
  60. contentPath: 'cpuVCores',
  61. getCellContent: function(row) {
  62. if (row.get('cpuVCores') > -1) {
  63. return row.get('cpuVCores');
  64. }
  65. return 'N/A';
  66. }
  67. });
  68. columns.push({
  69. id: 'memoryUsed',
  70. headerTitle: 'Memory Used',
  71. contentPath: 'memoryUsed',
  72. getCellContent: function(row) {
  73. if (row.get('memoryUsed') > -1) {
  74. return Converter.memoryBytesToMB(row.get('memoryUsed'));
  75. }
  76. return 'N/A';
  77. }
  78. });
  79. return ColumnDef.make(columns);
  80. }
  81. export default Ember.Controller.extend({
  82. vizWidgets: {
  83. cpuVcores: true,
  84. memoryUsed: false
  85. },
  86. actions: {
  87. addVizWidget(widget) {
  88. Ember.set(this.vizWidgets, widget, true);
  89. },
  90. removeVizWidget(widget) {
  91. Ember.set(this.vizWidgets, widget, false);
  92. }
  93. },
  94. columns: createColumn(),
  95. cpuVCoresVizData: function() {
  96. var data = [];
  97. this.get('model.apps').forEach(function(app) {
  98. var vizData = app.getCpuVCoresVizDataForBarChart();
  99. if (vizData.value > 0) {
  100. data.push(vizData);
  101. }
  102. });
  103. data = this.getSortedVizDataInDesc(data);
  104. return this.getRefactoredVizData(data);
  105. }.property('model.apps'),
  106. memoryVizData: function() {
  107. var data = [];
  108. this.get('model.apps').forEach(function(app) {
  109. var vizData = app.getMemoryVizDataForBarChart();
  110. if (vizData.value > 0) {
  111. data.push(vizData);
  112. }
  113. });
  114. data = this.getSortedVizDataInDesc(data);
  115. return this.getRefactoredVizData(data);
  116. }.property('model.apps'),
  117. memoryFormatter: function(tick) {
  118. return Converter.memoryBytesToMB(tick);
  119. },
  120. onBarChartClick: function() {
  121. var self = this;
  122. return function(data) {
  123. self.transitionToRoute('yarn-app', data.appId);
  124. };
  125. }.property(),
  126. getSortedVizDataInDesc: function(data) {
  127. return data.sort(function(d1, d2) {
  128. return d2.value - d1.value;
  129. });
  130. },
  131. getRefactoredVizData: function(data) {
  132. data.forEach(function(viz, idx) {
  133. viz.appId = viz.label;
  134. viz.label = "App " + (++idx);
  135. }, this);
  136. return data;
  137. }
  138. });