step2_controller.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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.clearStep();
  28. this.renderHostInfo();
  29. this.loadStepCallback(this.loadComponents(), this);
  30. // if moving NameNode with HA enabled
  31. if (this.get('content.reassign.component_name') === "NAMENODE" && App.get('isHaEnabled')) {
  32. this.set('showCurrentHost', false);
  33. this.set('componentToRebalance', 'NAMENODE');
  34. this.incrementProperty('rebalanceComponentHostsCounter');
  35. // if moving ResourceManager with HA enabled
  36. } else if (this.get('content.reassign.component_name') === "RESOURCEMANAGER" && App.get('isRMHaEnabled')) {
  37. this.set('showCurrentHost', false);
  38. this.set('componentToRebalance', 'RESOURCEMANAGER');
  39. this.incrementProperty('rebalanceComponentHostsCounter');
  40. } else {
  41. this.set('showCurrentHost', true);
  42. this.rebalanceSingleComponentHosts(this.get('content.reassign.component_name'));
  43. }
  44. },
  45. /**
  46. * load master components
  47. * @return {Array}
  48. */
  49. loadComponents: function () {
  50. var masterComponents = this.get('content.masterComponentHosts');
  51. this.set('currentHostId', this.get('content').get('reassign').host_id);
  52. var componentNameToReassign = this.get('content').get('reassign').component_name;
  53. var result = [];
  54. masterComponents.forEach(function (master) {
  55. var color = "grey";
  56. if (master.component == componentNameToReassign) {
  57. color = 'green';
  58. }
  59. result.push({
  60. component_name: master.component,
  61. display_name: App.format.role(master.component),
  62. selectedHost: master.hostName,
  63. isInstalled: true,
  64. serviceId: App.HostComponent.find().findProperty('componentName', master.component).get('serviceName'),
  65. isServiceCoHost: ['HIVE_METASTORE', 'WEBHCAT_SERVER'].contains(master.component),
  66. color: color
  67. });
  68. }, this);
  69. return result;
  70. },
  71. /**
  72. * rebalance single component among available hosts
  73. * @param componentName
  74. * @return {Boolean}
  75. */
  76. rebalanceSingleComponentHosts: function (componentName) {
  77. var currentComponents = this.get("selectedServicesMasters").filterProperty("component_name", componentName),
  78. availableComponentHosts = [];
  79. this.get("hosts").forEach(function (item) {
  80. if (this.get('currentHostId') !== item.get('host_name')) {
  81. availableComponentHosts.pushObject(item);
  82. }
  83. }, this);
  84. if (availableComponentHosts.length > 0) {
  85. currentComponents.forEach(function (item) {
  86. var preparedAvailableHosts = availableComponentHosts.slice(0);
  87. if (item.get('selectedHost') === this.get('currentHostId') && item.get('component_name') === this.get('content.reassign.component_name')) {
  88. item.set('selectedHost', preparedAvailableHosts.objectAt(0).host_name);
  89. }
  90. item.set("availableHosts", preparedAvailableHosts.sortProperty('host_name'));
  91. }, this);
  92. return true;
  93. }
  94. return false;
  95. },
  96. updateIsSubmitDisabled: function () {
  97. var isSubmitDisabled = this._super();
  98. if (!isSubmitDisabled) {
  99. var reassigned = 0;
  100. var existedComponents = App.HostComponent.find().filterProperty('componentName', this.get('content.reassign.component_name')).mapProperty('hostName');
  101. var newComponents = this.get('servicesMasters').mapProperty('selectedHost');
  102. existedComponents.forEach(function (host) {
  103. if (!newComponents.contains(host)) {
  104. reassigned++;
  105. }
  106. }, this);
  107. isSubmitDisabled = reassigned !== 1;
  108. }
  109. this.set('submitDisabled', isSubmitDisabled);
  110. return isSubmitDisabled;
  111. }.observes('servicesMasters.@each.selectedHost', 'servicesMasters.@each.isHostNameValid')
  112. });