step6_controller.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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.ReassignMasterWizardStep6Controller = App.HighAvailabilityProgressPageController.extend(App.WizardEnableDone, {
  20. name: "reassignMasterWizardStep6Controller",
  21. commands: [
  22. 'stopMysqlService',
  23. 'putHostComponentsInMaintenanceMode',
  24. 'stopHostComponentsInMaintenanceMode',
  25. 'deleteHostComponents',
  26. 'startAllServices'
  27. ],
  28. clusterDeployState: 'REASSIGN_MASTER_INSTALLING',
  29. multiTaskCounter: 0,
  30. hostComponents: [],
  31. loadStep: function () {
  32. if (this.get('content.reassign.component_name') === 'NAMENODE' && App.get('isHaEnabled')) {
  33. this.set('hostComponents', ['NAMENODE', 'ZKFC']);
  34. } else {
  35. this.set('hostComponents', [this.get('content.reassign.component_name')]);
  36. }
  37. if (App.Service.find().someProperty('serviceName', 'PXF') && this.get('content.reassign.component_name') === 'NAMENODE') {
  38. var pxfHosts = App.HostComponent.find().filterProperty('componentName', 'PXF').mapProperty('hostName');
  39. var dataNodeHosts = App.HostComponent.find().filterProperty('componentName', 'DATANODE').mapProperty('hostName');
  40. // If NAMENODE is being moved and source host does not have DATANODE, PXF should be removed from source host
  41. if (pxfHosts.contains(this.get('content.reassignHosts.source')) && !dataNodeHosts.contains(this.get('content.reassignHosts.source')))
  42. this.get('hostComponents').push('PXF');
  43. // If NAMENODE is being moved and target host does not have PXF, PXF should be added to target host
  44. if (!pxfHosts.contains(this.get('content.reassignHosts.target')))
  45. this.get('commands').splice(this.get('commands').indexOf('startAllServices'), 0, 'installPxf');
  46. }
  47. this._super();
  48. },
  49. initializeTasks: function () {
  50. var commands = this.get('commands');
  51. var hostComponentsNames = '';
  52. this.get('hostComponents').forEach(function (comp, index) {
  53. hostComponentsNames += index ? '+' : '';
  54. hostComponentsNames += comp === 'ZKFC' ? comp : App.format.role(comp, false);
  55. }, this);
  56. var currentStep = App.router.get('reassignMasterController.currentStep');
  57. for (var i = 0; i < commands.length; i++) {
  58. var title = Em.I18n.t('services.reassign.step6.tasks.' + commands[i] + '.title').format(hostComponentsNames);
  59. this.get('tasks').pushObject(Ember.Object.create({
  60. title: title,
  61. status: 'PENDING',
  62. id: i,
  63. command: commands[i],
  64. showRetry: false,
  65. showRollback: false,
  66. name: title,
  67. displayName: title,
  68. progress: 0,
  69. isRunning: false,
  70. hosts: []
  71. }));
  72. }
  73. this.removeUnneededTasks();
  74. this.set('isLoaded', true);
  75. },
  76. removeUnneededTasks: function () {
  77. if (this.get('content.reassign.component_name') !== 'MYSQL_SERVER') {
  78. this.removeTasks(['putHostComponentsInMaintenanceMode', 'stopMysqlService']);
  79. if (!this.get('content.reassignComponentsInMM.length')) {
  80. this.removeTasks(['stopHostComponentsInMaintenanceMode']);
  81. }
  82. } else {
  83. this.removeTasks(['stopHostComponentsInMaintenanceMode']);
  84. }
  85. },
  86. hideRollbackButton: function () {
  87. var failedTask = this.get('tasks').findProperty('showRollback');
  88. if (failedTask) {
  89. failedTask.set('showRollback', false)
  90. }
  91. }.observes('tasks.@each.showRollback'),
  92. onComponentsTasksSuccess: function () {
  93. this.decrementProperty('multiTaskCounter');
  94. if (this.get('multiTaskCounter') <= 0) {
  95. this.onTaskCompleted();
  96. }
  97. },
  98. installPxf: function () {
  99. this.createInstallComponentTask('PXF', this.get('content.reassignHosts.target'), "PXF");
  100. },
  101. startAllServices: function () {
  102. this.startServices(true);
  103. },
  104. deleteHostComponents: function () {
  105. var hostComponents = this.get('hostComponents');
  106. var hostName = this.get('content.reassignHosts.source');
  107. this.set('multiTaskCounter', hostComponents.length);
  108. for (var i = 0; i < hostComponents.length; i++) {
  109. App.ajax.send({
  110. name: 'common.delete.host_component',
  111. sender: this,
  112. data: {
  113. hostName: hostName,
  114. componentName: hostComponents[i]
  115. },
  116. success: 'onComponentsTasksSuccess',
  117. error: 'onDeleteHostComponentsError'
  118. });
  119. }
  120. },
  121. onDeleteHostComponentsError: function (error) {
  122. if (error.responseText.indexOf('org.apache.ambari.server.controller.spi.NoSuchResourceException') !== -1) {
  123. this.onComponentsTasksSuccess();
  124. } else {
  125. this.onTaskError();
  126. }
  127. },
  128. putHostComponentsInMaintenanceMode: function () {
  129. var hostComponents = this.get('hostComponents');
  130. var hostName = this.get('content.reassignHosts.source');
  131. this.set('multiTaskCounter', hostComponents.length);
  132. for (var i = 0; i < hostComponents.length; i++) {
  133. App.ajax.send({
  134. name: 'common.host.host_component.passive',
  135. sender: this,
  136. data: {
  137. hostName: hostName,
  138. passive_state: "ON",
  139. componentName: hostComponents[i]
  140. },
  141. success: 'onComponentsTasksSuccess',
  142. error: 'onTaskError'
  143. });
  144. }
  145. },
  146. stopHostComponentsInMaintenanceMode: function () {
  147. var hostComponentsInMM = this.get('content.reassignComponentsInMM');
  148. var hostName = this.get('content.reassignHosts.source');
  149. var serviceName = this.get('content.reassign.service_id');
  150. hostComponentsInMM = hostComponentsInMM.map(function(componentName){
  151. return {
  152. hostName: hostName,
  153. serviceName: serviceName,
  154. componentName: componentName
  155. };
  156. });
  157. this.set('multiTaskCounter', hostComponentsInMM.length);
  158. this.updateComponentsState(hostComponentsInMM, 'INSTALLED');
  159. },
  160. /**
  161. * make server call to stop services
  162. */
  163. stopMysqlService: function () {
  164. var data = {};
  165. data.context = "Stop required services";
  166. data.hostName = this.get('content.reassignHosts.source');
  167. data.serviceName = 'HIVE';
  168. data.HostRoles = { "state": "INSTALLED" };
  169. data.componentName = "MYSQL_SERVER";
  170. App.ajax.send({
  171. name: 'common.host.host_component.update',
  172. sender: this,
  173. data: data,
  174. success: 'startPolling',
  175. error: 'onTaskError'
  176. });
  177. }
  178. });