config_group.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. /**
  40. * Parent configuration group for this group.
  41. * When {@link #isDefault} is true, this value is <code>null</code>
  42. * When {@link #isDefault} is false, this represents the configuration
  43. * deltas that are applied on the default.
  44. */
  45. parentConfigGroup: null,
  46. /**
  47. * Children configuration groups for this group.
  48. * When {@link #isDefault} is false, this value is <code>null</code>
  49. * When {@link #isDefault} is true, this represents the various
  50. * configuration groups that override the default.
  51. */
  52. childConfigGroups: [],
  53. /**
  54. * Service for which this configuration-group
  55. * is applicable.
  56. */
  57. service: null,
  58. /**
  59. * Hosts on which this configuration-group
  60. * is to be applied. For a service, a host can
  61. * belong to only one non-default configuration-group.
  62. *
  63. * When {#isDefault} is false, this contains hosts
  64. * for which the overrides will apply.
  65. *
  66. * When {#isDefault} is true, this value is empty, as
  67. * it dynamically reflects hosts not belonging to other
  68. * non-default groups.
  69. *
  70. */
  71. hosts: [],
  72. displayName: function () {
  73. return this.get('name') + ' (' + this.get('hosts.length') + ')';
  74. }.property('name', 'hosts.length'),
  75. apiResponse: null,
  76. /**
  77. * Provides hosts which are available for inclusion in
  78. * non-default configuration groups.
  79. */
  80. availableHosts: function () {
  81. if (this.get('isDefault')) return [];
  82. var unusedHostsMap = {};
  83. var availableHosts = [];
  84. // parentConfigGroup.hosts(hosts from default group) - are available hosts, which don't belong to any group
  85. this.get('parentConfigGroup.hosts').forEach(function (hostName) {
  86. unusedHostsMap[hostName] = true;
  87. });
  88. App.Host.find().filter(function (host) {
  89. if(unusedHostsMap[host.get('id')]) {
  90. availableHosts.pushObject(Ember.Object.create({
  91. selected: false,
  92. host: host
  93. }));
  94. }
  95. });
  96. return availableHosts;
  97. }.property('isDefault', 'parentConfigGroup', 'childConfigGroups', 'parentConfigGroup.hosts.@each'),
  98. isAddHostsDisabled: function () {
  99. return (this.get('isDefault') || this.get('availableHosts.length') === 0);
  100. }.property('availableHosts.length'),
  101. /**
  102. * Collection of (site, tag) pairs representing properties.
  103. *
  104. * When {#isDefault} is true, this represents the
  105. * default cluster configurations for that service.
  106. *
  107. * When {#isDefault} is false, this represents the
  108. * configuration overrides on top of the cluster default for the
  109. * hosts identified by 'hosts'.
  110. */
  111. configSiteTags: [],
  112. properties: [],
  113. propertiesList: function () {
  114. var result = '';
  115. this.get('properties').forEach(function (item) {
  116. result += item.name + " : " + item.value + '<br/>';
  117. }, this);
  118. return result;
  119. }.property('properties.length')
  120. });