serviceAccounts_controller.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. var stringUtils = require('utils/string_utils');
  20. require('controllers/main/service/info/configs');
  21. App.MainAdminServiceAccountsController = App.MainServiceInfoConfigsController.extend({
  22. name: 'mainAdminServiceAccountsController',
  23. users: null,
  24. content: Em.Object.create({
  25. serviceName: 'MISC'
  26. }),
  27. loadUsers: function () {
  28. this.set('selectedService', this.get('content.serviceName') ? this.get('content.serviceName') : "MISC");
  29. this.loadServiceConfig();
  30. },
  31. loadServiceConfig: function () {
  32. App.ajax.send({
  33. name: 'config.tags',
  34. sender: this,
  35. data: {
  36. serviceName: this.get('selectedService'),
  37. serviceConfigsDef: this.get('serviceConfigs').findProperty('serviceName', this.get('selectedService'))
  38. },
  39. success: 'loadServiceTagSuccess'
  40. });
  41. },
  42. loadServiceTagSuccess: function (data, opt, params) {
  43. var self = this;
  44. var installedServices = App.Service.find().mapProperty("serviceName");
  45. var serviceConfigsDef = params.serviceConfigsDef;
  46. var serviceName = this.get('selectedService');
  47. var loadedClusterSiteToTagMap = {};
  48. for (var site in data.Clusters.desired_configs) {
  49. if (!!serviceConfigsDef.configTypes[site]) {
  50. loadedClusterSiteToTagMap[site] = data.Clusters.desired_configs[site]['tag'];
  51. }
  52. }
  53. this.setServiceConfigTags(loadedClusterSiteToTagMap);
  54. // load server stored configurations
  55. App.router.get('configurationController').getConfigsByTags(this.get('serviceConfigTags')).done(function (serverConfigs) {
  56. // load configurations list for installed services
  57. App.config.loadAdvancedConfigPartial(installedServices, {
  58. queryFilter: 'configurations/StackConfigurations/property_type.matches(.*[USER,GROUP].*)'
  59. }, function(advancedConfigs) {
  60. // load cluster configs
  61. App.config.loadClusterConfig(function(clusterConfigs) {
  62. self.createConfigObject(serverConfigs, advancedConfigs.concat(clusterConfigs));
  63. });
  64. });
  65. });
  66. },
  67. /**
  68. * Generate configuration object that will be rendered
  69. *
  70. * @param {Object[]} serverConfigs
  71. * @param {Object[]} advancedConfigs
  72. */
  73. createConfigObject: function(serverConfigs, advancedConfigs) {
  74. var configSet = App.config.mergePreDefinedWithLoaded(serverConfigs, advancedConfigs, this.get('serviceConfigTags'), this.get('selectedService'));
  75. var miscConfigs = configSet.configs.filterProperty('serviceName', this.get('selectedService')).filterProperty('category', 'Users and Groups').filterProperty('isVisible', true).rejectProperty('displayType', 'password');
  76. miscConfigs = App.config.miscConfigVisibleProperty(miscConfigs, App.Service.find().mapProperty('serviceName'));
  77. this.set('users', miscConfigs.filterProperty('isVisible'));
  78. this.set('dataIsLoaded', true);
  79. },
  80. /**
  81. * set config value to property of "content"
  82. * @param key
  83. * @param configName
  84. * @param misc_configs
  85. * @return {Boolean}
  86. */
  87. setContentProperty: function (key, configName, misc_configs) {
  88. var content = this.get('content');
  89. if (key && configName && misc_configs.someProperty('name', configName) && content.get(key)) {
  90. content.set(key, misc_configs.findProperty('name', configName).get("value"));
  91. return true;
  92. }
  93. return false;
  94. },
  95. /**
  96. * sort miscellaneous configs by specific order
  97. * @param sortOrder
  98. * @param arrayToSort
  99. * @return {Array}
  100. */
  101. sortByOrder: function (sortOrder, arrayToSort) {
  102. var sorted = [];
  103. if (sortOrder && sortOrder.length > 0) {
  104. sortOrder.forEach(function (name) {
  105. var user = arrayToSort.findProperty('name', name);
  106. if (user) {
  107. sorted.push({
  108. isVisible: user.get('isVisible'),
  109. displayName: user.get('displayName'),
  110. value: user.get('value')
  111. });
  112. }
  113. });
  114. return sorted;
  115. } else {
  116. return arrayToSort;
  117. }
  118. },
  119. /**
  120. * set displayName of "proxyuser_group" depending on stack version
  121. * @param misc_configs
  122. */
  123. setProxyUserGroupLabel: function (misc_configs) {
  124. var proxyUserGroup = misc_configs.findProperty('name', 'proxyuser_group');
  125. //stack, with version lower than 2.1, doesn't have Falcon service
  126. if (proxyUserGroup) {
  127. var proxyServices = ['HIVE', 'OOZIE', 'FALCON'];
  128. var services = Em.A([]);
  129. proxyServices.forEach(function (serviceName) {
  130. var stackService = App.StackService.find(serviceName);
  131. if (stackService) {
  132. services.push(stackService.get('displayName'));
  133. }
  134. }, this);
  135. proxyUserGroup.set('displayName', "Proxy group for " + stringUtils.getFormattedStringFromArray(services));
  136. }
  137. }
  138. });