admin.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.MainAdminController = Em.Controller.extend({
  20. name: 'mainAdminController',
  21. category: 'user',
  22. securityEnabled: false,
  23. serviceUsers: [],
  24. /**
  25. * return true if security status is loaded and false otherwise
  26. */
  27. securityStatusLoading: function () {
  28. var dfd = $.Deferred();
  29. this.connectOutlet('loading');
  30. if (App.testMode) {
  31. window.setTimeout(function () {
  32. dfd.resolve();
  33. }, 50);
  34. } else {
  35. this.getSecurityStatusFromServer(dfd);
  36. }
  37. return dfd.promise();
  38. },
  39. /**
  40. * return true if security status is loaded and false otherwise
  41. */
  42. getSecurityStatusFromServer: function (dfd) { //TODO: this should be obtain from cluster level config rather than HDFS global config
  43. var self = this;
  44. var url = App.apiPrefix + '/clusters/' + App.router.getClusterName();
  45. $.ajax({
  46. type: 'GET',
  47. url: url,
  48. async: false, // we are retrieving user information that is used ahead in addSecurity/apply stage
  49. timeout: 10000,
  50. dataType: 'text',
  51. success: function (data) {
  52. console.log("TRACE: The url is: " + url);
  53. var jsonData = jQuery.parseJSON(data);
  54. var configs = jsonData.Clusters.desired_configs;
  55. if ('global' in configs) {
  56. self.getServiceConfigsFromServer(dfd, 'global', configs['global'].tag);
  57. } else {
  58. if (dfd) {
  59. dfd.reject();
  60. }
  61. }
  62. },
  63. error: function (request, ajaxOptions, error) {
  64. if (dfd) {
  65. dfd.reject();
  66. }
  67. },
  68. statusCode: require('data/statusCodes')
  69. });
  70. },
  71. getServiceConfigsFromServer: function (dfd, siteName, tagName) {
  72. var self = this;
  73. var url = App.apiPrefix + '/clusters/' + App.router.getClusterName() + '/configurations/?type=' + siteName + '&tag=' + tagName;
  74. $.ajax({
  75. type: 'GET',
  76. url: url,
  77. async: false, // we are retrieving user information that is used ahead in addSecurity/apply stage
  78. timeout: 10000,
  79. dataType: 'json',
  80. success: function (data) {
  81. console.log("TRACE: In success function for the GET getServiceConfigsFromServer call");
  82. console.log("TRACE: The url is: " + url);
  83. var configs = data.items.findProperty('tag', tagName).properties;
  84. if (configs && configs['security_enabled'] === 'true') {
  85. self.set('securityEnabled', true);
  86. } else {
  87. self.loadUsers(configs);
  88. self.set('securityEnabled', false);
  89. }
  90. if (dfd) {
  91. dfd.resolve();
  92. }
  93. },
  94. error: function (request, ajaxOptions, error) {
  95. if (dfd) {
  96. dfd.reject();
  97. }
  98. },
  99. statusCode: require('data/statusCodes')
  100. });
  101. },
  102. loadUsers: function (configs) {
  103. var serviceUsers = this.get('serviceUsers');
  104. if (configs['hdfs_user']) {
  105. serviceUsers.pushObject({id: 'puppet var', name: 'hdfs_user', value: configs['hdfs_user']});
  106. } else {
  107. serviceUsers.pushObject({id: 'puppet var', name: 'hdfs_user', value: 'hdfs'});
  108. }
  109. if (configs['mapred_user']) {
  110. serviceUsers.pushObject({id: 'puppet var', name: 'mapred_user', value: configs['mapred_user']});
  111. } else {
  112. serviceUsers.pushObject({id: 'puppet var', name: 'mapred_user', value: 'mapred'});
  113. }
  114. if (configs['hbase_user']) {
  115. serviceUsers.pushObject({id: 'puppet var', name: 'hbase_user', value: configs['hbase_user']});
  116. } else {
  117. serviceUsers.pushObject({id: 'puppet var', name: 'hbase_user', value: 'hbase'});
  118. }
  119. if (configs['hive_user']) {
  120. serviceUsers.pushObject({id: 'puppet var', name: 'hive_user', value: configs['hive_user']});
  121. } else {
  122. serviceUsers.pushObject({id: 'puppet var', name: 'hive_user', value: 'hive'});
  123. }
  124. }
  125. });