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.rebalanceComponentHosts('NAMENODE');
  27. }else{
  28. this.set('showCurrentHost', true);
  29. this.rebalanceSingleComponentHosts(this.get('content.reassign.component_name'));
  30. }
  31. },
  32. loadComponents: function () {
  33. var components = this.get('components').filterProperty('isMaster', true);
  34. var masterComponents = this.get('content.masterComponentHosts');
  35. this.set('currentHostId', this.get('content').get('reassign').host_id);
  36. var componentNameToReassign = this.get('content').get('reassign').component_name;
  37. var result = [];
  38. masterComponents.forEach(function (master) {
  39. var color = "grey";
  40. if(master.component == componentNameToReassign){
  41. color = 'green';
  42. }
  43. result.push({
  44. component_name: master.component,
  45. display_name: App.format.role(master.component),
  46. selectedHost: master.hostName,
  47. isInstalled: true,
  48. serviceId: App.HostComponent.find().findProperty('componentName', master.component).get('serviceName'),
  49. availableHosts: [],
  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 false;
  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.sort(this.sortHostsByName, this);
  75. item.set("availableHosts", preparedAvailableHosts);
  76. }, this);
  77. }
  78. });