config_group.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. * all hosts that belong to cluster
  49. */
  50. clusterHostsBinding: 'App.router.manageConfigGroupsController.clusterHosts',
  51. /**
  52. * Children configuration groups for this group.
  53. * When {@link #isDefault} is false, this value is <code>null</code>
  54. * When {@link #isDefault} is true, this represents the various
  55. * configuration groups that override the default.
  56. */
  57. childConfigGroups: [],
  58. /**
  59. * Service for which this configuration-group
  60. * is applicable.
  61. */
  62. service: null,
  63. /**
  64. * Hosts on which this configuration-group
  65. * is to be applied. For a service, a host can
  66. * belong to only one non-default configuration-group.
  67. *
  68. * When {#isDefault} is false, this contains hosts
  69. * for which the overrides will apply.
  70. *
  71. * When {#isDefault} is true, this value is empty, as
  72. * it dynamically reflects hosts not belonging to other
  73. * non-default groups.
  74. *
  75. */
  76. hosts: [],
  77. /**
  78. * Public host names related by host_name.
  79. */
  80. publicHosts: [],
  81. /**
  82. * this flag is used for installed services' config groups
  83. * if user make changes to them - mark this flag to true
  84. */
  85. isForUpdate: false,
  86. /**
  87. * mark config groups for installed services
  88. */
  89. isForInstalledService: false,
  90. /**
  91. * Provides a display friendly name. This includes trimming
  92. * names to a certain length.
  93. */
  94. displayName: function () {
  95. var name = this.get('name');
  96. if (name && name.length>App.config.CONFIG_GROUP_NAME_MAX_LENGTH) {
  97. var middle = Math.floor(App.config.CONFIG_GROUP_NAME_MAX_LENGTH / 2);
  98. name = name.substring(0, middle) + "..." + name.substring(name.length-middle);
  99. }
  100. return name;
  101. }.property('name'),
  102. displayNameHosts: function () {
  103. return this.get('displayName') + ' (' + this.get('hosts.length') + ')';
  104. }.property('displayName', 'hosts.length'),
  105. apiResponse: null,
  106. /**
  107. * Provides hosts which are available for inclusion in
  108. * non-default configuration groups.
  109. */
  110. availableHosts: function () {
  111. if (this.get('isDefault')) return [];
  112. var unusedHostsMap = {};
  113. var availableHosts = [];
  114. var sharedHosts = this.get('clusterHosts');
  115. // parentConfigGroup.hosts(hosts from default group) - are available hosts, which don't belong to any group
  116. this.get('parentConfigGroup.hosts').forEach(function (hostName) {
  117. unusedHostsMap[hostName] = true;
  118. });
  119. sharedHosts.forEach(function (host) {
  120. if (unusedHostsMap[host.get('id')]) {
  121. availableHosts.pushObject(Ember.Object.create({
  122. selected: false,
  123. host: host,
  124. hostComponentNames: host.get('hostComponents').mapProperty('componentName')
  125. }));
  126. }
  127. });
  128. return availableHosts;
  129. }.property('isDefault', 'parentConfigGroup', 'childConfigGroups', 'parentConfigGroup.hosts.@each'),
  130. isAddHostsDisabled: function () {
  131. return (this.get('isDefault') || this.get('availableHosts.length') === 0);
  132. }.property('availableHosts.length'),
  133. /**
  134. * Collection of (site, tag) pairs representing properties.
  135. *
  136. * When {#isDefault} is true, this represents the
  137. * default cluster configurations for that service.
  138. *
  139. * When {#isDefault} is false, this represents the
  140. * configuration overrides on top of the cluster default for the
  141. * hosts identified by 'hosts'.
  142. */
  143. configSiteTags: [],
  144. properties: [],
  145. propertiesList: function () {
  146. var result = '';
  147. this.get('properties').forEach(function (item) {
  148. result += item.name + " : " + item.value + '<br/>';
  149. }, this);
  150. return result;
  151. }.property('properties.length'),
  152. hash: null
  153. });