step3_controller.js 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332
  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 = this.get('bootHosts').mapProperty('name');
  729. var filteredData = {
  730. href: data.href,
  731. items: []
  732. };
  733. data.items.forEach(function (host) {
  734. if (bootHostNames.contains(host.Hosts.host_name)) {
  735. filteredData.items.push(host);
  736. }
  737. });
  738. return filteredData;
  739. },
  740. /**
  741. * parse warnings data for each host and total
  742. * @param data
  743. */
  744. parseWarnings: function (data) {
  745. data = App.testMode ? data : this.filterBootHosts(data);
  746. var warnings = [];
  747. var warning;
  748. var hosts = [];
  749. data.items.sort(function (a, b) {
  750. if (a.Hosts.host_name > b.Hosts.host_name) {
  751. return 1;
  752. }
  753. if (a.Hosts.host_name < b.Hosts.host_name) {
  754. return -1;
  755. }
  756. return 0;
  757. });
  758. data.items.forEach(function (_host) {
  759. var host = {
  760. name: _host.Hosts.host_name,
  761. warnings: []
  762. };
  763. if (!_host.Hosts.last_agent_env) {
  764. // in some unusual circumstances when last_agent_env is not available from the _host,
  765. // skip the _host and proceed to process the rest of the hosts.
  766. console.log("last_agent_env is missing for " + _host.Hosts.host_name + ". Skipping _host check.");
  767. return;
  768. }
  769. //parse all directories and files warnings for host
  770. //todo: to be removed after check in new API
  771. var stackFoldersAndFiles = _host.Hosts.last_agent_env.stackFoldersAndFiles || _host.Hosts.last_agent_env.paths;
  772. stackFoldersAndFiles.forEach(function (path) {
  773. warning = warnings.filterProperty('category', 'fileFolders').findProperty('name', path.name);
  774. if (warning) {
  775. warning.hosts.push(_host.Hosts.host_name);
  776. warning.onSingleHost = false;
  777. } else {
  778. warning = {
  779. name: path.name,
  780. hosts: [_host.Hosts.host_name],
  781. category: 'fileFolders',
  782. onSingleHost: true
  783. };
  784. warnings.push(warning);
  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 = warnings.filterProperty('category', 'packages').findProperty('name', _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. warning = {
  797. name: _package.name,
  798. version: _package.version,
  799. hosts: [_host.Hosts.host_name],
  800. category: 'packages',
  801. onSingleHost: true
  802. };
  803. warnings.push(warning);
  804. }
  805. host.warnings.push(warning);
  806. }, this);
  807. //parse all process warnings for host
  808. //todo: to be removed after check in new API
  809. var javaProcs = _host.Hosts.last_agent_env.hostHealth ? _host.Hosts.last_agent_env.hostHealth.activeJavaProcs : _host.Hosts.last_agent_env.javaProcs;
  810. javaProcs.forEach(function (process) {
  811. warning = warnings.filterProperty('category', 'processes').findProperty('pid', process.pid);
  812. if (warning) {
  813. warning.hosts.push(_host.Hosts.host_name);
  814. warning.onSingleHost = false;
  815. } else {
  816. warning = {
  817. name: (process.command.substr(0, 35) + '...'),
  818. hosts: [_host.Hosts.host_name],
  819. category: 'processes',
  820. user: process.user,
  821. pid: process.pid,
  822. command: '<table><tr><td style="word-break: break-all;">' +
  823. ((process.command.length < 500) ? process.command : process.command.substr(0, 230) + '...' +
  824. '<p style="text-align: center">................</p>' +
  825. '...' + process.command.substr(-230)) + '</td></tr></table>',
  826. onSingleHost: true
  827. };
  828. warnings.push(warning);
  829. }
  830. host.warnings.push(warning);
  831. }, this);
  832. //parse all service warnings for host
  833. //todo: to be removed after check in new API
  834. if (_host.Hosts.last_agent_env.hostHealth && _host.Hosts.last_agent_env.hostHealth.liveServices) {
  835. _host.Hosts.last_agent_env.hostHealth.liveServices.forEach(function (service) {
  836. if (service.status === 'Unhealthy') {
  837. warning = warnings.filterProperty('category', 'services').findProperty('name', service.name);
  838. if (warning) {
  839. warning.hosts.push(_host.Hosts.host_name);
  840. warning.onSingleHost = false;
  841. } else {
  842. warning = {
  843. name: service.name,
  844. hosts: [_host.Hosts.host_name],
  845. category: 'services',
  846. onSingleHost: true
  847. };
  848. warnings.push(warning);
  849. }
  850. host.warnings.push(warning);
  851. }
  852. }, this);
  853. }
  854. //parse all user warnings for host
  855. //todo: to be removed after check in new API
  856. if (_host.Hosts.last_agent_env.existingUsers) {
  857. _host.Hosts.last_agent_env.existingUsers.forEach(function (user) {
  858. warning = warnings.filterProperty('category', 'users').findProperty('name', user.userName);
  859. if (warning) {
  860. warning.hosts.push(_host.Hosts.host_name);
  861. warning.onSingleHost = false;
  862. } else {
  863. warning = {
  864. name: user.userName,
  865. hosts: [_host.Hosts.host_name],
  866. category: 'users',
  867. onSingleHost: true
  868. };
  869. warnings.push(warning);
  870. }
  871. host.warnings.push(warning);
  872. }, this);
  873. }
  874. //parse misc warnings for host
  875. var umask = _host.Hosts.last_agent_env.umask;
  876. if (umask && umask !== 18) {
  877. warning = warnings.filterProperty('category', 'misc').findProperty('name', umask);
  878. if (warning) {
  879. warning.hosts.push(_host.Hosts.host_name);
  880. warning.onSingleHost = false;
  881. } else {
  882. warning = {
  883. name: umask,
  884. hosts: [_host.Hosts.host_name],
  885. category: 'misc',
  886. onSingleHost: true
  887. };
  888. warnings.push(warning);
  889. }
  890. host.warnings.push(warning);
  891. }
  892. var firewallRunning = _host.Hosts.last_agent_env.iptablesIsRunning;
  893. if (firewallRunning!==null && firewallRunning) {
  894. var name = Em.I18n.t('installer.step3.hostWarningsPopup.firewall.name');
  895. warning = warnings.filterProperty('category', 'firewall').findProperty('name', name);
  896. if (warning) {
  897. warning.hosts.push(_host.Hosts.host_name);
  898. warning.onSingleHost = false;
  899. } else {
  900. warning = {
  901. name: name,
  902. hosts: [_host.Hosts.host_name],
  903. category: 'firewall',
  904. onSingleHost: true
  905. };
  906. warnings.push(warning);
  907. }
  908. host.warnings.push(warning);
  909. }
  910. hosts.push(host);
  911. }, this);
  912. warnings.forEach(function (warn) {
  913. if (warn.hosts.length < 11) {
  914. warn.hostsList = warn.hosts.join('<br>')
  915. } else {
  916. warn.hostsList = warn.hosts.slice(0,10).join('<br>') + '<br> ' + Em.I18n.t('installer.step3.hostWarningsPopup.moreHosts').format(warn.hosts.length - 10);
  917. }
  918. });
  919. hosts.unshift({
  920. name: 'All Hosts',
  921. warnings: warnings
  922. });
  923. this.set('warnings', warnings);
  924. this.set('warningsByHost', hosts);
  925. },
  926. /**
  927. * open popup that contain hosts' warnings
  928. * @param event
  929. */
  930. hostWarningsPopup: function(event){
  931. var self = this;
  932. var repoCategoryWarnings = this.get('repoCategoryWarnings');
  933. var diskCategoryWarnings = this.get('diskCategoryWarnings');
  934. App.ModalPopup.show({
  935. header: Em.I18n.t('installer.step3.warnings.popup.header'),
  936. secondary: Em.I18n.t('installer.step3.hostWarningsPopup.rerunChecks'),
  937. primary: Em.I18n.t('common.close'),
  938. onPrimary: function () {
  939. self.set('checksUpdateStatus', null);
  940. this.hide();
  941. },
  942. onClose: function(){
  943. self.set('checksUpdateStatus', null);
  944. this.hide();
  945. },
  946. onSecondary: function() {
  947. self.rerunChecks();
  948. },
  949. didInsertElement: function () {
  950. this.fitHeight();
  951. },
  952. footerClass: Ember.View.extend({
  953. templateName: require('templates/wizard/step3_host_warning_popup_footer'),
  954. classNames: ['modal-footer', 'host-checks-update'],
  955. progressWidth: function(){
  956. return 'width:'+App.router.get('wizardStep3Controller.checksUpdateProgress')+'%';
  957. }.property('App.router.wizardStep3Controller.checksUpdateProgress'),
  958. isUpdateInProgress: function(){
  959. if((App.router.get('wizardStep3Controller.checksUpdateProgress') > 0) &&
  960. (App.router.get('wizardStep3Controller.checksUpdateProgress') < 100)){
  961. return true;
  962. }
  963. }.property('App.router.wizardStep3Controller.checksUpdateProgress'),
  964. updateStatusClass:function(){
  965. var status = App.router.get('wizardStep3Controller.checksUpdateStatus');
  966. if(status === 'SUCCESS'){
  967. return 'text-success';
  968. } else if(status === 'FAILED'){
  969. return 'text-error';
  970. } else {
  971. return null;
  972. }
  973. }.property('App.router.wizardStep3Controller.checksUpdateStatus'),
  974. updateStatus:function(){
  975. var status = App.router.get('wizardStep3Controller.checksUpdateStatus');
  976. if(status === 'SUCCESS'){
  977. return Em.I18n.t('installer.step3.warnings.updateChecks.success');
  978. } else if(status === 'FAILED'){
  979. return Em.I18n.t('installer.step3.warnings.updateChecks.failed');
  980. } else {
  981. return null;
  982. }
  983. }.property('App.router.wizardStep3Controller.checksUpdateStatus')
  984. }),
  985. bodyClass: Ember.View.extend({
  986. templateName: require('templates/wizard/step3_host_warnings_popup'),
  987. classNames: ['host-check'],
  988. didInsertElement: function () {
  989. Ember.run.next(this, function () {
  990. App.tooltip(this.$("[rel='HostsListTooltip']"), {html: true, placement: "right"});
  991. App.tooltip(this.$('#process .warning-name'), {html: true, placement: "top"});
  992. })
  993. }.observes('content'),
  994. warningsByHost: function () {
  995. return App.router.get('wizardStep3Controller.warningsByHost');
  996. }.property('App.router.wizardStep3Controller.warningsByHost'),
  997. warnings: function () {
  998. return App.router.get('wizardStep3Controller.warnings');
  999. }.property('App.router.wizardStep3Controller.warnings'),
  1000. categories: function () {
  1001. return this.get('warningsByHost').mapProperty('name');
  1002. }.property('warningsByHost'),
  1003. category: 'All Hosts',
  1004. categoryWarnings: function () {
  1005. return this.get('warningsByHost').findProperty('name', this.get('category')).warnings
  1006. }.property('warningsByHost', 'category'),
  1007. content: function () {
  1008. var categoryWarnings = this.get('categoryWarnings');
  1009. return [
  1010. Ember.Object.create({
  1011. warnings: diskCategoryWarnings,
  1012. title: Em.I18n.t('installer.step3.hostWarningsPopup.disk'),
  1013. message: Em.I18n.t('installer.step3.hostWarningsPopup.disk.message'),
  1014. type: Em.I18n.t('common.issues'),
  1015. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.disk'),
  1016. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  1017. category: 'disk',
  1018. isCollapsed: true
  1019. }),
  1020. Ember.Object.create({
  1021. warnings: repoCategoryWarnings,
  1022. title: Em.I18n.t('installer.step3.hostWarningsPopup.repositories'),
  1023. message: Em.I18n.t('installer.step3.hostWarningsPopup.repositories.message'),
  1024. type: Em.I18n.t('common.issues'),
  1025. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.repositories'),
  1026. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.invalid'),
  1027. category: 'repositories',
  1028. isCollapsed: true
  1029. }),
  1030. Ember.Object.create({
  1031. warnings: categoryWarnings.filterProperty('category', 'firewall'),
  1032. title: Em.I18n.t('installer.step3.hostWarningsPopup.firewall'),
  1033. message: Em.I18n.t('installer.step3.hostWarningsPopup.firewall.message'),
  1034. type: Em.I18n.t('common.issues'),
  1035. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.firewall'),
  1036. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.running'),
  1037. category: 'firewall',
  1038. isCollapsed: true
  1039. }),
  1040. Ember.Object.create({
  1041. warnings: categoryWarnings.filterProperty('category', 'processes'),
  1042. title: Em.I18n.t('installer.step3.hostWarningsPopup.process'),
  1043. message: Em.I18n.t('installer.step3.hostWarningsPopup.processes.message'),
  1044. type: Em.I18n.t('common.process'),
  1045. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.processes'),
  1046. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.running'),
  1047. category: 'process',
  1048. isCollapsed: true
  1049. }),
  1050. Ember.Object.create({
  1051. warnings: categoryWarnings.filterProperty('category', 'packages'),
  1052. title: Em.I18n.t('installer.step3.hostWarningsPopup.package'),
  1053. message: Em.I18n.t('installer.step3.hostWarningsPopup.packages.message'),
  1054. type: Em.I18n.t('common.package'),
  1055. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.packages'),
  1056. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.installed'),
  1057. category: 'package',
  1058. isCollapsed: true
  1059. }),
  1060. Ember.Object.create({
  1061. warnings: categoryWarnings.filterProperty('category', 'fileFolders'),
  1062. title: Em.I18n.t('installer.step3.hostWarningsPopup.fileAndFolder'),
  1063. message: Em.I18n.t('installer.step3.hostWarningsPopup.fileFolders.message'),
  1064. type: Em.I18n.t('common.path'),
  1065. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.filesAndFolders'),
  1066. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  1067. category: 'fileFolders',
  1068. isCollapsed: true
  1069. }),
  1070. Ember.Object.create({
  1071. warnings: categoryWarnings.filterProperty('category', 'services'),
  1072. title: Em.I18n.t('installer.step3.hostWarningsPopup.service'),
  1073. message: Em.I18n.t('installer.step3.hostWarningsPopup.services.message'),
  1074. type: Em.I18n.t('common.service'),
  1075. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.services'),
  1076. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.notRunning'),
  1077. category: 'service',
  1078. isCollapsed: true
  1079. }),
  1080. Ember.Object.create({
  1081. warnings: categoryWarnings.filterProperty('category', 'users'),
  1082. title: Em.I18n.t('installer.step3.hostWarningsPopup.user'),
  1083. message: Em.I18n.t('installer.step3.hostWarningsPopup.users.message'),
  1084. type: Em.I18n.t('common.user'),
  1085. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.users'),
  1086. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  1087. category: 'user',
  1088. isCollapsed: true
  1089. }),
  1090. Ember.Object.create({
  1091. warnings: categoryWarnings.filterProperty('category', 'misc'),
  1092. title: Em.I18n.t('installer.step3.hostWarningsPopup.misc'),
  1093. message: Em.I18n.t('installer.step3.hostWarningsPopup.misc.message'),
  1094. type: Em.I18n.t('installer.step3.hostWarningsPopup.misc.umask'),
  1095. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.misc'),
  1096. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  1097. category: 'misc',
  1098. isCollapsed: true
  1099. })
  1100. ]
  1101. }.property('category', 'warningsByHost'),
  1102. showHostsPopup: function (hosts) {
  1103. $('.tooltip').hide();
  1104. App.ModalPopup.show({
  1105. header: Em.I18n.t('installer.step3.hostWarningsPopup.allHosts'),
  1106. bodyClass: Ember.View.extend({
  1107. hosts: hosts.context,
  1108. template: Ember.Handlebars.compile('<ul>{{#each host in view.hosts}}<li>{{host}}</li>{{/each}}</ul>')
  1109. }),
  1110. secondary: null
  1111. });
  1112. },
  1113. onToggleBlock: function (category) {
  1114. this.$('#' + category.context.category).toggle('blind', 500);
  1115. category.context.set("isCollapsed", !category.context.get("isCollapsed"));
  1116. },
  1117. /**
  1118. * generate number of hosts which had warnings, avoid duplicated host names in different warnings.
  1119. */
  1120. warningHostsNamesCount: function () {
  1121. var hostNameMap = Ember.Object.create();
  1122. var warningsByHost = self.get('warningsByHost').slice();
  1123. warningsByHost.shift();
  1124. warningsByHost.forEach( function( _host) {
  1125. if (_host.warnings.length) {
  1126. hostNameMap[_host.name] = true;
  1127. }
  1128. })
  1129. if (repoCategoryWarnings.length) {
  1130. repoCategoryWarnings[0].hostsNames.forEach(function (_hostName) {
  1131. if (!hostNameMap[_hostName]) {
  1132. hostNameMap[_hostName] = true;
  1133. }
  1134. })
  1135. }
  1136. if (diskCategoryWarnings.length) {
  1137. diskCategoryWarnings[0].hostsNames.forEach(function (_hostName) {
  1138. if (!hostNameMap[_hostName]) {
  1139. hostNameMap[_hostName] = true;
  1140. }
  1141. })
  1142. }
  1143. var size = 0;
  1144. for (var key in hostNameMap) {
  1145. if (hostNameMap.hasOwnProperty(key)) size++;
  1146. }
  1147. return size;
  1148. },
  1149. warningsNotice: function () {
  1150. var warnings = this.get('warnings');
  1151. var issuesNumber = warnings.length + repoCategoryWarnings.length + diskCategoryWarnings.length;
  1152. var issues = issuesNumber + ' ' + (issuesNumber.length === 1 ? Em.I18n.t('installer.step3.hostWarningsPopup.issue') : Em.I18n.t('installer.step3.hostWarningsPopup.issues'));
  1153. var hostsCnt = this.warningHostsNamesCount();
  1154. var hosts = hostsCnt + ' ' + (hostsCnt === 1 ? Em.I18n.t('installer.step3.hostWarningsPopup.host') : Em.I18n.t('installer.step3.hostWarningsPopup.hosts'));
  1155. return Em.I18n.t('installer.step3.hostWarningsPopup.summary').format(issues, hosts);
  1156. }.property('warnings', 'warningsByHost'),
  1157. /**
  1158. * generate detailed content to show it in new window
  1159. */
  1160. contentInDetails: function () {
  1161. var content = this.get('content');
  1162. var warningsByHost = this.get('warningsByHost').slice();
  1163. warningsByHost.shift();
  1164. var newContent = '';
  1165. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.header') + new Date;
  1166. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.hosts');
  1167. newContent += warningsByHost.filterProperty('warnings.length').mapProperty('name').join(' ');
  1168. if (content.findProperty('category', 'firewall').warnings.length) {
  1169. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.firewall');
  1170. newContent += content.findProperty('category', 'firewall').warnings.mapProperty('name').join('<br>');
  1171. }
  1172. if (content.findProperty('category', 'fileFolders').warnings.length) {
  1173. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.fileFolders');
  1174. newContent += content.findProperty('category', 'fileFolders').warnings.mapProperty('name').join(' ');
  1175. }
  1176. if (content.findProperty('category', 'process').warnings.length) {
  1177. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.process');
  1178. content.findProperty('category', 'process').warnings.forEach(function (process, i) {
  1179. process.hosts.forEach(function (host, j) {
  1180. if (!!i || !!j) {
  1181. newContent += ',';
  1182. }
  1183. newContent += '(' + host + ',' + process.user + ',' + process.pid + ')';
  1184. });
  1185. });
  1186. }
  1187. if (content.findProperty('category', 'package').warnings.length) {
  1188. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.package');
  1189. newContent += content.findProperty('category', 'package').warnings.mapProperty('name').join(' ');
  1190. }
  1191. if (content.findProperty('category', 'service').warnings.length) {
  1192. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.service');
  1193. newContent += content.findProperty('category', 'service').warnings.mapProperty('name').join(' ');
  1194. }
  1195. if (content.findProperty('category', 'user').warnings.length) {
  1196. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.user');
  1197. newContent += content.findProperty('category', 'user').warnings.mapProperty('name').join(' ');
  1198. }
  1199. newContent += '</p>';
  1200. return newContent;
  1201. }.property('content', 'warningsByHost'),
  1202. /**
  1203. * open new browser tab with detailed content
  1204. */
  1205. openWarningsInDialog: function(){
  1206. var newWindow = window.open('');
  1207. var newDocument = newWindow.document;
  1208. newDocument.write(this.get('contentInDetails'));
  1209. newWindow.focus();
  1210. }
  1211. })
  1212. })
  1213. },
  1214. registeredHostsPopup: function(){
  1215. var self = this;
  1216. App.ModalPopup.show({
  1217. header: Em.I18n.t('installer.step3.warning.registeredHosts').format(this.get('registeredHosts').length),
  1218. secondary: null,
  1219. bodyClass: Ember.View.extend({
  1220. templateName: require('templates/wizard/step3_registered_hosts_popup'),
  1221. message: Em.I18n.t('installer.step3.registeredHostsPopup'),
  1222. registeredHosts: self.get('registeredHosts')
  1223. })
  1224. })
  1225. },
  1226. back: function () {
  1227. if (this.get('isRegistrationInProgress')) {
  1228. return;
  1229. }
  1230. App.router.send('back');
  1231. }
  1232. });