highAvailability_controller.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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.MainAdminHighAvailabilityController = Em.Controller.extend({
  20. name: 'mainAdminHighAvailabilityController',
  21. securityEnabled: false,
  22. tag: null,
  23. dataIsLoaded: false,
  24. /**
  25. * enable High Availability
  26. * @return {Boolean}
  27. */
  28. enableHighAvailability: function () {
  29. var message = [];
  30. var hostComponents = App.HostComponent.find();
  31. //Prerequisite Checks
  32. if (this.get('securityEnabled')) {
  33. this.showErrorPopup(Em.I18n.t('admin.highAvailability.error.security'));
  34. return false;
  35. } else {
  36. if (hostComponents.findProperty('componentName', 'NAMENODE').get('workStatus') !== 'STARTED') {
  37. message.push(Em.I18n.t('admin.highAvailability.error.namenodeStarted'));
  38. }
  39. if (hostComponents.filterProperty('componentName', 'ZOOKEEPER_SERVER').length < 3) {
  40. message.push(Em.I18n.t('admin.highAvailability.error.zooKeeperNum'));
  41. }
  42. if (App.router.get('mainHostController.hostsCountMap.TOTAL') < 3) {
  43. message.push(Em.I18n.t('admin.highAvailability.error.hostsNum'));
  44. }
  45. if (message.length > 0) {
  46. this.showErrorPopup(message);
  47. return false;
  48. }
  49. }
  50. App.router.transitionTo('main.admin.enableHighAvailability');
  51. return true;
  52. },
  53. disableHighAvailability: function () {
  54. App.router.transitionTo('main.admin.rollbackHighAvailability');
  55. },
  56. /**
  57. * enable ResourceManager High Availability
  58. * @return {Boolean}
  59. */
  60. enableRMHighAvailability: function () {
  61. //Prerequisite Checks
  62. var message = [];
  63. if (App.HostComponent.find().filterProperty('componentName', 'ZOOKEEPER_SERVER').length < 3) {
  64. message.push(Em.I18n.t('admin.rm_highAvailability.error.zooKeeperNum'));
  65. }
  66. if (App.router.get('mainHostController.hostsCountMap.TOTAL') < 3) {
  67. message.push(Em.I18n.t('admin.rm_highAvailability.error.hostsNum'));
  68. }
  69. if (message.length > 0) {
  70. this.showErrorPopup(message);
  71. return false;
  72. }
  73. App.router.transitionTo('main.admin.enableRMHighAvailability');
  74. return true;
  75. },
  76. setSecurityStatus: function () {
  77. if (App.testMode) {
  78. this.set('securityEnabled', !App.testEnableSecurity);
  79. this.set('dataIsLoaded', true);
  80. } else {
  81. //get Security Status From Server
  82. App.ajax.send({
  83. name: 'admin.security_status',
  84. sender: this,
  85. success: 'getSecurityStatusFromServerSuccessCallback',
  86. error: 'errorCallback'
  87. });
  88. }
  89. },
  90. errorCallback: function () {
  91. this.showErrorPopup(Em.I18n.t('admin.security.status.error'));
  92. },
  93. getSecurityStatusFromServerSuccessCallback: function (data) {
  94. var configs = data.Clusters.desired_configs;
  95. if ('hadoop-env' in configs) {
  96. this.set('tag', configs['hadoop-env'].tag);
  97. this.getServiceConfigsFromServer();
  98. } else {
  99. this.showErrorPopup(Em.I18n.t('admin.security.status.error'));
  100. }
  101. },
  102. /**
  103. * get service configs from server and
  104. * indicate whether security is enabled
  105. */
  106. getServiceConfigsFromServer: function () {
  107. var self = this;
  108. var tags = [
  109. {
  110. siteName: "hadoop-env",
  111. tagName: this.get('tag')
  112. }
  113. ];
  114. App.router.get('configurationController').getConfigsByTags(tags).done(function (data) {
  115. var configs = data.findProperty('tag', self.get('tag')).properties;
  116. var securityEnabled = !!(configs && (configs['security_enabled'] === 'true' || configs['security_enabled'] === true));
  117. self.set('securityEnabled', securityEnabled);
  118. self.set('dataIsLoaded', true);
  119. });
  120. },
  121. /**
  122. * join or wrap message depending on whether it is array or string
  123. * @param message
  124. * @return {*}
  125. */
  126. joinMessage: function (message) {
  127. if (Array.isArray(message)) {
  128. return message.join('<br/>');
  129. } else {
  130. return '<p>' + message + '</p>';
  131. }
  132. },
  133. showErrorPopup: function (message) {
  134. message = this.joinMessage(message);
  135. App.ModalPopup.show({
  136. header: Em.I18n.t('common.error'),
  137. bodyClass: Ember.View.extend({
  138. template: Ember.Handlebars.compile(message)
  139. }),
  140. secondary: false
  141. });
  142. }
  143. });