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