step13_controller.js 11 KB

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