step6_controller.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. isReassign: true,
  21. commands: ['stopMysqlService', 'putHostComponentsInMaintenanceMode', 'deleteHostComponents', 'startServices'],
  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. index = null
  71. cmd = null;
  72. commands.forEach(function(command) {
  73. cmd = tasks.filterProperty('command', command);
  74. if (cmd.length === 0) {
  75. return false;
  76. } else {
  77. index = tasks.indexOf( cmd[0] );
  78. }
  79. tasks.splice( index, 1 );
  80. });
  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. startServices: function () {
  95. App.ajax.send({
  96. name: 'common.services.update',
  97. sender: this,
  98. data: {
  99. "context": "Start all services",
  100. "ServiceInfo": {
  101. "state": "STARTED"
  102. },
  103. urlParams: "params/run_smoke_test=true"
  104. },
  105. success: 'startPolling',
  106. error: 'onTaskError'
  107. });
  108. },
  109. deleteHostComponents: function () {
  110. this.set('multiTaskCounter', 0);
  111. var hostComponents = this.get('hostComponents');
  112. var hostName = this.get('content.reassignHosts.source');
  113. for (var i = 0; i < hostComponents.length; i++) {
  114. App.ajax.send({
  115. name: 'common.delete.host_component',
  116. sender: this,
  117. data: {
  118. hostName: hostName,
  119. componentName: hostComponents[i]
  120. },
  121. success: 'onComponentsTasksSuccess',
  122. error: 'onDeleteHostComponentsError'
  123. });
  124. }
  125. },
  126. onDeleteHostComponentsError: function (error) {
  127. if (error.responseText.indexOf('org.apache.ambari.server.controller.spi.NoSuchResourceException') !== -1) {
  128. this.onComponentsTasksSuccess();
  129. } else {
  130. this.onTaskError();
  131. }
  132. },
  133. putHostComponentsInMaintenanceMode: function () {
  134. this.set('multiTaskCounter', 0);
  135. var hostComponents = this.get('hostComponents');
  136. var hostName = this.get('content.reassignHosts.source');
  137. for (var i = 0; i < hostComponents.length; i++) {
  138. App.ajax.send({
  139. name: 'common.host.host_component.passive',
  140. sender: this,
  141. data: {
  142. hostName: hostName,
  143. passive_state: "ON",
  144. componentName: hostComponents[i]
  145. },
  146. success: 'onComponentsTasksSuccess',
  147. error: 'onTaskError'
  148. });
  149. }
  150. },
  151. /**
  152. * make server call to stop services
  153. */
  154. stopMysqlService: function () {
  155. var data = {};
  156. data.context = "Stop required services";
  157. data.hostName = this.get('content.reassignHosts.source');
  158. data.serviceName = 'HIVE';
  159. data.HostRoles = { "desired_state": "INSTALLED" };
  160. data.componentName = "MYSQL_SERVER";
  161. App.ajax.send({
  162. name: 'common.host.host_component.update',
  163. sender: this,
  164. data: data,
  165. success: 'startPolling',
  166. error: 'onTaskError'
  167. });
  168. }
  169. });