config_group.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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: function() {
  59. return this.get('configGroupId') == "-1";
  60. }.property('configGroupId'),
  61. /**
  62. * list of group names that shows which config
  63. * groups should be updated as dependent when current is changed
  64. * @type App.ServiceConfigGroup[]
  65. */
  66. dependentConfigGroups: DS.attr('object', {defaultValue: {}}),
  67. /**
  68. * Parent configuration group for this group.
  69. * When {@link #isDefault} is true, this value is <code>null</code>
  70. * When {@link #isDefault} is false, this represents the configuration
  71. * deltas that are applied on the default.
  72. */
  73. parentConfigGroup: DS.belongsTo('App.ServiceConfigGroup'),
  74. /**
  75. * Children configuration groups for this group.
  76. * When {@link #isDefault} is false, this value is <code>null</code>
  77. * When {@link #isDefault} is true, this represents the various
  78. * configuration groups that override the default.
  79. */
  80. childConfigGroups: DS.hasMany('App.ServiceConfigGroup'),
  81. hash: DS.attr('string'),
  82. /**
  83. * Provides a display friendly name. This includes trimming
  84. * names to a certain length.
  85. */
  86. displayName: function () {
  87. var name = this.get('name');
  88. if (name && name.length>App.config.CONFIG_GROUP_NAME_MAX_LENGTH) {
  89. var middle = Math.floor(App.config.CONFIG_GROUP_NAME_MAX_LENGTH / 2);
  90. name = name.substring(0, middle) + "..." + name.substring(name.length-middle);
  91. }
  92. return name;
  93. }.property('name'),
  94. /**
  95. *
  96. */
  97. displayNameHosts: Em.computed.format('{0} ({1})', 'displayName', 'hosts.length'),
  98. /**
  99. * Provides hosts which are available for inclusion in
  100. * non-default configuration groups.
  101. */
  102. availableHosts: function () {
  103. if (this.get('isDefault')) return [];
  104. var unusedHostsMap = this.get('parentConfigGroup.hosts').toWickMap();
  105. var availableHosts = [];
  106. var sharedHosts = this.get('clusterHosts');
  107. // parentConfigGroup.hosts(hosts from default group) - are available hosts, which don't belong to any group
  108. sharedHosts.forEach(function (host) {
  109. if (unusedHostsMap[host.get('id')]) {
  110. availableHosts.pushObject(Ember.Object.create({
  111. selected: false,
  112. host: host,
  113. hostComponentNames: host.get('hostComponents').mapProperty('componentName')
  114. }));
  115. }
  116. });
  117. return availableHosts;
  118. }.property('isDefault', 'parentConfigGroup', 'childConfigGroups', 'parentConfigGroup.hosts.@each', 'clusterHosts'),
  119. isAddHostsDisabled: Em.computed.or('isDefault', '!availableHosts.length'),
  120. /**
  121. * @type {Array}
  122. */
  123. properties: DS.attr('array', {defaultValue: []}),
  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. };