highAvailability_controller.js 3.9 KB

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