step2_controller.js 4.3 KB

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