config_group.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 a configuration-group on the cluster.
  21. * A configuration-group is a collection of hosts
  22. * on which a collection of configurations are applied.
  23. *
  24. * Configuration group hierarchy is at 2 levels. For
  25. * each service there is a 'Default' configuration group
  26. * containing all hosts not belonging to any group of that
  27. * service.
  28. *
  29. * A default configuration group has child configuration
  30. * groups which contain configuration overrides (deltas)
  31. * for a bunch of hosts. This allows different configurations
  32. * for different hosts in a heterogeneous cluster environment.
  33. */
  34. App.ConfigGroup = Ember.Object.extend({
  35. id: null,
  36. name: null,
  37. description: null,
  38. isDefault: null,
  39. serviceName: null,
  40. /**
  41. * Parent configuration group for this group.
  42. * When {@link #isDefault} is true, this value is <code>null</code>
  43. * When {@link #isDefault} is false, this represents the configuration
  44. * deltas that are applied on the default.
  45. */
  46. parentConfigGroup: null,
  47. /**
  48. * Children configuration groups for this group.
  49. * When {@link #isDefault} is false, this value is <code>null</code>
  50. * When {@link #isDefault} is true, this represents the various
  51. * configuration groups that override the default.
  52. */
  53. childConfigGroups: [],
  54. /**
  55. * Service for which this configuration-group
  56. * is applicable.
  57. */
  58. service: null,
  59. /**
  60. * Hosts on which this configuration-group
  61. * is to be applied. For a service, a host can
  62. * belong to only one non-default configuration-group.
  63. *
  64. * When {#isDefault} is false, this contains hosts
  65. * for which the overrides will apply.
  66. *
  67. * When {#isDefault} is true, this value is empty, as
  68. * it dynamically reflects hosts not belonging to other
  69. * non-default groups.
  70. *
  71. */
  72. hosts: [],
  73. /**
  74. * Provides a display friendly name. This includes trimming
  75. * names to a certain length.
  76. */
  77. displayName: function () {
  78. var name = this.get('name');
  79. if (name && name == "Default") {
  80. if (this.get('serviceName')) {
  81. name = App.Service.DisplayNames[this.get('serviceName').toUpperCase()] + " Default";
  82. }
  83. if (this.get('service')) {
  84. name = App.Service.DisplayNames[this.get('service.id')] + " Default";
  85. }
  86. }
  87. if (name && name.length>App.config.CONFIG_GROUP_NAME_MAX_LENGTH) {
  88. var middle = Math.floor(App.config.CONFIG_GROUP_NAME_MAX_LENGTH / 2);
  89. name = name.substring(0, middle) + "..." + name.substring(name.length-middle);
  90. }
  91. return name;
  92. }.property('name'),
  93. displayNameHosts: function () {
  94. return this.get('displayName') + ' (' + this.get('hosts.length') + ')';
  95. }.property('displayName', 'hosts.length'),
  96. apiResponse: null,
  97. /**
  98. * Provides hosts which are available for inclusion in
  99. * non-default configuration groups.
  100. */
  101. availableHosts: function () {
  102. if (this.get('isDefault')) return [];
  103. var unusedHostsMap = {};
  104. var availableHosts = [];
  105. // parentConfigGroup.hosts(hosts from default group) - are available hosts, which don't belong to any group
  106. this.get('parentConfigGroup.hosts').forEach(function (hostName) {
  107. unusedHostsMap[hostName] = true;
  108. });
  109. App.Host.find().filter(function (host) {
  110. if(unusedHostsMap[host.get('id')]) {
  111. availableHosts.pushObject(Ember.Object.create({
  112. selected: false,
  113. host: host
  114. }));
  115. }
  116. });
  117. return availableHosts;
  118. }.property('isDefault', 'parentConfigGroup', 'childConfigGroups', 'parentConfigGroup.hosts.@each'),
  119. isAddHostsDisabled: function () {
  120. return (this.get('isDefault') || this.get('availableHosts.length') === 0);
  121. }.property('availableHosts.length'),
  122. /**
  123. * Collection of (site, tag) pairs representing properties.
  124. *
  125. * When {#isDefault} is true, this represents the
  126. * default cluster configurations for that service.
  127. *
  128. * When {#isDefault} is false, this represents the
  129. * configuration overrides on top of the cluster default for the
  130. * hosts identified by 'hosts'.
  131. */
  132. configSiteTags: [],
  133. properties: [],
  134. propertiesList: function () {
  135. var result = '';
  136. this.get('properties').forEach(function (item) {
  137. result += item.name + " : " + item.value + '<br/>';
  138. }, this);
  139. return result;
  140. }.property('properties.length')
  141. });