step4_controller.js 39 KB

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