highAvailability_controller.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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: function () {
  22. return App.router.get('mainAdminSecurityController.securityEnabled');
  23. }.property('App.router.mainAdminSecurityController.securityEnabled'),
  24. tag: null,
  25. dataIsLoaded: false,
  26. /**
  27. * enable High Availability
  28. * @return {Boolean}
  29. */
  30. enableHighAvailability: function () {
  31. var message = [];
  32. var hostComponents = App.HostComponent.find();
  33. //Prerequisite Checks
  34. if (this.get('securityEnabled')) {
  35. this.showErrorPopup(Em.I18n.t('admin.highAvailability.error.security'));
  36. return false;
  37. } else {
  38. if (hostComponents.findProperty('componentName', 'NAMENODE').get('workStatus') !== 'STARTED') {
  39. message.push(Em.I18n.t('admin.highAvailability.error.namenodeStarted'));
  40. }
  41. if (hostComponents.filterProperty('componentName', 'ZOOKEEPER_SERVER').length < 3) {
  42. message.push(Em.I18n.t('admin.highAvailability.error.zooKeeperNum'));
  43. }
  44. if (App.router.get('mainHostController.hostsCountMap.TOTAL') < 3) {
  45. message.push(Em.I18n.t('admin.highAvailability.error.hostsNum'));
  46. }
  47. if (message.length > 0) {
  48. this.showErrorPopup(message);
  49. return false;
  50. }
  51. }
  52. App.router.transitionTo('main.services.enableHighAvailability');
  53. return true;
  54. },
  55. disableHighAvailability: function () {
  56. App.router.transitionTo('main.admin.rollbackHighAvailability');
  57. },
  58. /**
  59. * enable ResourceManager High Availability
  60. * @return {Boolean}
  61. */
  62. enableRMHighAvailability: function () {
  63. //Prerequisite Checks
  64. var message = [];
  65. if (App.HostComponent.find().filterProperty('componentName', 'ZOOKEEPER_SERVER').length < 3) {
  66. message.push(Em.I18n.t('admin.rm_highAvailability.error.zooKeeperNum'));
  67. }
  68. if (App.router.get('mainHostController.hostsCountMap.TOTAL') < 3) {
  69. message.push(Em.I18n.t('admin.rm_highAvailability.error.hostsNum'));
  70. }
  71. if (message.length > 0) {
  72. this.showErrorPopup(message);
  73. return false;
  74. }
  75. App.router.transitionTo('main.services.enableRMHighAvailability');
  76. return true;
  77. },
  78. /**
  79. * join or wrap message depending on whether it is array or string
  80. * @param message
  81. * @return {*}
  82. */
  83. joinMessage: function (message) {
  84. if (Array.isArray(message)) {
  85. return message.join('<br/>');
  86. } else {
  87. return '<p>' + message + '</p>';
  88. }
  89. },
  90. showErrorPopup: function (message) {
  91. message = this.joinMessage(message);
  92. App.ModalPopup.show({
  93. header: Em.I18n.t('common.error'),
  94. bodyClass: Ember.View.extend({
  95. template: Ember.Handlebars.compile(message)
  96. }),
  97. secondary: false
  98. });
  99. }
  100. });