step8_controller.js 63 KB

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