alert_group.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. /**
  20. * Represents an alert-group on the cluster.
  21. * A alert group is a collection of alert definitions
  22. *
  23. * Alert group hierarchy is at 2 levels. For
  24. * each service there is a 'Default' alert group
  25. * containing all definitions , this group is read-only
  26. *
  27. * User can create new alert group containing alert definitions from
  28. * any service.
  29. */
  30. App.AlertGroup = DS.Model.extend({
  31. name: DS.attr('string'),
  32. description: DS.attr('string'),
  33. /**
  34. * Is this group default for some service
  35. * @type {boolean}
  36. */
  37. default: DS.attr('boolean'),
  38. /**
  39. * @type {App.AlertDefinition[]}
  40. */
  41. definitions: function () {
  42. return Array.prototype.concat.call(
  43. Array.prototype, this.get('portAlertDefinitions').toArray(),
  44. this.get('metricsAlertDefinitions').toArray(),
  45. this.get('webAlertDefinitions').toArray(),
  46. this.get('aggregateAlertDefinitions').toArray(),
  47. this.get('scriptAlertDefinitions').toArray()
  48. );
  49. }.property('portAlertDefinitions.length', 'metricsAlertDefinitions.length', 'webAlertDefinitions.length', 'aggregateAlertDefinitions.length', 'scriptAlertDefinitions.length'),
  50. /**
  51. * @type {App.PortAlertDefinition[]}
  52. */
  53. portAlertDefinitions: DS.hasMany('App.PortAlertDefinition'),
  54. /**
  55. * @type {App.MetricsAlertDefinition[]}
  56. */
  57. metricsAlertDefinitions: DS.hasMany('App.MetricsAlertDefinition'),
  58. /**
  59. * @type {App.WebAlertDefinition[]}
  60. */
  61. webAlertDefinitions: DS.hasMany('App.WebAlertDefinition'),
  62. /**
  63. * @type {App.AggregateAlertDefinition[]}
  64. */
  65. aggregateAlertDefinitions: DS.hasMany('App.AggregateAlertDefinition'),
  66. /**
  67. * @type {App.ScriptAlertDefinition[]}
  68. */
  69. scriptAlertDefinitions: DS.hasMany('App.ScriptAlertDefinition'),
  70. /**
  71. * @type {App.AlertNotification[]}
  72. */
  73. targets: DS.hasMany('App.AlertNotification'),
  74. /**
  75. * @type {string}
  76. */
  77. displayName: function () {
  78. var name = this.get('name');
  79. if (name && name.length > App.config.CONFIG_GROUP_NAME_MAX_LENGTH) {
  80. var middle = Math.floor(App.config.CONFIG_GROUP_NAME_MAX_LENGTH / 2);
  81. name = name.substring(0, middle) + "..." + name.substring(name.length - middle);
  82. }
  83. return this.get('default') ? (name + ' Default') : name;
  84. }.property('name', 'default'),
  85. /**
  86. * @type {string}
  87. */
  88. displayNameDefinitions: function () {
  89. return this.get('displayName') + ' (' + this.get('definitions.length') + ')';
  90. }.property('displayName', 'definitions.length'),
  91. isAddDefinitionsDisabled: function () {
  92. return this.get('default');
  93. }.property('default')
  94. });
  95. App.AlertGroup.FIXTURES = [];