alert_instance.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 dateUtils = require('utils/date');
  20. App.AlertInstance = DS.Model.extend({
  21. id: DS.attr('number'),
  22. label: DS.attr('string'),
  23. definitionName: DS.attr('string'),
  24. definitionId: DS.attr('number'),
  25. service: DS.belongsTo('App.Service'),
  26. serviceName: DS.attr('string'),
  27. componentName: DS.attr('string'),
  28. host: DS.belongsTo('App.Host'),
  29. scope: DS.attr('string'),
  30. originalTimestamp: DS.attr('number'),
  31. latestTimestamp: DS.attr('number'),
  32. maintenanceState: DS.attr('string'),
  33. instance: DS.attr('string'),
  34. state: DS.attr('string'),
  35. text: DS.attr('string'),
  36. notification: DS.hasMany('App.AlertNotification'),
  37. /**
  38. * Status icon markup
  39. * @type {string}
  40. */
  41. status: function () {
  42. var state = this.get('state');
  43. return '<span class="label alert-state-single-host alert-state-' + state + '">' + state + '</span>';
  44. }.property('state'),
  45. /**
  46. * For alerts we will have processes which are not typical
  47. * cluster services - like Ambari-Server. This method unifies
  48. * cluster services and other services into a common display-name.
  49. * @see App.AlertDefinition#serviceDisplayName()
  50. */
  51. serviceDisplayName : function() {
  52. var serviceName = this.get('service.displayName');
  53. if (!serviceName) {
  54. serviceName = this.get('serviceName');
  55. if (serviceName) {
  56. serviceName = serviceName.toCapital();
  57. }
  58. }
  59. return serviceName;
  60. }.property('serviceName', 'service.displayName'),
  61. /**
  62. * Formatted timestamp for latest instance triggering
  63. * @type {string}
  64. */
  65. lastCheckedFormatted: function() {
  66. return dateUtils.dateFormat(this.get('latestTimestamp'));
  67. }.property('latestTimestamp'),
  68. /**
  69. * Formatted timestamp for latest instance triggering
  70. * @type {string}
  71. */
  72. lastTriggeredFormatted: function() {
  73. return dateUtils.dateFormat(this.get('originalTimestamp'));
  74. }.property('originalTimestamp'),
  75. /**
  76. * Formatted timestamp with <code>$.timeago</code>
  77. * @type {string}
  78. */
  79. lastTriggeredAgoFormatted: function () {
  80. var lastTriggered = this.get('originalTimestamp');
  81. return lastTriggered ? $.timeago(new Date(lastTriggered)): '';
  82. }.property('originalTimestamp'),
  83. lastTriggeredVerboseDisplay : function() {
  84. var originalTimestamp = this.get('originalTimestamp');
  85. var latestTimestamp = this.get('latestTimestamp');
  86. return Em.I18n.t('models.alert_instance.tiggered.verbose').format(
  87. dateUtils.dateFormat(originalTimestamp),
  88. dateUtils.dateFormat(latestTimestamp));
  89. }.property('originalTimestamp', 'latestTimestamp'),
  90. /**
  91. * Formatted timestamp with <code>$.timeago</code>
  92. * @type {string}
  93. */
  94. lastTriggeredForFormatted: function () {
  95. var lastTriggered = this.get('originalTimestamp');
  96. var previousSuffixAgo = $.timeago.settings.strings.suffixAgo;
  97. var previousPrefixAgo = $.timeago.settings.strings.prefixAgo;
  98. $.timeago.settings.strings.suffixAgo = null;
  99. $.timeago.settings.strings.prefixAgo = 'for';
  100. var triggeredFor = lastTriggered ? $.timeago(new Date(lastTriggered)): '';
  101. $.timeago.settings.strings.suffixAgo = previousSuffixAgo;
  102. $.timeago.settings.strings.prefixAgo = previousPrefixAgo;
  103. return triggeredFor;
  104. }.property('originalTimestamp'),
  105. /**
  106. * List of css-classes for alert instance status
  107. * @type {object}
  108. */
  109. typeIcons: {
  110. 'DISABLED': 'icon-off'
  111. }
  112. });
  113. App.AlertInstance.FIXTURES = [];