config_group.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. App.ServiceConfigGroup = DS.Model.extend({
  20. /**
  21. * unique id generated as <code>serviceName<code><code>configGroupId<code>
  22. * in case default configGroup <code>serviceName<code><code>0<code>
  23. * @property {string}
  24. */
  25. id: DS.attr('string'),
  26. /**
  27. * original id for config group that is get from server
  28. * for default groups "-1"
  29. * @property {number}
  30. */
  31. configGroupId: DS.attr('number'),
  32. name: DS.attr('string'),
  33. serviceName: DS.attr('string'),
  34. description: DS.attr('string'),
  35. hosts: DS.attr('array'),
  36. configVersions: DS.hasMany('App.ConfigVersion'),
  37. service: DS.belongsTo('App.Service'),
  38. desiredConfigs: DS.attr('array', {defaultValue: []}),
  39. /**
  40. * this flag is used for installed services' config groups
  41. * if user make changes to them - mark this flag to true
  42. * @default [false]
  43. */
  44. isForUpdate: DS.attr('boolean', {defaultValue: false}),
  45. /**
  46. * mark config groups for installed services
  47. * @default [false]
  48. */
  49. isForInstalledService: DS.attr('boolean', {defaultValue: false}),
  50. /**
  51. * all hosts that belong to cluster
  52. */
  53. clusterHostsBinding: 'App.router.manageConfigGroupsController.clusterHosts',
  54. /**
  55. * defines if group is default
  56. * @type {boolean}
  57. */
  58. isDefault: Em.computed.equal('configGroupId', '-1'),
  59. /**
  60. * list of group names that shows which config
  61. * groups should be updated as dependent when current is changed
  62. * @type App.ServiceConfigGroup[]
  63. */
  64. dependentConfigGroups: DS.attr('object', {defaultValue: {}}),
  65. /**
  66. * Parent configuration group for this group.
  67. * When {@link #isDefault} is true, this value is <code>null</code>
  68. * When {@link #isDefault} is false, this represents the configuration
  69. * deltas that are applied on the default.
  70. */
  71. parentConfigGroup: DS.belongsTo('App.ServiceConfigGroup'),
  72. /**
  73. * Children configuration groups for this group.
  74. * When {@link #isDefault} is false, this value is <code>null</code>
  75. * When {@link #isDefault} is true, this represents the various
  76. * configuration groups that override the default.
  77. */
  78. childConfigGroups: DS.hasMany('App.ServiceConfigGroup'),
  79. hash: DS.attr('string'),
  80. /**
  81. * Provides a display friendly name. This includes trimming
  82. * names to a certain length.
  83. */
  84. displayName: function () {
  85. return App.config.truncateGroupName(this.get('name'));
  86. }.property('name'),
  87. /**
  88. *
  89. */
  90. displayNameHosts: Em.computed.format('{0} ({1})', 'displayName', 'hosts.length'),
  91. /**
  92. * Provides hosts which are available for inclusion in
  93. * non-default configuration groups.
  94. * @type {Array}
  95. */
  96. availableHosts: function () {
  97. if (this.get('isDefault')) return [];
  98. var unusedHostsMap = this.get('parentConfigGroup.hosts').toWickMap();
  99. var availableHosts = [];
  100. var sharedHosts = this.get('clusterHosts');
  101. // parentConfigGroup.hosts(hosts from default group) - are available hosts, which don't belong to any group
  102. sharedHosts.forEach(function (host) {
  103. if (unusedHostsMap[host.get('id')]) {
  104. availableHosts.pushObject(Ember.Object.create({
  105. selected: false,
  106. host: host,
  107. hostComponentNames: host.get('hostComponents').mapProperty('componentName')
  108. }));
  109. }
  110. });
  111. return availableHosts;
  112. }.property('isDefault', 'parentConfigGroup', 'childConfigGroups', 'parentConfigGroup.hosts.@each', 'clusterHosts'),
  113. /**
  114. * @type {boolean}
  115. */
  116. isAddHostsDisabled: Em.computed.or('isDefault', '!availableHosts.length'),
  117. /**
  118. * @type {Array}
  119. */
  120. properties: DS.attr('array', {defaultValue: []}),
  121. /**
  122. * @type {string}
  123. */
  124. propertiesList: function () {
  125. var result = '';
  126. if (Array.isArray(this.get('properties'))) {
  127. this.get('properties').forEach(function (item) {
  128. result += item.name + " : " + item.value + '<br/>';
  129. }, this);
  130. }
  131. return result;
  132. }.property('properties.length')
  133. });
  134. App.ServiceConfigGroup.FIXTURES = [];
  135. App.ServiceConfigGroup.getParentConfigGroupId = function(serviceName) {
  136. return App.ServiceConfigGroup.groupId(serviceName, 'Default');
  137. };
  138. App.ServiceConfigGroup.groupId = function(serviceName, groupName) {
  139. return serviceName + "_" + groupName;
  140. };