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