jobtracker_rpc.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. App.JobTrackerRpcView = App.TextDashboardWidgetView.extend({
  20. title: Em.I18n.t('dashboard.widgets.JobTrackerRpc'),
  21. id:'9',
  22. model_type: 'mapreduce',
  23. hiddenInfo: function (){
  24. var result = [];
  25. result.pushObject(this.get('content') + ' average RPC');
  26. result.pushObject('queue wait time');
  27. return result;
  28. }.property('model.jobTrackerRpc'),
  29. thresh1: 0.5,
  30. thresh2: 2,
  31. maxValue: 'infinity',
  32. data: function (){
  33. if (this.get('model.jobTrackerRpc')) {
  34. return (this.get('model.jobTrackerRpc')).toFixed(2);
  35. } else {
  36. if (this.get('model.jobTrackerRpc') == 0) {
  37. return 0;
  38. } else {
  39. return null;
  40. }
  41. }
  42. }.property('model.jobTrackerRpc'),
  43. content: function () {
  44. if (this.get('data') || this.get('data') == 0) {
  45. return this.get('data') + " ms";
  46. } else {
  47. return Em.I18n.t('services.service.summary.notAvailable');
  48. }
  49. }.property('model.jobTrackerRpc'),
  50. editWidget: function (event) {
  51. var parent = this;
  52. var configObj = Ember.Object.create({
  53. thresh1: parent.get('thresh1') + '',
  54. thresh2: parent.get('thresh2') + '',
  55. hintInfo: Em.I18n.t('dashboard.widgets.hintInfo.hint3'),
  56. isThresh1Error: false,
  57. isThresh2Error: false,
  58. errorMessage1: "",
  59. errorMessage2: "",
  60. maxValue: 'infinity',
  61. observeNewThresholdValue: function () {
  62. var thresh1 = this.get('thresh1');
  63. var thresh2 = this.get('thresh2');
  64. if (thresh1.trim() != "") {
  65. if (isNaN(thresh1) || thresh1 < 0) {
  66. this.set('isThresh1Error', true);
  67. this.set('errorMessage1', 'Invalid! Enter a number larger than 0');
  68. } else if (this.get('isThresh2Error') === false && parseFloat(thresh2)<= parseFloat(thresh1)) {
  69. this.set('isThresh1Error', true);
  70. this.set('errorMessage1', 'Threshold 1 should be smaller than threshold 2 !');
  71. } else {
  72. this.set('isThresh1Error', false);
  73. this.set('errorMessage1', '');
  74. }
  75. } else {
  76. this.set('isThresh1Error', true);
  77. this.set('errorMessage1', 'This is required');
  78. }
  79. if (thresh2.trim() != "") {
  80. if (isNaN(thresh2) || thresh2 < 0) {
  81. this.set('isThresh2Error', true);
  82. this.set('errorMessage2', 'Invalid! Enter a number larger than 0');
  83. } else {
  84. this.set('isThresh2Error', false);
  85. this.set('errorMessage2', '');
  86. }
  87. } else{
  88. this.set('isThresh2Error', true);
  89. this.set('errorMessage2', 'This is required');
  90. }
  91. }.observes('thresh1', 'thresh2')
  92. });
  93. var browserVerion = this.getInternetExplorerVersion();
  94. App.ModalPopup.show({
  95. header: Em.I18n.t('dashboard.widgets.popupHeader'),
  96. classNames: [ 'sixty-percent-width-modal-edit-widget'],
  97. bodyClass: Ember.View.extend({
  98. templateName: require('templates/main/dashboard/edit_widget_popup'),
  99. configPropertyObj: configObj
  100. }),
  101. primary: Em.I18n.t('common.apply'),
  102. onPrimary: function () {
  103. configObj.observeNewThresholdValue();
  104. if (!configObj.isThresh1Error && !configObj.isThresh2Error) {
  105. parent.set('thresh1', parseFloat(configObj.get('thresh1')) );
  106. parent.set('thresh2', parseFloat(configObj.get('thresh2')) );
  107. if (!App.testMode) {
  108. // save to persist
  109. var big_parent = parent.get('parentView');
  110. big_parent.getUserPref(big_parent.get('persistKey'));
  111. var oldValue = big_parent.get('currentPrefObject');
  112. oldValue.threshold[parseInt(parent.id)] = [configObj.get('thresh1'), configObj.get('thresh2')];
  113. big_parent.postUserPref(big_parent.get('persistKey'),oldValue);
  114. }
  115. this.hide();
  116. }
  117. },
  118. didInsertElement: function () {
  119. var colors = ['#95A800', '#FF8E00', '#B80000']; //color green, orange ,red
  120. var handlers = [33, 66]; //fixed value
  121. if (browserVerion == -1 || browserVerion > 9) {
  122. configObj.set('isIE9', false);
  123. configObj.set('isGreenOrangeRed', true);
  124. $("#slider-range").slider({
  125. range:true,
  126. disabled:true,
  127. min: 0,
  128. max: 100,
  129. values: handlers,
  130. create: function (event, ui) {
  131. parent.updateColors(handlers, colors);
  132. }
  133. });
  134. } else {
  135. configObj.set('isIE9', true);
  136. configObj.set('isGreenOrangeRed', true);
  137. }
  138. }
  139. });
  140. }
  141. });