step3_controller.js 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  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 lazyloading = require('utils/lazy_loading');
  20. var numberUtils = require('utils/number_utils');
  21. App.WizardStep3Controller = Em.Controller.extend({
  22. name: 'wizardStep3Controller',
  23. hosts: [],
  24. content: [],
  25. bootHosts: [],
  26. registeredHosts: [],
  27. repoCategoryWarnings: [],
  28. diskCategoryWarnings: [],
  29. registrationStartedAt: null,
  30. registrationTimeoutSecs: function(){
  31. if(this.get('content.installOptions.manualInstall')){
  32. return 15;
  33. }
  34. return 120;
  35. }.property('content.installOptions.manualInstall'),
  36. stopBootstrap: false,
  37. isSubmitDisabled: true,
  38. isRetryDisabled: true,
  39. isLoaded: false,
  40. navigateStep: function () {
  41. if(this.get('isLoaded')){
  42. if (this.get('content.installOptions.manualInstall') !== true) {
  43. if (!this.get('wizardController').getDBProperty('bootStatus')) {
  44. this.startBootstrap();
  45. }
  46. } else {
  47. this.set('bootHosts', this.get('hosts'));
  48. if (App.testMode) {
  49. this.getHostInfo();
  50. this.get('bootHosts').setEach('bootStatus', 'REGISTERED');
  51. this.get('bootHosts').setEach('cpu', '2');
  52. this.get('bootHosts').setEach('memory', '2000000');
  53. this.set('isSubmitDisabled', false);
  54. } else {
  55. this.set('registrationStartedAt', null);
  56. this.get('bootHosts').setEach('bootStatus', 'DONE');
  57. this.startRegistration();
  58. }
  59. }
  60. }
  61. }.observes('isLoaded'),
  62. clearStep: function () {
  63. this.set('stopBootstrap', false);
  64. this.set('hosts', []);
  65. this.get('bootHosts').clear();
  66. this.get('wizardController').setDBProperty('bootStatus', false);
  67. this.set('isSubmitDisabled', true);
  68. this.set('isRetryDisabled', true);
  69. },
  70. loadStep: function () {
  71. console.log("TRACE: Loading step3: Confirm Hosts");
  72. this.set('registrationStartedAt', null);
  73. this.set('isLoaded', false);
  74. this.disablePreviousSteps();
  75. this.clearStep();
  76. this.loadHosts();
  77. // hosts.setEach('bootStatus', 'RUNNING');
  78. },
  79. /* Loads the hostinfo from localStorage on the insertion of view. It's being called from view */
  80. loadHosts: function () {
  81. var hostsInfo = this.get('content.hosts');
  82. var hosts = [];
  83. for (var index in hostsInfo) {
  84. var hostInfo = App.HostInfo.create({
  85. name: hostsInfo[index].name,
  86. bootStatus: hostsInfo[index].bootStatus,
  87. isChecked: false
  88. });
  89. hosts.pushObject(hostInfo);
  90. }
  91. this.set('hosts', hosts);
  92. this.set('isLoaded', true);
  93. },
  94. /**
  95. * Parses and updates the content based on bootstrap API response.
  96. * Returns true if polling should continue (some hosts are in "RUNNING" state); false otherwise
  97. */
  98. parseHostInfo: function (hostsStatusFromServer) {
  99. hostsStatusFromServer.forEach(function (_hostStatus) {
  100. var host = this.get('bootHosts').findProperty('name', _hostStatus.hostName);
  101. // check if hostname extracted from REST API data matches any hostname in content
  102. // also, make sure that bootStatus modified by isHostsRegistered call does not get overwritten
  103. // since these calls are being made in parallel
  104. if (host && !['REGISTERED', 'REGISTERING'].contains(host.get('bootStatus'))) {
  105. host.set('bootStatus', _hostStatus.status);
  106. host.set('bootLog', _hostStatus.log);
  107. }
  108. }, this);
  109. // if the data rendered by REST API has hosts in "RUNNING" state, polling will continue
  110. return this.get('bootHosts').length != 0 && this.get('bootHosts').someProperty('bootStatus', 'RUNNING');
  111. },
  112. removeHosts: function (hosts) {
  113. var self = this;
  114. App.showConfirmationPopup(function() {
  115. App.router.send('removeHosts', hosts);
  116. self.hosts.removeObjects(hosts);
  117. if (!self.hosts.length) {
  118. self.set('isSubmitDisabled', true);
  119. }
  120. },Em.I18n.t('installer.step3.hosts.remove.popup.body'));
  121. },
  122. /* Removes a single element on the trash icon click. Called from View */
  123. removeHost: function (hostInfo) {
  124. this.removeHosts([hostInfo]);
  125. },
  126. removeSelectedHosts: function () {
  127. if (!this.get('noHostsSelected')) {
  128. var selectedHosts = this.get('hosts').filterProperty('isChecked', true);
  129. selectedHosts.forEach(function (_hostInfo) {
  130. console.log('Removing: ' + _hostInfo.name);
  131. });
  132. this.removeHosts(selectedHosts);
  133. }
  134. },
  135. /**
  136. * show popup with the list of hosts which are selected
  137. */
  138. selectedHostsPopup: function () {
  139. var selectedHosts = this.get('hosts').filterProperty('isChecked').mapProperty('name');
  140. App.ModalPopup.show({
  141. header: Em.I18n.t('installer.step3.selectedHosts.popup.header'),
  142. onPrimary: function () {
  143. this.hide();
  144. },
  145. secondary: null,
  146. bodyClass: Ember.View.extend({
  147. items: selectedHosts,
  148. templateName: require('templates/common/items_list_popup')
  149. })
  150. });
  151. },
  152. retryHost: function (hostInfo) {
  153. this.retryHosts([hostInfo]);
  154. },
  155. retryHosts: function (hosts) {
  156. this.selectAllCategory();
  157. var bootStrapData = JSON.stringify({'verbose': true, 'sshKey': this.get('content.installOptions.sshKey'), 'hosts': hosts.mapProperty('name'), 'user': this.get('content.installOptions.sshUser')});
  158. this.numPolls = 0;
  159. if (this.get('content.installOptions.manualInstall') !== true) {
  160. var requestId = App.router.get('installerController').launchBootstrap(bootStrapData);
  161. this.set('content.installOptions.bootRequestId', requestId);
  162. this.set('registrationStartedAt', null);
  163. this.doBootstrap();
  164. } else {
  165. this.set('registrationStartedAt', null);
  166. this.get('bootHosts').setEach('bootStatus', 'DONE');
  167. this.startRegistration();
  168. }
  169. },
  170. retrySelectedHosts: function () {
  171. //to display all hosts
  172. this.set('category', 'All');
  173. if (!this.get('isRetryDisabled')) {
  174. this.set('isRetryDisabled', true);
  175. var selectedHosts = this.get('bootHosts').filterProperty('bootStatus', 'FAILED');
  176. selectedHosts.forEach(function (_host) {
  177. _host.set('bootStatus', 'RUNNING');
  178. _host.set('bootLog', 'Retrying ...');
  179. }, this);
  180. this.retryHosts(selectedHosts);
  181. }
  182. },
  183. numPolls: 0,
  184. startBootstrap: function () {
  185. //this.set('isSubmitDisabled', true); //TODO: uncomment after actual hookup
  186. this.numPolls = 0;
  187. this.set('registrationStartedAt', null);
  188. this.set('bootHosts', this.get('hosts'));
  189. this.get('bootHosts').setEach('bootStatus', 'PENDING');
  190. this.doBootstrap();
  191. },
  192. isRegistrationInProgress: true,
  193. setRegistrationInProgress: function () {
  194. var bootHosts = this.get('bootHosts');
  195. //if hosts aren't loaded yet then registration should be in progress
  196. var result = (bootHosts.length === 0 && !this.get('isLoaded'));
  197. for (var i = 0, l = bootHosts.length; i < l; i++) {
  198. if (bootHosts[i].get('bootStatus') !== 'REGISTERED' && bootHosts[i].get('bootStatus') !== 'FAILED') {
  199. result = true;
  200. break;
  201. }
  202. }
  203. this.set('isRegistrationInProgress', result);
  204. }.observes('bootHosts.@each.bootStatus'),
  205. disablePreviousSteps: function () {
  206. App.router.get('installerController.isStepDisabled').filter(function (step) {
  207. return step.step >= 0 && step.step <= 2;
  208. }).setEach('value', this.get('isRegistrationInProgress'));
  209. if (this.get('isRegistrationInProgress')) {
  210. this.set('isSubmitDisabled', true);
  211. }
  212. }.observes('isRegistrationInProgress'),
  213. doBootstrap: function () {
  214. if (this.get('stopBootstrap')) {
  215. return;
  216. }
  217. this.numPolls++;
  218. App.ajax.send({
  219. name: 'wizard.step3.bootstrap',
  220. sender: this,
  221. data: {
  222. bootRequestId: this.get('content.installOptions.bootRequestId'),
  223. numPolls: this.numPolls
  224. },
  225. success: 'doBootstrapSuccessCallback'
  226. }).
  227. retry({
  228. times: App.maxRetries,
  229. timeout: App.timeout
  230. }).
  231. then(
  232. null,
  233. function () {
  234. App.showReloadPopup();
  235. console.log('Bootstrap failed');
  236. }
  237. );
  238. },
  239. doBootstrapSuccessCallback: function (data) {
  240. var self = this;
  241. var pollingInterval = 3000;
  242. if (data.hostsStatus === undefined) {
  243. console.log('Invalid response, setting timeout');
  244. window.setTimeout(function () {
  245. self.doBootstrap()
  246. }, pollingInterval);
  247. } else {
  248. // in case of bootstrapping just one host, the server returns an object rather than an array, so
  249. // force into an array
  250. if (!(data.hostsStatus instanceof Array)) {
  251. data.hostsStatus = [ data.hostsStatus ];
  252. }
  253. console.log("TRACE: In success function for the GET bootstrap call");
  254. var keepPolling = this.parseHostInfo(data.hostsStatus);
  255. // Single host : if the only hostname is invalid (data.status == 'ERROR')
  256. // Multiple hosts : if one or more hostnames are invalid
  257. // following check will mark the bootStatus as 'FAILED' for the invalid hostname
  258. if (data.status == 'ERROR' || data.hostsStatus.length != this.get('bootHosts').length) {
  259. var hosts = this.get('bootHosts');
  260. for (var i = 0; i < hosts.length; i++) {
  261. var isValidHost = data.hostsStatus.someProperty('hostName', hosts[i].get('name'));
  262. if(hosts[i].get('bootStatus') !== 'REGISTERED'){
  263. if (!isValidHost) {
  264. hosts[i].set('bootStatus', 'FAILED');
  265. hosts[i].set('bootLog', Em.I18n.t('installer.step3.hosts.bootLog.failed'));
  266. }
  267. }
  268. }
  269. }
  270. if (data.status == 'ERROR' || data.hostsStatus.someProperty('status', 'DONE') || data.hostsStatus.someProperty('status', 'FAILED')) {
  271. // kicking off registration polls after at least one host has succeeded
  272. this.startRegistration();
  273. }
  274. if (keepPolling) {
  275. window.setTimeout(function () {
  276. self.doBootstrap()
  277. }, pollingInterval);
  278. }
  279. }
  280. },
  281. startRegistration: function () {
  282. if (this.get('registrationStartedAt') == null) {
  283. this.set('registrationStartedAt', App.dateTime());
  284. console.log('registration started at ' + this.get('registrationStartedAt'));
  285. this.isHostsRegistered();
  286. }
  287. },
  288. isHostsRegistered: function () {
  289. if (this.get('stopBootstrap')) {
  290. return;
  291. }
  292. App.ajax.send({
  293. name: 'wizard.step3.is_hosts_registered',
  294. sender: this,
  295. success: 'isHostsRegisteredSuccessCallback'
  296. }).
  297. retry({
  298. times: App.maxRetries,
  299. timeout: App.timeout
  300. }).
  301. then(
  302. null,
  303. function () {
  304. App.showReloadPopup();
  305. console.log('Error: Getting registered host information from the server');
  306. }
  307. );
  308. },
  309. isHostsRegisteredSuccessCallback: function (data) {
  310. console.log('registration attempt...');
  311. var hosts = this.get('bootHosts');
  312. var jsonData = data;
  313. if (!jsonData) {
  314. console.warn("Error: jsonData is null");
  315. return;
  316. }
  317. // keep polling until all hosts have registered/failed, or registrationTimeout seconds after the last host finished bootstrapping
  318. var stopPolling = true;
  319. hosts.forEach(function (_host, index) {
  320. // Change name of first host for test mode.
  321. if (App.testMode) {
  322. if (index == 0) {
  323. _host.set('name', 'localhost.localdomain');
  324. }
  325. }
  326. // actions to take depending on the host's current bootStatus
  327. // RUNNING - bootstrap is running; leave it alone
  328. // DONE - bootstrap is done; transition to REGISTERING
  329. // REGISTERING - bootstrap is done but has not registered; transition to REGISTERED if host found in polling API result
  330. // REGISTERED - bootstrap and registration is done; leave it alone
  331. // FAILED - either bootstrap or registration failed; leave it alone
  332. switch (_host.get('bootStatus')) {
  333. case 'DONE':
  334. _host.set('bootStatus', 'REGISTERING');
  335. _host.set('bootLog', (_host.get('bootLog') != null ? _host.get('bootLog') : '') + Em.I18n.t('installer.step3.hosts.bootLog.registering'));
  336. // update registration timestamp so that the timeout is computed from the last host that finished bootstrapping
  337. this.set('registrationStartedAt', App.dateTime());
  338. stopPolling = false;
  339. break;
  340. case 'REGISTERING':
  341. if (jsonData.items.someProperty('Hosts.host_name', _host.name)) {
  342. _host.set('bootStatus', 'REGISTERED');
  343. _host.set('bootLog', (_host.get('bootLog') != null ? _host.get('bootLog') : '') + Em.I18n.t('installer.step3.hosts.bootLog.registering'));
  344. } else {
  345. stopPolling = false;
  346. }
  347. break;
  348. case 'RUNNING':
  349. stopPolling = false;
  350. break;
  351. case 'REGISTERED':
  352. case 'FAILED':
  353. default:
  354. break;
  355. }
  356. }, this);
  357. if (stopPolling) {
  358. this.getHostInfo();
  359. } else if (hosts.someProperty('bootStatus', 'RUNNING') || App.dateTime() - this.get('registrationStartedAt') < this.get('registrationTimeoutSecs') * 1000) {
  360. // we want to keep polling for registration status if any of the hosts are still bootstrapping (so we check for RUNNING).
  361. var self = this;
  362. window.setTimeout(function () {
  363. self.isHostsRegistered();
  364. }, 3000);
  365. } else {
  366. // registration timed out. mark all REGISTERING hosts to FAILED
  367. console.log('registration timed out');
  368. hosts.filterProperty('bootStatus', 'REGISTERING').forEach(function (_host) {
  369. _host.set('bootStatus', 'FAILED');
  370. _host.set('bootLog', (_host.get('bootLog') != null ? _host.get('bootLog') : '') + Em.I18n.t('installer.step3.hosts.bootLog.failed'));
  371. });
  372. this.getHostInfo();
  373. }
  374. },
  375. hasMoreRegisteredHosts: false,
  376. getAllRegisteredHosts: function() {
  377. App.ajax.send({
  378. name: 'wizard.step3.is_hosts_registered',
  379. sender: this,
  380. success: 'getAllRegisteredHostsCallback'
  381. });
  382. }.observes('bootHosts'),
  383. hostsInCluster: function() {
  384. return App.Host.find().getEach('hostName');
  385. }.property().volatile(),
  386. getAllRegisteredHostsCallback: function(hosts) {
  387. var registeredHosts = [];
  388. var hostsInCluster = this.get('hostsInCluster');
  389. var addedHosts = this.get('bootHosts').getEach('name');
  390. hosts.items.forEach(function(host){
  391. if (!hostsInCluster.contains(host.Hosts.host_name) && !addedHosts.contains(host.Hosts.host_name)) {
  392. registeredHosts.push(host.Hosts.host_name);
  393. }
  394. });
  395. if(registeredHosts.length) {
  396. this.set('hasMoreRegisteredHosts',true);
  397. this.set('registeredHosts',registeredHosts);
  398. } else {
  399. this.set('hasMoreRegisteredHosts',false);
  400. this.set('registeredHosts','');
  401. }
  402. },
  403. registerErrPopup: function (header, message) {
  404. App.ModalPopup.show({
  405. header: header,
  406. secondary: false,
  407. bodyClass: Ember.View.extend({
  408. template: Ember.Handlebars.compile('<p>{{view.message}}</p>'),
  409. message: message
  410. })
  411. });
  412. },
  413. /**
  414. * Get disk info and cpu count of booted hosts from server
  415. */
  416. getHostInfo: function () {
  417. this.set('isWarningsLoaded', false);
  418. App.ajax.send({
  419. name: 'wizard.step3.host_info',
  420. sender: this,
  421. success: 'getHostInfoSuccessCallback',
  422. error: 'getHostInfoErrorCallback'
  423. });
  424. },
  425. getHostInfoSuccessCallback: function (jsonData) {
  426. var hosts = this.get('bootHosts');
  427. var self = this;
  428. this.parseWarnings(jsonData);
  429. var repoWarnings = [];
  430. var hostsContext = [];
  431. var diskWarnings = [];
  432. var hostsDiskContext = [];
  433. var hostsDiskNames = [];
  434. var hostsRepoNames = [];
  435. hosts.forEach(function (_host) {
  436. var host = (App.testMode) ? jsonData.items[0] : jsonData.items.findProperty('Hosts.host_name', _host.name);
  437. if (App.skipBootstrap) {
  438. _host.cpu = 2;
  439. _host.memory = ((parseInt(2000000))).toFixed(2);
  440. _host.disk_info = [{"mountpoint": "/", "type":"ext4"},{"mountpoint": "/grid/0", "type":"ext4"}, {"mountpoint": "/grid/1", "type":"ext4"}, {"mountpoint": "/grid/2", "type":"ext4"}];
  441. } else if (host) {
  442. _host.cpu = host.Hosts.cpu_count;
  443. _host.memory = ((parseInt(host.Hosts.total_mem))).toFixed(2);
  444. _host.disk_info = host.Hosts.disk_info;
  445. _host.os_type = host.Hosts.os_type;
  446. _host.os_arch = host.Hosts.os_arch;
  447. _host.ip = host.Hosts.ip;
  448. var context = self.checkHostOSType(host.Hosts.os_type, host.Hosts.host_name);
  449. if(context) {
  450. hostsContext.push(context);
  451. hostsRepoNames.push(host.Hosts.host_name);
  452. }
  453. var diskContext = self.checkHostDiskSpace(host.Hosts.host_name, host.Hosts.disk_info);
  454. if (diskContext) {
  455. hostsDiskContext.push(diskContext);
  456. hostsDiskNames.push(host.Hosts.host_name);
  457. }
  458. }
  459. });
  460. if (hostsContext.length > 0) { // warning exist
  461. var repoWarning = {
  462. name: Em.I18n.t('installer.step3.hostWarningsPopup.repositories.name'),
  463. hosts: hostsContext,
  464. hostsNames: hostsRepoNames,
  465. category: 'repositories',
  466. onSingleHost: false
  467. };
  468. repoWarnings.push(repoWarning);
  469. }
  470. if (hostsDiskContext.length > 0) { // disk space warning exist
  471. var diskWarning = {
  472. name: Em.I18n.t('installer.step3.hostWarningsPopup.disk.name'),
  473. hosts: hostsDiskContext,
  474. hostsNames: hostsDiskNames,
  475. category: 'disk',
  476. onSingleHost: false
  477. };
  478. diskWarnings.push(diskWarning);
  479. }
  480. this.set('repoCategoryWarnings', repoWarnings);
  481. this.set('diskCategoryWarnings', diskWarnings);
  482. this.set('bootHosts', hosts);
  483. this.stopRegistration();
  484. },
  485. getHostInfoErrorCallback: function () {
  486. console.log('INFO: Getting host information(cpu_count and total_mem) from the server failed');
  487. this.set('isWarningsLoaded', true);
  488. this.registerErrPopup(Em.I18n.t('installer.step3.hostInformation.popup.header'), Em.I18n.t('installer.step3.hostInformation.popup.body'));
  489. },
  490. stopRegistration: function () {
  491. this.set('isSubmitDisabled', !this.get('bootHosts').someProperty('bootStatus', 'REGISTERED'));
  492. this.set('isRetryDisabled', !this.get('bootHosts').someProperty('bootStatus', 'FAILED'));
  493. },
  494. /**
  495. * Check if the customized os group contains the registered host os type. If not the repo on that host is invalid.
  496. */
  497. checkHostOSType: function (osType, hostName) {
  498. if(this.get('content.stacks')){
  499. var selectedStack = this.get('content.stacks').findProperty('isSelected', true);
  500. var selectedOS = [];
  501. var isValid = false;
  502. if (selectedStack && selectedStack.operatingSystems) {
  503. selectedStack.get('operatingSystems').filterProperty('selected', true).forEach( function(os) {
  504. selectedOS.pushObject(os.osType);
  505. if ( os.osType == osType) {
  506. isValid = true;
  507. }
  508. });
  509. }
  510. if (!isValid) {
  511. console.log('WARNING: Getting host os type does NOT match the user selected os group in step1. ' +
  512. 'Host Name: '+ hostName + '. Host os type:' + osType + '. Selected group:' + selectedOS);
  513. return Em.I18n.t('installer.step3.hostWarningsPopup.repositories.context').format(hostName, osType, selectedOS);
  514. } else {
  515. return null;
  516. }
  517. }else{
  518. return null;
  519. }
  520. },
  521. /**
  522. * Check if current host has enough free disk usage.
  523. */
  524. checkHostDiskSpace: function (hostName, diskInfo) {
  525. var minFreeRootSpace = App.minDiskSpace * 1024 * 1024; //in kilobyte
  526. var minFreeUsrLibSpace = App.minDiskSpaceUsrLib * 1024 * 1024; //in kilobyte
  527. var warningString = '';
  528. diskInfo.forEach( function(info) {
  529. switch (info.mountpoint) {
  530. case '/':
  531. warningString = info.available < minFreeRootSpace ? Em.I18n.t('installer.step3.hostWarningsPopup.disk.context2').format(App.minDiskSpace + 'GB', info.mountpoint) + ' ' + warningString : warningString;
  532. break;
  533. case '/usr':
  534. case '/usr/lib':
  535. warningString = info.available < minFreeUsrLibSpace ? Em.I18n.t('installer.step3.hostWarningsPopup.disk.context2').format(App.minDiskSpaceUsrLib + 'GB', info.mountpoint) + ' ' + warningString : warningString;
  536. break;
  537. default:
  538. break;
  539. }
  540. });
  541. if (warningString) {
  542. console.log('WARNING: Getting host free disk space. ' + 'Host Name: '+ hostName);
  543. return Em.I18n.t('installer.step3.hostWarningsPopup.disk.context1').format(hostName) + ' ' + warningString;
  544. } else {
  545. return null;
  546. }
  547. },
  548. selectCategory: function(event, context){
  549. this.set('category', event.context);
  550. },
  551. selectAllCategory: function(){
  552. this.set('category', this.get('categories').get('firstObject'));
  553. },
  554. submit: function () {
  555. if (this.get('isHostHaveWarnings')) {
  556. var self = this;
  557. App.showConfirmationPopup(
  558. function () {
  559. self.set('content.hosts', self.get('bootHosts'));
  560. App.router.send('next');
  561. },
  562. Em.I18n.t('installer.step3.hostWarningsPopup.hostHasWarnings'));
  563. }
  564. else {
  565. this.set('content.hosts', this.get('bootHosts'));
  566. App.router.send('next');
  567. }
  568. },
  569. hostLogPopup: function (event, context) {
  570. var host = event.context;
  571. App.ModalPopup.show({
  572. header: Em.I18n.t('installer.step3.hostLog.popup.header').format(host.get('name')),
  573. secondary: null,
  574. bodyClass: Ember.View.extend({
  575. templateName: require('templates/wizard/step3_host_log_popup'),
  576. host: host,
  577. didInsertElement: function () {
  578. var self = this;
  579. var button = $(this.get('element')).find('.textTrigger');
  580. button.click(function () {
  581. if (self.get('isTextArea')) {
  582. $(this).text(Em.I18n.t('installer.step3.hostLogPopup.highlight'));
  583. } else {
  584. $(this).text(Em.I18n.t('installer.step3.hostLogPopup.copy'));
  585. }
  586. self.set('isTextArea', !self.get('isTextArea'));
  587. });
  588. $(this.get('element')).find('.content-area').mouseenter(
  589. function () {
  590. var element = $(this);
  591. element.css('border', '1px solid #dcdcdc');
  592. button.css('visibility', 'visible');
  593. }).mouseleave(
  594. function () {
  595. var element = $(this);
  596. element.css('border', 'none');
  597. button.css('visibility', 'hidden');
  598. })
  599. },
  600. isTextArea: false,
  601. textArea: Em.TextArea.extend({
  602. didInsertElement: function () {
  603. var element = $(this.get('element'));
  604. element.width($(this.get('parentView').get('element')).width() - 10);
  605. element.height($(this.get('parentView').get('element')).height());
  606. element.select();
  607. element.css('resize', 'none');
  608. },
  609. readOnly: true,
  610. value: function () {
  611. return this.get('content');
  612. }.property('content')
  613. })
  614. })
  615. });
  616. },
  617. /**
  618. * check warnings from server and put it in parsing
  619. */
  620. rerunChecks: function () {
  621. var self = this;
  622. var currentProgress = 0;
  623. var interval = setInterval(function () {
  624. currentProgress += 100000 / self.get('warningsTimeInterval');
  625. if (currentProgress < 100) {
  626. self.set('checksUpdateProgress', currentProgress);
  627. } else {
  628. clearInterval(interval);
  629. App.ajax.send({
  630. name: 'wizard.step3.rerun_checks',
  631. sender: self,
  632. success: 'rerunChecksSuccessCallback',
  633. error: 'rerunChecksErrorCallback'
  634. });
  635. }
  636. }, 1000);
  637. },
  638. rerunChecksSuccessCallback: function (data) {
  639. this.set('checksUpdateProgress', 100);
  640. this.set('checksUpdateStatus', 'SUCCESS');
  641. this.parseWarnings(data);
  642. },
  643. rerunChecksErrorCallback: function () {
  644. this.set('checksUpdateProgress', 100);
  645. this.set('checksUpdateStatus', 'FAILED');
  646. console.log('INFO: Getting host information(last_agent_env) from the server failed');
  647. },
  648. warnings: [],
  649. warningsByHost: [],
  650. warningsTimeInterval: 60000,
  651. isWarningsLoaded: false,
  652. /**
  653. * check are hosts have any warnings
  654. */
  655. isHostHaveWarnings: function(){
  656. return this.get('warnings.length') > 0;
  657. }.property('warnings'),
  658. isWarningsBoxVisible: function(){
  659. return (App.testMode) ? true : !this.get('isRegistrationInProgress');
  660. }.property('isRegistrationInProgress'),
  661. checksUpdateProgress:0,
  662. checksUpdateStatus: null,
  663. /**
  664. * filter data for warnings parse
  665. * is data from host in bootStrap
  666. * @param data
  667. * @return {Object}
  668. */
  669. filterBootHosts: function (data) {
  670. var bootHostNames = {};
  671. this.get('bootHosts').forEach(function (bootHost) {
  672. bootHostNames[bootHost.get('name')] = true;
  673. });
  674. var filteredData = {
  675. href: data.href,
  676. items: []
  677. };
  678. data.items.forEach(function (host) {
  679. if (bootHostNames[host.Hosts.host_name]) {
  680. filteredData.items.push(host);
  681. }
  682. });
  683. return filteredData;
  684. },
  685. /**
  686. * parse warnings data for each host and total
  687. * @param data
  688. */
  689. parseWarnings: function (data) {
  690. data = App.testMode ? data : this.filterBootHosts(data);
  691. var warnings = [];
  692. var warning;
  693. var hosts = [];
  694. var warningCategories = {
  695. fileFoldersWarnings: {},
  696. packagesWarnings: {},
  697. processesWarnings: {},
  698. servicesWarnings: {},
  699. usersWarnings: {}
  700. };
  701. data.items.sortPropertyLight('Hosts.host_name').forEach(function (_host) {
  702. var host = {
  703. name: _host.Hosts.host_name,
  704. warnings: []
  705. };
  706. if (!_host.Hosts.last_agent_env) {
  707. // in some unusual circumstances when last_agent_env is not available from the _host,
  708. // skip the _host and proceed to process the rest of the hosts.
  709. console.log("last_agent_env is missing for " + _host.Hosts.host_name + ". Skipping _host check.");
  710. return;
  711. }
  712. //parse all directories and files warnings for host
  713. //todo: to be removed after check in new API
  714. var stackFoldersAndFiles = _host.Hosts.last_agent_env.stackFoldersAndFiles || [];
  715. stackFoldersAndFiles.forEach(function (path) {
  716. warning = warningCategories.fileFoldersWarnings[path.name];
  717. if (warning) {
  718. warning.hosts.push(_host.Hosts.host_name);
  719. warning.onSingleHost = false;
  720. } else {
  721. warningCategories.fileFoldersWarnings[path.name] = warning = {
  722. name: path.name,
  723. hosts: [_host.Hosts.host_name],
  724. category: 'fileFolders',
  725. onSingleHost: true
  726. };
  727. }
  728. host.warnings.push(warning);
  729. }, this);
  730. //parse all package warnings for host
  731. _host.Hosts.last_agent_env.installedPackages.forEach(function (_package) {
  732. warning = warningCategories.packagesWarnings[_package.name];
  733. if (warning) {
  734. warning.hosts.push(_host.Hosts.host_name);
  735. warning.version = _package.version;
  736. warning.onSingleHost = false;
  737. } else {
  738. warningCategories.packagesWarnings[_package.name] = warning = {
  739. name: _package.name,
  740. version: _package.version,
  741. hosts: [_host.Hosts.host_name],
  742. category: 'packages',
  743. onSingleHost: true
  744. };
  745. }
  746. host.warnings.push(warning);
  747. }, this);
  748. //parse all process warnings for host
  749. //todo: to be removed after check in new API
  750. var javaProcs = _host.Hosts.last_agent_env.hostHealth ? _host.Hosts.last_agent_env.hostHealth.activeJavaProcs : _host.Hosts.last_agent_env.javaProcs;
  751. javaProcs.forEach(function (process) {
  752. warning = warningCategories.processesWarnings[process.pid];
  753. if (warning) {
  754. warning.hosts.push(_host.Hosts.host_name);
  755. warning.onSingleHost = false;
  756. } else {
  757. warningCategories.processesWarnings[process.pid] = warning = {
  758. name: (process.command.substr(0, 35) + '...'),
  759. hosts: [_host.Hosts.host_name],
  760. category: 'processes',
  761. user: process.user,
  762. pid: process.pid,
  763. command: '<table><tr><td style="word-break: break-all;">' +
  764. ((process.command.length < 500) ? process.command : process.command.substr(0, 230) + '...' +
  765. '<p style="text-align: center">................</p>' +
  766. '...' + process.command.substr(-230)) + '</td></tr></table>',
  767. onSingleHost: true
  768. };
  769. }
  770. host.warnings.push(warning);
  771. }, this);
  772. //parse all service warnings for host
  773. //todo: to be removed after check in new API
  774. if (_host.Hosts.last_agent_env.hostHealth && _host.Hosts.last_agent_env.hostHealth.liveServices) {
  775. _host.Hosts.last_agent_env.hostHealth.liveServices.forEach(function (service) {
  776. if (service.status === 'Unhealthy') {
  777. warning = warningCategories.servicesWarnings[service.name];
  778. if (warning) {
  779. warning.hosts.push(_host.Hosts.host_name);
  780. warning.onSingleHost = false;
  781. } else {
  782. warningCategories.servicesWarnings[service.name] = warning = {
  783. name: service.name,
  784. hosts: [_host.Hosts.host_name],
  785. category: 'services',
  786. onSingleHost: true
  787. };
  788. }
  789. host.warnings.push(warning);
  790. }
  791. }, this);
  792. }
  793. //parse all user warnings for host
  794. //todo: to be removed after check in new API
  795. if (_host.Hosts.last_agent_env.existingUsers) {
  796. _host.Hosts.last_agent_env.existingUsers.forEach(function (user) {
  797. warning = warningCategories.usersWarnings[user.userName];
  798. if (warning) {
  799. warning.hosts.push(_host.Hosts.host_name);
  800. warning.onSingleHost = false;
  801. } else {
  802. warningCategories.usersWarnings[user.userName] = warning = {
  803. name: user.userName,
  804. hosts: [_host.Hosts.host_name],
  805. category: 'users',
  806. onSingleHost: true
  807. };
  808. }
  809. host.warnings.push(warning);
  810. }, this);
  811. }
  812. //parse misc warnings for host
  813. var umask = _host.Hosts.last_agent_env.umask;
  814. if (umask && umask !== 18) {
  815. warning = warnings.filterProperty('category', 'misc').findProperty('name', umask);
  816. if (warning) {
  817. warning.hosts.push(_host.Hosts.host_name);
  818. warning.onSingleHost = false;
  819. } else {
  820. warning = {
  821. name: umask,
  822. hosts: [_host.Hosts.host_name],
  823. category: 'misc',
  824. onSingleHost: true
  825. };
  826. warnings.push(warning);
  827. }
  828. host.warnings.push(warning);
  829. }
  830. var firewallRunning = _host.Hosts.last_agent_env.iptablesIsRunning;
  831. if (firewallRunning!==null && firewallRunning) {
  832. var name = Em.I18n.t('installer.step3.hostWarningsPopup.firewall.name');
  833. warning = warnings.filterProperty('category', 'firewall').findProperty('name', name);
  834. if (warning) {
  835. warning.hosts.push(_host.Hosts.host_name);
  836. warning.onSingleHost = false;
  837. } else {
  838. warning = {
  839. name: name,
  840. hosts: [_host.Hosts.host_name],
  841. category: 'firewall',
  842. onSingleHost: true
  843. };
  844. warnings.push(warning);
  845. }
  846. host.warnings.push(warning);
  847. }
  848. hosts.push(host);
  849. }, this);
  850. for (var categoryId in warningCategories) {
  851. var category = warningCategories[categoryId]
  852. for (var warningId in category) {
  853. warnings.push(category[warningId]);
  854. }
  855. }
  856. warnings.forEach(function (warn) {
  857. if (warn.hosts.length < 11) {
  858. warn.hostsList = warn.hosts.join('<br>')
  859. } else {
  860. warn.hostsList = warn.hosts.slice(0,10).join('<br>') + '<br> ' + Em.I18n.t('installer.step3.hostWarningsPopup.moreHosts').format(warn.hosts.length - 10);
  861. }
  862. });
  863. hosts.unshift({
  864. name: 'All Hosts',
  865. warnings: warnings
  866. });
  867. this.set('warnings', warnings);
  868. this.set('warningsByHost', hosts);
  869. this.set('isWarningsLoaded', true);
  870. },
  871. /**
  872. * open popup that contain hosts' warnings
  873. * @param event
  874. */
  875. hostWarningsPopup: function(event){
  876. var self = this;
  877. var repoCategoryWarnings = this.get('repoCategoryWarnings');
  878. var diskCategoryWarnings = this.get('diskCategoryWarnings');
  879. App.ModalPopup.show({
  880. header: Em.I18n.t('installer.step3.warnings.popup.header'),
  881. secondary: Em.I18n.t('installer.step3.hostWarningsPopup.rerunChecks'),
  882. primary: Em.I18n.t('common.close'),
  883. onPrimary: function () {
  884. self.set('checksUpdateStatus', null);
  885. this.hide();
  886. },
  887. onClose: function(){
  888. self.set('checksUpdateStatus', null);
  889. this.hide();
  890. },
  891. onSecondary: function() {
  892. self.rerunChecks();
  893. },
  894. didInsertElement: function () {
  895. this.fitHeight();
  896. },
  897. footerClass: Ember.View.extend({
  898. templateName: require('templates/wizard/step3_host_warning_popup_footer'),
  899. classNames: ['modal-footer', 'host-checks-update'],
  900. footerControllerBinding: 'App.router.wizardStep3Controller',
  901. progressWidth: function(){
  902. return 'width:'+this.get('footerController.checksUpdateProgress')+'%';
  903. }.property('footerController.checksUpdateProgress'),
  904. isUpdateInProgress: function(){
  905. if((this.get('footerController.checksUpdateProgress') > 0) &&
  906. (this.get('footerController.checksUpdateProgress') < 100)){
  907. return true;
  908. }
  909. }.property('footerController.checksUpdateProgress'),
  910. updateStatusClass:function(){
  911. var status = this.get('footerController.checksUpdateStatus');
  912. if(status === 'SUCCESS'){
  913. return 'text-success';
  914. } else if(status === 'FAILED'){
  915. return 'text-error';
  916. } else {
  917. return null;
  918. }
  919. }.property('footerController.checksUpdateStatus'),
  920. updateStatus:function(){
  921. var status = this.get('footerController.checksUpdateStatus');
  922. if(status === 'SUCCESS'){
  923. return Em.I18n.t('installer.step3.warnings.updateChecks.success');
  924. } else if(status === 'FAILED'){
  925. return Em.I18n.t('installer.step3.warnings.updateChecks.failed');
  926. } else {
  927. return null;
  928. }
  929. }.property('footerController.checksUpdateStatus')
  930. }),
  931. bodyClass: Ember.View.extend({
  932. templateName: require('templates/wizard/step3_host_warnings_popup'),
  933. classNames: ['host-check'],
  934. bodyControllerBinding: 'App.router.wizardStep3Controller',
  935. didInsertElement: function () {
  936. Ember.run.next(this, function () {
  937. App.tooltip(this.$("[rel='HostsListTooltip']"), {html: true, placement: "right"});
  938. App.tooltip(this.$('#process .warning-name'), {html: true, placement: "top"});
  939. });
  940. }.observes('content'),
  941. hostSelectView: Ember.Select.extend({
  942. //content has default value "All Hosts" to bind selection to category
  943. content: ['All Hosts'],
  944. hosts: function () {
  945. return this.get('parentView.warningsByHost').mapProperty('name');
  946. }.property('parentView.warningsByHost'),
  947. isLoaded: false,
  948. selectionBinding: "parentView.category",
  949. didInsertElement: function(){
  950. this.initContent();
  951. },
  952. initContent: function () {
  953. this.set('isLoaded', false);
  954. //The lazy loading for select elements supported only by Firefox and Chrome
  955. var isBrowserSupported = $.browser.mozilla || ($.browser.safari && navigator.userAgent.indexOf('Chrome') !== -1);
  956. var isLazyLoading = isBrowserSupported && this.get('hosts').length > 100;
  957. this.set('isLazyLoading', isLazyLoading);
  958. if (isLazyLoading) {
  959. //select need at least 30 hosts to have scrollbar
  960. this.set('content', this.get('hosts').slice(0, 30));
  961. } else {
  962. this.set('content', this.get('hosts'));
  963. this.set('isLoaded', true);
  964. }
  965. }.observes('parentView.warningsByHost'),
  966. /**
  967. * on click start lazy loading
  968. */
  969. click: function () {
  970. if (!this.get('isLoaded') && this.get('isLazyLoading')) {
  971. //filter out hosts, which already pushed in select
  972. var source = this.get('hosts').filter(function (_host) {
  973. return !this.get('content').contains(_host);
  974. }, this).slice();
  975. lazyloading.run({
  976. destination: this.get('content'),
  977. source: source,
  978. context: this,
  979. initSize: 30,
  980. chunkSize: 200,
  981. delay: 50
  982. });
  983. }
  984. }
  985. }),
  986. warningsByHost: function () {
  987. return this.get('bodyController.warningsByHost');
  988. }.property('bodyController.warningsByHost'),
  989. warnings: function () {
  990. return this.get('bodyController.warnings');
  991. }.property('bodyController.warnings'),
  992. category: 'All Hosts',
  993. categoryWarnings: function () {
  994. return this.get('warningsByHost').findProperty('name', this.get('category')).warnings
  995. }.property('warningsByHost', 'category'),
  996. content: function () {
  997. var categoryWarnings = this.get('categoryWarnings');
  998. return [
  999. Ember.Object.create({
  1000. warnings: diskCategoryWarnings,
  1001. title: Em.I18n.t('installer.step3.hostWarningsPopup.disk'),
  1002. message: Em.I18n.t('installer.step3.hostWarningsPopup.disk.message'),
  1003. type: Em.I18n.t('common.issues'),
  1004. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.disk'),
  1005. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  1006. category: 'disk',
  1007. isCollapsed: true
  1008. }),
  1009. Ember.Object.create({
  1010. warnings: repoCategoryWarnings,
  1011. title: Em.I18n.t('installer.step3.hostWarningsPopup.repositories'),
  1012. message: Em.I18n.t('installer.step3.hostWarningsPopup.repositories.message'),
  1013. type: Em.I18n.t('common.issues'),
  1014. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.repositories'),
  1015. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.invalid'),
  1016. category: 'repositories',
  1017. isCollapsed: true
  1018. }),
  1019. Ember.Object.create({
  1020. warnings: categoryWarnings.filterProperty('category', 'firewall'),
  1021. title: Em.I18n.t('installer.step3.hostWarningsPopup.firewall'),
  1022. message: Em.I18n.t('installer.step3.hostWarningsPopup.firewall.message'),
  1023. type: Em.I18n.t('common.issues'),
  1024. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.firewall'),
  1025. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.running'),
  1026. category: 'firewall',
  1027. isCollapsed: true
  1028. }),
  1029. Ember.Object.create({
  1030. warnings: categoryWarnings.filterProperty('category', 'processes'),
  1031. title: Em.I18n.t('installer.step3.hostWarningsPopup.process'),
  1032. message: Em.I18n.t('installer.step3.hostWarningsPopup.processes.message'),
  1033. type: Em.I18n.t('common.process'),
  1034. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.processes'),
  1035. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.running'),
  1036. category: 'process',
  1037. isCollapsed: true
  1038. }),
  1039. Ember.Object.create({
  1040. warnings: categoryWarnings.filterProperty('category', 'packages'),
  1041. title: Em.I18n.t('installer.step3.hostWarningsPopup.package'),
  1042. message: Em.I18n.t('installer.step3.hostWarningsPopup.packages.message'),
  1043. type: Em.I18n.t('common.package'),
  1044. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.packages'),
  1045. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.installed'),
  1046. category: 'package',
  1047. isCollapsed: true
  1048. }),
  1049. Ember.Object.create({
  1050. warnings: categoryWarnings.filterProperty('category', 'fileFolders'),
  1051. title: Em.I18n.t('installer.step3.hostWarningsPopup.fileAndFolder'),
  1052. message: Em.I18n.t('installer.step3.hostWarningsPopup.fileFolders.message'),
  1053. type: Em.I18n.t('common.path'),
  1054. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.filesAndFolders'),
  1055. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  1056. category: 'fileFolders',
  1057. isCollapsed: true
  1058. }),
  1059. Ember.Object.create({
  1060. warnings: categoryWarnings.filterProperty('category', 'services'),
  1061. title: Em.I18n.t('installer.step3.hostWarningsPopup.service'),
  1062. message: Em.I18n.t('installer.step3.hostWarningsPopup.services.message'),
  1063. type: Em.I18n.t('common.service'),
  1064. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.services'),
  1065. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.notRunning'),
  1066. category: 'service',
  1067. isCollapsed: true
  1068. }),
  1069. Ember.Object.create({
  1070. warnings: categoryWarnings.filterProperty('category', 'users'),
  1071. title: Em.I18n.t('installer.step3.hostWarningsPopup.user'),
  1072. message: Em.I18n.t('installer.step3.hostWarningsPopup.users.message'),
  1073. type: Em.I18n.t('common.user'),
  1074. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.users'),
  1075. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  1076. category: 'user',
  1077. isCollapsed: true
  1078. }),
  1079. Ember.Object.create({
  1080. warnings: categoryWarnings.filterProperty('category', 'misc'),
  1081. title: Em.I18n.t('installer.step3.hostWarningsPopup.misc'),
  1082. message: Em.I18n.t('installer.step3.hostWarningsPopup.misc.message'),
  1083. type: Em.I18n.t('installer.step3.hostWarningsPopup.misc.umask'),
  1084. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.misc'),
  1085. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  1086. category: 'misc',
  1087. isCollapsed: true
  1088. })
  1089. ]
  1090. }.property('category', 'warningsByHost'),
  1091. showHostsPopup: function (hosts) {
  1092. $('.tooltip').hide();
  1093. App.ModalPopup.show({
  1094. header: Em.I18n.t('installer.step3.hostWarningsPopup.allHosts'),
  1095. bodyClass: Ember.View.extend({
  1096. hosts: hosts.context,
  1097. template: Ember.Handlebars.compile('<ul>{{#each host in view.hosts}}<li>{{host}}</li>{{/each}}</ul>')
  1098. }),
  1099. secondary: null
  1100. });
  1101. },
  1102. onToggleBlock: function (category) {
  1103. this.$('#' + category.context.category).toggle('blind', 500);
  1104. category.context.set("isCollapsed", !category.context.get("isCollapsed"));
  1105. },
  1106. /**
  1107. * generate number of hosts which had warnings, avoid duplicated host names in different warnings.
  1108. */
  1109. warningHostsNamesCount: function () {
  1110. var hostNameMap = Ember.Object.create();
  1111. var warningsByHost = self.get('warningsByHost').slice();
  1112. warningsByHost.shift();
  1113. warningsByHost.forEach( function( _host) {
  1114. if (_host.warnings.length) {
  1115. hostNameMap[_host.name] = true;
  1116. }
  1117. })
  1118. if (repoCategoryWarnings.length) {
  1119. repoCategoryWarnings[0].hostsNames.forEach(function (_hostName) {
  1120. if (!hostNameMap[_hostName]) {
  1121. hostNameMap[_hostName] = true;
  1122. }
  1123. })
  1124. }
  1125. if (diskCategoryWarnings.length) {
  1126. diskCategoryWarnings[0].hostsNames.forEach(function (_hostName) {
  1127. if (!hostNameMap[_hostName]) {
  1128. hostNameMap[_hostName] = true;
  1129. }
  1130. })
  1131. }
  1132. var size = 0;
  1133. for (var key in hostNameMap) {
  1134. if (hostNameMap.hasOwnProperty(key)) size++;
  1135. }
  1136. return size;
  1137. },
  1138. warningsNotice: function () {
  1139. var warnings = this.get('warnings');
  1140. var issuesNumber = warnings.length + repoCategoryWarnings.length + diskCategoryWarnings.length;
  1141. var issues = issuesNumber + ' ' + (issuesNumber.length === 1 ? Em.I18n.t('installer.step3.hostWarningsPopup.issue') : Em.I18n.t('installer.step3.hostWarningsPopup.issues'));
  1142. var hostsCnt = this.warningHostsNamesCount();
  1143. var hosts = hostsCnt + ' ' + (hostsCnt === 1 ? Em.I18n.t('installer.step3.hostWarningsPopup.host') : Em.I18n.t('installer.step3.hostWarningsPopup.hosts'));
  1144. return Em.I18n.t('installer.step3.hostWarningsPopup.summary').format(issues, hosts);
  1145. }.property('warnings', 'warningsByHost'),
  1146. /**
  1147. * generate detailed content to show it in new window
  1148. */
  1149. contentInDetails: function () {
  1150. var content = this.get('content');
  1151. var warningsByHost = this.get('warningsByHost').slice();
  1152. warningsByHost.shift();
  1153. var newContent = '';
  1154. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.header') + new Date;
  1155. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.hosts');
  1156. newContent += warningsByHost.filterProperty('warnings.length').mapProperty('name').join(' ');
  1157. if (content.findProperty('category', 'firewall').warnings.length) {
  1158. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.firewall');
  1159. newContent += content.findProperty('category', 'firewall').warnings.mapProperty('name').join('<br>');
  1160. }
  1161. if (content.findProperty('category', 'fileFolders').warnings.length) {
  1162. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.fileFolders');
  1163. newContent += content.findProperty('category', 'fileFolders').warnings.mapProperty('name').join(' ');
  1164. }
  1165. if (content.findProperty('category', 'process').warnings.length) {
  1166. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.process');
  1167. content.findProperty('category', 'process').warnings.forEach(function (process, i) {
  1168. process.hosts.forEach(function (host, j) {
  1169. if (!!i || !!j) {
  1170. newContent += ',';
  1171. }
  1172. newContent += '(' + host + ',' + process.user + ',' + process.pid + ')';
  1173. });
  1174. });
  1175. }
  1176. if (content.findProperty('category', 'package').warnings.length) {
  1177. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.package');
  1178. newContent += content.findProperty('category', 'package').warnings.mapProperty('name').join(' ');
  1179. }
  1180. if (content.findProperty('category', 'service').warnings.length) {
  1181. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.service');
  1182. newContent += content.findProperty('category', 'service').warnings.mapProperty('name').join(' ');
  1183. }
  1184. if (content.findProperty('category', 'user').warnings.length) {
  1185. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.user');
  1186. newContent += content.findProperty('category', 'user').warnings.mapProperty('name').join(' ');
  1187. }
  1188. newContent += '</p>';
  1189. return newContent;
  1190. }.property('content', 'warningsByHost'),
  1191. /**
  1192. * open new browser tab with detailed content
  1193. */
  1194. openWarningsInDialog: function(){
  1195. var newWindow = window.open('');
  1196. var newDocument = newWindow.document;
  1197. newDocument.write(this.get('contentInDetails'));
  1198. newWindow.focus();
  1199. }
  1200. })
  1201. })
  1202. },
  1203. registeredHostsPopup: function(){
  1204. var self = this;
  1205. App.ModalPopup.show({
  1206. header: Em.I18n.t('installer.step3.warning.registeredHosts').format(this.get('registeredHosts').length),
  1207. secondary: null,
  1208. bodyClass: Ember.View.extend({
  1209. templateName: require('templates/wizard/step3_registered_hosts_popup'),
  1210. message: Em.I18n.t('installer.step3.registeredHostsPopup'),
  1211. registeredHosts: self.get('registeredHosts')
  1212. })
  1213. })
  1214. }
  1215. });