step6_controller.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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({
  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. },
  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. startServices: function () {
  94. App.ajax.send({
  95. name: 'common.services.update',
  96. sender: this,
  97. data: {
  98. "context": "Start all services",
  99. "ServiceInfo": {
  100. "state": "STARTED"
  101. },
  102. urlParams: "params/run_smoke_test=true"
  103. },
  104. success: 'startPolling',
  105. error: 'onTaskError'
  106. });
  107. },
  108. deleteHostComponents: function () {
  109. this.set('multiTaskCounter', 0);
  110. var hostComponents = this.get('hostComponents');
  111. var hostName = this.get('content.reassignHosts.source');
  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. this.set('multiTaskCounter', 0);
  134. var hostComponents = this.get('hostComponents');
  135. var hostName = this.get('content.reassignHosts.source');
  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. /**
  151. * make server call to stop services
  152. */
  153. stopMysqlService: function () {
  154. var data = {};
  155. data.context = "Stop required services";
  156. data.hostName = this.get('content.reassignHosts.source');
  157. data.serviceName = 'HIVE';
  158. data.HostRoles = { "state": "INSTALLED" };
  159. data.componentName = "MYSQL_SERVER";
  160. App.ajax.send({
  161. name: 'common.host.host_component.update',
  162. sender: this,
  163. data: data,
  164. success: 'startPolling',
  165. error: 'onTaskError'
  166. });
  167. }
  168. });