step13_controller.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. urlParams.push('(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')');
  153. break;
  154. case 'JOBTRACKER':
  155. urlParams.push('(type=mapred-site&tag=' + data.Clusters.desired_configs['mapred-site'].tag + ')');
  156. break;
  157. }
  158. App.ajax.send({
  159. name: 'reassign.load_configs',
  160. sender: this,
  161. data: {
  162. urlParams: urlParams.join('|')
  163. },
  164. success: 'onLoadConfigs',
  165. error: 'onTaskError'
  166. });
  167. },
  168. configsSitesCount: null,
  169. configsSitesNumber: null,
  170. onLoadConfigs: function (data) {
  171. var isHadoop2Stack = App.get('isHadoop2Stack');
  172. var componentName = this.get('content.reassign.component_name');
  173. var targetHostName = this.get('content.masterComponentHosts').findProperty('component', this.get('content.reassign.component_name')).hostName;
  174. var configs = {};
  175. var componentDir = '';
  176. this.set('configsSitesNumber', data.items.length);
  177. this.set('configsSitesCount', 0);
  178. data.items.forEach(function (item) {
  179. configs[item.type] = item.properties;
  180. }, this);
  181. switch (componentName) {
  182. case 'NAMENODE':
  183. if (isHadoop2Stack) {
  184. componentDir = configs['hdfs-site']['dfs.namenode.name.dir'];
  185. configs['hdfs-site']['dfs.namenode.http-address'] = targetHostName + ':50070';
  186. configs['hdfs-site']['dfs.namenode.https-address'] = targetHostName + ':50470';
  187. } else {
  188. componentDir = configs['hdfs-site']['dfs.name.dir'];
  189. configs['hdfs-site']['dfs.http.address'] = targetHostName + ':50070';
  190. configs['hdfs-site']['dfs.https.address'] = targetHostName + ':50470';
  191. }
  192. configs['core-site']['fs.default.name'] = 'hdfs://' + targetHostName + ':8020';
  193. configs['hdfs-site']['dfs.safemode.threshold.pct'] = '1.1f';
  194. if (App.Service.find().someProperty('serviceName', 'HBASE')) {
  195. configs['hbase-site']['hbase.rootdir'] = configs['hbase-site']['hbase.rootdir'].replace(/\/\/[^\/]*/, '//' + targetHostName);
  196. }
  197. break;
  198. case 'SECONDARY_NAMENODE':
  199. componentDir = configs['core-site']['fs.checkpoint.dir'];
  200. configs['hdfs-site']['dfs.secondary.http.address'] = targetHostName + ':50090';
  201. break;
  202. case 'JOBTRACKER':
  203. componentDir = configs['mapred-site']['mapred.local.dir'];
  204. configs['mapred-site']['mapreduce.history.server.http.address'] = targetHostName + ':51111';
  205. configs['mapred-site']['mapred.job.tracker.http.address'] = targetHostName + ':50030';
  206. configs['mapred-site']['mapred.job.tracker'] = targetHostName + ':50300';
  207. break;
  208. }
  209. App.router.get(this.get('content.controllerName')).saveComponentDir(componentDir);
  210. App.clusterStatus.setClusterStatus({
  211. clusterName: this.get('content.cluster.name'),
  212. clusterState: this.get('clusterDeployState'),
  213. wizardControllerName: this.get('content.controllerName'),
  214. localdb: App.db.data
  215. });
  216. for (var site in configs) {
  217. if (!configs.hasOwnProperty(site)) continue;
  218. App.ajax.send({
  219. name: 'reassign.save_configs',
  220. sender: this,
  221. data: {
  222. siteName: site,
  223. properties: configs[site]
  224. },
  225. success: 'onSaveConfigs',
  226. error: 'onTaskError'
  227. });
  228. }
  229. },
  230. onSaveConfigs: function () {
  231. this.set('configsSitesCount', this.get('configsSitesCount') + 1);
  232. if (this.get('configsSitesCount') === this.get('configsSitesNumber')) {
  233. this.onTaskCompleted();
  234. }
  235. },
  236. startServices: function () {
  237. this.set('multiTaskCounter', 0);
  238. var serviceNames = this.get('serviceNames');
  239. for (var i = 0; i < serviceNames.length; i++) {
  240. App.ajax.send({
  241. name: 'reassign.start_components',
  242. sender: this,
  243. data: {
  244. serviceName: serviceNames[i],
  245. displayName: App.Service.find().findProperty('serviceName', serviceNames[i]).get('displayName'),
  246. taskNum: serviceNames.length
  247. },
  248. success: 'startPolling',
  249. error: 'onTaskError'
  250. });
  251. }
  252. },
  253. deleteHostComponents: function () {
  254. this.set('multiTaskCounter', 0);
  255. var hostComponents = this.get('hostComponents');
  256. var hostName = this.get('content.reassign.host_id');
  257. for (var i = 0; i < hostComponents.length; i++) {
  258. App.ajax.send({
  259. name: 'reassign.remove_component',
  260. sender: this,
  261. data: {
  262. hostName: hostName,
  263. componentName: hostComponents[i]
  264. },
  265. success: 'onComponentsTasksSuccess',
  266. error: 'onTaskError'
  267. });
  268. }
  269. },
  270. done: function () {
  271. if (!this.get('isSubmitDisabled')) {
  272. this.removeObserver('tasks.@each.status', this, 'onTaskStatusChange');
  273. if (this.get('content.hasManualSteps')) {
  274. App.router.send('next');
  275. } else {
  276. App.router.send('complete');
  277. }
  278. }
  279. }
  280. })