serviceAccounts_controller.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. serviceConfigTags: [],
  25. content: Em.Object.create({
  26. serviceName: 'MISC'
  27. }),
  28. loadUsers: function () {
  29. this.set('selectedService', this.get('content.serviceName') ? this.get('content.serviceName') : "MISC");
  30. this.loadServiceConfig();
  31. },
  32. loadServiceConfig: function () {
  33. App.ajax.send({
  34. name: 'config.tags',
  35. sender: this,
  36. data: {
  37. serviceName: this.get('selectedService'),
  38. serviceConfigsDef: this.get('serviceConfigs').findProperty('serviceName', this.get('selectedService'))
  39. },
  40. success: 'loadServiceTagSuccess'
  41. });
  42. },
  43. loadServiceTagSuccess: function (data, opt, params) {
  44. var self = this;
  45. var serviceConfigsDef = params.serviceConfigsDef;
  46. var loadedClusterSiteToTagMap = {};
  47. for (var site in Em.get(data, 'Clusters.desired_configs')) {
  48. if (serviceConfigsDef.get('configTypes').hasOwnProperty(site)) {
  49. loadedClusterSiteToTagMap[site] = data.Clusters.desired_configs[site]['tag'];
  50. }
  51. }
  52. this.setServiceConfigTags(loadedClusterSiteToTagMap);
  53. // load server stored configurations
  54. App.router.get('configurationController').getConfigsByTags(this.get('serviceConfigTags')).done(function (serverConfigs) {
  55. self.createConfigObject(serverConfigs);
  56. });
  57. },
  58. /**
  59. * Changes format from Object to Array
  60. *
  61. * {
  62. * 'core-site': 'version1',
  63. * 'hdfs-site': 'version1',
  64. * ...
  65. * }
  66. *
  67. * to
  68. *
  69. * [
  70. * {
  71. * siteName: 'core-site',
  72. * tagName: 'version1',
  73. * newTageName: null
  74. * },
  75. * ...
  76. * ]
  77. *
  78. * set tagnames for configuration of the *-site.xml
  79. * @private
  80. * @method setServiceConfigTags
  81. */
  82. setServiceConfigTags: function (desiredConfigsSiteTags) {
  83. var newServiceConfigTags = [];
  84. for (var index in desiredConfigsSiteTags) {
  85. newServiceConfigTags.pushObject({
  86. siteName: index,
  87. tagName: desiredConfigsSiteTags[index],
  88. newTagName: null
  89. }, this);
  90. }
  91. this.set('serviceConfigTags', newServiceConfigTags);
  92. },
  93. /**
  94. * Generate configuration object that will be rendered
  95. *
  96. * @param {Object[]} serverConfigs
  97. */
  98. createConfigObject: function(serverConfigs) {
  99. var configs = [];
  100. serverConfigs.forEach(function(configObject) {
  101. configs = configs.concat(App.config.getConfigsFromJSON(configObject, true));
  102. });
  103. var miscConfigs = configs.filterProperty('displayType', 'user').filterProperty('category', 'Users and Groups');
  104. miscConfigs.setEach('isVisible', true);
  105. this.set('users', miscConfigs);
  106. this.set('dataIsLoaded', true);
  107. },
  108. /**
  109. * sort miscellaneous configs by specific order
  110. * @param sortOrder
  111. * @param arrayToSort
  112. * @return {Array}
  113. */
  114. sortByOrder: function (sortOrder, arrayToSort) {
  115. var sorted = [];
  116. if (sortOrder && sortOrder.length > 0) {
  117. sortOrder.forEach(function (name) {
  118. var user = arrayToSort.findProperty('name', name);
  119. if (user) {
  120. sorted.push({
  121. isVisible: user.get('isVisible'),
  122. displayName: user.get('displayName'),
  123. value: user.get('value')
  124. });
  125. }
  126. });
  127. return sorted;
  128. } else {
  129. return arrayToSort;
  130. }
  131. }
  132. });