step8_controller.js 60 KB

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