step3_controller.js 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096
  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. currentProgress += 100000 / self.get('warningsTimeInterval');
  554. if (currentProgress < 100) {
  555. self.set('checksUpdateProgress', currentProgress);
  556. } else {
  557. clearInterval(interval);
  558. App.ajax.send({
  559. name: 'wizard.step3.rerun_checks',
  560. sender: self,
  561. success: 'rerunChecksSuccessCallback',
  562. error: 'rerunChecksErrorCallback'
  563. });
  564. }
  565. }, 1000);
  566. },
  567. rerunChecksSuccessCallback: function (data) {
  568. this.set('checksUpdateProgress', 100);
  569. this.set('checksUpdateStatus', 'SUCCESS');
  570. this.parseWarnings(data);
  571. },
  572. rerunChecksErrorCallback: function () {
  573. this.set('checksUpdateProgress', 100);
  574. this.set('checksUpdateStatus', 'FAILED');
  575. console.log('INFO: Getting host information(last_agent_env) from the server failed');
  576. },
  577. warnings: [],
  578. warningsByHost: [],
  579. warningsTimeInterval: 60000,
  580. /**
  581. * check are hosts have any warnings
  582. */
  583. isHostHaveWarnings: function(){
  584. return this.get('warnings.length') > 0;
  585. }.property('warnings'),
  586. isWarningsBoxVisible: function(){
  587. return (App.testMode) ? true : this.get('allHostsComplete');
  588. }.property('allHostsComplete'),
  589. checksUpdateProgress:0,
  590. checksUpdateStatus: null,
  591. /**
  592. * filter data for warnings parse
  593. * is data from host in bootStrap
  594. * @param data
  595. * @return {Object}
  596. */
  597. filterBootHosts: function (data) {
  598. var bootHostNames = this.get('bootHosts').mapProperty('name');
  599. var filteredData = {
  600. href: data.href,
  601. items: []
  602. };
  603. data.items.forEach(function (host) {
  604. if (bootHostNames.contains(host.Hosts.host_name)) {
  605. filteredData.items.push(host);
  606. }
  607. });
  608. return filteredData;
  609. },
  610. /**
  611. * parse warnings data for each host and total
  612. * @param data
  613. */
  614. parseWarnings: function (data) {
  615. data = App.testMode ? data : this.filterBootHosts(data);
  616. var warnings = [];
  617. var warning;
  618. var hosts = [];
  619. data.items.sort(function (a, b) {
  620. if (a.Hosts.host_name > b.Hosts.host_name) {
  621. return 1;
  622. }
  623. if (a.Hosts.host_name < b.Hosts.host_name) {
  624. return -1;
  625. }
  626. return 0;
  627. });
  628. data.items.forEach(function (_host) {
  629. var host = {
  630. name: _host.Hosts.host_name,
  631. warnings: []
  632. }
  633. if (!_host.Hosts.last_agent_env) {
  634. // in some unusual circumstances when last_agent_env is not available from the _host,
  635. // skip the _host and proceed to process the rest of the hosts.
  636. console.log("last_agent_env is missing for " + _host.Hosts.host_name + ". Skipping _host check.");
  637. return;
  638. }
  639. //parse all directories and files warnings for host
  640. //todo: to be removed after check in new API
  641. var stackFoldersAndFiles = _host.Hosts.last_agent_env.stackFoldersAndFiles || _host.Hosts.last_agent_env.paths;
  642. stackFoldersAndFiles.forEach(function (path) {
  643. warning = warnings.filterProperty('category', 'fileFolders').findProperty('name', path.name);
  644. if (warning) {
  645. warning.hosts.push(_host.Hosts.host_name);
  646. warning.onSingleHost = false;
  647. } else {
  648. warning = {
  649. name: path.name,
  650. hosts: [_host.Hosts.host_name],
  651. category: 'fileFolders',
  652. onSingleHost: true
  653. }
  654. warnings.push(warning);
  655. }
  656. host.warnings.push(warning);
  657. }, this);
  658. //parse all package warnings for host
  659. _host.Hosts.last_agent_env.installedPackages.forEach(function (_package) {
  660. warning = warnings.filterProperty('category', 'packages').findProperty('name', _package.name);
  661. if (warning) {
  662. warning.hosts.push(_host.Hosts.host_name);
  663. warning.version = _package.version,
  664. warning.onSingleHost = false;
  665. } else {
  666. warning = {
  667. name: _package.name,
  668. version: _package.version,
  669. hosts: [_host.Hosts.host_name],
  670. category: 'packages',
  671. onSingleHost: true
  672. }
  673. warnings.push(warning);
  674. }
  675. host.warnings.push(warning);
  676. }, this);
  677. //parse all process warnings for host
  678. //todo: to be removed after check in new API
  679. var javaProcs = _host.Hosts.last_agent_env.hostHealth ? _host.Hosts.last_agent_env.hostHealth.activeJavaProcs : _host.Hosts.last_agent_env.javaProcs;
  680. javaProcs.forEach(function (process) {
  681. warning = warnings.filterProperty('category', 'processes').findProperty('pid', process.pid);
  682. if (warning) {
  683. warning.hosts.push(_host.Hosts.host_name);
  684. warning.onSingleHost = false;
  685. } else {
  686. warning = {
  687. name: (process.command.substr(0, 35) + '...'),
  688. hosts: [_host.Hosts.host_name],
  689. category: 'processes',
  690. user: process.user,
  691. pid: process.pid,
  692. command: '<table><tr><td style="word-break: break-all;">' +
  693. ((process.command.length < 500) ? process.command : process.command.substr(0, 230) + '...' +
  694. '<p style="text-align: center">................</p>' +
  695. '...' + process.command.substr(-230)) + '</td></tr></table>',
  696. onSingleHost: true
  697. }
  698. warnings.push(warning);
  699. }
  700. host.warnings.push(warning);
  701. }, this);
  702. //parse all service warnings for host
  703. //todo: to be removed after check in new API
  704. if (_host.Hosts.last_agent_env.hostHealth && _host.Hosts.last_agent_env.hostHealth.liveServices) {
  705. _host.Hosts.last_agent_env.hostHealth.liveServices.forEach(function (service) {
  706. if (service.status === 'Unhealthy') {
  707. warning = warnings.filterProperty('category', 'services').findProperty('name', service.name);
  708. if (warning) {
  709. warning.hosts.push(_host.Hosts.host_name);
  710. warning.onSingleHost = false;
  711. } else {
  712. warning = {
  713. name: service.name,
  714. hosts: [_host.Hosts.host_name],
  715. category: 'services',
  716. onSingleHost: true
  717. }
  718. warnings.push(warning);
  719. }
  720. host.warnings.push(warning);
  721. }
  722. }, this);
  723. }
  724. //parse all user warnings for host
  725. //todo: to be removed after check in new API
  726. if (_host.Hosts.last_agent_env.existingUsers) {
  727. _host.Hosts.last_agent_env.existingUsers.forEach(function (user) {
  728. warning = warnings.filterProperty('category', 'users').findProperty('name', user.userName);
  729. if (warning) {
  730. warning.hosts.push(_host.Hosts.host_name);
  731. warning.onSingleHost = false;
  732. } else {
  733. warning = {
  734. name: user.userName,
  735. hosts: [_host.Hosts.host_name],
  736. category: 'users',
  737. onSingleHost: true
  738. }
  739. warnings.push(warning);
  740. }
  741. host.warnings.push(warning);
  742. }, this);
  743. }
  744. //parse misc warnings for host
  745. var umask = _host.Hosts.last_agent_env.umask;
  746. if (umask && umask !== 18) {
  747. warning = warnings.filterProperty('category', 'misc').findProperty('name', umask);
  748. if (warning) {
  749. warning.hosts.push(_host.Hosts.host_name);
  750. warning.onSingleHost = false;
  751. } else {
  752. warning = {
  753. name: umask,
  754. hosts: [_host.Hosts.host_name],
  755. category: 'misc',
  756. onSingleHost: true
  757. }
  758. warnings.push(warning);
  759. }
  760. host.warnings.push(warning);
  761. }
  762. hosts.push(host);
  763. }, this);
  764. warnings.forEach(function (warn) {
  765. if (warn.hosts.length < 11) {
  766. warn.hostsList = warn.hosts.join('<br>')
  767. } else {
  768. warn.hostsList = warn.hosts.slice(0,10).join('<br>') + '<br> ' + Em.I18n.t('installer.step3.hostWarningsPopup.moreHosts').format(warn.hosts.length - 10);
  769. }
  770. });
  771. hosts.unshift({
  772. name: 'All Hosts',
  773. warnings: warnings
  774. });
  775. this.set('warnings', warnings);
  776. this.set('warningsByHost', hosts);
  777. },
  778. /**
  779. * open popup that contain hosts' warnings
  780. * @param event
  781. */
  782. hostWarningsPopup: function(event){
  783. var self = this;
  784. App.ModalPopup.show({
  785. header: Em.I18n.t('installer.step3.warnings.popup.header'),
  786. secondary: Em.I18n.t('installer.step3.hostWarningsPopup.rerunChecks'),
  787. primary: Em.I18n.t('common.close'),
  788. onPrimary: function () {
  789. self.set('checksUpdateStatus', null);
  790. this.hide();
  791. },
  792. onClose: function(){
  793. self.set('checksUpdateStatus', null);
  794. this.hide();
  795. },
  796. onSecondary: function() {
  797. self.rerunChecks();
  798. },
  799. didInsertElement: function () {
  800. this.fitHeight();
  801. },
  802. footerClass: Ember.View.extend({
  803. template: Ember.Handlebars.compile([
  804. '<div class="update-progress pull-left">',
  805. '{{#if view.isUpdateInProgress}}',
  806. '<div class="progress-info active progress">',
  807. '<div class="bar" {{bindAttr style="view.progressWidth"}}></div></div>',
  808. '{{else}}<label {{bindAttr class="view.updateStatusClass"}}>{{view.updateStatus}}</label>',
  809. '{{/if}}</div>',
  810. '{{#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}}',
  811. '{{#if view.parentView.primary}}<button type="button" class="btn" {{action onPrimary target="view.parentView"}}>{{view.parentView.primary}}</button>{{/if}}'
  812. ].join('')),
  813. classNames: ['modal-footer', 'host-checks-update'],
  814. progressWidth: function(){
  815. return 'width:'+App.router.get('wizardStep3Controller.checksUpdateProgress')+'%';
  816. }.property('App.router.wizardStep3Controller.checksUpdateProgress'),
  817. isUpdateInProgress: function(){
  818. if((App.router.get('wizardStep3Controller.checksUpdateProgress') > 0) &&
  819. (App.router.get('wizardStep3Controller.checksUpdateProgress') < 100)){
  820. return true;
  821. }
  822. }.property('App.router.wizardStep3Controller.checksUpdateProgress'),
  823. updateStatusClass:function(){
  824. var status = App.router.get('wizardStep3Controller.checksUpdateStatus');
  825. if(status === 'SUCCESS'){
  826. return 'text-success';
  827. } else if(status === 'FAILED'){
  828. return 'text-error';
  829. } else {
  830. return null;
  831. }
  832. }.property('App.router.wizardStep3Controller.checksUpdateStatus'),
  833. updateStatus:function(){
  834. var status = App.router.get('wizardStep3Controller.checksUpdateStatus');
  835. if(status === 'SUCCESS'){
  836. return Em.I18n.t('installer.step3.warnings.updateChecks.success');
  837. } else if(status === 'FAILED'){
  838. return Em.I18n.t('installer.step3.warnings.updateChecks.failed');
  839. } else {
  840. return null;
  841. }
  842. }.property('App.router.wizardStep3Controller.checksUpdateStatus')
  843. }),
  844. bodyClass: Ember.View.extend({
  845. templateName: require('templates/wizard/step3_host_warnings_popup'),
  846. classNames: ['host-check'],
  847. didInsertElement: function () {
  848. Ember.run.next(this, function () {
  849. this.$("[rel='HostsListTooltip']").tooltip({html: true, placement: "right"});
  850. this.$('#process .warning-name').tooltip({html: true, placement: "top"});
  851. })
  852. }.observes('content'),
  853. warningsByHost: function () {
  854. return App.router.get('wizardStep3Controller.warningsByHost');
  855. }.property('App.router.wizardStep3Controller.warningsByHost'),
  856. warnings: function () {
  857. return App.router.get('wizardStep3Controller.warnings');
  858. }.property('App.router.wizardStep3Controller.warnings'),
  859. categories: function () {
  860. return this.get('warningsByHost').mapProperty('name');
  861. }.property('warningsByHost'),
  862. category: 'All Hosts',
  863. categoryWarnings: function () {
  864. return this.get('warningsByHost').findProperty('name', this.get('category')).warnings
  865. }.property('warningsByHost', 'category'),
  866. content: function () {
  867. var categoryWarnings = this.get('categoryWarnings');
  868. return [
  869. Ember.Object.create({
  870. warnings: categoryWarnings.filterProperty('category', 'processes'),
  871. title: Em.I18n.t('installer.step3.hostWarningsPopup.process'),
  872. message: Em.I18n.t('installer.step3.hostWarningsPopup.processes.message'),
  873. type: Em.I18n.t('common.process'),
  874. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.processes'),
  875. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.running'),
  876. category: 'process'
  877. }),
  878. Ember.Object.create({
  879. warnings: categoryWarnings.filterProperty('category', 'packages'),
  880. title: Em.I18n.t('installer.step3.hostWarningsPopup.package'),
  881. message: Em.I18n.t('installer.step3.hostWarningsPopup.packages.message'),
  882. type: Em.I18n.t('common.package'),
  883. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.packages'),
  884. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.installed'),
  885. category: 'package'
  886. }),
  887. Ember.Object.create({
  888. warnings: categoryWarnings.filterProperty('category', 'fileFolders'),
  889. title: Em.I18n.t('installer.step3.hostWarningsPopup.fileAndFolder'),
  890. message: Em.I18n.t('installer.step3.hostWarningsPopup.fileFolders.message'),
  891. type: Em.I18n.t('common.path'),
  892. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.filesAndFolders'),
  893. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  894. category: 'fileFolders'
  895. }),
  896. Ember.Object.create({
  897. warnings: categoryWarnings.filterProperty('category', 'services'),
  898. title: Em.I18n.t('installer.step3.hostWarningsPopup.service'),
  899. message: Em.I18n.t('installer.step3.hostWarningsPopup.services.message'),
  900. type: Em.I18n.t('common.service'),
  901. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.services'),
  902. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.notRunning'),
  903. category: 'service'
  904. }),
  905. Ember.Object.create({
  906. warnings: categoryWarnings.filterProperty('category', 'users'),
  907. title: Em.I18n.t('installer.step3.hostWarningsPopup.user'),
  908. message: Em.I18n.t('installer.step3.hostWarningsPopup.users.message'),
  909. type: Em.I18n.t('common.user'),
  910. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.users'),
  911. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  912. category: 'user'
  913. }),
  914. Ember.Object.create({
  915. warnings: categoryWarnings.filterProperty('category', 'misc'),
  916. title: Em.I18n.t('installer.step3.hostWarningsPopup.misc'),
  917. message: Em.I18n.t('installer.step3.hostWarningsPopup.misc.message'),
  918. type: Em.I18n.t('installer.step3.hostWarningsPopup.misc.umask'),
  919. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.misc'),
  920. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  921. category: 'misc'
  922. })
  923. ]
  924. }.property('category', 'warningsByHost'),
  925. showHostsPopup: function (hosts) {
  926. $('.tooltip').hide();
  927. App.ModalPopup.show({
  928. header: Em.I18n.t('installer.step3.hostWarningsPopup.allHosts'),
  929. bodyClass: Ember.View.extend({
  930. hosts: hosts.context,
  931. template: Ember.Handlebars.compile('<ul>{{#each host in view.hosts}}<li>{{host}}</li>{{/each}}</ul>')
  932. }),
  933. onPrimary: function () {
  934. this.hide();
  935. },
  936. secondary: null
  937. });
  938. },
  939. onToggleBlock: function (category) {
  940. this.$('#' + category.context.category).toggle('blind', 500);
  941. },
  942. warningsNotice: function () {
  943. var warnings = this.get('warnings');
  944. var warningsByHost = self.get('warningsByHost').slice();
  945. warningsByHost.shift();
  946. var issues = warnings.length + ' ' + (warnings.length === 1 ? Em.I18n.t('installer.step3.hostWarningsPopup.issue') : Em.I18n.t('installer.step3.hostWarningsPopup.issues'));
  947. var hostsNumber = warningsByHost.length - warningsByHost.filterProperty('warnings.length', 0).length;
  948. var hosts = hostsNumber + ' ' + (hostsNumber === 1 ? Em.I18n.t('installer.step3.hostWarningsPopup.host') : Em.I18n.t('installer.step3.hostWarningsPopup.hosts'));
  949. return Em.I18n.t('installer.step3.hostWarningsPopup.summary').format(issues, hosts);
  950. }.property('warnings', 'warningsByHost'),
  951. /**
  952. * generate detailed content to show it in new window
  953. */
  954. contentInDetails: function () {
  955. var content = this.get('content');
  956. var warningsByHost = this.get('warningsByHost').slice();
  957. warningsByHost.shift();
  958. var newContent = '';
  959. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.header') + new Date;
  960. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.hosts');
  961. newContent += warningsByHost.filterProperty('warnings.length').mapProperty('name').join(' ');
  962. if (content.findProperty('category', 'fileFolders').warnings.length) {
  963. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.fileFolders');
  964. newContent += content.findProperty('category', 'fileFolders').warnings.mapProperty('name').join(' ');
  965. }
  966. if (content.findProperty('category', 'process').warnings.length) {
  967. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.process');
  968. content.findProperty('category', 'process').warnings.forEach(function (process, i) {
  969. process.hosts.forEach(function (host, j) {
  970. if (!!i || !!j) {
  971. newContent += ',';
  972. }
  973. newContent += '(' + host + ',' + process.user + ',' + process.pid + ')';
  974. });
  975. });
  976. }
  977. if (content.findProperty('category', 'package').warnings.length) {
  978. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.package');
  979. newContent += content.findProperty('category', 'package').warnings.mapProperty('name').join(' ');
  980. }
  981. if (content.findProperty('category', 'service').warnings.length) {
  982. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.service');
  983. newContent += content.findProperty('category', 'service').warnings.mapProperty('name').join(' ');
  984. }
  985. if (content.findProperty('category', 'user').warnings.length) {
  986. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.user');
  987. newContent += content.findProperty('category', 'user').warnings.mapProperty('name').join(' ');
  988. }
  989. newContent += '</p>';
  990. return newContent;
  991. }.property('content', 'warningsByHost'),
  992. /**
  993. * open new browser tab with detailed content
  994. */
  995. openWarningsInDialog: function(){
  996. var newWindow = window.open('');
  997. var newDocument = newWindow.document;
  998. newDocument.write(this.get('contentInDetails'));
  999. newWindow.focus();
  1000. }
  1001. })
  1002. })
  1003. },
  1004. back: function () {
  1005. if (this.get('isInstallInProgress')) {
  1006. return;
  1007. }
  1008. App.router.send('back');
  1009. }
  1010. });