hbase_master_uptime.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. var date = require('utils/date');
  20. App.HBaseMasterUptimeView = App.DashboardWidgetView.extend({
  21. templateName: require('templates/main/dashboard/widgets/uptime'),
  22. title: Em.I18n.t('dashboard.widgets.HBaseMasterUptime'),
  23. id: '23',
  24. isPieChart: false,
  25. isText: true,
  26. isProgressBar: false,
  27. model_type: 'hbase',
  28. hiddenInfo: [],
  29. hiddenInfoClass: "hidden-info-three-line",
  30. classNameBindings: ['isRed', 'isOrange', 'isGreen', 'isNA'],
  31. isGreen: function () {
  32. return this.get('data') != null;
  33. }.property('data'),
  34. isOrange: function () {
  35. return false;
  36. }.property('data'),
  37. isRed: function () {
  38. return false;
  39. }.property('data'),
  40. isNA: function () {
  41. return this.get('data') == null;
  42. }.property('data'),
  43. thresh1: 5,
  44. thresh2: 10,
  45. maxValue: 'infinity',
  46. data: function () {
  47. var uptime = this.get('model.masterStartTime');
  48. if (uptime && uptime > 0) {
  49. var uptimeString = this.timeConverter(uptime);
  50. var diff = (new Date()).getTime() - uptime;
  51. if (diff < 0) {
  52. diff = 0;
  53. }
  54. var formatted = date.timingFormat(diff); //17.67 days
  55. var timeUnit = null;
  56. switch (formatted.split(" ")[1]) {
  57. case 'secs':
  58. timeUnit = 's';
  59. break;
  60. case 'hours':
  61. timeUnit = 'hr';
  62. break;
  63. case 'days':
  64. timeUnit = 'd';
  65. break;
  66. case 'mins':
  67. timeUnit = 'min';
  68. break;
  69. default:
  70. timeUnit = formatted.split(" ")[1];
  71. }
  72. this.set('timeUnit', timeUnit);
  73. this.set('hiddenInfo', []);
  74. this.get('hiddenInfo').pushObject(formatted);
  75. this.get('hiddenInfo').pushObject(uptimeString[0]);
  76. this.get('hiddenInfo').pushObject(uptimeString[1]);
  77. return parseFloat(formatted.split(" ")[0]);
  78. }
  79. this.set('hiddenInfo', []);
  80. this.set('hiddenInfo', ['Hbase Master','Not Running']);
  81. return null;
  82. }.property('model.masterStartTime'),
  83. timeUnit: null,
  84. content: function () {
  85. var data = this.get('data');
  86. if (data) {
  87. return data.toFixed(1) + ' '+ this.get('timeUnit');
  88. } else {
  89. return this.t('services.service.summary.notAvailable');
  90. }
  91. }.property('model.masterStartTime'),
  92. timeConverter: function (timestamp){
  93. var origin = new Date(timestamp);
  94. origin = origin.toString();
  95. var result = [];
  96. var start = origin.indexOf('GMT');
  97. if (start == -1) { // ie
  98. var arr = origin.split(" ");
  99. result.pushObject(arr[0] + " " + arr[1] + " " + arr[2] + " " + arr[3]);
  100. var second = '';
  101. for (var i = 4; i < arr.length; i++) {
  102. second = second + " " + arr[i];
  103. }
  104. result.pushObject(second);
  105. } else { // other browsers
  106. var end = origin.indexOf(" ", start);
  107. result.pushObject(origin.slice(0, start-10));
  108. result.pushObject(origin.slice(start-9));
  109. }
  110. return result;
  111. }
  112. })