step6_controller.js 6.2 KB

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