step3_controller.js 47 KB

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