alert_instance.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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/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. hostName: DS.attr('string'),
  30. scope: DS.attr('string'),
  31. originalTimestamp: DS.attr('number'),
  32. originalRawTimestamp: DS.attr('number'),
  33. latestTimestamp: DS.attr('number'),
  34. maintenanceState: DS.attr('string'),
  35. instance: DS.attr('string'),
  36. state: DS.attr('string'),
  37. text: DS.attr('string'),
  38. repeatTolerance: DS.attr('number'),
  39. repeatToleranceRemaining: DS.attr('number'),
  40. notification: DS.hasMany('App.AlertNotification'),
  41. /**
  42. * @type {boolean}
  43. */
  44. isMaintenanceStateOn: Em.computed.equal('maintenanceState', 'ON'),
  45. /**
  46. * @type {string}
  47. */
  48. shortStateMsg: Em.computed.getByKey('shortState', 'state'),
  49. /**
  50. * @type {string}
  51. */
  52. stateClass: function () {
  53. return 'alert-state-' + (this.get('isMaintenanceStateOn') ? 'PENDING' : this.get('state'));
  54. }.property('isMaintenanceStateOn'),
  55. /**
  56. * For alerts we will have processes which are not typical
  57. * cluster services - like Ambari-Server. This method unifies
  58. * cluster services and other services into a common display-name.
  59. * @see App.AlertDefinition#serviceDisplayName()
  60. */
  61. serviceDisplayName: function () {
  62. var serviceName = this.get('service.displayName');
  63. if (!serviceName) {
  64. serviceName = this.get('serviceName');
  65. if (serviceName) {
  66. serviceName = serviceName.toCapital();
  67. }
  68. }
  69. return serviceName;
  70. }.property('serviceName', 'service.displayName'),
  71. /**
  72. * Formatted timestamp for latest instance triggering
  73. * @type {string}
  74. */
  75. lastCheckedFormatted: function () {
  76. return dateUtils.dateFormat(this.get('latestTimestamp'));
  77. }.property('latestTimestamp'),
  78. /**
  79. * Formatted timestamp for latest instance triggering
  80. * @type {string}
  81. */
  82. lastTriggeredFormatted: function () {
  83. return dateUtils.dateFormat(this.get('originalTimestamp'));
  84. }.property('originalTimestamp'),
  85. /**
  86. * Formatted timestamp with <code>$.timeago</code>
  87. * @type {string}
  88. */
  89. lastTriggeredAgoFormatted: function () {
  90. var lastTriggered = this.get('originalRawTimestamp');
  91. return lastTriggered ? $.timeago(new Date(lastTriggered)) : '';
  92. }.property('originalTimestamp'),
  93. lastTriggeredVerboseDisplay: function () {
  94. var originalTimestamp = this.get('originalTimestamp');
  95. var latestTimestamp = this.get('latestTimestamp');
  96. return Em.I18n.t('models.alert_instance.tiggered.verbose').format(
  97. dateUtils.dateFormat(originalTimestamp),
  98. dateUtils.dateFormat(latestTimestamp));
  99. }.property('originalTimestamp', 'latestTimestamp'),
  100. /**
  101. * Formatted timestamp with <code>$.timeago</code>
  102. * @type {string}
  103. */
  104. lastTriggeredForFormatted: function () {
  105. var lastTriggered = this.get('originalRawTimestamp');
  106. var previousSuffixAgo = $.timeago.settings.strings.suffixAgo;
  107. var previousPrefixAgo = $.timeago.settings.strings.prefixAgo;
  108. $.timeago.settings.strings.suffixAgo = null;
  109. $.timeago.settings.strings.prefixAgo = 'for';
  110. var triggeredFor = lastTriggered ? $.timeago(new Date(lastTriggered)) : '';
  111. $.timeago.settings.strings.suffixAgo = previousSuffixAgo;
  112. $.timeago.settings.strings.prefixAgo = previousPrefixAgo;
  113. return triggeredFor;
  114. }.property('originalTimestamp'),
  115. /**
  116. * escaped '<' and '>' special characters.
  117. * @type {string}
  118. */
  119. escapeSpecialCharactersFromTooltip: function () {
  120. var displayedText = this.get('text');
  121. return displayedText.replace(/[<>]/g, '');
  122. }.property('text'),
  123. /**
  124. * Formatted lastChecked and lastTriggered timestamp
  125. * @returns {string}
  126. */
  127. statusChangedAndLastCheckedFormatted: Em.computed.i18nFormat('models.alert_definition.triggered.checked', 'lastTriggeredFormatted', 'lastCheckedFormatted'),
  128. /**
  129. * List of css-classes for alert instance status
  130. * @type {object}
  131. */
  132. typeIcons: {
  133. 'DISABLED': 'icon-off'
  134. },
  135. repeatToleranceReceived: function () {
  136. return this.get('repeatTolerance') - this.get('repeatToleranceRemaining');
  137. }.property('repeatToleranceRemaining', 'repeatTolerance'),
  138. retryText: function () {
  139. return this.get('state') === 'OK' ? '' : Em.I18n.t('models.alert_definition.check.retry').format(this.get('repeatToleranceReceived'), this.get('repeatTolerance'));
  140. }.property('state','repeatToleranceRemaining', 'repeatTolerance'),
  141. /**
  142. * Define if definition serviceName is Ambari
  143. * Used in some logic in templates to distinguish definitions with Ambari serviceName
  144. * @returns {boolean}
  145. */
  146. isAmbariServiceName: Em.computed.equal('serviceName', 'AMBARI'),
  147. shortState: {
  148. 'CRITICAL': 'CRIT',
  149. 'WARNING': 'WARN',
  150. 'OK': 'OK',
  151. 'UNKNOWN': 'UNKWN',
  152. 'PENDING': 'NONE'
  153. }
  154. });
  155. App.AlertInstance.FIXTURES = [];