step3_controller.js 42 KB

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