step8_controller.js 59 KB

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