step3_controller.js 39 KB

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