step3_controller.js 35 KB

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