highAvailability_controller.js 3.2 KB

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