config_group.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. * In add service wizard we have installed services.
  75. * And on deploy step we need to update existing config groups
  76. * also mark it for be sure that config group data came from
  77. * installed service.
  78. *
  79. */
  80. isForUpdate: false,
  81. /**
  82. * Provides a display friendly name. This includes trimming
  83. * names to a certain length.
  84. */
  85. displayName: function () {
  86. var name = this.get('name');
  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. var sharedHosts = [];
  106. //if cluster is not installed then get hosts from installerController instead of model
  107. if (App.clusterStatus.get('isInstalled')) {
  108. sharedHosts = App.Host.find();
  109. } else {
  110. sharedHosts = App.router.get('installerController.allHosts');
  111. }
  112. // parentConfigGroup.hosts(hosts from default group) - are available hosts, which don't belong to any group
  113. this.get('parentConfigGroup.hosts').forEach(function (hostName) {
  114. unusedHostsMap[hostName] = true;
  115. });
  116. sharedHosts.forEach(function (host) {
  117. if (unusedHostsMap[host.get('id')]) {
  118. availableHosts.pushObject(Ember.Object.create({
  119. selected: false,
  120. host: host,
  121. hostComponentNames: host.get('hostComponents').mapProperty('componentName')
  122. }));
  123. }
  124. });
  125. return availableHosts;
  126. }.property('isDefault', 'parentConfigGroup', 'childConfigGroups', 'parentConfigGroup.hosts.@each'),
  127. isAddHostsDisabled: function () {
  128. return (this.get('isDefault') || this.get('availableHosts.length') === 0);
  129. }.property('availableHosts.length'),
  130. /**
  131. * Collection of (site, tag) pairs representing properties.
  132. *
  133. * When {#isDefault} is true, this represents the
  134. * default cluster configurations for that service.
  135. *
  136. * When {#isDefault} is false, this represents the
  137. * configuration overrides on top of the cluster default for the
  138. * hosts identified by 'hosts'.
  139. */
  140. configSiteTags: [],
  141. properties: [],
  142. propertiesList: function () {
  143. var result = '';
  144. this.get('properties').forEach(function (item) {
  145. result += item.name + " : " + item.value + '<br/>';
  146. }, this);
  147. return result;
  148. }.property('properties.length')
  149. });