step3_controller.js 42 KB

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