datanode_live.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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.DataNodeUpView = App.DashboardWidgetView.extend({
  20. templateName: require('templates/main/dashboard/widgets/simple_text'),
  21. title: Em.I18n.t('dashboard.widgets.DataNodeUp'),
  22. id: '4',
  23. isPieChart: false,
  24. isText: true,
  25. isProgressBar: false,
  26. model_type: 'hdfs',
  27. hiddenInfo: function () {
  28. var result = [];
  29. result.pushObject(this.get('model.liveDataNodes.length') + ' ' + this.t('dashboard.services.hdfs.nodes.live'));
  30. result.pushObject(this.get('model.deadDataNodes.length') + ' ' + this.t('dashboard.services.hdfs.nodes.dead'));
  31. result.pushObject(this.get('model.decommissionDataNodes.length')+ ' ' + this.t('dashboard.services.hdfs.nodes.decom'));
  32. return result;
  33. }.property('model.liveDataNodes.length','model.deadDataNodes.length','model.decommissionDataNodes.length'),
  34. hiddenInfoClass: "hidden-info-three-line",
  35. classNameBindings: ['isRed', 'isOrange', 'isGreen'],
  36. isRed: function () {
  37. var thresh1 = this.get('thresh1');
  38. var thresh2 = this.get('thresh2');
  39. return this.get('data') <= thresh1? true: false;
  40. }.property('data','thresh1','thresh2'),
  41. isOrange: function () {
  42. var thresh1 = this.get('thresh1');
  43. var thresh2 = this.get('thresh2');
  44. return (this.get('data') <= thresh2 && this.get('data') > thresh1 )? true: false;
  45. }.property('data','thresh1','thresh2'),
  46. isGreen: function () {
  47. var thresh1 = this.get('thresh1');
  48. var thresh2 = this.get('thresh2');
  49. return this.get('data') > thresh2? true: false;
  50. }.property('data','thresh1','thresh2'),
  51. thresh1: 40,
  52. thresh2: 70,
  53. maxValue: 100,
  54. data: function () {
  55. return ((this.get('model.liveDataNodes.length')/ this.get('model.dataNodes.length')).toFixed(2)) * 100;
  56. }.property('model.dataNodes.length', 'model.liveDataNodes.length'),
  57. content: function () {
  58. return this.get('model.liveDataNodes.length') + "/" + this.get('model.dataNodes.length');
  59. }.property('model.dataNodes.length', 'model.liveDataNodes.length'),
  60. editWidget: function (event) {
  61. var parent = this;
  62. var max_tmp = parseFloat(parent.get('maxValue'));
  63. var configObj = Ember.Object.create({
  64. thresh1: parent.get('thresh1') + '',
  65. thresh2: parent.get('thresh2') + '',
  66. hintInfo: 'Edit the percentage of thresholds to change the color of current widget. ' +
  67. ' Assume all data nodes UP is 100, and all DOWN is 0. '+
  68. ' So enter two numbers between 0 to ' + max_tmp,
  69. isThresh1Error: false,
  70. isThresh2Error: false,
  71. errorMessage1: "",
  72. errorMessage2: "",
  73. maxValue: max_tmp,
  74. observeNewThresholdValue: function () {
  75. var thresh1 = this.get('thresh1');
  76. var thresh2 = this.get('thresh2');
  77. if (thresh1.trim() != "") {
  78. if (isNaN(thresh1) || thresh1 > max_tmp || thresh1 < 0){
  79. this.set('isThresh1Error', true);
  80. this.set('errorMessage1', 'Invalid! Enter a number between 0 - ' + max_tmp);
  81. } else if ( this.get('isThresh2Error') === false && parseFloat(thresh2)<= parseFloat(thresh1)) {
  82. this.set('isThresh1Error', true);
  83. this.set('errorMessage1', 'Threshold 1 should be smaller than threshold 2 !');
  84. } else {
  85. this.set('isThresh1Error', false);
  86. this.set('errorMessage1', '');
  87. }
  88. } else {
  89. this.set('isThresh1Error', true);
  90. this.set('errorMessage1', 'This is required');
  91. }
  92. if (thresh2.trim() != "") {
  93. if (isNaN(thresh2) || thresh2 > max_tmp || thresh2 < 0) {
  94. this.set('isThresh2Error', true);
  95. this.set('errorMessage2', 'Invalid! Enter a number between 0 - ' + max_tmp);
  96. } else {
  97. this.set('isThresh2Error', false);
  98. this.set('errorMessage2', '');
  99. }
  100. } else {
  101. this.set('isThresh2Error', true);
  102. this.set('errorMessage2', 'This is required');
  103. }
  104. // update the slider handles and color
  105. if (this.get('isThresh1Error') === false && this.get('isThresh2Error') === false) {
  106. $("#slider-range").slider('values', 0 , parseFloat(thresh1));
  107. $("#slider-range").slider('values', 1 , parseFloat(thresh2));
  108. }
  109. }.observes('thresh1', 'thresh2')
  110. });
  111. var browserVerion = this.getInternetExplorerVersion();
  112. App.ModalPopup.show({
  113. header: 'Customize Widget',
  114. classNames: [ 'sixty-percent-width-modal-edit-widget'],
  115. bodyClass: Ember.View.extend({
  116. templateName: require('templates/main/dashboard/edit_widget_popup'),
  117. configPropertyObj: configObj
  118. }),
  119. primary: Em.I18n.t('common.apply'),
  120. onPrimary: function () {
  121. configObj.observeNewThresholdValue();
  122. if (!configObj.isThresh1Error && !configObj.isThresh2Error) {
  123. parent.set('thresh1', parseFloat(configObj.get('thresh1')) );
  124. parent.set('thresh2', parseFloat(configObj.get('thresh2')) );
  125. if (!App.testMode) {
  126. var big_parent = parent.get('parentView');
  127. big_parent.getUserPref(big_parent.get('persistKey'));
  128. var oldValue = big_parent.get('currentPrefObject');
  129. oldValue.threshold[parseInt(parent.id)] = [configObj.get('thresh1'), configObj.get('thresh2')];
  130. big_parent.postUserPref(big_parent.get('persistKey'),oldValue);
  131. }
  132. this.hide();
  133. }
  134. },
  135. secondary : Em.I18n.t('common.cancel'),
  136. onSecondary: function () {
  137. this.hide();
  138. },
  139. didInsertElement: function () {
  140. var handlers = [configObj.get('thresh1'), configObj.get('thresh2')];
  141. var colors = ['#B80000', '#FF8E00', '#95A800']; //color red, orange, green
  142. if (browserVerion == -1 || browserVerion > 9) {
  143. configObj.set('isIE9', false);
  144. configObj.set('isGreenOrangeRed', false);
  145. $("#slider-range").slider({
  146. range: true,
  147. min: 0,
  148. max: max_tmp,
  149. values: handlers,
  150. create: function (event, ui) {
  151. updateColors(handlers);
  152. },
  153. slide: function (event, ui) {
  154. updateColors(ui.values);
  155. configObj.set('thresh1', ui.values[0] + '');
  156. configObj.set('thresh2', ui.values[1] + '');
  157. },
  158. change: function (event, ui) {
  159. updateColors(ui.values);
  160. }
  161. });
  162. function updateColors(handlers) {
  163. var colorstops = colors[0] + ", "; // start with the first color
  164. for (var i = 0; i < handlers.length; i++) {
  165. colorstops += colors[i] + " " + handlers[i] + "%,";
  166. colorstops += colors[i+1] + " " + handlers[i] + "%,";
  167. }
  168. // end with the last color
  169. colorstops += colors[colors.length - 1];
  170. var css1 = '-webkit-linear-gradient(left,' + colorstops + ')'; // chrome & safari
  171. $('#slider-range').css('background-image', css1);
  172. var css2 = '-ms-linear-gradient(left,' + colorstops + ')'; // IE 10+
  173. $('#slider-range').css('background-image', css2);
  174. //$('#slider-range').css('filter', 'progid:DXImageTransform.Microsoft.gradient( startColorStr= ' + colors[0] + ', endColorStr= ' + colors[2] +', GradientType=1 )' ); // IE 10-
  175. var css3 = '-moz-linear-gradient(left,' + colorstops + ')'; // Firefox
  176. $('#slider-range').css('background-image', css3);
  177. $('#slider-range .ui-widget-header').css({'background-color': '#FF8E00', 'background-image': 'none'}); // change the original ranger color
  178. }
  179. } else {
  180. configObj.set('isIE9', true);
  181. configObj.set('isGreenOrangeRed', false);
  182. }
  183. }
  184. });
  185. }
  186. })