step13_controller.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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.WizardStep13Controller = App.HighAvailabilityProgressPageController.extend({
  20. commands: ['stopServices', 'createHostComponents', 'putHostComponentsInMaintenanceMode', 'reconfigure', 'installHostComponents', 'deleteHostComponents', 'startServices'],
  21. clusterDeployState: 'REASSIGN_MASTER_INSTALLING',
  22. multiTaskCounter: 0,
  23. hostComponents: [],
  24. serviceNames: [],
  25. loadStep: function () {
  26. this.get('hostComponents').pushObject(this.get('content.reassign.component_name'));
  27. this.get('serviceNames').pushObject(this.get('content.reassign.service_id'));
  28. this._super();
  29. },
  30. initializeTasks: function () {
  31. var commands = this.get('commands');
  32. var currentStep = App.router.get('reassignMasterController.currentStep');
  33. var hostComponentsNames = '';
  34. var serviceNames = '';
  35. this.get('hostComponents').forEach(function (comp, index) {
  36. hostComponentsNames += index ? ', ' : '';
  37. hostComponentsNames += App.format.role(comp);
  38. }, this);
  39. this.get('serviceNames').forEach(function (service, index) {
  40. serviceNames += index ? ', ' : '';
  41. serviceNames += App.Service.find().findProperty('serviceName', service).get('displayName');
  42. }, this);
  43. for (var i = 0; i < commands.length; i++) {
  44. var title = Em.I18n.t('installer.step13.task' + i + '.title').format(hostComponentsNames, serviceNames);
  45. this.get('tasks').pushObject(Ember.Object.create({
  46. title: title,
  47. status: 'PENDING',
  48. id: i,
  49. command: commands[i],
  50. showRetry: false,
  51. showRollback: false,
  52. name: title,
  53. displayName: title,
  54. progress: 0,
  55. isRunning: false,
  56. hosts: []
  57. }));
  58. }
  59. if (this.get('content.hasManualSteps')) {
  60. this.get('tasks').splice(5, 2);
  61. }
  62. },
  63. hideRollbackButton: function () {
  64. var failedTask = this.get('tasks').findProperty('showRollback');
  65. if (failedTask) {
  66. failedTask.set('showRollback', false)
  67. }
  68. }.observes('tasks.@each.showRollback'),
  69. onComponentsTasksSuccess: function () {
  70. this.set('multiTaskCounter', this.get('multiTaskCounter') + 1);
  71. if (this.get('multiTaskCounter') >= this.get('hostComponents').length) {
  72. this.onTaskCompleted();
  73. }
  74. },
  75. stopServices: function () {
  76. this.set('multiTaskCounter', 0);
  77. var serviceNames = this.get('serviceNames');
  78. for (var i = 0; i < serviceNames.length; i++) {
  79. App.ajax.send({
  80. name: 'reassign.stop_service',
  81. sender: this,
  82. data: {
  83. serviceName: serviceNames[i],
  84. displayName: App.Service.find().findProperty('serviceName', serviceNames[i]).get('displayName'),
  85. taskNum: serviceNames.length
  86. },
  87. success: 'startPolling',
  88. error: 'onTaskError'
  89. });
  90. }
  91. },
  92. createHostComponents: function () {
  93. this.set('multiTaskCounter', 0);
  94. var hostComponents = this.get('hostComponents');
  95. var hostName = this.get('content.masterComponentHosts').findProperty('component', this.get('content.reassign.component_name')).hostName;
  96. for (var i = 0; i < hostComponents.length; i++) {
  97. this.createComponent(hostComponents[i], hostName);
  98. }
  99. },
  100. onCreateComponent: function () {
  101. this.onComponentsTasksSuccess();
  102. },
  103. putHostComponentsInMaintenanceMode: function () {
  104. this.set('multiTaskCounter', 0);
  105. var hostComponents = this.get('hostComponents');
  106. var hostName = this.get('content.reassign.host_id');
  107. for (var i = 0; i < hostComponents.length; i++) {
  108. App.ajax.send({
  109. name: 'reassign.maintenance_mode',
  110. sender: this,
  111. data: {
  112. hostName: hostName,
  113. componentName: hostComponents[i]
  114. },
  115. success: 'onComponentsTasksSuccess',
  116. error: 'onTaskError'
  117. });
  118. }
  119. },
  120. installHostComponents: function () {
  121. this.set('multiTaskCounter', 0);
  122. var hostComponents = this.get('hostComponents');
  123. var hostName = this.get('content.masterComponentHosts').findProperty('component', this.get('content.reassign.component_name')).hostName;
  124. for (var i = 0; i < hostComponents.length; i++) {
  125. this.installComponent(hostComponents[i], hostName, hostComponents.length);
  126. }
  127. },
  128. reconfigure: function () {
  129. this.loadConfigsTags();
  130. },
  131. loadConfigsTags: function () {
  132. App.ajax.send({
  133. name: 'config.tags',
  134. sender: this,
  135. success: 'onLoadConfigsTags',
  136. error: 'onTaskError'
  137. });
  138. },
  139. onLoadConfigsTags: function (data) {
  140. var componentName = this.get('content.reassign.component_name');
  141. var urlParams = [];
  142. switch (componentName) {
  143. case 'NAMENODE':
  144. urlParams.push('(type=hdfs-site&tag=' + data.Clusters.desired_configs['hdfs-site'].tag + ')');
  145. urlParams.push('(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')');
  146. if (App.Service.find().someProperty('serviceName', 'HBASE')) {
  147. urlParams.push('(type=hbase-site&tag=' + data.Clusters.desired_configs['hbase-site'].tag + ')');
  148. }
  149. break;
  150. case 'SECONDARY_NAMENODE':
  151. urlParams.push('(type=hdfs-site&tag=' + data.Clusters.desired_configs['hdfs-site'].tag + ')');
  152. break;
  153. }
  154. App.ajax.send({
  155. name: 'reassign.load_configs',
  156. sender: this,
  157. data: {
  158. urlParams: urlParams.join('|')
  159. },
  160. success: 'onLoadConfigs',
  161. error: 'onTaskError'
  162. });
  163. },
  164. configsSitesCount: null,
  165. configsSitesNumber: null,
  166. onLoadConfigs: function (data) {
  167. var componentName = this.get('content.reassign.component_name');
  168. var targetHostName = this.get('content.masterComponentHosts').findProperty('component', this.get('content.reassign.component_name')).hostName;
  169. var configs = {};
  170. var componentDir = '';
  171. this.set('configsSitesNumber', data.items.length);
  172. this.set('configsSitesCount', 0);
  173. data.items.forEach(function (item) {
  174. configs[item.type] = item.properties;
  175. }, this);
  176. switch (componentName) {
  177. case 'NAMENODE':
  178. componentDir = configs['hdfs-site']['dfs.name.dir'];
  179. configs['core-site']['fs.default.name'] = 'hdfs://' + targetHostName + ':8020';
  180. configs['hdfs-site']['dfs.http.address'] = targetHostName + ':50070';
  181. configs['hdfs-site']['dfs.https.address'] = targetHostName + ':50470';
  182. configs['hdfs-site']['dfs.safemode.threshold.pct'] = '1.1f';
  183. if (App.Service.find().someProperty('serviceName', 'HBASE')) {
  184. configs['hbase-site']['hbase.rootdir'] = configs['hbase-site']['hbase.rootdir'].replace(/\/\/[^\/]*/, '//' + targetHostName);
  185. }
  186. break;
  187. case 'SECONDARY_NAMENODE':
  188. componentDir = configs['hdfs-site']['fs.checkpoint.dir'];
  189. configs['hdfs-site']['dfs.secondary.http.address'] = targetHostName + ':50090';
  190. break;
  191. }
  192. App.router.get(this.get('content.controllerName')).saveComponentDir(componentDir);
  193. App.clusterStatus.setClusterStatus({
  194. clusterName: this.get('content.cluster.name'),
  195. clusterState: this.get('clusterDeployState'),
  196. wizardControllerName: this.get('content.controllerName'),
  197. localdb: App.db.data
  198. });
  199. for (var site in configs) {
  200. if (!configs.hasOwnProperty(site)) continue;
  201. App.ajax.send({
  202. name: 'reassign.save_configs',
  203. sender: this,
  204. data: {
  205. siteName: site,
  206. properties: configs[site]
  207. },
  208. success: 'onSaveConfigs',
  209. error: 'onTaskError'
  210. });
  211. }
  212. },
  213. onSaveConfigs: function () {
  214. this.set('configsSitesCount', this.get('configsSitesCount') + 1);
  215. if (this.get('configsSitesCount') === this.get('configsSitesNumber')) {
  216. this.onTaskCompleted();
  217. }
  218. },
  219. startServices: function () {
  220. this.set('multiTaskCounter', 0);
  221. var serviceNames = this.get('serviceNames');
  222. for (var i = 0; i < serviceNames.length; i++) {
  223. App.ajax.send({
  224. name: 'reassign.start_components',
  225. sender: this,
  226. data: {
  227. serviceName: serviceNames[i],
  228. displayName: App.Service.find().findProperty('serviceName', serviceNames[i]).get('displayName'),
  229. taskNum: serviceNames.length
  230. },
  231. success: 'startPolling',
  232. error: 'onTaskError'
  233. });
  234. }
  235. },
  236. deleteHostComponents: function () {
  237. this.set('multiTaskCounter', 0);
  238. var hostComponents = this.get('hostComponents');
  239. var hostName = this.get('content.reassign.host_id');
  240. for (var i = 0; i < hostComponents.length; i++) {
  241. App.ajax.send({
  242. name: 'reassign.remove_component',
  243. sender: this,
  244. data: {
  245. hostName: hostName,
  246. componentName: hostComponents[i]
  247. },
  248. success: 'onComponentsTasksSuccess',
  249. error: 'onTaskError'
  250. });
  251. }
  252. },
  253. done: function () {
  254. if (!this.get('isSubmitDisabled')) {
  255. this.removeObserver('tasks.@each.status', this, 'onTaskStatusChange');
  256. if (this.get('content.hasManualSteps')) {
  257. App.router.send('next');
  258. } else {
  259. App.router.send('complete');
  260. }
  261. }
  262. }
  263. })