jobtracker_rpc.js 5.5 KB

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