highAvailability_controller.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. enableHighAvailability: function () {
  25. var message = [];
  26. //Prerequisite Checks
  27. if (this.get('securityEnabled')) {
  28. this.showErrorPopup(Em.I18n.t('admin.highAvailability.error.security'));
  29. return;
  30. } else {
  31. if (App.HostComponent.find().findProperty('componentName', 'NAMENODE').get('workStatus') !== 'STARTED') {
  32. message.push(Em.I18n.t('admin.highAvailability.error.namenodeStarted'));
  33. }
  34. if (App.HostComponent.find().filterProperty('componentName', 'ZOOKEEPER_SERVER').length < 3) {
  35. message.push(Em.I18n.t('admin.highAvailability.error.zooKeeperNum'));
  36. }
  37. if (App.Host.find().content.length < 3) {
  38. message.push(Em.I18n.t('admin.highAvailability.error.hostsNum'));
  39. }
  40. if (message.length > 0) {
  41. this.showErrorPopup(message);
  42. return;
  43. }
  44. }
  45. App.router.transitionTo('enableHighAvailability');
  46. },
  47. disableHighAvailability: function () {
  48. App.router.transitionTo('rollbackHighAvailability');
  49. },
  50. setSecurityStatus: function () {
  51. if (App.testMode) {
  52. this.set('securityEnabled', !App.testEnableSecurity);
  53. this.set('dataIsLoaded', true);
  54. } else {
  55. //get Security Status From Server
  56. App.ajax.send({
  57. name: 'admin.security_status',
  58. sender: this,
  59. success: 'getSecurityStatusFromServerSuccessCallback',
  60. error: 'errorCallback'
  61. });
  62. }
  63. },
  64. errorCallback: function () {
  65. this.showErrorPopup(Em.I18n.t('admin.security.status.error'));
  66. },
  67. getSecurityStatusFromServerSuccessCallback: function (data) {
  68. var configs = data.Clusters.desired_configs;
  69. if ('global' in configs) {
  70. this.set('tag', configs['global'].tag);
  71. this.getServiceConfigsFromServer();
  72. }
  73. else {
  74. this.showErrorPopup(Em.I18n.t('admin.security.status.error'));
  75. }
  76. },
  77. getServiceConfigsFromServer: function () {
  78. var tags = [
  79. {
  80. siteName: "global",
  81. tagName: this.get('tag')
  82. }
  83. ];
  84. var data = App.router.get('configurationController').getConfigsByTags(tags);
  85. var configs = data.findProperty('tag', this.get('tag')).properties;
  86. if (configs && (configs['security_enabled'] === 'true' || configs['security_enabled'] === true)) {
  87. this.set('securityEnabled', true);
  88. } else {
  89. this.set('securityEnabled', false);
  90. }
  91. this.set('dataIsLoaded', true);
  92. },
  93. showErrorPopup: function (message) {
  94. if(Array.isArray(message)){
  95. message = message.join('<br/>');
  96. } else {
  97. message = '<p>' + message + '</p>';
  98. }
  99. App.ModalPopup.show({
  100. header: Em.I18n.t('common.error'),
  101. bodyClass: Ember.View.extend({
  102. template: Ember.Handlebars.compile(message)
  103. }),
  104. secondary: false
  105. });
  106. }
  107. });