highAvailability_controller.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 (this.getTotalHosts() < 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. /**
  55. * get total hosts count from cluster API
  56. * @return {Number}
  57. */
  58. getTotalHosts: function () {
  59. App.ajax.send({
  60. name: 'hosts.total_count',
  61. data: {},
  62. sender: this,
  63. success: 'getTotalHostsSuccessCallback'
  64. });
  65. return totalHosts;
  66. },
  67. getTotalHostsSuccessCallback: function (data, opt, params) {
  68. totalHosts = data.Clusters.total_hosts;
  69. },
  70. disableHighAvailability: function () {
  71. App.router.transitionTo('main.admin.rollbackHighAvailability');
  72. },
  73. setSecurityStatus: function () {
  74. if (App.testMode) {
  75. this.set('securityEnabled', !App.testEnableSecurity);
  76. this.set('dataIsLoaded', true);
  77. } else {
  78. //get Security Status From Server
  79. App.ajax.send({
  80. name: 'admin.security_status',
  81. sender: this,
  82. success: 'getSecurityStatusFromServerSuccessCallback',
  83. error: 'errorCallback'
  84. });
  85. }
  86. },
  87. errorCallback: function () {
  88. this.showErrorPopup(Em.I18n.t('admin.security.status.error'));
  89. },
  90. getSecurityStatusFromServerSuccessCallback: function (data) {
  91. var configs = data.Clusters.desired_configs;
  92. if ('global' in configs) {
  93. this.set('tag', configs['global'].tag);
  94. this.getServiceConfigsFromServer();
  95. } else {
  96. this.showErrorPopup(Em.I18n.t('admin.security.status.error'));
  97. }
  98. },
  99. /**
  100. * get service configs from server and
  101. * indicate whether security is enabled
  102. */
  103. getServiceConfigsFromServer: function () {
  104. var tags = [
  105. {
  106. siteName: "global",
  107. tagName: this.get('tag')
  108. }
  109. ];
  110. var data = App.router.get('configurationController').getConfigsByTags(tags);
  111. var configs = data.findProperty('tag', this.get('tag')).properties;
  112. var securityEnabled = !!(configs && (configs['security_enabled'] === 'true' || configs['security_enabled'] === true));
  113. this.set('securityEnabled', securityEnabled);
  114. this.set('dataIsLoaded', true);
  115. },
  116. /**
  117. * join or wrap message depending on whether it is array or string
  118. * @param message
  119. * @return {*}
  120. */
  121. joinMessage: function (message) {
  122. if (Array.isArray(message)) {
  123. return message.join('<br/>');
  124. } else {
  125. return '<p>' + message + '</p>';
  126. }
  127. },
  128. showErrorPopup: function (message) {
  129. message = this.joinMessage(message);
  130. App.ModalPopup.show({
  131. header: Em.I18n.t('common.error'),
  132. bodyClass: Ember.View.extend({
  133. template: Ember.Handlebars.compile(message)
  134. }),
  135. secondary: false
  136. });
  137. }
  138. });