step8_controller.js 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728
  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' && App.get('isKerberosEnabled') && !this.get('isManualKerberos')) {
  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');
  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.isForInstalledService === 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', 'jobhistory_heapsize', 'nfsgateway_heapsize', 'accumulo_master_heapsize', 'accumulo_tserver_heapsize', 'accumulo_monitor_heapsize', 'accumulo_gc_heapsize', 'accumulo_other_heapsize', 'hbase_master_heapsize', 'hbase_regionserver_heapsize', 'metrics_collector_heapsize'];
  1467. // do not pass any globals whose name ends with _host or _hosts
  1468. if (_configProperty.isRequiredByAgent !== false) {
  1469. // append "m" to JVM memory options except for heapsizeExtensions
  1470. if (/_heapsize|_newsize|_maxnewsize|_permsize|_maxpermsize$/.test(_configProperty.name) && !heapsizeExceptions.contains(_configProperty.name) && !(_configProperty.value).endsWith("m")) {
  1471. properties[_configProperty.name] = _configProperty.value + "m";
  1472. } else {
  1473. properties[_configProperty.name] = _configProperty.value;
  1474. }
  1475. }
  1476. }, this);
  1477. var configObj = {"type": site, "tag": tag, "properties": properties };
  1478. if (attributes) {
  1479. configObj['properties_attributes'] = attributes;
  1480. }
  1481. return configObj;
  1482. },
  1483. /**
  1484. * Create site obj for Storm
  1485. * Some config-properties should be modified in custom way
  1486. * @param tag
  1487. * @returns {{type: string, tag: string, properties: {}}}
  1488. * @method createStormSiteObj
  1489. */
  1490. createStormSiteObj: function (tag) {
  1491. var configs = this.get('configs').filterProperty('filename', 'storm-site.xml');
  1492. var stormProperties = {};
  1493. configs.forEach(function (_configProperty) {
  1494. if (["nimbus.seeds", "storm.zookeeper.servers"].contains(_configProperty.name)) {
  1495. stormProperties[_configProperty.name] = JSON.stringify(_configProperty.value).replace(/"/g, "'");
  1496. } else {
  1497. stormProperties[_configProperty.name] = _configProperty.value;
  1498. }
  1499. }, this);
  1500. return {type: 'storm-site', tag: tag, properties: stormProperties};
  1501. },
  1502. /**
  1503. * Create one Alert Notification (if user select this on step7)
  1504. * Only for Install Wizard and stack
  1505. * @method createNotification
  1506. */
  1507. createNotification: function () {
  1508. if (this.get('content.controllerName') !== 'installerController') return;
  1509. var miscConfigs = this.get('configs').filterProperty('serviceName', 'MISC'),
  1510. createNotification = miscConfigs.findProperty('name', 'create_notification').value;
  1511. if (createNotification !== 'yes') return;
  1512. var predefinedNotificationConfigNames = require('data/HDP2/site_properties').configProperties.filterProperty('filename', 'alert_notification').mapProperty('name'),
  1513. configsForNotification = this.get('configs').filterProperty('filename', 'alert_notification');
  1514. var properties = {},
  1515. names = [
  1516. 'ambari.dispatch.recipients',
  1517. 'mail.smtp.host',
  1518. 'mail.smtp.port',
  1519. 'mail.smtp.from',
  1520. 'mail.smtp.starttls.enable',
  1521. 'mail.smtp.startssl.enable'
  1522. ];
  1523. if (miscConfigs.findProperty('name', 'smtp_use_auth').value == 'true') { // yes, it's not converted to boolean
  1524. names.pushObjects(['ambari.dispatch.credential.username', 'ambari.dispatch.credential.password']);
  1525. }
  1526. names.forEach(function (name) {
  1527. properties[name] = miscConfigs.findProperty('name', name).value;
  1528. });
  1529. properties['ambari.dispatch.recipients'] = properties['ambari.dispatch.recipients'].replace(/\s/g, '').split(',');
  1530. configsForNotification.forEach(function (config) {
  1531. if (predefinedNotificationConfigNames.contains(config.name)) return;
  1532. properties[config.name] = config.value;
  1533. });
  1534. var apiObject = {
  1535. AlertTarget: {
  1536. name: 'Initial Notification',
  1537. description: 'Notification created during cluster installing',
  1538. global: true,
  1539. notification_type: 'EMAIL',
  1540. alert_states: ['OK', 'WARNING', 'CRITICAL', 'UNKNOWN'],
  1541. properties: properties
  1542. }
  1543. };
  1544. this.addRequestToAjaxQueue({
  1545. name: 'alerts.create_alert_notification',
  1546. data: {
  1547. urlParams: 'overwrite_existing=true',
  1548. data: apiObject
  1549. }
  1550. });
  1551. },
  1552. /**
  1553. * Should ajax-queue progress bar be displayed
  1554. * @method showLoadingIndicator
  1555. */
  1556. showLoadingIndicator: function () {
  1557. return App.ModalPopup.show({
  1558. header: '',
  1559. showFooter: false,
  1560. showCloseButton: false,
  1561. bodyClass: Em.View.extend({
  1562. templateName: require('templates/wizard/step8/step8_log_popup'),
  1563. controllerBinding: 'App.router.wizardStep8Controller',
  1564. /**
  1565. * Css-property for progress-bar
  1566. * @type {string}
  1567. */
  1568. barWidth: '',
  1569. /**
  1570. * Popup-message
  1571. * @type {string}
  1572. */
  1573. message: '',
  1574. /**
  1575. * Set progress bar width and popup message when ajax-queue requests are proccessed
  1576. * @method ajaxQueueChangeObs
  1577. */
  1578. ajaxQueueChangeObs: function () {
  1579. var length = this.get('controller.ajaxQueueLength');
  1580. var left = this.get('controller.ajaxRequestsQueue.queue.length');
  1581. this.set('barWidth', 'width: ' + ((length - left) / length * 100) + '%;');
  1582. this.set('message', Em.I18n.t('installer.step8.deployPopup.message').format((length - left), length));
  1583. }.observes('controller.ajaxQueueLength', 'controller.ajaxRequestsQueue.queue.length'),
  1584. /**
  1585. * Hide popup when ajax-queue is finished
  1586. * @method autoHide
  1587. */
  1588. autoHide: function () {
  1589. if (this.get('controller.servicesInstalled')) {
  1590. this.get('parentView').hide();
  1591. }
  1592. }.observes('controller.servicesInstalled')
  1593. })
  1594. });
  1595. }
  1596. });