security.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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.MainAdminSecurityController = Em.Controller.extend({
  20. name: 'mainAdminSecurityController',
  21. isSubmitDisabled: false,
  22. securityEnabled: false,
  23. dataIsLoaded: false,
  24. serviceUsers: [],
  25. tag: {},
  26. getAddSecurityWizardStatus: function () {
  27. return App.db.getSecurityWizardStatus();
  28. },
  29. setAddSecurityWizardStatus: function (status) {
  30. App.db.setSecurityWizardStatus(status);
  31. },
  32. setDisableSecurityStatus: function (status) {
  33. App.db.setDisableSecurityStatus(status);
  34. },
  35. getDisableSecurityStatus: function (status) {
  36. return App.db.getDisableSecurityStatus();
  37. },
  38. notifySecurityOff: false,
  39. notifySecurityAdd: false,
  40. notifySecurityOffPopup: function () {
  41. var self = this;
  42. if (!this.get('isSubmitDisabled')) {
  43. App.ModalPopup.show({
  44. header: Em.I18n.t('popup.confirmation.commonHeader'),
  45. primary: Em.I18n.t('ok'),
  46. onPrimary: function () {
  47. App.db.setSecurityDeployStages(undefined);
  48. self.setDisableSecurityStatus("RUNNING");
  49. App.router.transitionTo('disableSecurity');
  50. this.hide();
  51. },
  52. bodyClass: Ember.View.extend({
  53. isMapReduceInstalled: App.Service.find().mapProperty('serviceName').contains('MAPREDUCE'),
  54. template: Ember.Handlebars.compile([
  55. '<div class="alert">',
  56. '{{t admin.security.disable.popup.body}}',
  57. '{{#if view.isMapReduceInstalled}}',
  58. '<br>',
  59. '{{t admin.security.disable.popup.body.warning}}',
  60. '{{/if}}',
  61. '</div>'
  62. ].join('\n'))
  63. })
  64. })
  65. }
  66. },
  67. getUpdatedSecurityStatus: function () {
  68. this.setSecurityStatus();
  69. return this.get('securityEnabled');
  70. },
  71. setSecurityStatus: function () {
  72. if (App.testMode) {
  73. this.set('securityEnabled', !App.testEnableSecurity);
  74. this.set('dataIsLoaded', true);
  75. } else {
  76. //get Security Status From Server
  77. App.ajax.send({
  78. name: 'admin.security_status',
  79. sender: this,
  80. success: 'getSecurityStatusFromServerSuccessCallback',
  81. error: 'errorCallback'
  82. });
  83. }
  84. },
  85. errorCallback: function () {
  86. this.set('dataIsLoaded', true);
  87. this.showSecurityErrorPopup();
  88. },
  89. getSecurityStatusFromServerSuccessCallback: function (data) {
  90. var configs = data.Clusters.desired_configs;
  91. if ('global' in configs && 'core-site' in configs) {
  92. this.set('tag.global', configs['global'].tag);
  93. this.set('tag.core-site', configs['core-site'].tag);
  94. this.getServiceConfigsFromServer();
  95. }
  96. else {
  97. this.showSecurityErrorPopup();
  98. }
  99. },
  100. getServiceConfigsFromServer: function () {
  101. var urlParams = [];
  102. urlParams.push('(type=global&tag=' + this.get('tag.global') + ')');
  103. urlParams.push('(type=core-site&tag=' + this.get('tag.core-site') + ')');
  104. App.ajax.send({
  105. name: 'admin.security.all_configurations',
  106. sender: this,
  107. data: {
  108. urlParams: urlParams.join('|')
  109. },
  110. success: 'getServiceConfigsFromServerSuccessCallback',
  111. error: 'errorCallback'
  112. });
  113. },
  114. getServiceConfigsFromServerSuccessCallback: function (data) {
  115. console.log("TRACE: In success function for the GET getServiceConfigsFromServer call");
  116. var configs = data.items.findProperty('tag', this.get('tag.global')).properties;
  117. if (configs && (configs['security_enabled'] === 'true' || configs['security_enabled'] === true)) {
  118. this.set('securityEnabled', true);
  119. }
  120. else {
  121. this.set('securityEnabled', false);
  122. var coreConfigs = data.items.findProperty('tag', this.get('tag.core-site')).properties;
  123. this.setNnHaStatus(coreConfigs);
  124. }
  125. this.loadUsers(configs);
  126. this.set('dataIsLoaded', true);
  127. },
  128. setNnHaStatus: function(coreConfigs) {
  129. if(coreConfigs && coreConfigs['dfs.nameservices'] && coreConfigs['dfs.ha.namenodes.mycluster']) {
  130. App.db.setIsNameNodeHa('true');
  131. } else {
  132. App.db.setIsNameNodeHa('false');
  133. }
  134. },
  135. loadUsers: function (configs) {
  136. var serviceUsers = this.get('serviceUsers');
  137. serviceUsers.pushObject({
  138. id: 'puppet var',
  139. name: 'hdfs_user',
  140. value: configs['hdfs_user'] ? configs['hdfs_user'] : 'hdfs'
  141. });
  142. serviceUsers.pushObject({
  143. id: 'puppet var',
  144. name: 'yarn_user',
  145. value: configs['yarn_user'] ? configs['yarn_user'] : 'yarn'
  146. });
  147. serviceUsers.pushObject({
  148. id: 'puppet var',
  149. name: 'mapred_user',
  150. value: configs['mapred_user'] ? configs['mapred_user'] : 'mapred'
  151. });
  152. serviceUsers.pushObject({
  153. id: 'puppet var',
  154. name: 'hbase_user',
  155. value: configs['hbase_user'] ? configs['hbase_user'] : 'hbase'
  156. });
  157. serviceUsers.pushObject({
  158. id: 'puppet var',
  159. name: 'hive_user',
  160. value: configs['hive_user'] ? configs['hive_user'] : 'hive'
  161. });
  162. serviceUsers.pushObject({
  163. id: 'puppet var',
  164. name: 'proxyuser_group',
  165. value: configs['proxyuser_group'] ? configs['proxyuser_group'] : 'users'
  166. });
  167. serviceUsers.pushObject({
  168. id: 'puppet var',
  169. name: 'smokeuser',
  170. value: configs['smokeuser'] ? configs['smokeuser'] : 'ambari-qa'
  171. });
  172. serviceUsers.pushObject({
  173. id: 'puppet var',
  174. name: 'zk_user',
  175. value: configs['zk_user'] ? configs['zk_user'] : 'zookeeper'
  176. });
  177. serviceUsers.pushObject({
  178. id: 'puppet var',
  179. name: 'oozie_user',
  180. value: configs['oozie_user'] ? configs['oozie_user'] : 'oozie'
  181. });
  182. serviceUsers.pushObject({
  183. id: 'puppet var',
  184. name: 'nagios_user',
  185. value: configs['nagios_user'] ? configs['nagios_user'] : 'nagios'
  186. });
  187. serviceUsers.pushObject({
  188. id: 'puppet var',
  189. name: 'user_group',
  190. value: configs['user_group'] ? configs['user_group'] : 'hadoop'
  191. });
  192. },
  193. showSecurityErrorPopup: function () {
  194. App.ModalPopup.show({
  195. header: Em.I18n.t('common.error'),
  196. secondary: false,
  197. onPrimary: function () {
  198. this.hide();
  199. },
  200. bodyClass: Ember.View.extend({
  201. template: Ember.Handlebars.compile('<p>{{t admin.security.status.error}}</p>')
  202. })
  203. });
  204. }
  205. });