highAvailability_controller.js 4.8 KB

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