step2_controller.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 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. isHiveCoHost: ['HIVE_METASTORE', 'WEBHCAT_SERVER'].contains(master.component),
  50. color: color
  51. });
  52. }, this);
  53. return result;
  54. },
  55. rebalanceSingleComponentHosts:function (componentName) {
  56. var currentComponents = this.get("selectedServicesMasters").filterProperty("component_name", componentName),
  57. componentHosts = currentComponents.mapProperty("selectedHost"),
  58. availableComponentHosts = [],
  59. preparedAvailableHosts = null;
  60. this.get("hosts").forEach(function (item) {
  61. if (this.get('currentHostId') !== item.get('host_name')) {
  62. availableComponentHosts.pushObject(item);
  63. }
  64. }, this);
  65. if (availableComponentHosts.length == 0) {
  66. return;
  67. }
  68. currentComponents.forEach(function (item) {
  69. preparedAvailableHosts = availableComponentHosts.slice(0);
  70. if (item.get('selectedHost') == this.get('currentHostId') && item.get('component_name') == this.get('content.reassign.component_name')) {
  71. item.set('selectedHost', preparedAvailableHosts.objectAt(0).host_name);
  72. }
  73. item.set("availableHosts", preparedAvailableHosts.sortProperty('host_name'));
  74. }, this);
  75. }
  76. });