datanode_live.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. function counterOrNA(key) {
  20. var _key = 'model.{0}.length'.format(key);
  21. return Em.computed(_key, function () {
  22. if (Em.isNone(this.get('model.'+ key)) || this.get('model.metricsNotAvailable')) {
  23. return Em.I18n.t('services.service.summary.notAvailable');
  24. }
  25. return this.get(_key);
  26. });
  27. }
  28. App.DataNodeUpView = App.TextDashboardWidgetView.extend(App.EditableWithLimitWidgetMixin, {
  29. title: Em.I18n.t('dashboard.widgets.DataNodeUp'),
  30. id: '4',
  31. model_type: 'hdfs',
  32. hiddenInfo: function () {
  33. return [
  34. this.get('dataNodesLive') + ' ' + Em.I18n.t('dashboard.services.hdfs.nodes.live'),
  35. this.get('dataNodesDead') + ' ' + Em.I18n.t('dashboard.services.hdfs.nodes.dead'),
  36. this.get('dataNodesDecom')+ ' ' + Em.I18n.t('dashboard.services.hdfs.nodes.decom')
  37. ];
  38. }.property('dataNodesLive', 'dataNodesDead', 'dataNodesDecom'),
  39. hiddenInfoClass: "hidden-info-three-line",
  40. thresh1: 40,
  41. thresh2: 70,
  42. maxValue: 100,
  43. dataNodesLive: counterOrNA('liveDataNodes'),
  44. dataNodesDead: counterOrNA('deadDataNodes'),
  45. dataNodesDecom: counterOrNA('decommissionDataNodes'),
  46. /**
  47. * @type {?number}
  48. */
  49. data: function () {
  50. if (this.get('someMetricsNA')) {
  51. return null;
  52. }
  53. return (this.get('dataNodesLive') / this.get('model.dataNodesTotal')).toFixed(2) * 100;
  54. }.property('model.dataNodesTotal', 'dataNodesLive', 'someMetricsNA'),
  55. /**
  56. * @type {string}
  57. */
  58. content: function () {
  59. if (this.get('someMetricsNA')) {
  60. return Em.I18n.t('services.service.summary.notAvailable');
  61. }
  62. return this.get('dataNodesLive') + "/" + this.get('model.dataNodesTotal');
  63. }.property('model.dataNodesTotal', 'dataNodesLive', 'someMetricsNA'),
  64. /**
  65. * @type {boolean}
  66. */
  67. someMetricsNA: function () {
  68. return Em.isNone(this.get('model.liveDataNodes')) || Em.isNone(this.get('model.dataNodesTotal')) || this.get('model.metricsNotAvailable');
  69. }.property('model.liveDataNodes.[]', 'model.dataNodesTotal.[]', 'model.metricsNotAvailable'),
  70. /**
  71. * @type {string}
  72. */
  73. hintInfo: function () {
  74. var maxTmp = parseFloat(this.get('maxValue'));
  75. return Em.I18n.t('dashboard.widgets.hintInfo.hint1').format(maxTmp);
  76. }.property('maxValue')
  77. });