step2_controller.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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.ReassignMasterWizardStep2Controller = App.WizardStep5Controller.extend({
  20. currentHostId: null,
  21. showCurrentHost: true,
  22. loadStep: function() {
  23. // If High Availability is enabled NameNode became a multiple component
  24. if (App.get('isHaEnabled')) {
  25. this.get('multipleComponents').push('NAMENODE');
  26. }
  27. this._super();
  28. if(this.get('content.reassign.component_name') == "NAMENODE" && !this.get('content.masterComponentHosts').findProperty('component', "SECONDARY_NAMENODE")){
  29. this.set('showCurrentHost', false);
  30. this.set('componentToRebalance', 'NAMENODE');
  31. this.incrementProperty('rebalanceComponentHostsCounter');
  32. }else{
  33. this.set('showCurrentHost', true);
  34. this.rebalanceSingleComponentHosts(this.get('content.reassign.component_name'));
  35. }
  36. },
  37. loadComponents: function () {
  38. var masterComponents = this.get('content.masterComponentHosts');
  39. this.set('currentHostId', this.get('content').get('reassign').host_id);
  40. var componentNameToReassign = this.get('content').get('reassign').component_name;
  41. var result = [];
  42. masterComponents.forEach(function (master) {
  43. var color = "grey";
  44. if(master.component == componentNameToReassign){
  45. color = 'green';
  46. }
  47. result.push({
  48. component_name: master.component,
  49. display_name: App.format.role(master.component),
  50. selectedHost: master.hostName,
  51. isInstalled: true,
  52. serviceId: App.HostComponent.find().findProperty('componentName', master.component).get('serviceName'),
  53. isHiveCoHost: ['HIVE_METASTORE', 'WEBHCAT_SERVER'].contains(master.component),
  54. color: color
  55. });
  56. }, this);
  57. return result;
  58. },
  59. rebalanceSingleComponentHosts:function (componentName) {
  60. var currentComponents = this.get("selectedServicesMasters").filterProperty("component_name", componentName),
  61. componentHosts = currentComponents.mapProperty("selectedHost"),
  62. availableComponentHosts = [],
  63. preparedAvailableHosts = null;
  64. this.get("hosts").forEach(function (item) {
  65. if (this.get('currentHostId') !== item.get('host_name')) {
  66. availableComponentHosts.pushObject(item);
  67. }
  68. }, this);
  69. if (availableComponentHosts.length == 0) {
  70. return;
  71. }
  72. currentComponents.forEach(function (item) {
  73. preparedAvailableHosts = availableComponentHosts.slice(0);
  74. if (item.get('selectedHost') == this.get('currentHostId') && item.get('component_name') == this.get('content.reassign.component_name')) {
  75. item.set('selectedHost', preparedAvailableHosts.objectAt(0).host_name);
  76. }
  77. item.set("availableHosts", preparedAvailableHosts.sortProperty('host_name'));
  78. }, this);
  79. },
  80. /**
  81. * Determines if hostName is valid for component:
  82. * <ul>
  83. * <li>host should have only one component with <code>componentName</code></li>
  84. * </ul>
  85. * @param {string} componentName
  86. * @param {string} selectedHost
  87. * @returns {boolean} true - valid, false - invalid
  88. * @method isHostNameValid
  89. */
  90. isHostNameValid: function (componentName, selectedHost) {
  91. var isValid = this._super(componentName, selectedHost);
  92. if (isValid) {
  93. var reassigned = 0;
  94. var existedComponents = App.HostComponent.find().filterProperty('componentName', this.get('content.reassign.component_name')).mapProperty('hostName');
  95. var newComponents = this.get('servicesMasters').mapProperty('selectedHost');
  96. existedComponents.forEach(function (host) {
  97. if (!newComponents.contains(host)) {
  98. reassigned++;
  99. }
  100. }, this);
  101. isValid = !(reassigned !== 1);
  102. }
  103. return isValid;
  104. }
  105. });