step3_controller.js 52 KB

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