step4_controller.js 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142
  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.ReassignMasterWizardStep4Controller = App.HighAvailabilityProgressPageController.extend({
  20. commands: [
  21. 'stopRequiredServices',
  22. 'cleanMySqlServer',
  23. 'createHostComponents',
  24. 'putHostComponentsInMaintenanceMode',
  25. 'reconfigure',
  26. 'installHostComponents',
  27. 'startZooKeeperServers',
  28. 'startNameNode',
  29. 'deleteHostComponents',
  30. 'configureMySqlServer',
  31. 'startMySqlServer',
  32. 'startNewMySqlServer',
  33. 'startRequiredServices'
  34. ],
  35. // custom commands for Components with DB Configuration and Check
  36. commandsForDB: [
  37. 'createHostComponents',
  38. 'installHostComponents',
  39. 'configureMySqlServer',
  40. 'restartMySqlServer',
  41. 'testDBConnection',
  42. 'stopRequiredServices',
  43. 'cleanMySqlServer',
  44. 'putHostComponentsInMaintenanceMode',
  45. 'reconfigure',
  46. 'deleteHostComponents',
  47. 'configureMySqlServer',
  48. 'startRequiredServices'
  49. ],
  50. clusterDeployState: 'REASSIGN_MASTER_INSTALLING',
  51. multiTaskCounter: 0,
  52. hostComponents: [],
  53. /**
  54. * Map with lists of unrelated services.
  55. * Used to define list of services to stop/start.
  56. */
  57. unrelatedServicesMap: {
  58. 'JOBTRACKER': ['HDFS', 'ZOOKEEPER', 'HBASE', 'FLUME', 'SQOOP', 'STORM'],
  59. 'RESOURCEMANAGER': ['HDFS', 'ZOOKEEPER', 'HBASE', 'FLUME', 'SQOOP', 'STORM'],
  60. 'APP_TIMELINE_SERVER': ['HDFS', 'ZOOKEEPER', 'HBASE', 'FLUME', 'SQOOP', 'STORM'],
  61. 'OOZIE_SERVER': ['ZOOKEEPER', 'HBASE', 'FLUME', 'SQOOP', 'STORM', 'HIVE'],
  62. 'WEBHCAT_SERVER': ['HDFS', 'ZOOKEEPER', 'HBASE', 'FLUME', 'SQOOP', 'STORM'],
  63. 'HIVE_SERVER': ['HDFS', 'ZOOKEEPER', 'HBASE', 'FLUME', 'SQOOP', 'STORM'],
  64. 'HIVE_METASTORE': ['HDFS', 'ZOOKEEPER', 'HBASE', 'FLUME', 'SQOOP', 'STORM'],
  65. 'MYSQL_SERVER': ['HDFS', 'ZOOKEEPER', 'HBASE', 'FLUME', 'SQOOP', 'STORM']
  66. },
  67. /**
  68. * additional configs with template values
  69. * Part of value to substitute has following format: "<replace-value>"
  70. */
  71. additionalConfigsMap: [
  72. {
  73. componentName: 'RESOURCEMANAGER',
  74. configs: {
  75. 'yarn-site': {
  76. 'yarn.resourcemanager.address': '<replace-value>:8050',
  77. 'yarn.resourcemanager.admin.address': '<replace-value>:8141',
  78. 'yarn.resourcemanager.resource-tracker.address': '<replace-value>:8025',
  79. 'yarn.resourcemanager.scheduler.address': '<replace-value>:8030',
  80. 'yarn.resourcemanager.webapp.address': '<replace-value>:8088',
  81. 'yarn.resourcemanager.hostname': '<replace-value>'
  82. }
  83. }
  84. },
  85. {
  86. componentName: 'JOBTRACKER',
  87. configs: {
  88. 'mapred-site': {
  89. 'mapred.job.tracker.http.address': '<replace-value>:50030',
  90. 'mapred.job.tracker': '<replace-value>:50300'
  91. }
  92. }
  93. },
  94. {
  95. componentName: 'SECONDARY_NAMENODE',
  96. configs: {
  97. 'hdfs-site': {
  98. 'dfs.secondary.http.address': '<replace-value>:50090'
  99. }
  100. },
  101. configs_Hadoop2: {
  102. 'hdfs-site': {
  103. 'dfs.namenode.secondary.http-address': '<replace-value>:50090'
  104. }
  105. }
  106. },
  107. {
  108. componentName: 'NAMENODE',
  109. configs: {
  110. 'hdfs-site': {
  111. 'dfs.http.address': '<replace-value>:50070',
  112. 'dfs.https.address': '<replace-value>:50470'
  113. },
  114. 'core-site': {
  115. 'fs.default.name': 'hdfs://<replace-value>:8020'
  116. }
  117. },
  118. configs_Hadoop2: {
  119. 'hdfs-site': {
  120. 'dfs.namenode.rpc-address': '<replace-value>:8020',
  121. 'dfs.namenode.http-address': '<replace-value>:50070',
  122. 'dfs.namenode.https-address': '<replace-value>:50470'
  123. },
  124. 'core-site': {
  125. 'fs.defaultFS': 'hdfs://<replace-value>:8020'
  126. }
  127. }
  128. },
  129. {
  130. componentName: 'APP_TIMELINE_SERVER',
  131. configs: {
  132. 'yarn-site': {
  133. 'yarn.timeline-service.webapp.address': '<replace-value>:8188',
  134. 'yarn.timeline-service.webapp.https.address': '<replace-value>:8190',
  135. 'yarn.timeline-service.address': '<replace-value>:10200'
  136. }
  137. }
  138. },
  139. {
  140. componentName: 'OOZIE_SERVER',
  141. configs: {
  142. 'oozie-site': {
  143. 'oozie.base.url': 'http://<replace-value>:11000/oozie'
  144. },
  145. 'core-site': {
  146. 'hadoop.proxyuser.oozie.hosts': '<replace-value>'
  147. }
  148. }
  149. },
  150. {
  151. componentName: 'HIVE_METASTORE',
  152. configs: {
  153. 'hive-site': {}
  154. }
  155. },
  156. {
  157. componentName: 'MYSQL_SERVER',
  158. configs: {
  159. 'hive-site': {
  160. 'javax.jdo.option.ConnectionURL': 'jdbc:mysql://<replace-value>/hive?createDatabaseIfNotExist=true'
  161. }
  162. }
  163. }
  164. ],
  165. secureConfigsMap: [
  166. {
  167. componentName: 'NAMENODE',
  168. configs: [
  169. {
  170. site: 'hdfs-site',
  171. keytab: 'dfs.namenode.keytab.file',
  172. principal: 'dfs.namenode.kerberos.principal'
  173. },
  174. {
  175. site: 'hdfs-site',
  176. keytab: 'dfs.web.authentication.kerberos.keytab',
  177. principal: 'dfs.web.authentication.kerberos.principal'
  178. }
  179. ]
  180. },
  181. {
  182. componentName: 'SECONDARY_NAMENODE',
  183. configs: [
  184. {
  185. site: 'hdfs-site',
  186. keytab: 'dfs.secondary.namenode.keytab.file',
  187. principal: 'dfs.secondary.namenode.kerberos.principal'
  188. },
  189. {
  190. site: 'hdfs-site',
  191. keytab: 'dfs.web.authentication.kerberos.keytab',
  192. principal: 'dfs.web.authentication.kerberos.principal'
  193. }
  194. ]
  195. },
  196. {
  197. componentName: 'RESOURCEMANAGER',
  198. configs: [
  199. {
  200. site: 'yarn-site',
  201. keytab: 'yarn.resourcemanager.keytab',
  202. principal: 'yarn.resourcemanager.principal'
  203. },
  204. {
  205. site: 'yarn-site',
  206. keytab: 'yarn.resourcemanager.webapp.spnego-keytab-file',
  207. principal: 'yarn.resourcemanager.webapp.spnego-principal'
  208. }
  209. ]
  210. },
  211. {
  212. componentName: 'OOZIE_SERVER',
  213. configs: [
  214. {
  215. site: 'oozie-site',
  216. keytab: 'oozie.authentication.kerberos.keytab',
  217. principal: 'oozie.authentication.kerberos.principal'
  218. },
  219. {
  220. site: 'oozie-site',
  221. keytab: 'oozie.service.HadoopAccessorService.keytab.file',
  222. principal: 'oozie.service.HadoopAccessorService.kerberos.principal'
  223. }
  224. ]
  225. },
  226. {
  227. componentName: 'WEBHCAT_SERVER',
  228. configs: [
  229. {
  230. site: 'webhcat-site',
  231. keytab: 'templeton.kerberos.keytab',
  232. principal: 'templeton.kerberos.principal'
  233. }
  234. ]
  235. },
  236. {
  237. componentName: 'HIVE_SERVER',
  238. configs: [
  239. {
  240. site: 'hive-site',
  241. keytab: 'hive.server2.authentication.kerberos.keytab',
  242. principal: 'hive.server2.authentication.kerberos.principal'
  243. },
  244. {
  245. site: 'hive-site',
  246. keytab: 'hive.server2.authentication.spnego.keytab',
  247. principal: 'hive.server2.authentication.spnego.principal'
  248. }
  249. ]
  250. },
  251. {
  252. componentName: 'HIVE_METASTORE',
  253. configs: [
  254. {
  255. site: 'hive-site',
  256. keytab: 'hive.metastore.kerberos.keytab.file',
  257. principal: 'hive.metastore.kerberos.principal'
  258. }
  259. ]
  260. }
  261. ],
  262. /**
  263. * set additional configs
  264. * configs_Hadoop2 - configs which belongs to Hadoop 2 stack only
  265. * @param configs
  266. * @param componentName
  267. * @param replaceValue
  268. * @return {Boolean}
  269. */
  270. setAdditionalConfigs: function (configs, componentName, replaceValue) {
  271. var component = this.get('additionalConfigsMap').findProperty('componentName', componentName);
  272. if (Em.isNone(component)) return false;
  273. var additionalConfigs = (component.configs_Hadoop2) ? component.configs_Hadoop2 : component.configs;
  274. for (var site in additionalConfigs) {
  275. if (additionalConfigs.hasOwnProperty(site)) {
  276. for (var property in additionalConfigs[site]) {
  277. if (additionalConfigs[site].hasOwnProperty(property)) {
  278. if (App.get('isHaEnabled') && componentName === 'NAMENODE' && property === 'fs.defaultFS') continue;
  279. configs[site][property] = additionalConfigs[site][property].replace('<replace-value>', replaceValue);
  280. }
  281. }
  282. }
  283. }
  284. return true;
  285. },
  286. /**
  287. * load step info
  288. */
  289. loadStep: function () {
  290. if (this.get('content.reassign.component_name') === 'NAMENODE' && App.get('isHaEnabled')) {
  291. this.set('hostComponents', ['NAMENODE', 'ZKFC']);
  292. } else {
  293. this.set('hostComponents', [this.get('content.reassign.component_name')]);
  294. }
  295. this.set('serviceName', [this.get('content.reassign.service_id')]);
  296. this._super();
  297. },
  298. /**
  299. * concat host-component names into string
  300. * @return {String}
  301. */
  302. getHostComponentsNames: function () {
  303. var hostComponentsNames = '';
  304. this.get('hostComponents').forEach(function (comp, index) {
  305. hostComponentsNames += index ? '+' : '';
  306. hostComponentsNames += comp === 'ZKFC' ? comp : App.format.role(comp);
  307. }, this);
  308. return hostComponentsNames;
  309. },
  310. /**
  311. * remove unneeded tasks
  312. */
  313. removeUnneededTasks: function () {
  314. if(this.isComponentWithDB()) {
  315. var db_type = this.get('content.databaseType');
  316. var is_remote_db = this.get('content.serviceProperties.is_remote_db');
  317. if(is_remote_db || db_type !== 'mysql') {
  318. this.removeTasks(['configureMySqlServer', 'startMySqlServer', 'restartMySqlServer', 'cleanMySqlServer', 'configureMySqlServer']);
  319. }
  320. if (db_type === 'derby') {
  321. this.removeTasks(['testDBConnection']);
  322. }
  323. }
  324. if ( this.get('content.reassign.component_name') !== 'MYSQL_SERVER' && !this.isComponentWithDB()) {
  325. this.removeTasks(['configureMySqlServer', 'startMySqlServer', 'restartMySqlServer', 'cleanMySqlServer', 'startNewMySqlServer', 'configureMySqlServer']);
  326. }
  327. if ( this.get('content.reassign.component_name') === 'MYSQL_SERVER' ) {
  328. this.removeTasks(['cleanMySqlServer']);
  329. }
  330. if (this.get('content.hasManualSteps')) {
  331. if (this.get('content.reassign.component_name') === 'NAMENODE' && App.get('isHaEnabled')) {
  332. // Only for reassign NameNode with HA enabled
  333. this.removeTasks(['deleteHostComponents', 'startRequiredServices']);
  334. } else {
  335. this.removeTasks(['startZooKeeperServers', 'startNameNode', 'deleteHostComponents', 'startRequiredServices']);
  336. }
  337. } else {
  338. this.removeTasks(['startZooKeeperServers', 'startNameNode']);
  339. }
  340. },
  341. /**
  342. * remove tasks by command name
  343. */
  344. removeTasks: function(commands) {
  345. var tasks = this.get('tasks');
  346. commands.forEach(function(command) {
  347. var cmd = tasks.filterProperty('command', command);
  348. var index = null;
  349. if (cmd.length === 0) {
  350. return false;
  351. } else {
  352. index = tasks.indexOf( cmd[0] );
  353. }
  354. tasks.splice( index, 1 );
  355. });
  356. },
  357. /**
  358. * initialize tasks
  359. */
  360. initializeTasks: function () {
  361. var commands = this.get('commands');
  362. var currentStep = App.router.get('reassignMasterController.currentStep');
  363. var hostComponentsNames = this.getHostComponentsNames();
  364. if (this.isComponentWithDB()) {
  365. commands = this.get('commandsForDB');
  366. }
  367. for (var i = 0; i < commands.length; i++) {
  368. var TaskLabel = i === 3 ? this.get('serviceName') : hostComponentsNames; //For Reconfigure task, show serviceName
  369. var title = Em.I18n.t('services.reassign.step4.tasks.' + commands[i] + '.title').format(TaskLabel);
  370. this.get('tasks').pushObject(Ember.Object.create({
  371. title: title,
  372. status: 'PENDING',
  373. id: i,
  374. command: commands[i],
  375. showRetry: false,
  376. showRollback: false,
  377. name: title,
  378. displayName: title,
  379. progress: 0,
  380. isRunning: false,
  381. hosts: []
  382. }));
  383. }
  384. this.removeUnneededTasks();
  385. this.set('isLoaded', true);
  386. },
  387. hideRollbackButton: function () {
  388. var failedTask = this.get('tasks').findProperty('showRollback');
  389. if (failedTask) {
  390. failedTask.set('showRollback', false);
  391. }
  392. }.observes('tasks.@each.showRollback'),
  393. onComponentsTasksSuccess: function () {
  394. this.incrementProperty('multiTaskCounter');
  395. if (this.get('multiTaskCounter') >= this.get('hostComponents').length) {
  396. this.onTaskCompleted();
  397. }
  398. },
  399. /**
  400. * make server call to stop services
  401. */
  402. stopRequiredServices: function () {
  403. this.stopServices(this.get('unrelatedServicesMap')[this.get('content.reassign.component_name')]);
  404. },
  405. createHostComponents: function () {
  406. this.set('multiTaskCounter', 0);
  407. var hostComponents = this.get('hostComponents');
  408. var hostName = this.get('content.reassignHosts.target');
  409. for (var i = 0; i < hostComponents.length; i++) {
  410. this.createComponent(hostComponents[i], hostName, this.get('content.reassign.service_id'));
  411. }
  412. },
  413. onCreateComponent: function () {
  414. this.onComponentsTasksSuccess();
  415. },
  416. putHostComponentsInMaintenanceMode: function () {
  417. this.set('multiTaskCounter', 0);
  418. var hostComponents = this.get('hostComponents');
  419. var hostName = this.get('content.reassignHosts.source');
  420. for (var i = 0; i < hostComponents.length; i++) {
  421. App.ajax.send({
  422. name: 'common.host.host_component.passive',
  423. sender: this,
  424. data: {
  425. hostName: hostName,
  426. passive_state: "ON",
  427. componentName: hostComponents[i]
  428. },
  429. success: 'onComponentsTasksSuccess',
  430. error: 'onTaskError'
  431. });
  432. }
  433. },
  434. installHostComponents: function () {
  435. this.set('multiTaskCounter', 0);
  436. var hostComponents = this.get('hostComponents');
  437. var hostName = this.get('content.reassignHosts.target');
  438. for (var i = 0; i < hostComponents.length; i++) {
  439. this.updateComponent(hostComponents[i], hostName, this.get('content.reassign.service_id'), "Install", hostComponents.length);
  440. }
  441. },
  442. reconfigure: function () {
  443. this.loadConfigsTags();
  444. },
  445. loadConfigsTags: function () {
  446. App.ajax.send({
  447. name: 'config.tags',
  448. sender: this,
  449. success: 'onLoadConfigsTags',
  450. error: 'onTaskError'
  451. });
  452. },
  453. /**
  454. * construct URL parameters for config call
  455. * @param componentName
  456. * @param data
  457. * @return {Array}
  458. */
  459. getConfigUrlParams: function (componentName, data) {
  460. var urlParams = [];
  461. switch (componentName) {
  462. case 'NAMENODE':
  463. urlParams.push('(type=hdfs-site&tag=' + data.Clusters.desired_configs['hdfs-site'].tag + ')');
  464. urlParams.push('(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')');
  465. if (App.Service.find().someProperty('serviceName', 'HBASE')) {
  466. urlParams.push('(type=hbase-site&tag=' + data.Clusters.desired_configs['hbase-site'].tag + ')');
  467. }
  468. if (App.Service.find().someProperty('serviceName', 'ACCUMULO')) {
  469. urlParams.push('(type=accumulo-site&tag=' + data.Clusters.desired_configs['accumulo-site'].tag + ')');
  470. }
  471. break;
  472. case 'SECONDARY_NAMENODE':
  473. urlParams.push('(type=hdfs-site&tag=' + data.Clusters.desired_configs['hdfs-site'].tag + ')');
  474. urlParams.push('(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')');
  475. break;
  476. case 'JOBTRACKER':
  477. urlParams.push('(type=mapred-site&tag=' + data.Clusters.desired_configs['mapred-site'].tag + ')');
  478. break;
  479. case 'RESOURCEMANAGER':
  480. urlParams.push('(type=yarn-site&tag=' + data.Clusters.desired_configs['yarn-site'].tag + ')');
  481. break;
  482. case 'WEBHCAT_SERVER':
  483. urlParams.push('(type=webhcat-site&tag=' + data.Clusters.desired_configs['webhcat-site'].tag + ')');
  484. break;
  485. case 'APP_TIMELINE_SERVER':
  486. urlParams.push('(type=yarn-site&tag=' + data.Clusters.desired_configs['yarn-site'].tag + ')');
  487. urlParams.push('(type=yarn-env&tag=' + data.Clusters.desired_configs['yarn-env'].tag + ')');
  488. break;
  489. case 'OOZIE_SERVER':
  490. urlParams.push('(type=oozie-site&tag=' + data.Clusters.desired_configs['oozie-site'].tag + ')');
  491. urlParams.push('(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')');
  492. break;
  493. case 'HIVE_SERVER':
  494. case 'HIVE_METASTORE':
  495. urlParams.push('(type=hive-site&tag=' + data.Clusters.desired_configs['hive-site'].tag + ')');
  496. urlParams.push('(type=webhcat-site&tag=' + data.Clusters.desired_configs['webhcat-site'].tag + ')');
  497. urlParams.push('(type=hive-env&tag=' + data.Clusters.desired_configs['hive-env'].tag + ')');
  498. urlParams.push('(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')');
  499. break;
  500. case 'MYSQL_SERVER':
  501. urlParams.push('(type=hive-site&tag=' + data.Clusters.desired_configs['hive-site'].tag + ')');
  502. break;
  503. }
  504. return urlParams;
  505. },
  506. onLoadConfigsTags: function (data) {
  507. var urlParams = this.getConfigUrlParams(this.get('content.reassign.component_name'), data);
  508. App.ajax.send({
  509. name: 'reassign.load_configs',
  510. sender: this,
  511. data: {
  512. urlParams: urlParams.join('|')
  513. },
  514. success: 'onLoadConfigs',
  515. error: 'onTaskError'
  516. });
  517. },
  518. onLoadConfigs: function (data) {
  519. var componentName = this.get('content.reassign.component_name');
  520. var targetHostName = this.get('content.reassignHosts.target');
  521. var configs = {};
  522. var secureConfigs = [];
  523. data.items.forEach(function (item) {
  524. configs[item.type] = item.properties;
  525. }, this);
  526. this.setAdditionalConfigs(configs, componentName, targetHostName);
  527. this.setSecureConfigs(secureConfigs, configs, componentName);
  528. if (componentName === 'NAMENODE') {
  529. this.setSpecificNamenodeConfigs(configs, targetHostName);
  530. }
  531. if (componentName === 'RESOURCEMANAGER') {
  532. this.setSpecificResourceMangerConfigs(configs, targetHostName);
  533. }
  534. if (componentName === 'HIVE_METASTORE' || componentName === 'HIVE_SERVER') {
  535. this.setSpecificHiveConfigs(configs, targetHostName);
  536. }
  537. this.saveClusterStatus(secureConfigs, this.getComponentDir(configs, componentName));
  538. this.saveConfigsToServer(configs);
  539. this.saveServiceProperties(configs);
  540. },
  541. /**
  542. * make PUT call to save configs to server
  543. * @param configs
  544. */
  545. saveConfigsToServer: function (configs) {
  546. App.ajax.send({
  547. name: 'common.across.services.configurations',
  548. sender: this,
  549. data: {
  550. data: '[' + this.getServiceConfigData(configs).toString() + ']'
  551. },
  552. success: 'onSaveConfigs',
  553. error: 'onTaskError'
  554. });
  555. },
  556. /**
  557. * gather and format config data before sending to server
  558. * @param configs
  559. * @return {Array}
  560. * @method getServiceConfigData
  561. */
  562. getServiceConfigData: function (configs) {
  563. var componentName = this.get('content.reassign.component_name');
  564. var tagName = 'version' + (new Date).getTime();
  565. var configData = Object.keys(configs).map(function (_siteName) {
  566. return {
  567. type: _siteName,
  568. tag: tagName,
  569. properties: configs[_siteName],
  570. service_config_version_note: Em.I18n.t('services.reassign.step4.save.configuration.note').format(App.format.role(componentName))
  571. }
  572. });
  573. var allConfigData = [];
  574. App.Service.find().forEach(function (service) {
  575. var stackService = App.StackService.find().findProperty('serviceName', service.get('serviceName'));
  576. if (stackService) {
  577. var serviceConfigData = [];
  578. Object.keys(stackService.get('configTypesRendered')).forEach(function (type) {
  579. var serviceConfigTag = configData.findProperty('type', type);
  580. if (serviceConfigTag) {
  581. serviceConfigData.pushObject(serviceConfigTag);
  582. }
  583. }, this);
  584. allConfigData.pushObject(JSON.stringify({
  585. Clusters: {
  586. desired_config: serviceConfigData
  587. }
  588. }));
  589. }
  590. }, this);
  591. return allConfigData;
  592. },
  593. /**
  594. * set specific configs which applies only to NameNode component
  595. * @param configs
  596. * @param targetHostName
  597. */
  598. setSpecificNamenodeConfigs: function (configs, targetHostName) {
  599. var sourceHostName = this.get('content.reassignHosts.source');
  600. if (App.get('isHaEnabled')) {
  601. var nameServices = configs['hdfs-site']['dfs.nameservices'];
  602. var suffix = (configs['hdfs-site']['dfs.namenode.http-address.' + nameServices + '.nn1'] === sourceHostName + ':50070') ? '.nn1' : '.nn2';
  603. configs['hdfs-site']['dfs.namenode.http-address.' + nameServices + suffix] = targetHostName + ':50070';
  604. configs['hdfs-site']['dfs.namenode.https-address.' + nameServices + suffix] = targetHostName + ':50470';
  605. configs['hdfs-site']['dfs.namenode.rpc-address.' + nameServices + suffix] = targetHostName + ':8020';
  606. }
  607. if (!App.get('isHaEnabled') && App.Service.find('HBASE').get('isLoaded')) {
  608. configs['hbase-site']['hbase.rootdir'] = configs['hbase-site']['hbase.rootdir'].replace(/\/\/[^\/]*/, '//' + targetHostName + ':8020');
  609. }
  610. if (!App.get('isHaEnabled') && App.Service.find('ACCUMULO').get('isLoaded')) {
  611. configs['accumulo-site']['instance.volumes'] = configs['accumulo-site']['instance.volumes'].replace(/\/\/[^\/]*/, '//' + targetHostName + ':8020');
  612. }
  613. },
  614. /**
  615. * set specific configs which applies only to ResourceManager component
  616. * @param configs
  617. * @param targetHostName
  618. */
  619. setSpecificResourceMangerConfigs: function (configs, targetHostName) {
  620. var sourceHostName = this.get('content.reassignHosts.source');
  621. if (App.get('isRMHaEnabled')) {
  622. if (configs['yarn-site']['yarn.resourcemanager.hostname.rm1'] === sourceHostName) {
  623. configs['yarn-site']['yarn.resourcemanager.hostname.rm1'] = targetHostName;
  624. } else {
  625. configs['yarn-site']['yarn.resourcemanager.hostname.rm2'] = targetHostName;
  626. }
  627. }
  628. },
  629. /**
  630. * set specific configs which applies only to Hive related configs
  631. * @param configs
  632. * @param targetHostName
  633. */
  634. setSpecificHiveConfigs: function (configs, targetHostName) {
  635. var sourceHostName = this.get('content.reassignHosts.source');
  636. var hiveMSHosts = App.HostComponent.find().filterProperty('componentName', 'HIVE_METASTORE').mapProperty('hostName');
  637. if (this.get('content.reassign.component_name') === 'HIVE_METASTORE') hiveMSHosts = hiveMSHosts.removeObject(sourceHostName).addObject(targetHostName);
  638. var hiveServerHosts = App.HostComponent.find().filterProperty('componentName', 'HIVE_SERVER').mapProperty('hostName');
  639. if (this.get('content.reassign.component_name') === 'HIVE_SERVER') hiveServerHosts = hiveServerHosts.removeObject(sourceHostName).addObject(targetHostName);
  640. var hiveMasterHosts = hiveMSHosts.concat(hiveServerHosts).uniq().join(',');
  641. var hiveUser = configs['hive-env']['hive_user'];
  642. var webhcatUser = configs['hive-env']['webhcat_user'];
  643. var port = configs['hive-site']['hive.metastore.uris'].match(/:[0-9]{2,4}/);
  644. port = port ? port[0].slice(1) : "9083";
  645. for (var i = 0; i < hiveMSHosts.length; i++) {
  646. hiveMSHosts[i] = "thrift://" + hiveMSHosts[i] + ":" + port;
  647. }
  648. configs['hive-site']['hive.metastore.uris'] = hiveMSHosts.join(',');
  649. configs['webhcat-site']['templeton.hive.properties'] = configs['webhcat-site']['templeton.hive.properties'].replace(/thrift.+[0-9]{2,},/i, hiveMSHosts.join('\\,') + ",");
  650. configs['core-site']['hadoop.proxyuser.' + hiveUser + '.hosts'] = hiveMasterHosts;
  651. configs['core-site']['hadoop.proxyuser.' + webhcatUser + '.hosts'] = hiveMasterHosts;
  652. },
  653. /**
  654. * set secure configs for component
  655. * @param secureConfigs
  656. * @param configs
  657. * @param componentName
  658. * @return {Boolean}
  659. */
  660. setSecureConfigs: function (secureConfigs, configs, componentName) {
  661. var securityEnabled = this.get('content.securityEnabled');
  662. var component = this.get('secureConfigsMap').findProperty('componentName', componentName);
  663. if (Em.isNone(component) || !securityEnabled) return false;
  664. component.configs.forEach(function (config) {
  665. secureConfigs.push({
  666. keytab: configs[config.site][config.keytab],
  667. principal: configs[config.site][config.principal]
  668. });
  669. });
  670. return true;
  671. },
  672. /**
  673. * derive component directory from configurations
  674. * @param configs
  675. * @param componentName
  676. * @return {String}
  677. */
  678. getComponentDir: function (configs, componentName) {
  679. if (componentName === 'NAMENODE') {
  680. return configs['hdfs-site']['dfs.namenode.name.dir'];
  681. } else if (componentName === 'SECONDARY_NAMENODE') {
  682. return configs['hdfs-site']['dfs.namenode.checkpoint.dir'];
  683. }
  684. return '';
  685. },
  686. /**
  687. * save cluster status to server
  688. *
  689. * @param secureConfigs
  690. * @param componentDir
  691. * @return {Boolean}
  692. */
  693. saveClusterStatus: function (secureConfigs, componentDir) {
  694. if (componentDir || secureConfigs.length) {
  695. App.router.get(this.get('content.controllerName')).saveComponentDir(componentDir);
  696. App.router.get(this.get('content.controllerName')).saveSecureConfigs(secureConfigs);
  697. App.clusterStatus.setClusterStatus({
  698. clusterName: this.get('content.cluster.name'),
  699. clusterState: this.get('clusterDeployState'),
  700. wizardControllerName: this.get('content.controllerName'),
  701. localdb: App.db.data
  702. });
  703. return true;
  704. }
  705. return false;
  706. },
  707. onSaveConfigs: function () {
  708. this.onTaskCompleted();
  709. },
  710. startZooKeeperServers: function () {
  711. var components = this.get('content.masterComponentHosts').filterProperty('component', 'ZOOKEEPER_SERVER');
  712. this.updateComponent('ZOOKEEPER_SERVER', components.mapProperty('hostName'), "ZOOKEEPER", "Start");
  713. },
  714. startNameNode: function () {
  715. var components = this.get('content.masterComponentHosts').filterProperty('component', 'NAMENODE');
  716. this.updateComponent('NAMENODE', components.mapProperty('hostName').without(this.get('content.reassignHosts.source')), "HDFS", "Start");
  717. },
  718. /**
  719. * make server call to start services
  720. */
  721. startRequiredServices: function () {
  722. var unrelatedServices = this.get('unrelatedServicesMap')[this.get('content.reassign.component_name')];
  723. if (unrelatedServices) {
  724. this.startServices(false, unrelatedServices);
  725. } else {
  726. this.startServices(true);
  727. }
  728. },
  729. /**
  730. * make DELETE call for each host component on host
  731. */
  732. deleteHostComponents: function () {
  733. this.set('multiTaskCounter', 0);
  734. var hostComponents = this.get('hostComponents');
  735. var hostName = this.get('content.reassignHosts.source');
  736. for (var i = 0; i < hostComponents.length; i++) {
  737. App.ajax.send({
  738. name: 'common.delete.host_component',
  739. sender: this,
  740. data: {
  741. hostName: hostName,
  742. componentName: hostComponents[i]
  743. },
  744. success: 'onComponentsTasksSuccess',
  745. error: 'onDeleteHostComponentsError'
  746. });
  747. }
  748. },
  749. onDeleteHostComponentsError: function (error) {
  750. if (error.responseText.indexOf('org.apache.ambari.server.controller.spi.NoSuchResourceException') !== -1) {
  751. this.onComponentsTasksSuccess();
  752. } else {
  753. this.onTaskError();
  754. }
  755. },
  756. done: function () {
  757. if (!this.get('isSubmitDisabled')) {
  758. this.removeObserver('tasks.@each.status', this, 'onTaskStatusChange');
  759. if (this.get('content.hasManualSteps')) {
  760. App.router.send('next');
  761. } else {
  762. App.router.send('complete');
  763. }
  764. }
  765. },
  766. /**
  767. * make server call to clean MYSQL
  768. */
  769. cleanMySqlServer: function () {
  770. var hostname = App.HostComponent.find().filterProperty('componentName', 'MYSQL_SERVER').get('firstObject.hostName');
  771. if (this.get('content.reassign.component_name') === 'MYSQL_SERVER') {
  772. hostname = this.get('content.reassignHosts.target');
  773. }
  774. App.ajax.send({
  775. name: 'service.mysql.clean',
  776. sender: this,
  777. data: {
  778. host: hostname
  779. },
  780. success: 'startPolling',
  781. error: 'onTaskError'
  782. });
  783. },
  784. /**
  785. * make server call to configure MYSQL
  786. */
  787. configureMySqlServer : function () {
  788. var hostname = App.HostComponent.find().filterProperty('componentName', 'MYSQL_SERVER').get('firstObject.hostName');
  789. if (this.get('content.reassign.component_name') === 'MYSQL_SERVER') {
  790. hostname = this.get('content.reassignHosts.target');
  791. }
  792. App.ajax.send({
  793. name: 'service.mysql.configure',
  794. sender: this,
  795. data: {
  796. host: hostname
  797. },
  798. success: 'startPolling',
  799. error: 'onTaskError'
  800. });
  801. },
  802. startMySqlServer: function() {
  803. App.ajax.send({
  804. name: 'common.host.host_component.update',
  805. sender: this,
  806. data: {
  807. context: "Start MySQL Server",
  808. hostName: App.HostComponent.find().filterProperty('componentName', 'MYSQL_SERVER').get('firstObject.hostName'),
  809. serviceName: "HIVE",
  810. componentName: "MYSQL_SERVER",
  811. HostRoles: {
  812. state: "STARTED"
  813. }
  814. },
  815. success: 'startPolling',
  816. error: 'onTaskError'
  817. });
  818. },
  819. restartMySqlServer: function() {
  820. var context = "Restart MySql Server";
  821. var resource_filters = {
  822. component_name: "MYSQL_SERVER",
  823. hosts: App.HostComponent.find().filterProperty('componentName', 'MYSQL_SERVER').get('firstObject.hostName'),
  824. service_name: "HIVE"
  825. };
  826. var operation_level = {
  827. level: "HOST_COMPONENT",
  828. cluster_name: this.get('content.cluster.name'),
  829. service_name: "HIVE",
  830. hostcomponent_name: "MYSQL_SERVER"
  831. };
  832. App.ajax.send({
  833. name: 'restart.hostComponents',
  834. sender: this,
  835. data: {
  836. context: context,
  837. resource_filters: [resource_filters],
  838. operation_level: operation_level
  839. },
  840. success: 'startPolling',
  841. error: 'onTaskError'
  842. });
  843. },
  844. startNewMySqlServer: function() {
  845. App.ajax.send({
  846. name: 'common.host.host_component.update',
  847. sender: this,
  848. data: {
  849. context: "Start MySQL Server",
  850. hostName: this.get('content.reassignHosts.target'),
  851. serviceName: "HIVE",
  852. componentName: "MYSQL_SERVER",
  853. HostRoles: {
  854. state: "STARTED"
  855. }
  856. },
  857. success: 'startPolling',
  858. error: 'onTaskError'
  859. });
  860. },
  861. testDBConnection: function() {
  862. this.prepareDBCheckAction();
  863. // this.onTaskCompleted();
  864. },
  865. isComponentWithDB: function() {
  866. return ['HIVE_SERVER', 'HIVE_METASTORE', 'OOZIE_SERVER'].contains(this.get('content.reassign.component_name'));
  867. },
  868. dbProperty: function() {
  869. var componentName = this.get('content.reassign.component_name');
  870. var property = null;
  871. switch(componentName) {
  872. case 'HIVE_SERVER':
  873. case 'HIVE_METASTORE':
  874. property = 'javax.jdo.option.ConnectionDriverName';
  875. break;
  876. case 'OOZIE_SERVER':
  877. property = 'oozie.service.JPAService.jdbc.url';
  878. break;
  879. }
  880. return property;
  881. }.property(),
  882. /** @property {Object} propertiesPattern - check pattern according to type of connection properties **/
  883. propertiesPattern: function() {
  884. return {
  885. user_name: /(username|dblogin)$/ig,
  886. user_passwd: /(dbpassword|password)$/ig,
  887. db_connection_url: /jdbc\.url|connectionurl/ig,
  888. driver_class: /ConnectionDriverName|jdbc\.driver/ig,
  889. schema_name: /db\.schema\.name/ig
  890. };
  891. }.property(),
  892. /** @property {Object} connectionProperties - service specific config values mapped for custom action request **/
  893. connectionProperties: function() {
  894. var propObj = {};
  895. for (var key in this.get('propertiesPattern')) {
  896. propObj[key] = this.getConnectionProperty(this.get('propertiesPattern')[key]);
  897. }
  898. return propObj;
  899. }.property('propertiesPattern'),
  900. getConnectionProperty: function(regexp) {
  901. var propertyName = this.get('requiredProperties').filter(function(item) {
  902. return regexp.test(item);
  903. })[0];
  904. return this.get('content.serviceProperties')[propertyName];
  905. },
  906. /**
  907. * Properties that stores in local storage used for handling
  908. * last success connection.
  909. *
  910. * @property {Object} preparedDBProperties
  911. **/
  912. preparedDBProperties: function() {
  913. var propObj = {};
  914. for (var key in this.get('propertiesPattern')) {
  915. var propValue = this.getConnectionProperty(this.get('propertiesPattern')[key]);
  916. propObj[key] = propValue;
  917. }
  918. return propObj;
  919. }.property(),
  920. /** @property {object} requiredProperties - properties that necessary for database connection **/
  921. requiredProperties: function() {
  922. var propertiesMap = {
  923. OOZIE: ['oozie.db.schema.name','oozie.service.JPAService.jdbc.username','oozie.service.JPAService.jdbc.password','oozie.service.JPAService.jdbc.driver','oozie.service.JPAService.jdbc.url'],
  924. HIVE: ['ambari.hive.db.schema.name','javax.jdo.option.ConnectionUserName','javax.jdo.option.ConnectionPassword','javax.jdo.option.ConnectionDriverName','javax.jdo.option.ConnectionURL']
  925. };
  926. return propertiesMap[this.get('content.reassign.service_id')];
  927. }.property(),
  928. dbType: function() {
  929. var databaseTypes = /MySQL|PostgreS|Oracle|Derby|MSSQL/gi;
  930. var databaseProp = this.get('content.serviceProperties')[this.get('dbProperty')];
  931. return databaseProp.match(databaseTypes)[0];
  932. }.property('dbProperty'),
  933. prepareDBCheckAction: function() {
  934. var ambariProperties = null;
  935. var properties = this.get('content.serviceProperties');
  936. var params = this.get('preparedDBProperties');
  937. ambariProperties = App.router.get('clusterController.ambariProperties');
  938. params['db_name'] = this.get('dbType');
  939. params['jdk_location'] = ambariProperties['jdk_location'];
  940. params['jdk_name'] = ambariProperties['jdk.name'];
  941. params['java_home'] = ambariProperties['java.home'];
  942. params['threshold'] = 60;
  943. params['ambari_server_host'] = location.hostname;
  944. params['check_execute_list'] = "db_connection_check";
  945. App.ajax.send({
  946. name: 'custom_action.create',
  947. sender: this,
  948. data: {
  949. requestInfo: {
  950. "context": "Check host",
  951. "action": "check_host",
  952. "parameters": params
  953. },
  954. filteredHosts: [this.get('content.reassignHosts.target')]
  955. },
  956. success: 'onCreateActionSuccess',
  957. error: 'onTaskError'
  958. });
  959. },
  960. onCreateActionSuccess: function(data) {
  961. this.set('checkDBRequestId', data.Requests.id);
  962. App.ajax.send({
  963. name: 'custom_action.request',
  964. sender: this,
  965. data: {
  966. requestId: this.get('checkDBRequestId')
  967. },
  968. success: 'setCheckDBTaskId'
  969. });
  970. },
  971. setCheckDBTaskId: function(data) {
  972. this.set('checkDBTaskId', data.items[0].Tasks.id);
  973. this.startDBCheckPolling();
  974. },
  975. startDBCheckPolling: function() {
  976. this.getDBConnTaskInfo();
  977. },
  978. getDBConnTaskInfo: function() {
  979. this.setTaskStatus(this.get('currentTaskId'), 'IN_PROGRESS');
  980. this.get('tasks').findProperty('id', this.get('currentTaskId')).set('progress', 100);
  981. this.set('logs', []);
  982. App.ajax.send({
  983. name: 'custom_action.request',
  984. sender: this,
  985. data: {
  986. requestId: this.get('checkDBRequestId'),
  987. taskId: this.get('checkDBTaskId')
  988. },
  989. success: 'getDBConnTaskInfoSuccess'
  990. });
  991. },
  992. getDBConnTaskInfoSuccess: function(data) {
  993. var task = data.Tasks;
  994. if (task.status === 'COMPLETED') {
  995. var structuredOut = task.structured_out.db_connection_check;
  996. if (structuredOut.exit_code != 0) {
  997. this.showConnectionErrorPopup(structuredOut.message);
  998. this.onTaskError();
  999. } else {
  1000. this.onTaskCompleted();
  1001. }
  1002. }
  1003. if (task.status === 'FAILED') {
  1004. this.onTaskError();
  1005. }
  1006. if (/PENDING|QUEUED|IN_PROGRESS/.test(task.status)) {
  1007. Em.run.later(this, function() {
  1008. this.startDBCheckPolling();
  1009. }, 3000);
  1010. }
  1011. },
  1012. showConnectionErrorPopup: function(error) {
  1013. var popup = App.showAlertPopup('Database Connection Error');
  1014. popup.set('body', error);
  1015. },
  1016. testDBRetryTooltip: function() {
  1017. var db_host = this.get('content.serviceProperties.database_hostname');
  1018. var db_type = this.get('dbType');
  1019. var db_props = this.get('preparedDBProperties');
  1020. return Em.I18n.t('services.reassign.step4.tasks.testDBConnection.tooltip').format(
  1021. db_host, db_type, db_props['schema_name'], db_props['user_name'],
  1022. db_props['user_passwd'], db_props['driver_class'], db_props['db_connection_url']
  1023. );
  1024. }.property('dbProperties'),
  1025. saveServiceProperties: function(configs) {
  1026. App.router.get(this.get('content.controllerName')).saveServiceProperties(configs);
  1027. }
  1028. });