misc_controller.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 installedServices = App.Service.find().mapProperty("serviceName");
  44. var serviceConfigsDef = params.serviceConfigsDef;
  45. var serviceName = this.get('content.serviceName');
  46. var loadedClusterSiteToTagMap = {};
  47. for (var site in data.Clusters.desired_configs) {
  48. if (!!serviceConfigsDef.configTypes[site]) {
  49. loadedClusterSiteToTagMap[site] = data.Clusters.desired_configs[site]['tag'];
  50. }
  51. }
  52. this.setServiceConfigTags(loadedClusterSiteToTagMap);
  53. var configGroups = App.router.get('configurationController').getConfigsByTags(this.get('serviceConfigTags'));
  54. var configSet = App.config.mergePreDefinedWithLoaded(configGroups, [], this.get('serviceConfigTags'), serviceName);
  55. var misc_configs = configSet.globalConfigs.filterProperty('serviceName', this.get('selectedService')).filterProperty('category', 'Users and Groups').filterProperty('isVisible', true);
  56. misc_configs = App.config.miscConfigVisibleProperty(misc_configs, installedServices);
  57. var sortOrder = this.get('configs').filterProperty('serviceName', this.get('selectedService')).filterProperty('category', 'Users and Groups').filterProperty('isVisible', true).mapProperty('name');
  58. //stack, with version lower than 2.1, doesn't have Falcon service
  59. this.setProxyUserGroupLabel(misc_configs);
  60. this.set('users', this.sortByOrder(sortOrder, misc_configs));
  61. this.setContentProperty('hdfsUser', 'hdfs_user', misc_configs);
  62. this.setContentProperty('group', 'user_group', misc_configs);
  63. this.set('dataIsLoaded', true);
  64. },
  65. /**
  66. * set config value to property of "content"
  67. * @param key
  68. * @param configName
  69. * @param misc_configs
  70. * @return {Boolean}
  71. */
  72. setContentProperty: function (key, configName, misc_configs) {
  73. var content = this.get('content');
  74. if (key && configName && misc_configs.someProperty('name', configName) && content.get(key)) {
  75. content.set(key, misc_configs.findProperty('name', configName).get("value"));
  76. return true;
  77. }
  78. return false;
  79. },
  80. /**
  81. * sort miscellaneous configs by specific order
  82. * @param sortOrder
  83. * @param arrayToSort
  84. * @return {Array}
  85. */
  86. sortByOrder: function (sortOrder, arrayToSort) {
  87. var sorted = [];
  88. if (sortOrder && sortOrder.length > 0) {
  89. sortOrder.forEach(function (name) {
  90. var user = arrayToSort.findProperty('name', name);
  91. if (user) {
  92. sorted.push({
  93. isVisible: user.get('isVisible'),
  94. displayName: user.get('displayName'),
  95. value: user.get('value')
  96. });
  97. }
  98. });
  99. return sorted;
  100. } else {
  101. return arrayToSort;
  102. }
  103. },
  104. /**
  105. * set displayName of "proxyuser_group" depending on stack version
  106. * @param misc_configs
  107. */
  108. setProxyUserGroupLabel: function (misc_configs) {
  109. var proxyUserGroup = misc_configs.findProperty('name', 'proxyuser_group');
  110. if (proxyUserGroup && !App.get('isHadoop21Stack')) {
  111. proxyUserGroup.set('displayName', "Proxy group for Hive, WebHCat and Oozie");
  112. }
  113. }
  114. });