step8_controller.js 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681
  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. var stringUtils = require('utils/string_utils');
  20. var validator = require('utils/validator');
  21. App.WizardStep8Controller = Em.Controller.extend(App.AddSecurityConfigs, App.wizardDeployProgressControllerMixin, App.ConfigOverridable, App.ConfigsSaverMixin, {
  22. name: 'wizardStep8Controller',
  23. /**
  24. * @type {boolean}
  25. */
  26. isAddService: Em.computed.equal('content.controllerName', 'addServiceController'),
  27. /**
  28. * @type {boolean}
  29. */
  30. isAddHost: Em.computed.equal('content.controllerName', 'addHostController'),
  31. /**
  32. * @type {boolean}
  33. */
  34. isInstaller: Em.computed.equal('content.controllerName', 'installerController'),
  35. /**
  36. * List of raw data about cluster that should be displayed
  37. * @type {Array}
  38. */
  39. rawContent: [
  40. {
  41. config_name: 'Admin',
  42. display_name: 'Admin Name',
  43. config_value: ''
  44. },
  45. {
  46. config_name: 'cluster',
  47. display_name: 'Cluster Name',
  48. config_value: ''
  49. },
  50. {
  51. config_name: 'hosts',
  52. display_name: 'Total Hosts',
  53. config_value: ''
  54. },
  55. {
  56. config_name: 'Repo',
  57. display_name: 'Local Repository',
  58. config_value: ''
  59. }
  60. ],
  61. /**
  62. * List of data about cluster (based on formatted <code>rawContent</code>)
  63. * @type {Object[]}
  64. */
  65. clusterInfo: [],
  66. /**
  67. * List of services with components assigned to hosts
  68. * @type {Object[]}
  69. */
  70. services: [],
  71. /**
  72. * @type {Object[]}
  73. */
  74. configs: [],
  75. /**
  76. * True if Kerberos is installed on the cluster and the kdc_type on the server is set to "none"
  77. * @type {Boolean}
  78. */
  79. isManualKerberos: Em.computed.equal('App.router.mainAdminKerberosController.kdc_type', 'none'),
  80. showDownloadCsv: function () {
  81. return !!App.get('router.mainAdminKerberosController.kdc_type')
  82. }.property('App.router.mainAdminKerberosController.kdc_type'),
  83. /**
  84. * Should Submit button be disabled
  85. * @type {bool}
  86. */
  87. isSubmitDisabled: false,
  88. /**
  89. * Should Back button be disabled
  90. * @type {bool}
  91. */
  92. isBackBtnDisabled: false,
  93. /**
  94. * Is error appears while <code>ajaxQueue</code> executes
  95. * @type {bool}
  96. */
  97. hasErrorOccurred: false,
  98. /**
  99. * Are services installed
  100. * Used to hide Deploy Progress Bar
  101. * @type {bool}
  102. */
  103. servicesInstalled: false,
  104. /**
  105. * List of service config tags
  106. * @type {Object[]}
  107. */
  108. serviceConfigTags: [],
  109. /**
  110. * Selected config group
  111. * @type {Object}
  112. */
  113. selectedConfigGroup: null,
  114. /**
  115. * List of config groups
  116. * @type {Object[]}
  117. */
  118. configGroups: [],
  119. /**
  120. * List of selected but not installed services
  121. * @type {Object[]}
  122. */
  123. selectedServices: function () {
  124. return this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false);
  125. }.property('content.services.@each.isSelected','content.services.@each.isInstalled').cacheable(),
  126. /**
  127. * List of installed services
  128. * @type {Object[]}
  129. */
  130. installedServices: Em.computed.filterBy('content.services', 'isInstalled', true),
  131. /**
  132. * Current cluster name
  133. * @type {string}
  134. */
  135. clusterName: Em.computed.alias('content.cluster.name'),
  136. /**
  137. * List of existing cluster names
  138. * @type {string[]}
  139. */
  140. clusterNames: [],
  141. /**
  142. * Number of completed cluster delete requests
  143. * @type {number}
  144. */
  145. clusterDeleteRequestsCompleted: 0,
  146. /**
  147. * Indicates if all cluster delete requests are completed
  148. * @type {boolean}
  149. */
  150. isAllClusterDeleteRequestsCompleted: Em.computed.equalProperties('clusterDeleteRequestsCompleted', 'clusterNames.length'),
  151. /**
  152. * Error popup body views for clusters that couldn't be deleted
  153. * @type {App.AjaxDefaultErrorPopupBodyView[]}
  154. */
  155. clusterDeleteErrorViews: [],
  156. /**
  157. * Clear current step data
  158. * @method clearStep
  159. */
  160. clearStep: function () {
  161. this.get('services').clear();
  162. this.get('configs').clear();
  163. this.get('clusterInfo').clear();
  164. this.get('serviceConfigTags').clear();
  165. this.set('servicesInstalled', false);
  166. this.set('ajaxQueueLength', 0);
  167. this.set('ajaxRequestsQueue', App.ajaxQueue.create());
  168. this.set('ajaxRequestsQueue.finishedCallback', this.ajaxQueueFinished);
  169. this.get('clusterDeleteErrorViews').clear();
  170. this.set('clusterDeleteRequestsCompleted', 0);
  171. },
  172. /**
  173. * Load current step data
  174. * @method loadStep
  175. */
  176. loadStep: function () {
  177. this.clearStep();
  178. if (this.get('content.serviceConfigProperties')) {
  179. this.formatProperties();
  180. this.loadConfigs();
  181. }
  182. this.loadClusterInfo();
  183. this.loadServices();
  184. this.set('isSubmitDisabled', false);
  185. this.set('isBackBtnDisabled', false);
  186. },
  187. /**
  188. * replace whitespace character with coma between directories
  189. * @method formatProperties
  190. */
  191. formatProperties: function () {
  192. this.get('content.serviceConfigProperties').forEach(function (_configProperty) {
  193. _configProperty.value = (typeof _configProperty.value === "boolean")
  194. ? _configProperty.value.toString() : App.config.trimProperty(_configProperty, false);
  195. });
  196. },
  197. /**
  198. * Load all site properties
  199. * @method loadConfigs
  200. */
  201. loadConfigs: function () {
  202. this.set('configs', this.get('content.serviceConfigProperties').filter(function (config) {
  203. return !config.group;
  204. }));
  205. },
  206. /**
  207. * Format <code>content.hosts</code> from Object to Array
  208. * @returns {Array}
  209. * @method getRegisteredHosts
  210. */
  211. getRegisteredHosts: function () {
  212. var allHosts = this.get('content.hosts');
  213. var hosts = [];
  214. for (var hostName in allHosts) {
  215. if (allHosts.hasOwnProperty(hostName)) {
  216. if (allHosts[hostName].bootStatus == 'REGISTERED') {
  217. allHosts[hostName].hostName = allHosts[hostName].name;
  218. hosts.pushObject(allHosts[hostName]);
  219. }
  220. }
  221. }
  222. return hosts;
  223. },
  224. /**
  225. * Load all info about cluster to <code>clusterInfo</code> variable
  226. * @method loadClusterInfo
  227. */
  228. loadClusterInfo: function () {
  229. //Admin name
  230. var admin = this.rawContent.findProperty('config_name', 'Admin');
  231. admin.config_value = App.db.getLoginName();
  232. if (admin.config_value) {
  233. this.get('clusterInfo').pushObject(Ember.Object.create(admin));
  234. }
  235. // cluster name
  236. var cluster = this.rawContent.findProperty('config_name', 'cluster');
  237. cluster.config_value = this.get('content.cluster.name');
  238. this.get('clusterInfo').pushObject(Ember.Object.create(cluster));
  239. //hosts
  240. var newHostsCount = 0;
  241. var totalHostsCount = 0;
  242. var hosts = this.get('content.hosts');
  243. for (var hostName in hosts) {
  244. newHostsCount += ~~(!hosts[hostName].isInstalled);
  245. totalHostsCount++;
  246. }
  247. var totalHostsObj = this.rawContent.findProperty('config_name', 'hosts');
  248. totalHostsObj.config_value = totalHostsCount + ' (' + newHostsCount + ' new)';
  249. this.get('clusterInfo').pushObject(Em.Object.create(totalHostsObj));
  250. //repo
  251. if (['addHostController', 'addServiceController'].contains(this.get('content.controllerName'))) {
  252. // For some stacks there is no info regarding stack versions to upgrade, e.g. HDP-2.1
  253. if (App.StackVersion.find().get('content.length')) {
  254. this.loadRepoInfo();
  255. } else {
  256. this.loadDefaultRepoInfo();
  257. }
  258. } else {
  259. // from install wizard
  260. var selectedStack = App.Stack.find().findProperty('isSelected');
  261. var allRepos = [];
  262. if (selectedStack && selectedStack.get('operatingSystems')) {
  263. selectedStack.get('operatingSystems').forEach(function (os) {
  264. if (os.get('isSelected')) {
  265. os.get('repositories').forEach(function(repo) {
  266. allRepos.push(Em.Object.create({
  267. base_url: repo.get('baseUrl'),
  268. os_type: repo.get('osType'),
  269. repo_id: repo.get('repoId')
  270. }));
  271. }, this);
  272. }
  273. }, this);
  274. }
  275. allRepos.set('display_name', Em.I18n.t("installer.step8.repoInfo.displayName"));
  276. this.get('clusterInfo').set('repoInfo', allRepos);
  277. }
  278. },
  279. /**
  280. * Load repo info for add Service/Host wizard review page
  281. * @return {$.ajax|null}
  282. * @method loadRepoInfo
  283. */
  284. loadRepoInfo: function () {
  285. var currentRepoVersion = App.StackVersion.find().findProperty('state', 'CURRENT').get('repositoryVersion.repositoryVersion');
  286. var stackName = App.get('currentStackName');
  287. return App.ajax.send({
  288. name: 'cluster.load_repo_version',
  289. sender: this,
  290. data: {
  291. stackName: stackName,
  292. repositoryVersion: currentRepoVersion
  293. },
  294. success: 'loadRepoInfoSuccessCallback',
  295. error: 'loadRepoInfoErrorCallback'
  296. });
  297. },
  298. /**
  299. * Save all repo base URL of all OS type to <code>repoInfo<code>
  300. * @param {object} data
  301. * @method loadRepoInfoSuccessCallback
  302. */
  303. loadRepoInfoSuccessCallback: function (data) {
  304. Em.assert('Current repo-version may be only one', data.items.length === 1);
  305. if (data.items.length) {
  306. var allRepos = this.generateRepoInfo(Em.getWithDefault(data, 'items.0.repository_versions.0.operating_systems', []));
  307. allRepos.set('display_name', Em.I18n.t("installer.step8.repoInfo.displayName"));
  308. this.get('clusterInfo').set('repoInfo', allRepos);
  309. } else {
  310. this.loadDefaultRepoInfo();
  311. }
  312. },
  313. /**
  314. * Generate list regarding info about OS versions and repositories.
  315. *
  316. * @param {Object{}} oses - OS array
  317. * @returns {Em.Object[]}
  318. */
  319. generateRepoInfo: function(oses) {
  320. return oses.map(function(os) {
  321. return os.repositories.map(function (repository) {
  322. return Em.Object.create({
  323. base_url: repository.Repositories.base_url,
  324. os_type: repository.Repositories.os_type,
  325. repo_id: repository.Repositories.repo_id
  326. });
  327. });
  328. }).reduce(function(p, c) { return p.concat(c); });
  329. },
  330. /**
  331. * Load repo info from stack. Used if installed stack doesn't have upgrade info.
  332. *
  333. * @returns {$.Deferred}
  334. * @method loadDefaultRepoInfo
  335. */
  336. loadDefaultRepoInfo: function() {
  337. var nameVersionCombo = App.get('currentStackVersion').split('-');
  338. return App.ajax.send({
  339. name: 'cluster.load_repositories',
  340. sender: this,
  341. data: {
  342. stackName: nameVersionCombo[0],
  343. stackVersion: nameVersionCombo[1]
  344. },
  345. success: 'loadDefaultRepoInfoSuccessCallback',
  346. error: 'loadRepoInfoErrorCallback'
  347. });
  348. },
  349. /**
  350. * @param {Object} data - JSON data from server
  351. * @method loadDefaultRepoInfoSuccessCallback
  352. */
  353. loadDefaultRepoInfoSuccessCallback: function (data) {
  354. var allRepos = this.generateRepoInfo(Em.getWithDefault(data, 'items', []));
  355. allRepos.set('display_name', Em.I18n.t("installer.step8.repoInfo.displayName"));
  356. this.get('clusterInfo').set('repoInfo', allRepos);
  357. },
  358. /**
  359. * @param {object} request
  360. * @method loadRepoInfoErrorCallback
  361. */
  362. loadRepoInfoErrorCallback: function (request) {
  363. var allRepos = [];
  364. allRepos.set('display_name', Em.I18n.t("installer.step8.repoInfo.displayName"));
  365. this.get('clusterInfo').set('repoInfo', allRepos);
  366. },
  367. /**
  368. * Load all info about services to <code>services</code> variable
  369. * @method loadServices
  370. */
  371. loadServices: function () {
  372. this.get('selectedServices').filterProperty('isHiddenOnSelectServicePage', false).forEach(function (service) {
  373. var serviceObj = Em.Object.create({
  374. service_name: service.get('serviceName'),
  375. display_name: service.get('displayNameOnSelectServicePage'),
  376. service_components: Em.A([])
  377. });
  378. service.get('serviceComponents').forEach(function (component) {
  379. // show clients for services that have only clients components
  380. if ((component.get('isClient') || component.get('isRequiredOnAllHosts')) && !service.get('isClientOnlyService')) return;
  381. // no HA component
  382. if (component.get('isHAComponentOnly')) return;
  383. // skip if component is not allowed on single node cluster
  384. if (Object.keys(this.get('content.hosts')).length == 1 && component.get('isNotAllowedOnSingleNodeCluster')) return;
  385. var displayName;
  386. if (component.get('isClient')) {
  387. displayName = Em.I18n.t('common.clients')
  388. } else {
  389. // remove service name from component display name
  390. displayName = App.format.role(component.get('componentName'), false).replace(new RegExp('^' + service.get('serviceName') + '\\s', 'i'), '');
  391. }
  392. var componentName = component.get('componentName');
  393. var masterComponents = this.get('content.masterComponentHosts');
  394. var isMasterComponentSelected = masterComponents.someProperty('component', componentName);
  395. var isMaster = component.get('isMaster');
  396. if (!isMaster || isMasterComponentSelected) {
  397. serviceObj.get('service_components').pushObject(Em.Object.create({
  398. component_name: component.get('isClient') ? Em.I18n.t('common.client').toUpperCase() : component.get('componentName'),
  399. display_name: displayName,
  400. component_value: this.assignComponentHosts(component)
  401. }));
  402. }
  403. }, this);
  404. if (service.get('customReviewHandler')) {
  405. for (var displayName in service.get('customReviewHandler')) {
  406. serviceObj.get('service_components').pushObject(Em.Object.create({
  407. display_name: displayName,
  408. component_value: this.assignComponentHosts(Em.Object.create({
  409. customHandler: service.get('customReviewHandler.' + displayName)
  410. }))
  411. }));
  412. }
  413. }
  414. this.get('services').pushObject(serviceObj);
  415. }, this);
  416. },
  417. /**
  418. * Set <code>component_value</code> property to <code>component</code>
  419. * @param {Em.Object} component
  420. * @return {String}
  421. * @method assignComponentHosts
  422. */
  423. assignComponentHosts: function (component) {
  424. var componentValue;
  425. if (component.get('customHandler')) {
  426. componentValue = this[component.get('customHandler')].call(this, component);
  427. }
  428. else {
  429. if (component.get('isMaster')) {
  430. componentValue = this.getMasterComponentValue(component.get('componentName'));
  431. }
  432. else {
  433. var componentName = component.get('isClient') ? Em.I18n.t('common.client').toUpperCase() : component.get('componentName');
  434. var hostsLength = this.get('content.slaveComponentHosts')
  435. .findProperty('componentName', componentName).hosts.length;
  436. componentValue = hostsLength + Em.I18n.t('installer.step8.host' + ((hostsLength > 1) ? 's' : ''));
  437. }
  438. }
  439. return componentValue;
  440. },
  441. getMasterComponentValue: function (componentName) {
  442. var masterComponents = this.get('content.masterComponentHosts');
  443. var hostsCount = masterComponents.filterProperty('component', componentName).length;
  444. return stringUtils.pluralize(hostsCount,
  445. masterComponents.findProperty('component', componentName).hostName,
  446. hostsCount + ' ' + Em.I18n.t('installer.step8.hosts'));
  447. },
  448. loadHiveDbValue: function() {
  449. return this.loadDbValue('HIVE');
  450. },
  451. loadOozieDbValue: function() {
  452. return this.loadDbValue('OOZIE');
  453. },
  454. /**
  455. * Set displayed Hive DB value based on DB type
  456. * @method loadHiveDbValue
  457. */
  458. loadDbValue: function (serviceName) {
  459. var serviceConfigProperties = this.get('wizardController').getDBProperty('serviceConfigProperties');
  460. var dbFull = serviceConfigProperties.findProperty('name', serviceName.toLowerCase() + '_database'),
  461. db = serviceConfigProperties.findProperty('name', serviceName.toLowerCase() + '_ambari_database');
  462. return db && dbFull ? db.value + ' (' + dbFull.value + ')' : '';
  463. },
  464. /**
  465. * Set displayed HBase master value
  466. * @param {Object} hbaseMaster
  467. * @method loadHbaseMasterValue
  468. */
  469. loadHbaseMasterValue: function (hbaseMaster) {
  470. var hbaseHostName = this.get('content.masterComponentHosts').filterProperty('component', hbaseMaster.component_name);
  471. if (hbaseHostName.length == 1) {
  472. hbaseMaster.set('component_value', hbaseHostName[0].hostName);
  473. } else {
  474. hbaseMaster.set('component_value', hbaseHostName[0].hostName + " " + Em.I18n.t('installer.step8.other').format(hbaseHostName.length - 1));
  475. }
  476. },
  477. /**
  478. * Set displayed ZooKeeper Server value
  479. * @param {Object} serverComponent
  480. * @method loadZkServerValue
  481. */
  482. loadZkServerValue: function (serverComponent) {
  483. var zkHostNames = this.get('content.masterComponentHosts').filterProperty('component', serverComponent.component_name).length;
  484. var hostSuffix;
  485. if (zkHostNames === 1) {
  486. hostSuffix = Em.I18n.t('installer.step8.host');
  487. } else {
  488. hostSuffix = Em.I18n.t('installer.step8.hosts');
  489. }
  490. serverComponent.set('component_value', zkHostNames + hostSuffix);
  491. },
  492. /**
  493. * Onclick handler for <code>next</code> button
  494. * @method submit
  495. * @return {void}
  496. */
  497. submit: function () {
  498. var wizardController;
  499. if (!this.get('isSubmitDisabled')) {
  500. wizardController = App.router.get(this.get('content.controllerName'));
  501. wizardController.setLowerStepsDisable(wizardController.get('currentStep'));
  502. this.set('isSubmitDisabled', true);
  503. this.set('isBackBtnDisabled', true);
  504. this.showRestartWarnings()
  505. .then(this.checkKDCSession.bind(this));
  506. }
  507. },
  508. /**
  509. * Warn user about services that will be restarted during installation.
  510. *
  511. * @returns {$.Deferred}
  512. */
  513. showRestartWarnings: function() {
  514. var self = this;
  515. var dfd = $.Deferred();
  516. var wizardController = App.router.get(this.get('content.controllerName'));
  517. var selectedServiceNames = this.get('selectedServices').mapProperty('serviceName');
  518. var installedServiceNames = this.get('installedServices').mapProperty('serviceName');
  519. if (this.get('content.controllerName') === 'addServiceController' && selectedServiceNames.contains('OOZIE')) {
  520. var affectedServices = ['HDFS', 'YARN'].filter(function(serviceName) {
  521. return installedServiceNames.contains(serviceName);
  522. });
  523. if (affectedServices.length) {
  524. var serviceNames = affectedServices.length > 1 ?
  525. '<b>{0}</b> {1} <b>{2}</b>'.format(affectedServices[0], Em.I18n.t('and'), affectedServices[1]) : '<b>' + affectedServices[0] + '</b> ';
  526. App.ModalPopup.show({
  527. encodeBody: false,
  528. header: Em.I18n.t('common.warning'),
  529. body: Em.I18n.t('installer.step8.services.restart.required').format(serviceNames, stringUtils.pluralize(affectedServices.length, Em.I18n.t('common.service').toLowerCase())),
  530. secondary: Em.I18n.t('common.cancel'),
  531. primary: Em.I18n.t('common.proceedAnyway'),
  532. onPrimary: function() {
  533. this.hide();
  534. dfd.resolve();
  535. },
  536. onClose: function() {
  537. this.hide();
  538. self.set('isSubmitDisabled', false);
  539. self.set('isBackBtnDisabled', false);
  540. wizardController.setStepsEnable();
  541. dfd.reject();
  542. },
  543. onSecondary: function() {
  544. this.onClose();
  545. }
  546. });
  547. } else {
  548. dfd.resolve();
  549. }
  550. } else {
  551. dfd.resolve();
  552. }
  553. return dfd.promise();
  554. },
  555. checkKDCSession: function() {
  556. var self = this;
  557. var wizardController = App.router.get(this.get('content.controllerName'));
  558. if (this.get('content.controllerName') != 'installerController') {
  559. App.get('router.mainAdminKerberosController').getKDCSessionState(this.submitProceed.bind(this), function () {
  560. self.set('isSubmitDisabled', false);
  561. self.set('isBackBtnDisabled', false);
  562. wizardController.setStepsEnable();
  563. if (self.get('content.controllerName') === 'addServiceController') {
  564. wizardController.setSkipSlavesStep(wizardController.getDBProperty('selectedServiceNames'), 3);
  565. }
  566. });
  567. } else {
  568. this.submitProceed();
  569. }
  570. },
  571. /**
  572. * Prepare <code>ajaxQueue</code> and start to execute it
  573. * @method submitProceed
  574. */
  575. submitProceed: function () {
  576. var self = this;
  577. this.set('clusterDeleteRequestsCompleted', 0);
  578. this.get('clusterDeleteErrorViews').clear();
  579. if (this.get('content.controllerName') == 'addHostController') {
  580. App.router.get('addHostController').setLowerStepsDisable(4);
  581. }
  582. // checkpoint the cluster status on the server so that the user can resume from where they left off
  583. switch (this.get('content.controllerName')) {
  584. case 'installerController':
  585. App.clusterStatus.setClusterStatus({
  586. clusterName: this.get('clusterName'),
  587. clusterState: 'CLUSTER_DEPLOY_PREP_2',
  588. wizardControllerName: this.get('content.controllerName'),
  589. localdb: App.db.data
  590. });
  591. break;
  592. case 'addHostController':
  593. App.clusterStatus.setClusterStatus({
  594. clusterName: this.get('clusterName'),
  595. clusterState: 'ADD_HOSTS_DEPLOY_PREP_2',
  596. wizardControllerName: this.get('content.controllerName'),
  597. localdb: App.db.data
  598. });
  599. break;
  600. case 'addServiceController':
  601. App.clusterStatus.setClusterStatus({
  602. clusterName: this.get('clusterName'),
  603. clusterState: 'ADD_SERVICES_DEPLOY_PREP_2',
  604. wizardControllerName: this.get('content.controllerName'),
  605. localdb: App.db.data
  606. });
  607. break;
  608. default:
  609. break;
  610. }
  611. // delete any existing clusters to start from a clean slate
  612. // before creating a new cluster in install wizard
  613. // TODO: modify for multi-cluster support
  614. this.getExistingClusterNames().complete(function () {
  615. var clusterNames = self.get('clusterNames');
  616. if (self.get('content.controllerName') == 'installerController' && (!App.get('testMode')) && clusterNames.length) {
  617. self.deleteClusters(clusterNames);
  618. } else {
  619. self.startDeploy();
  620. }
  621. });
  622. },
  623. /**
  624. * Get list of existing cluster names
  625. * @returns {object|null}
  626. * returns an array of existing cluster names.
  627. * returns an empty array if there are no existing clusters.
  628. * @method getExistingClusterNames
  629. */
  630. getExistingClusterNames: function () {
  631. return App.ajax.send({
  632. name: 'wizard.step8.existing_cluster_names',
  633. sender: this,
  634. success: 'getExistingClusterNamesSuccessCallBack',
  635. error: 'getExistingClusterNamesErrorCallback'
  636. });
  637. },
  638. /**
  639. * Save received list to <code>clusterNames</code>
  640. * @param {Object} data
  641. * @method getExistingClusterNamesSuccessCallBack
  642. */
  643. getExistingClusterNamesSuccessCallBack: function (data) {
  644. var clusterNames = data.items.mapProperty('Clusters.cluster_name');
  645. this.set('clusterNames', clusterNames);
  646. },
  647. /**
  648. * If error appears, set <code>clusterNames</code> to <code>[]</code>
  649. * @method getExistingClusterNamesErrorCallback
  650. */
  651. getExistingClusterNamesErrorCallback: function () {
  652. this.set('clusterNames', []);
  653. },
  654. /**
  655. * Delete cluster by name
  656. * One request for one cluster!
  657. * @param {string[]} clusterNames
  658. * @method deleteClusters
  659. */
  660. deleteClusters: function (clusterNames) {
  661. this.get('clusterDeleteErrorViews').clear();
  662. clusterNames.forEach(function (clusterName, index) {
  663. App.ajax.send({
  664. name: 'common.delete.cluster',
  665. sender: this,
  666. data: {
  667. name: clusterName,
  668. isLast: index == clusterNames.length - 1
  669. },
  670. success: 'deleteClusterSuccessCallback',
  671. error: 'deleteClusterErrorCallback'
  672. });
  673. }, this);
  674. },
  675. /**
  676. * Method to execute after successful cluster deletion
  677. * @method deleteClusterSuccessCallback
  678. */
  679. deleteClusterSuccessCallback: function () {
  680. this.incrementProperty('clusterDeleteRequestsCompleted');
  681. if (this.get('isAllClusterDeleteRequestsCompleted')) {
  682. if (this.get('clusterDeleteErrorViews.length')) {
  683. this.showDeleteClustersErrorPopup();
  684. } else {
  685. this.startDeploy();
  686. }
  687. }
  688. },
  689. /**
  690. * Method to execute after failed cluster deletion
  691. * @param {object} request
  692. * @param {string} ajaxOptions
  693. * @param {string} error
  694. * @param {object} opt
  695. * @method deleteClusterErrorCallback
  696. */
  697. deleteClusterErrorCallback: function (request, ajaxOptions, error, opt) {
  698. this.incrementProperty('clusterDeleteRequestsCompleted');
  699. try {
  700. var json = $.parseJSON(request.responseText);
  701. var message = json.message;
  702. } catch (err) {
  703. }
  704. this.get('clusterDeleteErrorViews').pushObject(App.AjaxDefaultErrorPopupBodyView.create({
  705. url: opt.url,
  706. type: opt.type,
  707. status: request.status,
  708. message: message
  709. }));
  710. if (this.get('isAllClusterDeleteRequestsCompleted')) {
  711. this.showDeleteClustersErrorPopup();
  712. }
  713. },
  714. /**
  715. * Show error popup if cluster deletion failed
  716. * @method showDeleteClustersErrorPopup
  717. */
  718. showDeleteClustersErrorPopup: function () {
  719. var self = this;
  720. this.setProperties({
  721. isSubmitDisabled: false,
  722. isBackBtnDisabled: false
  723. });
  724. App.ModalPopup.show({
  725. header: Em.I18n.t('common.error'),
  726. secondary: false,
  727. onPrimary: function () {
  728. this.hide();
  729. },
  730. bodyClass: Em.ContainerView.extend({
  731. childViews: self.get('clusterDeleteErrorViews')
  732. })
  733. });
  734. },
  735. /**
  736. * updates kerberosDescriptorConfigs
  737. * @method updateKerberosDescriptor
  738. */
  739. updateKerberosDescriptor: function(instant) {
  740. var kerberosDescriptor = App.db.get('KerberosWizard', 'kerberosDescriptorConfigs');
  741. var descriptorExists = this.get('wizardController').getDBProperty('isClusterDescriptorExists') === true;
  742. var ajaxOpts = {
  743. name: descriptorExists ? 'admin.kerberos.cluster.artifact.update' : 'admin.kerberos.cluster.artifact.create',
  744. data: {
  745. artifactName: 'kerberos_descriptor',
  746. data: {
  747. artifact_data: kerberosDescriptor
  748. }
  749. }
  750. };
  751. if (instant) {
  752. ajaxOpts.sender = this;
  753. App.ajax.send(ajaxOpts);
  754. } else {
  755. this.addRequestToAjaxQueue(ajaxOpts);
  756. }
  757. },
  758. /**
  759. * To Start deploy process
  760. * @method startDeploy
  761. */
  762. startDeploy: function () {
  763. if (this.get('content.controllerName') !== 'installerController') {
  764. this._startDeploy();
  765. } else {
  766. var installerController = App.router.get('installerController');
  767. var versionData = installerController.getSelectedRepoVersionData();
  768. if (versionData) {
  769. var self = this;
  770. installerController.postVersionDefinitionFileStep8(versionData.isXMLdata, versionData.data).done(function (versionInfo) {
  771. if (versionInfo.id && versionInfo.stackName && versionInfo.stackVersion) {
  772. var selectedStack = App.Stack.find().findProperty('isSelected', true);
  773. installerController.updateRepoOSInfo(versionInfo, selectedStack).done(function() {
  774. self._startDeploy();
  775. });
  776. }
  777. });
  778. } else {
  779. this._startDeploy();
  780. }
  781. }
  782. },
  783. /**
  784. * Start deploy process
  785. * @method startDeploy
  786. */
  787. _startDeploy: function () {
  788. this.createCluster();
  789. this.createSelectedServices();
  790. if (this.get('content.controllerName') !== 'addHostController') {
  791. if (this.get('content.controllerName') === 'addServiceController') {
  792. // for manually enabled Kerberos descriptor was updated on transition to this step
  793. if (App.get('isKerberosEnabled') && !this.get('isManualKerberos')) {
  794. this.updateKerberosDescriptor();
  795. }
  796. var fileNamesToUpdate = this.get('wizardController').getDBProperty('fileNamesToUpdate').uniq();
  797. if (fileNamesToUpdate && fileNamesToUpdate.length) {
  798. this.applyConfigurationsToCluster(this.generateDesiredConfigsJSON(this.get('configs'), fileNamesToUpdate));
  799. }
  800. }
  801. this.createConfigurations();
  802. this.applyConfigurationsToCluster(this.get('serviceConfigTags'));
  803. }
  804. this.createComponents();
  805. this.registerHostsToCluster();
  806. this.createConfigurationGroups();
  807. this.createMasterHostComponents();
  808. this.createSlaveAndClientsHostComponents();
  809. if (this.get('content.controllerName') === 'addServiceController') {
  810. this.createAdditionalClientComponents();
  811. }
  812. this.createAdditionalHostComponents();
  813. this.set('ajaxQueueLength', this.get('ajaxRequestsQueue.queue.length'));
  814. this.get('ajaxRequestsQueue').start();
  815. this.showLoadingIndicator();
  816. },
  817. /**
  818. * *******************************************************************
  819. * The following create* functions are called upon submitting Step 8.
  820. * *******************************************************************
  821. */
  822. /**
  823. * Create cluster using selected stack version
  824. * Queued request
  825. * @method createCluster
  826. */
  827. createCluster: function () {
  828. if (this.get('content.controllerName') !== 'installerController') return;
  829. var stackVersion = (this.get('content.installOptions.localRepo')) ? App.currentStackVersion.replace(/(-\d+(\.\d)*)/ig, "Local$&") : App.currentStackVersion;
  830. var selectedStack = App.Stack.find().findProperty('isSelected', true);
  831. this.addRequestToAjaxQueue({
  832. name: 'wizard.step8.create_cluster',
  833. data: {
  834. data: JSON.stringify({ "Clusters": {"version": stackVersion, "repository_version": selectedStack.get('repositoryVersion')}})
  835. },
  836. success: 'createClusterSuccess'
  837. });
  838. },
  839. createClusterSuccess: function (data, xhr, params) {
  840. App.set('clusterName', params.cluster)
  841. },
  842. /**
  843. * Create selected to install services
  844. * Queued request
  845. * Skipped if no services where selected!
  846. * @method createSelectedServices
  847. */
  848. createSelectedServices: function () {
  849. var data = this.createSelectedServicesData();
  850. if (!data.length) return;
  851. this.addRequestToAjaxQueue({
  852. name: 'wizard.step8.create_selected_services',
  853. data: {
  854. data: JSON.stringify(data)
  855. }
  856. });
  857. },
  858. /**
  859. * Format data for <code>createSelectedServices</code> request
  860. * @returns {Object[]}
  861. * @method createSelectedServicesData
  862. */
  863. createSelectedServicesData: function () {
  864. return this.get('selectedServices').map(function (_service) {
  865. return {"ServiceInfo": { "service_name": _service.get('serviceName') }};
  866. });
  867. },
  868. /**
  869. * Create components for selected services
  870. * Queued requests
  871. * One request for each service!
  872. * @method createComponents
  873. */
  874. createComponents: function () {
  875. var serviceComponents = App.StackServiceComponent.find();
  876. this.get('selectedServices').forEach(function (_service) {
  877. var serviceName = _service.get('serviceName');
  878. var componentsData = serviceComponents.filterProperty('serviceName', serviceName).map(function (_component) {
  879. return { "ServiceComponentInfo": { "component_name": _component.get('componentName') } };
  880. });
  881. // Service must be specified in terms of a query for creating multiple components at the same time.
  882. // See AMBARI-1018.
  883. this.addRequestToCreateComponent(componentsData, serviceName);
  884. }, this);
  885. if (this.get('content.controllerName') === 'addHostController') {
  886. var allServiceComponents = [];
  887. var services = App.Service.find().mapProperty('serviceName');
  888. services.forEach(function(_service){
  889. var _serviceComponents = App.Service.find(_service).get('serviceComponents');
  890. allServiceComponents = allServiceComponents.concat(_serviceComponents);
  891. }, this);
  892. this.get('content.slaveComponentHosts').forEach(function (component) {
  893. if (component.componentName !== 'CLIENT' && !allServiceComponents.contains(component.componentName)) {
  894. this.addRequestToCreateComponent(
  895. [{"ServiceComponentInfo": {"component_name": component.componentName}}],
  896. App.StackServiceComponent.find().findProperty('componentName', component.componentName).get('serviceName')
  897. );
  898. }
  899. }, this);
  900. this.get('content.clients').forEach(function (component) {
  901. if (!allServiceComponents.contains(component.component_name)) {
  902. this.addRequestToCreateComponent(
  903. [{"ServiceComponentInfo": {"component_name": component.component_name}}],
  904. App.StackServiceComponent.find().findProperty('componentName', component.component_name).get('serviceName')
  905. );
  906. }
  907. }, this);
  908. }
  909. },
  910. /**
  911. * Add request to ajax queue to create service component
  912. * @param componentsData
  913. * @param serviceName
  914. */
  915. addRequestToCreateComponent: function (componentsData, serviceName) {
  916. this.addRequestToAjaxQueue({
  917. name: 'wizard.step8.create_components',
  918. data: {
  919. data: JSON.stringify({"components": componentsData}),
  920. serviceName: serviceName
  921. }
  922. });
  923. },
  924. /**
  925. * Error callback for new service component request
  926. * So, if component doesn't exist we should create it
  927. * @param {object} request
  928. * @param {object} ajaxOptions
  929. * @param {string} error
  930. * @param {object} opt
  931. * @param {object} params
  932. * @method newServiceComponentErrorCallback
  933. */
  934. newServiceComponentErrorCallback: function (request, ajaxOptions, error, opt, params) {
  935. this.addRequestToAjaxQueue({
  936. name: 'wizard.step8.create_components',
  937. data: {
  938. serviceName: params.serviceName,
  939. data: JSON.stringify({
  940. "components": [
  941. {
  942. "ServiceComponentInfo": {
  943. "component_name": params.componentName
  944. }
  945. }
  946. ]
  947. })
  948. }
  949. });
  950. },
  951. /**
  952. * Register hosts
  953. * Queued request
  954. * @method registerHostsToCluster
  955. */
  956. registerHostsToCluster: function () {
  957. var data = this.createRegisterHostData();
  958. if (!data.length) return;
  959. this.addRequestToAjaxQueue({
  960. name: 'wizard.step8.register_host_to_cluster',
  961. data: {
  962. data: JSON.stringify(data)
  963. }
  964. });
  965. },
  966. /**
  967. * Format request-data for <code>registerHostsToCluster</code>
  968. * @returns {Object}
  969. * @method createRegisterHostData
  970. */
  971. createRegisterHostData: function () {
  972. return this.getRegisteredHosts().filterProperty('isInstalled', false).map(function (host) {
  973. return {"Hosts": { "host_name": host.hostName}};
  974. });
  975. },
  976. /**
  977. * Register new master components
  978. * @uses registerHostsToComponent
  979. * @method createMasterHostComponents
  980. */
  981. createMasterHostComponents: function () {
  982. var masterOnAllHosts = [];
  983. this.get('content.services').filterProperty('isSelected').forEach(function (service) {
  984. service.get('serviceComponents').filterProperty('isRequiredOnAllHosts').forEach(function (component) {
  985. if (component.get('isMaster')) {
  986. masterOnAllHosts.push(component.get('componentName'));
  987. }
  988. }, this);
  989. }, this);
  990. // create master components for only selected services.
  991. var selectedMasterComponents = this.get('content.masterComponentHosts').filter(function (_component) {
  992. return this.get('selectedServices').mapProperty('serviceName').contains(_component.serviceId)
  993. }, this);
  994. selectedMasterComponents.mapProperty('component').uniq().forEach(function (component) {
  995. if (masterOnAllHosts.length > 0) {
  996. var compOnAllHosts = false;
  997. for (var i=0; i < masterOnAllHosts.length; i++) {
  998. if (component.component_name == masterOnAllHosts[i]) {
  999. compOnAllHosts = true;
  1000. break;
  1001. }
  1002. }
  1003. if (!compOnAllHosts) {
  1004. var hostNames = selectedMasterComponents.filterProperty('component', component).filterProperty('isInstalled', false).mapProperty('hostName');
  1005. this.registerHostsToComponent(hostNames, component);
  1006. }
  1007. } else {
  1008. var hostNames = selectedMasterComponents.filterProperty('component', component).filterProperty('isInstalled', false).mapProperty('hostName');
  1009. this.registerHostsToComponent(hostNames, component);
  1010. }
  1011. }, this);
  1012. },
  1013. getClientsMap: function (flag) {
  1014. var clientNames = App.StackServiceComponent.find().filterProperty('isClient').mapProperty('componentName'),
  1015. clientsMap = {},
  1016. dependedComponents = flag ? App.StackServiceComponent.find().filterProperty(flag) : App.StackServiceComponent.find();
  1017. clientNames.forEach(function (clientName) {
  1018. clientsMap[clientName] = Em.A([]);
  1019. dependedComponents.forEach(function (component) {
  1020. if (component.get('dependencies').mapProperty('componentName').contains(clientName)) clientsMap[clientName].push(component.get('componentName'));
  1021. });
  1022. if (!clientsMap[clientName].length) delete clientsMap[clientName];
  1023. });
  1024. return clientsMap;
  1025. },
  1026. /**
  1027. * Register slave components and clients
  1028. * @uses registerHostsToComponent
  1029. * @method createSlaveAndClientsHostComponents
  1030. */
  1031. createSlaveAndClientsHostComponents: function () {
  1032. var masterHosts = this.get('content.masterComponentHosts');
  1033. var slaveHosts = this.get('content.slaveComponentHosts');
  1034. var clients = this.get('content.clients').filterProperty('isInstalled', false);
  1035. var slaveOnAllHosts = [];
  1036. var clientOnAllHosts = [];
  1037. this.get('content.services').filterProperty('isSelected').forEach(function (service) {
  1038. service.get('serviceComponents').filterProperty('isRequiredOnAllHosts').forEach(function (component) {
  1039. if (component.get('isClient')) {
  1040. clientOnAllHosts.push(component.get('componentName'));
  1041. } else if (component.get('isSlave')) {
  1042. slaveOnAllHosts.push(component.get('componentName'));
  1043. }
  1044. }, this);
  1045. }, this);
  1046. /**
  1047. * Determines on which hosts client should be installed (based on availability of master components on hosts)
  1048. * @type {Object}
  1049. * Format:
  1050. * <code>
  1051. * {
  1052. * CLIENT1: Em.A([MASTER1, MASTER2, ...]),
  1053. * CLIENT2: Em.A([MASTER3, MASTER1, ...])
  1054. * ...
  1055. * }
  1056. * </code>
  1057. */
  1058. var clientsToMasterMap = this.getClientsMap('isMaster');
  1059. slaveHosts.forEach(function (_slave) {
  1060. if (_slave.componentName !== 'CLIENT') {
  1061. if (slaveOnAllHosts.length > 0) {
  1062. var compOnAllHosts = false;
  1063. for (var i=0; i < slaveOnAllHosts.length; i++) {
  1064. if (_slave.component_name == slaveOnAllHosts[i]) {
  1065. // component with ALL cardinality should not
  1066. // registerHostsToComponent in createSlaveAndClientsHostComponents
  1067. compOnAllHosts = true;
  1068. break;
  1069. }
  1070. }
  1071. if (!compOnAllHosts) {
  1072. var hostNames = _slave.hosts.filterProperty('isInstalled', false).mapProperty('hostName');
  1073. this.registerHostsToComponent(hostNames, _slave.componentName);
  1074. }
  1075. } else {
  1076. var hostNames = _slave.hosts.filterProperty('isInstalled', false).mapProperty('hostName');
  1077. this.registerHostsToComponent(hostNames, _slave.componentName);
  1078. }
  1079. }
  1080. else {
  1081. clients.forEach(function (_client) {
  1082. var hostNames = _slave.hosts.mapProperty('hostName');
  1083. // The below logic to install clients to existing/New master hosts should not be applied to Add Host wizard.
  1084. // This is with the presumption that Add Host controller does not add any new Master component to the cluster
  1085. if (this.get('content.controllerName') !== 'addHostController') {
  1086. if (clientsToMasterMap[_client.component_name]) {
  1087. clientsToMasterMap[_client.component_name].forEach(function (componentName) {
  1088. masterHosts.filterProperty('component', componentName).forEach(function (_masterHost) {
  1089. hostNames.pushObject(_masterHost.hostName);
  1090. });
  1091. });
  1092. }
  1093. }
  1094. if (clientOnAllHosts.length > 0) {
  1095. var compOnAllHosts = false;
  1096. for (var i=0; i < clientOnAllHosts.length; i++) {
  1097. if (_client.component_name == clientOnAllHosts[i]) {
  1098. // component with ALL cardinality should not
  1099. // registerHostsToComponent in createSlaveAndClientsHostComponents
  1100. compOnAllHosts = true;
  1101. break;
  1102. }
  1103. }
  1104. if (!compOnAllHosts) {
  1105. hostNames = hostNames.uniq();
  1106. this.registerHostsToComponent(hostNames, _client.component_name);
  1107. }
  1108. } else {
  1109. hostNames = hostNames.uniq();
  1110. this.registerHostsToComponent(hostNames, _client.component_name);
  1111. }
  1112. }, this);
  1113. }
  1114. }, this);
  1115. },
  1116. /**
  1117. * This function is specific to addServiceController
  1118. * Newly introduced master components requires some existing client components to be hosted along with them
  1119. */
  1120. createAdditionalClientComponents: function () {
  1121. var masterHosts = this.get('content.masterComponentHosts');
  1122. var clientHosts = [];
  1123. if (this.get('content.slaveComponentHosts').someProperty('componentName', 'CLIENT')) {
  1124. clientHosts = this.get('content.slaveComponentHosts').findProperty('componentName', 'CLIENT').hosts;
  1125. }
  1126. var clients = this.get('content.clients').filterProperty('isInstalled', false);
  1127. var clientsToMasterMap = this.getClientsMap('isMaster');
  1128. var clientsToClientMap = this.getClientsMap('isClient');
  1129. var installedClients = [];
  1130. // Get all the installed Client components
  1131. this.get('content.services').filterProperty('isInstalled').forEach(function (_service) {
  1132. var serviceClients = App.StackServiceComponent.find().filterProperty('serviceName', _service.get('serviceName')).filterProperty('isClient');
  1133. serviceClients.forEach(function (client) {
  1134. installedClients.push(client.get('componentName'));
  1135. }, this);
  1136. }, this);
  1137. // Check if there is a dependency for being co-hosted between existing client and selected new master
  1138. installedClients.forEach(function (_clientName) {
  1139. if (clientsToMasterMap[_clientName] || clientsToClientMap[_clientName]) {
  1140. var hostNames = [];
  1141. if (clientsToMasterMap[_clientName]) {
  1142. clientsToMasterMap[_clientName].forEach(function (componentName) {
  1143. masterHosts.filterProperty('component', componentName).filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1144. hostNames.pushObject(_masterHost.hostName);
  1145. }, this);
  1146. }, this);
  1147. }
  1148. if (clientsToClientMap[_clientName]) {
  1149. clientsToClientMap[_clientName].forEach(function (componentName) {
  1150. clientHosts.forEach(function (_clientHost) {
  1151. var host = this.get('content.hosts')[_clientHost.hostName];
  1152. if (host.isInstalled && !host.hostComponents.someProperty('HostRoles.component_name', componentName)) {
  1153. hostNames.pushObject(_clientHost.hostName);
  1154. }
  1155. }, this);
  1156. }, this);
  1157. }
  1158. hostNames = hostNames.uniq();
  1159. if (hostNames.length > 0) {
  1160. // If a dependency for being co-hosted is derived between existing client and selected new master but that
  1161. // dependency is already satisfied in the cluster then disregard the derived dependency
  1162. this.removeClientsFromList(_clientName, hostNames);
  1163. this.registerHostsToComponent(hostNames, _clientName);
  1164. if(hostNames.length > 0) {
  1165. this.get('content.additionalClients').pushObject({hostNames: hostNames, componentName: _clientName});
  1166. }
  1167. }
  1168. }
  1169. }, this);
  1170. },
  1171. /**
  1172. *
  1173. * @param clientName
  1174. * @param hostList
  1175. */
  1176. removeClientsFromList: function (clientName, hostList) {
  1177. var clientHosts = [];
  1178. var installedHosts = this.get('content.hosts');
  1179. for (var hostName in installedHosts) {
  1180. if (installedHosts[hostName].isInstalled) {
  1181. if (installedHosts[hostName].hostComponents.mapProperty('HostRoles.component_name').contains(clientName)) {
  1182. clientHosts.push(hostName);
  1183. }
  1184. }
  1185. }
  1186. if (clientHosts.length > 0) {
  1187. clientHosts.forEach(function (hostName) {
  1188. if (hostList.contains(hostName)) {
  1189. hostList.splice(hostList.indexOf(hostName), 1);
  1190. }
  1191. }, this);
  1192. }
  1193. },
  1194. /**
  1195. * Register additional components
  1196. * Based on availability of some services
  1197. * @uses registerHostsToComponent
  1198. * @method createAdditionalHostComponents
  1199. */
  1200. createAdditionalHostComponents: function () {
  1201. var masterHosts = this.get('content.masterComponentHosts');
  1202. // add all components with cardinality == ALL of selected services
  1203. var registeredHosts = this.getRegisteredHosts();
  1204. var notInstalledHosts = registeredHosts.filterProperty('isInstalled', false);
  1205. this.get('content.services').filterProperty('isSelected').forEach(function (service) {
  1206. service.get('serviceComponents').filterProperty('isRequiredOnAllHosts').forEach(function (component) {
  1207. if (service.get('isInstalled') && notInstalledHosts.length) {
  1208. this.registerHostsToComponent(notInstalledHosts.mapProperty('hostName'), component.get('componentName'));
  1209. } else if (!service.get('isInstalled') && registeredHosts.length) {
  1210. this.registerHostsToComponent(registeredHosts.mapProperty('hostName'), component.get('componentName'));
  1211. }
  1212. }, this);
  1213. }, this);
  1214. // add MySQL Server if Hive is selected
  1215. var hiveService = this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).findProperty('serviceName', 'HIVE');
  1216. if (hiveService) {
  1217. var hiveDb = this.get('content.serviceConfigProperties').findProperty('name', 'hive_database');
  1218. if (hiveDb.value == "New MySQL Database") {
  1219. this.registerHostsToComponent(masterHosts.filterProperty('component', 'HIVE_METASTORE').mapProperty('hostName'), 'MYSQL_SERVER');
  1220. } else if (hiveDb.value === "New PostgreSQL Database") {
  1221. this.registerHostsToComponent(masterHosts.filterProperty('component', 'HIVE_SERVER').mapProperty('hostName'), 'POSTGRESQL_SERVER');
  1222. }
  1223. }
  1224. },
  1225. /**
  1226. * Register component to hosts
  1227. * Queued request
  1228. * @param {String[]} hostNames
  1229. * @param {String} componentName
  1230. * @method registerHostsToComponent
  1231. */
  1232. registerHostsToComponent: function (hostNames, componentName) {
  1233. if (!hostNames.length) return;
  1234. var queryStr = '';
  1235. hostNames.forEach(function (hostName) {
  1236. queryStr += 'Hosts/host_name=' + hostName + '|';
  1237. });
  1238. //slice off last symbol '|'
  1239. queryStr = queryStr.slice(0, -1);
  1240. var data = {
  1241. "RequestInfo": {
  1242. "query": queryStr
  1243. },
  1244. "Body": {
  1245. "host_components": [
  1246. {
  1247. "HostRoles": {
  1248. "component_name": componentName
  1249. }
  1250. }
  1251. ]
  1252. }
  1253. };
  1254. this.addRequestToAjaxQueue({
  1255. name: 'wizard.step8.register_host_to_component',
  1256. data: {
  1257. data: JSON.stringify(data)
  1258. }
  1259. });
  1260. },
  1261. /**
  1262. * Create config objects for cluster and services
  1263. * @method createConfigurations
  1264. */
  1265. createConfigurations: function () {
  1266. var tag = this.getServiceConfigVersion();
  1267. if (this.get('isInstaller')) {
  1268. /** add cluster-env **/
  1269. this.get('serviceConfigTags').pushObject(this.createDesiredConfig('cluster-env', tag, this.get('configs').filterProperty('filename', 'cluster-env.xml')));
  1270. }
  1271. this.get('selectedServices').forEach(function (service) {
  1272. Object.keys(service.get('configTypes')).forEach(function (type) {
  1273. if (!this.get('serviceConfigTags').someProperty('type', type)) {
  1274. var configs = this.get('configs').filterProperty('filename', App.config.getOriginalFileName(type));
  1275. var serviceConfigNote = this.getServiceConfigNote(type, service.get('displayName'));
  1276. this.get('serviceConfigTags').pushObject(this.createDesiredConfig(type, tag, configs, serviceConfigNote));
  1277. }
  1278. }, this);
  1279. }, this);
  1280. this.createNotification();
  1281. },
  1282. /**
  1283. * Get config version tag
  1284. *
  1285. * @returns {string}
  1286. */
  1287. getServiceConfigVersion: function() {
  1288. return 'version' + (this.get('isAddService') ? (new Date).getTime() : '1');
  1289. },
  1290. /**
  1291. * Get config version message
  1292. *
  1293. * @param type
  1294. * @param serviceDisplayName
  1295. * @returns {*}
  1296. */
  1297. getServiceConfigNote: function(type, serviceDisplayName) {
  1298. return (this.get('isAddService') && (type === 'core-site')) ?
  1299. Em.I18n.t('dashboard.configHistory.table.notes.addService') : Em.I18n.t('dashboard.configHistory.table.notes.default').format(serviceDisplayName);
  1300. },
  1301. /**
  1302. * Send <code>serviceConfigTags</code> to server
  1303. * Queued request
  1304. * One request for each service config tag
  1305. * @param serviceConfigTags
  1306. * @method applyConfigurationsToCluster
  1307. */
  1308. applyConfigurationsToCluster: function (serviceConfigTags) {
  1309. var allServices = this.get('installedServices').concat(this.get('selectedServices'));
  1310. var allConfigData = [];
  1311. allServices.forEach(function (service) {
  1312. var serviceConfigData = [];
  1313. Object.keys(service.get('configTypesRendered')).forEach(function (type) {
  1314. var serviceConfigTag = serviceConfigTags.findProperty('type', type);
  1315. if (serviceConfigTag) {
  1316. serviceConfigData.pushObject(serviceConfigTag);
  1317. }
  1318. }, this);
  1319. if (serviceConfigData.length) {
  1320. allConfigData.pushObject(JSON.stringify({
  1321. Clusters: {
  1322. desired_config: serviceConfigData.map(function(item) {
  1323. var props = {};
  1324. Em.keys(item.properties).forEach(function(propName) {
  1325. if (item.properties[propName] !== null) {
  1326. props[propName] = item.properties[propName];
  1327. }
  1328. });
  1329. item.properties = props;
  1330. return item;
  1331. })
  1332. }
  1333. }));
  1334. }
  1335. }, this);
  1336. var clusterConfig = serviceConfigTags.findProperty('type', 'cluster-env');
  1337. if (clusterConfig) {
  1338. allConfigData.pushObject(JSON.stringify({
  1339. Clusters: {
  1340. desired_config: [clusterConfig]
  1341. }
  1342. }));
  1343. }
  1344. this.addRequestToAjaxQueue({
  1345. name: 'common.across.services.configurations',
  1346. data: {
  1347. data: '[' + allConfigData.toString() + ']'
  1348. }
  1349. });
  1350. },
  1351. /**
  1352. * Create and update config groups
  1353. * @method createConfigurationGroups
  1354. */
  1355. createConfigurationGroups: function () {
  1356. var configGroups = this.get('content.configGroups').filterProperty('is_default', false);
  1357. var groupsToDelete = App.router.get(this.get('content.controllerName')).getDBProperty('groupsToDelete');
  1358. if (groupsToDelete && groupsToDelete.length > 0) {
  1359. this.removeInstalledServicesConfigurationGroups(groupsToDelete);
  1360. }
  1361. configGroups.forEach(function (configGroup) {
  1362. if (configGroup.is_for_update || configGroup.is_temporary) {
  1363. this.saveGroup(configGroup.properties, configGroup, this.getServiceConfigNote('', configGroup.service_id));
  1364. }
  1365. }, this);
  1366. App.ServiceConfigGroup.deleteTemporaryRecords();
  1367. },
  1368. /**
  1369. * add request to create config group to queue
  1370. *
  1371. * @param data
  1372. * @method createConfigGroup
  1373. */
  1374. createConfigGroup: function(data) {
  1375. this.addRequestToAjaxQueue({
  1376. name: 'wizard.step8.apply_configuration_groups',
  1377. sender: this,
  1378. data: {
  1379. data: JSON.stringify(data)
  1380. }
  1381. });
  1382. },
  1383. /**
  1384. * add request to update config group to queue
  1385. *
  1386. * @param data {Object}
  1387. * @method updateConfigGroup
  1388. */
  1389. updateConfigGroup: function (data) {
  1390. this.addRequestToAjaxQueue({
  1391. name: 'config_groups.update_config_group',
  1392. sender: this,
  1393. data: {
  1394. id: data.ConfigGroup.id,
  1395. configGroup: data
  1396. }
  1397. });
  1398. },
  1399. /**
  1400. * Delete selected config groups
  1401. * @param {Object[]} groupsToDelete
  1402. * @method removeInstalledServicesConfigurationGroups
  1403. */
  1404. removeInstalledServicesConfigurationGroups: function (groupsToDelete) {
  1405. var self = this;
  1406. groupsToDelete.forEach(function (item) {
  1407. self.deleteConfigurationGroup(Em.Object.create(item));
  1408. });
  1409. },
  1410. /**
  1411. * Selected and installed services
  1412. * @override
  1413. */
  1414. currentServices: function() {
  1415. return this.get('installedServices').concat(this.get('selectedServices'));
  1416. }.property('installedServices.length', 'selectedServices.length'),
  1417. /**
  1418. * Add handling GLUSTREFS properties
  1419. * @param property
  1420. * @returns {*}
  1421. * @override
  1422. */
  1423. formatValueBeforeSave: function(property) {
  1424. if (this.formatGLUSTERFSProperties(Em.get(property, 'filename'))) {
  1425. switch (property.name) {
  1426. case "fs.default.name":
  1427. return this.get('configs').someProperty('name', 'fs_glusterfs_default_name') ?
  1428. this.get('configs').findProperty('name', 'fs_glusterfs_default_name').value : null;
  1429. case "fs.defaultFS":
  1430. return this.get('configs').someProperty('name', 'glusterfs_defaultFS_name') ?
  1431. this.get('configs').findProperty('name', 'glusterfs_defaultFS_name').value : null;
  1432. }
  1433. }
  1434. return this._super(property);
  1435. },
  1436. /**
  1437. * Defines if some GLUSTERFS properties should be changed
  1438. *
  1439. * @param {String} type
  1440. * @returns {boolean}
  1441. */
  1442. formatGLUSTERFSProperties: function(type) {
  1443. return App.config.getConfigTagFromFileName(type) === 'core-site'
  1444. && this.get('installedServices').concat(this.get('selectedServices')).someProperty('serviceName', 'GLUSTERFS');
  1445. },
  1446. /**
  1447. * Create one Alert Notification (if user select this on step7)
  1448. * Only for Install Wizard and stack
  1449. * @method createNotification
  1450. */
  1451. createNotification: function () {
  1452. if (this.get('content.controllerName') !== 'installerController') return;
  1453. var miscConfigs = this.get('configs').filterProperty('serviceName', 'MISC'),
  1454. createNotification = miscConfigs.findProperty('name', 'create_notification').value;
  1455. if (createNotification !== 'yes') return;
  1456. var predefinedNotificationConfigNames = require('data/HDP2/alert_notification').mapProperty('name'),
  1457. configsForNotification = this.get('configs').filterProperty('filename', 'alert_notification');
  1458. var properties = {},
  1459. names = [
  1460. 'ambari.dispatch.recipients',
  1461. 'mail.smtp.host',
  1462. 'mail.smtp.port',
  1463. 'mail.smtp.from',
  1464. 'mail.smtp.starttls.enable',
  1465. 'mail.smtp.startssl.enable'
  1466. ];
  1467. if (miscConfigs.findProperty('name', 'smtp_use_auth').value == 'true') { // yes, it's not converted to boolean
  1468. names.pushObjects(['ambari.dispatch.credential.username', 'ambari.dispatch.credential.password']);
  1469. }
  1470. names.forEach(function (name) {
  1471. properties[name] = miscConfigs.findProperty('name', name).value;
  1472. });
  1473. properties['ambari.dispatch.recipients'] = properties['ambari.dispatch.recipients'].replace(/\s/g, '').split(',');
  1474. configsForNotification.forEach(function (config) {
  1475. if (predefinedNotificationConfigNames.contains(config.name)) return;
  1476. properties[config.name] = config.value;
  1477. });
  1478. var apiObject = {
  1479. AlertTarget: {
  1480. name: 'Initial Notification',
  1481. description: 'Notification created during cluster installing',
  1482. global: true,
  1483. notification_type: 'EMAIL',
  1484. alert_states: ['OK', 'WARNING', 'CRITICAL', 'UNKNOWN'],
  1485. properties: properties
  1486. }
  1487. };
  1488. this.addRequestToAjaxQueue({
  1489. name: 'alerts.create_alert_notification',
  1490. data: {
  1491. urlParams: 'overwrite_existing=true',
  1492. data: apiObject
  1493. }
  1494. });
  1495. },
  1496. /**
  1497. * Should ajax-queue progress bar be displayed
  1498. * @method showLoadingIndicator
  1499. */
  1500. showLoadingIndicator: function () {
  1501. return App.ModalPopup.show({
  1502. header: '',
  1503. showFooter: false,
  1504. showCloseButton: false,
  1505. bodyClass: Em.View.extend({
  1506. templateName: require('templates/wizard/step8/step8_log_popup'),
  1507. controllerBinding: 'App.router.wizardStep8Controller',
  1508. /**
  1509. * Css-property for progress-bar
  1510. * @type {string}
  1511. */
  1512. barWidth: '',
  1513. progressBarClass: 'progress log_popup',
  1514. /**
  1515. * Popup-message
  1516. * @type {string}
  1517. */
  1518. message: '',
  1519. /**
  1520. * Set progress bar width and popup message when ajax-queue requests are proccessed
  1521. * @method ajaxQueueChangeObs
  1522. */
  1523. ajaxQueueChangeObs: function () {
  1524. var length = this.get('controller.ajaxQueueLength');
  1525. var left = this.get('controller.ajaxRequestsQueue.queue.length');
  1526. this.set('barWidth', 'width: ' + ((length - left) / length * 100) + '%;');
  1527. this.set('message', Em.I18n.t('installer.step8.deployPopup.message').format((length - left), length));
  1528. }.observes('controller.ajaxQueueLength', 'controller.ajaxRequestsQueue.queue.length'),
  1529. /**
  1530. * Hide popup when ajax-queue is finished
  1531. * @method autoHide
  1532. */
  1533. autoHide: function () {
  1534. if (this.get('controller.servicesInstalled')) {
  1535. this.get('parentView').hide();
  1536. }
  1537. }.observes('controller.servicesInstalled')
  1538. })
  1539. });
  1540. }
  1541. });