step3_controller.js 41 KB

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