misc_controller.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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.MainAdminMiscController = App.MainServiceInfoConfigsController.extend({
  22. name: 'mainAdminMiscController',
  23. users: null,
  24. content: Em.Object.create({
  25. serviceName: 'MISC'
  26. }),
  27. loadUsers: function () {
  28. this.set('selectedService', this.get('content.serviceName'));
  29. this.loadServiceConfig();
  30. },
  31. loadServiceConfig: function () {
  32. App.ajax.send({
  33. name: 'config.tags',
  34. sender: this,
  35. data: {
  36. serviceName: this.get('content.serviceName'),
  37. serviceConfigsDef: this.get('serviceConfigs').findProperty('serviceName', this.get('content.serviceName'))
  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('content.serviceName');
  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. App.router.get('configurationController').getConfigsByTags(this.get('serviceConfigTags')).done(function(configGroups){
  55. var configSet = App.config.mergePreDefinedWithLoaded(configGroups, [], self.get('serviceConfigTags'), serviceName);
  56. var misc_configs = configSet.globalConfigs.filterProperty('serviceName', self.get('selectedService')).filterProperty('category', 'Users and Groups').filterProperty('isVisible', true);
  57. misc_configs = App.config.miscConfigVisibleProperty(misc_configs, installedServices);
  58. var sortOrder = self.get('configs').filterProperty('serviceName', self.get('selectedService')).filterProperty('category', 'Users and Groups').filterProperty('isVisible', true).mapProperty('name');
  59. //stack, with version lower than 2.1, doesn't have Falcon service
  60. self.setProxyUserGroupLabel(misc_configs);
  61. self.set('users', self.sortByOrder(sortOrder, misc_configs));
  62. self.setContentProperty('hdfsUser', 'hdfs_user', misc_configs);
  63. self.setContentProperty('group', 'user_group', misc_configs);
  64. self.set('dataIsLoaded', true);
  65. });
  66. },
  67. /**
  68. * set config value to property of "content"
  69. * @param key
  70. * @param configName
  71. * @param misc_configs
  72. * @return {Boolean}
  73. */
  74. setContentProperty: function (key, configName, misc_configs) {
  75. var content = this.get('content');
  76. if (key && configName && misc_configs.someProperty('name', configName) && content.get(key)) {
  77. content.set(key, misc_configs.findProperty('name', configName).get("value"));
  78. return true;
  79. }
  80. return false;
  81. },
  82. /**
  83. * sort miscellaneous configs by specific order
  84. * @param sortOrder
  85. * @param arrayToSort
  86. * @return {Array}
  87. */
  88. sortByOrder: function (sortOrder, arrayToSort) {
  89. var sorted = [];
  90. if (sortOrder && sortOrder.length > 0) {
  91. sortOrder.forEach(function (name) {
  92. var user = arrayToSort.findProperty('name', name);
  93. if (user) {
  94. sorted.push({
  95. isVisible: user.get('isVisible'),
  96. displayName: user.get('displayName'),
  97. value: user.get('value')
  98. });
  99. }
  100. });
  101. return sorted;
  102. } else {
  103. return arrayToSort;
  104. }
  105. },
  106. /**
  107. * set displayName of "proxyuser_group" depending on stack version
  108. * @param misc_configs
  109. */
  110. setProxyUserGroupLabel: function (misc_configs) {
  111. var proxyUserGroup = misc_configs.findProperty('name', 'proxyuser_group');
  112. if (proxyUserGroup && !App.get('isHadoop21Stack')) {
  113. proxyUserGroup.set('displayName', "Proxy group for Hive, WebHCat and Oozie");
  114. }
  115. }
  116. });