step2_controller.js 4.7 KB

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