step3_controller.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  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. // TODO - Remove when correct parsing code in place.
  629. if (!_host.Hosts.last_agent_env.paths) {
  630. return;
  631. }
  632. //parse all directories and files warnings for host
  633. //todo: to be removed after check in new API
  634. var stackFoldersAndFiles = _host.Hosts.last_agent_env.stackFoldersAndFiles || _host.Hosts.last_agent_env.paths;
  635. stackFoldersAndFiles.forEach(function (path) {
  636. //todo: to be removed after check in new API
  637. if (path.type === 'not_exist') {
  638. warning = warnings.findProperty('name', path.name);
  639. if (warning) {
  640. warning.hosts.push(_host.Hosts.host_name);
  641. warning.onSingleHost = false;
  642. } else {
  643. warning = {
  644. name: path.name,
  645. hosts: [_host.Hosts.host_name],
  646. category: 'fileFolders',
  647. onSingleHost: true
  648. }
  649. warnings.push(warning);
  650. }
  651. host.warnings.push(warning);
  652. }
  653. }, this);
  654. //parse all package warnings for host
  655. _host.Hosts.last_agent_env.rpms.forEach(function (_package) {
  656. //todo: to be removed after check in new API
  657. if (_package.installed) {
  658. warning = warnings.findProperty('name', _package.name);
  659. if (warning) {
  660. warning.hosts.push(_host.Hosts.host_name);
  661. warning.onSingleHost = false;
  662. } else {
  663. warning = {
  664. name: _package.name,
  665. hosts: [_host.Hosts.host_name],
  666. category: 'packages',
  667. onSingleHost: true
  668. }
  669. warnings.push(warning);
  670. }
  671. host.warnings.push(warning);
  672. }
  673. }, this);
  674. //parse all process warnings for host
  675. //todo: to be removed after check in new API
  676. var javaProcs = _host.Hosts.last_agent_env.hostHealth ? _host.Hosts.last_agent_env.hostHealth.activeJavaProcs : _host.Hosts.last_agent_env.javaProcs;
  677. javaProcs.forEach(function (process) {
  678. //todo: to be removed after check in new API
  679. if (process.hadoop) {
  680. warning = warnings.findProperty('name', (process.command.substr(0, 15) + '...'));
  681. if (warning) {
  682. warning.hosts.push(_host.Hosts.host_name);
  683. warning.onSingleHost = false;
  684. } else {
  685. warning = {
  686. name: (process.command.substr(0, 15) + '...'),
  687. hosts: [_host.Hosts.host_name],
  688. category: 'processes',
  689. user: process.user,
  690. pid: process.pid,
  691. command: process.command,
  692. onSingleHost: true
  693. }
  694. warnings.push(warning);
  695. }
  696. host.warnings.push(warning);
  697. }
  698. }, this);
  699. //parse all service warnings for host
  700. //todo: to be removed after check in new API
  701. if (_host.Hosts.last_agent_env.hostHealth && _host.Hosts.last_agent_env.hostHealth.liveServices) {
  702. _host.Hosts.last_agent_env.hostHealth.liveServices.forEach(function (service) {
  703. if (service.status === 'Healthy') {
  704. warning = warnings.findProperty('name', service.name);
  705. if (warning) {
  706. warning.hosts.push(_host.Hosts.host_name);
  707. warning.onSingleHost = false;
  708. } else {
  709. warning = {
  710. name: service.name,
  711. hosts: [_host.Hosts.host_name],
  712. category: 'services',
  713. onSingleHost: true
  714. }
  715. warnings.push(warning);
  716. }
  717. host.warnings.push(warning);
  718. }
  719. }, this);
  720. }
  721. //parse all user warnings for host
  722. //todo: to be removed after check in new API
  723. if (_host.Hosts.last_agent_env.existingUsers) {
  724. _host.Hosts.last_agent_env.existingUsers.forEach(function (user) {
  725. warning = warnings.findProperty('name', user.userName);
  726. if (warning) {
  727. warning.hosts.push(_host.Hosts.host_name);
  728. warning.onSingleHost = false;
  729. } else {
  730. warning = {
  731. name: user.userName,
  732. hosts: [_host.Hosts.host_name],
  733. category: 'users',
  734. onSingleHost: true
  735. }
  736. warnings.push(warning);
  737. }
  738. host.warnings.push(warning);
  739. }, this);
  740. }
  741. hosts.push(host);
  742. }, this);
  743. hosts.unshift({
  744. name: 'All Hosts',
  745. warnings: warnings
  746. });
  747. this.set('warnings', warnings);
  748. this.set('warningsByHost', hosts);
  749. },
  750. /**
  751. * open popup that contain hosts' warnings
  752. * @param event
  753. */
  754. hostWarningsPopup: function(event){
  755. var self = this;
  756. App.ModalPopup.show({
  757. header: Em.I18n.t('installer.step3.warnings.popup.header'),
  758. secondary: Em.I18n.t('installer.step3.hostWarningsPopup.rerunChecks'),
  759. primary: Em.I18n.t('common.close'),
  760. onPrimary: function () {
  761. self.set('checksUpdateStatus', null);
  762. this.hide();
  763. },
  764. onClose: function(){
  765. self.set('checksUpdateStatus', null);
  766. this.hide();
  767. },
  768. onSecondary: function() {
  769. self.rerunChecks();
  770. },
  771. footerClass: Ember.View.extend({
  772. template: Ember.Handlebars.compile([
  773. '<div class="update-progress pull-left">',
  774. '{{#if view.isUpdateInProgress}}',
  775. '<div class="progress-info active progress">',
  776. '<div class="bar" {{bindAttr style="view.progressWidth"}}></div></div>',
  777. '{{else}}<label {{bindAttr class="view.updateStatusClass"}}>{{view.updateStatus}}</label>',
  778. '{{/if}}</div>',
  779. '{{#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}}',
  780. '{{#if view.parentView.primary}}<button type="button" class="btn" {{action onPrimary target="view.parentView"}}>{{view.parentView.primary}}</button>{{/if}}'
  781. ].join('')),
  782. classNames: ['modal-footer', 'host-checks-update'],
  783. progressWidth: function(){
  784. return 'width:'+App.router.get('wizardStep3Controller.checksUpdateProgress')+'%';
  785. }.property('App.router.wizardStep3Controller.checksUpdateProgress'),
  786. isUpdateInProgress: function(){
  787. if((App.router.get('wizardStep3Controller.checksUpdateProgress') > 0) &&
  788. (App.router.get('wizardStep3Controller.checksUpdateProgress') < 100)){
  789. return true;
  790. }
  791. }.property('App.router.wizardStep3Controller.checksUpdateProgress'),
  792. updateStatusClass:function(){
  793. var status = App.router.get('wizardStep3Controller.checksUpdateStatus');
  794. if(status === 'SUCCESS'){
  795. return 'text-success';
  796. } else if(status === 'FAILED'){
  797. return 'text-error';
  798. } else {
  799. return null;
  800. }
  801. }.property('App.router.wizardStep3Controller.checksUpdateStatus'),
  802. updateStatus:function(){
  803. var status = App.router.get('wizardStep3Controller.checksUpdateStatus');
  804. if(status === 'SUCCESS'){
  805. return Em.I18n.t('installer.step3.warnings.updateChecks.success');
  806. } else if(status === 'FAILED'){
  807. return Em.I18n.t('installer.step3.warnings.updateChecks.failed');
  808. } else {
  809. return null;
  810. }
  811. }.property('App.router.wizardStep3Controller.checksUpdateStatus')
  812. }),
  813. bodyClass: Ember.View.extend({
  814. templateName: require('templates/wizard/step3_host_warnings_popup'),
  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. return [
  828. {
  829. warnings: categoryWarnings.filterProperty('category', 'processes'),
  830. title: Em.I18n.t('installer.step3.hostWarningsPopup.processes'),
  831. message: Em.I18n.t('installer.step3.hostWarningsPopup.processes.message'),
  832. type: Em.I18n.t('common.process')
  833. },
  834. {
  835. warnings: categoryWarnings.filterProperty('category', 'packages'),
  836. title: Em.I18n.t('installer.step3.hostWarningsPopup.packages'),
  837. message: Em.I18n.t('installer.step3.hostWarningsPopup.packages.message'),
  838. type: Em.I18n.t('common.package')
  839. },
  840. {
  841. warnings: categoryWarnings.filterProperty('category', 'fileFolders'),
  842. title: Em.I18n.t('installer.step3.hostWarningsPopup.fileFolders'),
  843. message: Em.I18n.t('installer.step3.hostWarningsPopup.fileFolders.message'),
  844. type: Em.I18n.t('common.path')
  845. },
  846. {
  847. warnings: categoryWarnings.filterProperty('category', 'services'),
  848. title: Em.I18n.t('installer.step3.hostWarningsPopup.services'),
  849. message: Em.I18n.t('installer.step3.hostWarningsPopup.services.message'),
  850. type: Em.I18n.t('common.service')
  851. },
  852. {
  853. warnings: categoryWarnings.filterProperty('category', 'users'),
  854. title: Em.I18n.t('installer.step3.hostWarningsPopup.users'),
  855. message: Em.I18n.t('installer.step3.hostWarningsPopup.users.message'),
  856. type: Em.I18n.t('common.user')
  857. }
  858. ]
  859. }.property('category', 'warningsByHost'),
  860. warningsSummary: function () {
  861. var warnings = this.get('warnings');
  862. var warningsByHost = self.get('warningsByHost').slice();
  863. warningsByHost.shift();
  864. return Em.I18n.t('installer.step3.hostWarningsPopup.summary').format(warnings.length, warningsByHost.length - warningsByHost.filterProperty('warnings.length', 0).length);
  865. }.property('warnings', 'warningsByHost'),
  866. /**
  867. * generate detailed content to show it in new window
  868. */
  869. contentInDetails: function(){
  870. var content = this.get('content');
  871. var newContent = '';
  872. if(content.hostName == 'All Hosts'){
  873. newContent += '<h4>'+Em.I18n.t('installer.step3.warningsWindow.allHosts')+'</h4>';
  874. } else {
  875. newContent += '<h4>' + Em.I18n.t('installer.step3.warningsWindow.warningsOn') + content.hostName + '</h4>';
  876. }
  877. newContent += '<div>' + Em.I18n.t('installer.step3.warningsWindow.directoriesAndFiles') + '</div><div>';
  878. content.directoriesFiles.filterProperty('isWarn', true).forEach(function(path){
  879. newContent += path.name + '&nbsp;'
  880. });
  881. if(content.directoriesFiles.filterProperty('isWarn', true).length == 0){
  882. newContent += Em.I18n.t('installer.step3.warningsWindow.noWarnings');
  883. }
  884. newContent += '</div><br/><div>PACKAGES</div><div>';
  885. content.packages.filterProperty('isWarn', true).forEach(function(_package){
  886. newContent += _package.name + '&nbsp;'
  887. });
  888. if(content.packages.filterProperty('isWarn', true).length == 0){
  889. newContent += Em.I18n.t('installer.step3.warningsWindow.noWarnings');
  890. }
  891. newContent += '</div><br/><div>PROCESSES</div><div>';
  892. content.processes.filterProperty('isWarn', true).forEach(function(process, index){
  893. newContent += '(' + content.hostName + ',' + process.pid + ',' + process.user + ')';
  894. newContent += (index != (content.processes.filterProperty('isWarn', true).length-1)) ? ',' : '';
  895. })
  896. if(content.processes.filterProperty('isWarn', true).length == 0){
  897. newContent += Em.I18n.t('installer.step3.warningsWindow.noWarnings');
  898. }
  899. return newContent;
  900. }.property('content'),
  901. /**
  902. * open new browser tab with detailed content
  903. */
  904. openWarningsInDialog: function(){
  905. var newWindow = window.open('', this.get('category')+' warnings');
  906. var newDocument = newWindow.document;
  907. newDocument.write(this.get('contentInDetails'));
  908. newWindow.focus();
  909. }
  910. })
  911. })
  912. },
  913. back: function () {
  914. if (this.get('isInstallInProgress')) {
  915. return;
  916. }
  917. App.router.send('back');
  918. }
  919. });