step2_controller.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. this._super();
  24. if(this.get('content.reassign.component_name') == "NAMENODE" && !this.get('content.masterComponentHosts').findProperty('component', "SECONDARY_NAMENODE")){
  25. this.set('showCurrentHost', false);
  26. this.set('componentToRebalance', 'NAMENODE');
  27. this.incrementProperty('rebalanceComponentHostsCounter');
  28. }else{
  29. this.set('showCurrentHost', true);
  30. this.rebalanceSingleComponentHosts(this.get('content.reassign.component_name'));
  31. }
  32. },
  33. loadComponents: function () {
  34. var components = this.get('components').filterProperty('isMaster', true);
  35. var masterComponents = this.get('content.masterComponentHosts');
  36. this.set('currentHostId', this.get('content').get('reassign').host_id);
  37. var componentNameToReassign = this.get('content').get('reassign').component_name;
  38. var result = [];
  39. masterComponents.forEach(function (master) {
  40. var color = "grey";
  41. if(master.component == componentNameToReassign){
  42. color = 'green';
  43. }
  44. result.push({
  45. component_name: master.component,
  46. display_name: App.format.role(master.component),
  47. selectedHost: master.hostName,
  48. isInstalled: true,
  49. serviceId: App.HostComponent.find().findProperty('componentName', master.component).get('serviceName'),
  50. isHiveCoHost: ['HIVE_METASTORE', 'WEBHCAT_SERVER'].contains(master.component),
  51. color: color
  52. });
  53. }, this);
  54. return result;
  55. },
  56. rebalanceSingleComponentHosts:function (componentName) {
  57. var currentComponents = this.get("selectedServicesMasters").filterProperty("component_name", componentName),
  58. componentHosts = currentComponents.mapProperty("selectedHost"),
  59. availableComponentHosts = [],
  60. preparedAvailableHosts = null;
  61. this.get("hosts").forEach(function (item) {
  62. if (this.get('currentHostId') !== item.get('host_name')) {
  63. availableComponentHosts.pushObject(item);
  64. }
  65. }, this);
  66. if (availableComponentHosts.length == 0) {
  67. return;
  68. }
  69. currentComponents.forEach(function (item) {
  70. preparedAvailableHosts = availableComponentHosts.slice(0);
  71. if (item.get('selectedHost') == this.get('currentHostId') && item.get('component_name') == this.get('content.reassign.component_name')) {
  72. item.set('selectedHost', preparedAvailableHosts.objectAt(0).host_name);
  73. }
  74. preparedAvailableHosts.sortBy('host_name');
  75. item.set("availableHosts", preparedAvailableHosts);
  76. }, this);
  77. }
  78. });