step6_controller.js 5.4 KB

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