| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935 |
1
1
1
1
1
1
31
4
4
4
4
2
4
2
7
5
2
1
3
3
3
3
9
9
9
9
9
9
9
9
9
9
4
4
4
4
4
4
8
8
8
4
4
4
4
4
4
4
4
4
4
4
4
3
3
3
3
3
4
4
3
3
9
27
27
4
4
9
2
2
1
1
1
1
1
1
1
1
1
1
1
6
6
6
6
6
6
6
6
1
5
2
1
1
1
1
1
2
2
2
2
8
8
8
10
6
6
8
22
264
22
154
6
4
2
1
1
1
3
2
2
7
1
6
5
5
5
5
5
5
5
5
1
1
1
1
1
3
1
1
2
3
1
1
5
1
4
3
3
3
1
1
1
1
31
7
7
7
7
14
5
7
4
4
3
3
1
1
1
1
1
1
3
1
3
2
1
1
3
3
2
2
1
1
1
2
1
1
2
1
3
1
1
1
1
1
1
1
2
1
1
1
1
2
2
3
3
3
2
1
1
1
1
4
4
1
1
1
1
1
2
2
1
1
| 'use strict';
;require.register("controllers/wizard/step3_controller", function (exports, require, module) {
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var App = require('app');
var lazyloading = require('utils/lazy_loading');
var numberUtils = require('utils/number_utils');
App.WizardStep3Controller = Em.Controller.extend(App.ReloadPopupMixin, App.CheckHostMixin, {
name: 'wizardStep3Controller',
hosts: [],
content: [],
registeredHosts: [],
jdkRequestIndex: null,
registrationStartedAt: null,
/**
* Timeout for registration
* Based on <code>installOptions.manualInstall</code>
* @type {number}
*/
registrationTimeoutSecs: Em.computed.ifThenElse('content.installOptions.manualInstall', 15, 120),
/**
* Bootstrap calls are stopped
* @type {bool}
*/
stopBootstrap: false,
/**
* is Submit button disabled
* @type {bool}
*/
isSubmitDisabled: true,
/**
* True if bootstrap POST request failed
* @type {bool}
*/
isBootstrapFailed: false,
/**
* is Retry button disabled
* @type {bool}
*/
isRetryDisabled: function () {
return this.get('isBackDisabled') ? this.get('isBackDisabled') : !this.get('bootHosts').filterProperty('bootStatus', 'FAILED').length;
}.property('bootHosts.@each.bootStatus', 'isBackDisabled'),
/**
* Is Back button disabled
* @return {bool}
*/
isBackDisabled: function () {
return (this.get('isRegistrationInProgress') || !this.get('isWarningsLoaded')) && !this.get('isBootstrapFailed') || App.get('router.btnClickInProgress');
}.property('isRegistrationInProgress', 'isWarningsLoaded', 'isBootstrapFailed'),
/**
* Controller is using in Add Host Wizard
* @return {bool}
*/
isAddHostWizard: Em.computed.equal('content.controllerName', 'addHostController'),
/**
* @type {bool}
*/
isLoaded: false,
/**
* Polls count
* @type {number}
*/
numPolls: 0,
/**
* Is hosts registration in progress
* @type {bool}
*/
isRegistrationInProgress: true,
/**
* Are some registered hosts which are not added by user
* @type {bool}
*/
hasMoreRegisteredHosts: false,
/**
* List of installed hostnames
* @type {string[]}
*/
hostsInCluster: function () {
var installedHostsName = [];
var hosts = this.get('content.hosts');
for (var hostName in hosts) {
if (hosts[hostName].isInstalled) {
installedHostsName.push(hostName);
}
}
return installedHostsName;
}.property('content.hosts'),
/**
* Are hosts warnings loaded
* @type {bool}
*/
isWarningsLoaded: Em.computed.and('isJDKWarningsLoaded', 'isHostsWarningsLoaded'),
/**
* Check are hosts have any warnings
* @type {bool}
*/
isHostHaveWarnings: Em.computed.gt('warnings.length', 0),
/**
* Should warnings-box be visible
* @type {bool}
*/
isWarningsBoxVisible: function () {
return App.get('testMode') ? true : !this.get('isRegistrationInProgress');
}.property('isRegistrationInProgress'),
isNextButtonDisabled: Em.computed.or('App.router.btnClickInProgress', 'isSubmitDisabled'),
isBackButtonDisabled: Em.computed.or('App.router.btnClickInProgress', 'isBackDisabled'),
/**
*
* @method navigateStep
*/
navigateStep: function () {
if (this.get('isLoaded')) {
if (!this.get('content.installOptions.manualInstall')) {
if (!this.get('wizardController').getDBProperty('bootStatus')) {
this.setupBootStrap();
}
} else {
this.set('bootHosts', this.get('hosts'));
Iif (App.get('testMode')) {
this.startHostcheck(this.get('hosts'));
this.get('bootHosts').setEach('cpu', '2');
this.get('bootHosts').setEach('memory', '2000000');
this.set('isSubmitDisabled', false);
} else {
this.set('registrationStartedAt', null);
this.startRegistration();
}
}
}
}.observes('isLoaded'),
/**
* Clear controller data
* @method clearStep
*/
clearStep: function clearStep() {
this.set('stopBootstrap', false);
this.set('hosts', []);
this.get('bootHosts').clear();
this.get('wizardController').setDBProperty('bootStatus', false);
this.set('isHostsWarningsLoaded', false);
this.set('isJDKWarningsLoaded', false);
this.set('registrationStartedAt', null);
this.set('isLoaded', false);
this.set('isSubmitDisabled', true);
this.set('stopChecking', false);
},
/**
* setup bootstrap data and completion callback for bootstrap call
* @method setupBootStrap
*/
setupBootStrap: function setupBootStrap() {
var self = this;
var bootStrapData = JSON.stringify({
'verbose': true,
'sshKey': this.get('content.installOptions.sshKey'),
'hosts': this.getBootstrapHosts(),
'user': this.get('content.installOptions.sshUser'),
'sshPort': this.get('content.installOptions.sshPort'),
'userRunAs': App.get('supports.customizeAgentUserAccount') ? this.get('content.installOptions.agentUser') : 'root'
});
App.router.get(this.get('content.controllerName')).launchBootstrap(bootStrapData, function (requestId) {
if (requestId == '0') {
self.startBootstrap();
} else if (requestId) {
self.set('content.installOptions.bootRequestId', requestId);
App.router.get(self.get('content.controllerName')).save('installOptions');
self.startBootstrap();
}
});
},
getBootstrapHosts: function getBootstrapHosts() {
var hosts = this.get('content.hosts');
var bootstrapHosts = [];
for (var host in hosts) {
Eif (hosts.hasOwnProperty(host)) {
Eif (!hosts[host].isInstalled) {
bootstrapHosts.push(host);
}
}
}
return bootstrapHosts;
},
/**
* Make basic init steps
* @method loadStep
*/
loadStep: function loadStep() {
var wizardController = this.get('wizardController');
var previousStep = wizardController && wizardController.get('previousStep');
var currentStep = wizardController && wizardController.get('currentStep');
var isHostsLoaded = this.get('hosts').length !== 0;
var isPrevAndCurrStepsSetted = previousStep && currentStep;
var isPrevStepSmallerThenCurrent = previousStep < currentStep;
Eif (!isHostsLoaded || isPrevStepSmallerThenCurrent || !wizardController || !isPrevAndCurrStepsSetted) {
this.disablePreviousSteps();
this.clearStep();
App.router.get('clusterController').loadAmbariProperties();
this.loadHosts();
}
},
/**
* Loads the hostinfo from localStorage on the insertion of view. It's being called from view
* @method loadHosts
*/
loadHosts: function loadHosts() {
var hostsInfo = this.get('content.hosts');
var hosts = [];
var bootStatus = this.get('content.installOptions.manualInstall') ? 'DONE' : 'PENDING';
Iif (App.get('testMode')) {
bootStatus = 'REGISTERED';
}
for (var index in hostsInfo) {
Eif (hostsInfo.hasOwnProperty(index) && !hostsInfo[index].isInstalled) {
hosts.pushObject(App.HostInfo.create({
name: hostsInfo[index].name,
bootStatus: bootStatus,
isChecked: false
}));
}
}
this.set('hosts', hosts);
this.set('isLoaded', true);
},
/**
* Parses and updates the content based on bootstrap API response.
* @return {bool} true if polling should continue (some hosts are in "RUNNING" state); false otherwise
* @method parseHostInfo
*/
parseHostInfo: function parseHostInfo(hostsStatusFromServer) {
hostsStatusFromServer.forEach(function (_hostStatus) {
var host = this.get('bootHosts').findProperty('name', _hostStatus.hostName);
// check if hostname extracted from REST API data matches any hostname in content
// also, make sure that bootStatus modified by isHostsRegistered call does not get overwritten
// since these calls are being made in parallel
if (host && !['REGISTERED', 'REGISTERING'].contains(host.get('bootStatus'))) {
host.set('bootStatus', _hostStatus.status);
host.set('bootLog', _hostStatus.log);
}
}, this);
// if the data rendered by REST API has hosts in "RUNNING" state, polling will continue
return this.get('bootHosts').length != 0 && this.get('bootHosts').someProperty('bootStatus', 'RUNNING');
},
/**
* Remove list of hosts
* @param {Ember.Enumerable} hosts
* @return {App.ModalPopup}
* @method removeHosts
*/
removeHosts: function removeHosts(hosts) {
var self = this;
return App.showConfirmationPopup(function () {
App.router.send('removeHosts', hosts);
self.hosts.removeObjects(hosts);
self.stopRegistration();
Eif (!self.hosts.length) {
self.set('isSubmitDisabled', true);
}
}, Em.I18n.t('installer.step3.hosts.remove.popup.body'));
},
/**
* Removes a single element on the trash icon click. Called from View
* @param {object} hostInfo
* @method removeHost
*/
removeHost: function removeHost(hostInfo) {
if (!this.get('isBackDisabled')) this.removeHosts([hostInfo]);
},
/**
* Remove selected hosts (click-handler)
* @return App.ModalPopup
* @method removeSelectedHosts
*/
removeSelectedHosts: function removeSelectedHosts() {
var selectedHosts = this.get('hosts').filterProperty('isChecked', true);
return this.removeHosts(selectedHosts);
},
/**
* Show popup with the list of hosts which are selected
* @return App.ModalPopup
* @method selectedHostsPopup
*/
selectedHostsPopup: function selectedHostsPopup() {
var selectedHosts = this.get('hosts').filterProperty('isChecked').mapProperty('name');
return App.ModalPopup.show({
header: Em.I18n.t('installer.step3.selectedHosts.popup.header'),
secondary: null,
bodyClass: Em.View.extend({
templateName: require('templates/common/items_list_popup'),
items: selectedHosts,
insertedItems: [],
didInsertElement: function didInsertElement() {
lazyloading.run({
destination: this.get('insertedItems'),
source: this.get('items'),
context: this,
initSize: 100,
chunkSize: 500,
delay: 100
});
}
})
});
},
/**
* Retry one host {click-handler}
* @param {object} hostInfo
* @method retryHost
*/
retryHost: function retryHost(hostInfo) {
this.retryHosts([hostInfo]);
},
/**
* Retry list of hosts
* @param {object[]} hosts
* @method retryHosts
*/
retryHosts: function retryHosts(hosts) {
var self = this;
var bootStrapData = JSON.stringify({
'verbose': true,
'sshKey': this.get('content.installOptions.sshKey'),
'hosts': hosts.mapProperty('name'),
'user': this.get('content.installOptions.sshUser'),
'sshPort': this.get('content.installOptions.sshPort'),
'userRunAs': App.get('supports.customizeAgentUserAccount') ? this.get('content.installOptions.agentUser') : 'root'
});
this.set('numPolls', 0);
this.set('registrationStartedAt', null);
this.set('isHostsWarningsLoaded', false);
this.set('stopChecking', false);
this.set('isSubmitDisabled', true);
if (this.get('content.installOptions.manualInstall')) {
this.startRegistration();
} else {
App.router.get(this.get('content.controllerName')).launchBootstrap(bootStrapData, function (requestId) {
self.set('content.installOptions.bootRequestId', requestId);
self.doBootstrap();
});
}
},
/**
* Retry selected hosts (click-handler)
* @method retrySelectedHosts
*/
retrySelectedHosts: function retrySelectedHosts() {
if (!this.get('isRetryDisabled')) {
var selectedHosts = this.get('bootHosts').filterProperty('bootStatus', 'FAILED');
selectedHosts.forEach(function (_host) {
_host.set('bootStatus', 'DONE');
_host.set('bootLog', 'Retrying ...');
}, this);
this.retryHosts(selectedHosts);
}
},
/**
* Init bootstrap settings and start it
* @method startBootstrap
*/
startBootstrap: function startBootstrap() {
//this.set('isSubmitDisabled', true); //TODO: uncomment after actual hookup
this.set('numPolls', 0);
this.set('registrationStartedAt', null);
this.set('bootHosts', this.get('hosts'));
this.doBootstrap();
},
/**
* Update <code>isRegistrationInProgress</code> once
* @method setRegistrationInProgressOnce
*/
setRegistrationInProgressOnce: function () {
Em.run.once(this, 'setRegistrationInProgress');
}.observes('bootHosts.@each.bootStatus'),
/**
* Set <code>isRegistrationInProgress</code> value based on each host boot status
* @method setRegistrationInProgress
*/
setRegistrationInProgress: function setRegistrationInProgress() {
var bootHosts = this.get('bootHosts');
//if hosts aren't loaded yet then registration should be in progress
var result = bootHosts.length === 0 && !this.get('isLoaded');
for (var i = 0, l = bootHosts.length; i < l; i++) {
if (bootHosts[i].get('bootStatus') !== 'REGISTERED' && bootHosts[i].get('bootStatus') !== 'FAILED') {
result = true;
break;
}
}
this.set('isRegistrationInProgress', result);
},
/**
* Disable wizard's previous steps (while registering)
* @method disablePreviousSteps
*/
disablePreviousSteps: function () {
App.router.get('installerController.isStepDisabled').filter(function (step) {
return step.step >= 0 && step.step <= 2;
}).setEach('value', this.get('isBackDisabled'));
App.router.get('addHostController.isStepDisabled').filter(function (step) {
return step.step >= 0 && step.step <= 1;
}).setEach('value', this.get('isBackDisabled'));
}.observes('isBackDisabled'),
/**
* Close reload popup on exit from Confirm Hosts step
* @method closeReloadPopupOnExit
*/
closeReloadPopupOnExit: function () {
if (this.get('stopBootstrap')) {
this.closeReloadPopup();
}
}.observes('stopBootstrap'),
/**
* Do bootstrap calls
* @method doBootstrap
* @return {$.ajax|null}
*/
doBootstrap: function doBootstrap() {
if (this.get('stopBootstrap')) {
return null;
}
this.incrementProperty('numPolls');
return App.ajax.send({
name: 'wizard.step3.bootstrap',
sender: this,
data: {
bootRequestId: this.get('content.installOptions.bootRequestId'),
numPolls: this.get('numPolls'),
callback: this.doBootstrap,
timeout: 3000,
shouldUseDefaultHandler: true
},
success: 'doBootstrapSuccessCallback',
error: 'reloadErrorCallback'
});
},
/**
* Success-callback for each boostrap request
* @param {object} data
* @method doBootstrapSuccessCallback
*/
doBootstrapSuccessCallback: function doBootstrapSuccessCallback(data) {
var self = this;
var pollingInterval = 3000;
this.reloadSuccessCallback();
if (Em.isNone(data.hostsStatus)) {
window.setTimeout(function () {
self.doBootstrap();
}, pollingInterval);
} else {
// in case of bootstrapping just one host, the server returns an object rather than an array, so
// force into an array
if (!(data.hostsStatus instanceof Array)) {
data.hostsStatus = [data.hostsStatus];
}
var keepPolling = this.parseHostInfo(data.hostsStatus);
// Single host : if the only hostname is invalid (data.status == 'ERROR')
// Multiple hosts : if one or more hostnames are invalid
// following check will mark the bootStatus as 'FAILED' for the invalid hostname
var installedHosts = App.Host.find().mapProperty('hostName');
var isErrorStatus = data.status == 'ERROR';
this.set('isBootstrapFailed', isErrorStatus);
if (isErrorStatus || data.hostsStatus.mapProperty('hostName').removeObjects(installedHosts).length != this.get('bootHosts').length) {
var hosts = this.get('bootHosts');
for (var i = 0; i < hosts.length; i++) {
var isValidHost = data.hostsStatus.someProperty('hostName', hosts[i].get('name'));
if (hosts[i].get('bootStatus') !== 'REGISTERED') {
if (!isValidHost) {
hosts[i].set('bootStatus', 'FAILED');
hosts[i].set('bootLog', Em.I18n.t('installer.step3.hosts.bootLog.failed'));
}
}
}
}
if (isErrorStatus || data.hostsStatus.someProperty('status', 'DONE') || data.hostsStatus.someProperty('status', 'FAILED')) {
// kicking off registration polls after at least one host has succeeded
this.startRegistration();
}
if (keepPolling) {
window.setTimeout(function () {
self.doBootstrap();
}, pollingInterval);
}
}
},
/**
* Start hosts registration
* @method startRegistration
*/
startRegistration: function startRegistration() {
if (Em.isNone(this.get('registrationStartedAt'))) {
this.set('registrationStartedAt', App.dateTime());
this.isHostsRegistered();
}
},
/**
* Do requests to check if hosts are already registered
* @return {$.ajax|null}
* @method isHostsRegistered
*/
isHostsRegistered: function isHostsRegistered() {
if (this.get('stopBootstrap')) {
return null;
}
return App.ajax.send({
name: 'wizard.step3.is_hosts_registered',
sender: this,
success: 'isHostsRegisteredSuccessCallback',
error: 'reloadErrorCallback',
data: {
callback: this.isHostsRegistered,
timeout: 3000,
shouldUseDefaultHandler: true
}
});
},
/**
* Success-callback for registered hosts request
* @param {object} data
* @method isHostsRegisteredSuccessCallback
*/
isHostsRegisteredSuccessCallback: function isHostsRegisteredSuccessCallback(data) {
var hosts = this.get('bootHosts');
var jsonData = data;
this.reloadSuccessCallback();
Iif (!jsonData) {
return;
}
// keep polling until all hosts have registered/failed, or registrationTimeout seconds after the last host finished bootstrapping
var stopPolling = true;
hosts.forEach(function (_host, index) {
// Change name of first host for test mode.
Iif (App.get('testMode')) {
if (index == 0) {
_host.set('name', 'localhost.localdomain');
}
}
// actions to take depending on the host's current bootStatus
// RUNNING - bootstrap is running; leave it alone
// DONE - bootstrap is done; transition to REGISTERING
// REGISTERING - bootstrap is done but has not registered; transition to REGISTERED if host found in polling API result
// REGISTERED - bootstrap and registration is done; leave it alone
// FAILED - either bootstrap or registration failed; leave it alone
switch (_host.get('bootStatus')) {
case 'DONE':
_host.set('bootStatus', 'REGISTERING');
_host.set('bootLog', (_host.get('bootLog') != null ? _host.get('bootLog') : '') + Em.I18n.t('installer.step3.hosts.bootLog.registering'));
// update registration timestamp so that the timeout is computed from the last host that finished bootstrapping
this.set('registrationStartedAt', App.dateTime());
stopPolling = false;
break;
case 'REGISTERING':
if (jsonData.items.someProperty('Hosts.host_name', _host.name) && !jsonData.items.filterProperty('Hosts.host_name', _host.name).someProperty('Hosts.host_status', 'UNKNOWN')) {
_host.set('bootStatus', 'REGISTERED');
_host.set('bootLog', (_host.get('bootLog') != null ? _host.get('bootLog') : '') + Em.I18n.t('installer.step3.hosts.bootLog.registering'));
} else {
stopPolling = false;
}
break;
case 'RUNNING':
stopPolling = false;
break;
case 'REGISTERED':
case 'FAILED':
default:
break;
}
}, this);
if (stopPolling) {
this.startHostcheck(hosts);
} else {
if (hosts.someProperty('bootStatus', 'RUNNING') || App.dateTime() - this.get('registrationStartedAt') < this.get('registrationTimeoutSecs') * 1000) {
// we want to keep polling for registration status if any of the hosts are still bootstrapping (so we check for RUNNING).
var self = this;
window.setTimeout(function () {
self.isHostsRegistered();
}, 3000);
} else {
// registration timed out. mark all REGISTERING hosts to FAILED
hosts.filterProperty('bootStatus', 'REGISTERING').forEach(function (_host) {
_host.set('bootStatus', 'FAILED');
_host.set('bootLog', (_host.get('bootLog') != null ? _host.get('bootLog') : '') + Em.I18n.t('installer.step3.hosts.bootLog.failed'));
});
this.startHostcheck(hosts);
}
}
},
/**
* Do request for all registered hosts
* @return {$.ajax}
* @method getAllRegisteredHosts
*/
getAllRegisteredHosts: function () {
return App.ajax.send({
name: 'wizard.step3.is_hosts_registered',
sender: this,
success: 'getAllRegisteredHostsCallback'
});
}.observes('bootHosts'),
/**
* Success-callback for all registered hosts request
* @param {object} hosts
* @method getAllRegisteredHostsCallback
*/
getAllRegisteredHostsCallback: function getAllRegisteredHostsCallback(hosts) {
var registeredHosts = [];
var hostsInCluster = this.get('hostsInCluster');
var addedHosts = this.get('bootHosts').getEach('name');
hosts.items.forEach(function (host) {
if (!hostsInCluster.contains(host.Hosts.host_name) && !addedHosts.contains(host.Hosts.host_name)) {
registeredHosts.push(host.Hosts.host_name);
}
});
if (registeredHosts.length) {
this.set('hasMoreRegisteredHosts', true);
this.set('registeredHosts', registeredHosts);
} else {
this.set('hasMoreRegisteredHosts', false);
this.set('registeredHosts', '');
}
},
/**
* Get JDK name from server to determine if user had setup a customized JDK path when doing 'ambari-server setup'.
* The Ambari properties are different from default ambari-server setup, property 'jdk.name' will be missing if a customized jdk path is applied.
* @return {$.ajax}
* @method getJDKName
*/
getJDKName: function getJDKName() {
return App.ajax.send({
name: 'ambari.service',
sender: this,
data: {
fields: '?fields=RootServiceComponents/properties/jdk.name,RootServiceComponents/properties/java.home,RootServiceComponents/properties/jdk_location'
},
success: 'getJDKNameSuccessCallback'
});
},
/**
* Success callback for JDK name, property 'jdk.name' will be missing if a customized jdk path is applied
* @param {object} data
* @method getJDKNameSuccessCallback
*/
getJDKNameSuccessCallback: function getJDKNameSuccessCallback(data) {
this.set('needJDKCheckOnHosts', !data.RootServiceComponents.properties["jdk.name"]);
this.set('jdkLocation', Em.get(data, "RootServiceComponents.properties.jdk_location"));
this.set('javaHome', data.RootServiceComponents.properties["java.home"]);
},
doCheckJDK: function doCheckJDK() {
var hostsNames = this.get('bootHosts').filterProperty('bootStatus', 'REGISTERED').getEach('name').join(','),
javaHome = this.get('javaHome'),
jdkLocation = this.get('jdkLocation');
App.ajax.send({
name: 'wizard.step3.jdk_check',
sender: this,
data: {
host_names: hostsNames,
java_home: javaHome,
jdk_location: jdkLocation
},
success: 'doCheckJDKsuccessCallback',
error: 'doCheckJDKerrorCallback'
});
},
doCheckJDKsuccessCallback: function doCheckJDKsuccessCallback(data) {
if (data) {
this.set('jdkRequestIndex', data.href.split('/')[data.href.split('/').length - 1]);
}
if (this.get('jdkCategoryWarnings') == null) {
// get jdk check results for all hosts
App.ajax.send({
name: 'wizard.step3.jdk_check.get_results',
sender: this,
data: {
requestIndex: this.get('jdkRequestIndex')
},
success: 'parseJDKCheckResults'
});
} else {
this.set('isJDKWarningsLoaded', true);
}
},
doCheckJDKerrorCallback: function doCheckJDKerrorCallback() {
this.set('isJDKWarningsLoaded', true);
},
parseJDKCheckResults: function parseJDKCheckResults(data) {
var jdkWarnings = [],
hostsJDKContext = [],
hostsJDKNames = [];
// check if the request ended
if (data.Requests.end_time > 0 && data.tasks) {
data.tasks.forEach(function (task) {
// generate warning context
if (Em.get(task, "Tasks.structured_out.java_home_check.exit_code") == 1) {
var jdkContext = Em.I18n.t('installer.step3.hostWarningsPopup.jdk.context').format(task.Tasks.host_name);
hostsJDKContext.push(jdkContext);
hostsJDKNames.push(task.Tasks.host_name);
}
});
if (hostsJDKContext.length > 0) {
// java jdk warning exist
var invalidJavaHome = this.get('javaHome');
jdkWarnings.push({
name: Em.I18n.t('installer.step3.hostWarningsPopup.jdk.name').format(invalidJavaHome),
hosts: hostsJDKContext,
hostsLong: hostsJDKContext,
hostsNames: hostsJDKNames,
category: 'jdk'
});
}
this.set('jdkCategoryWarnings', jdkWarnings);
} else {
// still doing JDK check, data not ready to be parsed
this.set('jdkCategoryWarnings', null);
}
this.doCheckJDKsuccessCallback();
},
/**
* Check JDK issues on registered hosts.
*/
checkHostJDK: function checkHostJDK() {
this.set('isJDKWarningsLoaded', false);
this.set('jdkCategoryWarnings', null);
var self = this;
this.getJDKName().done(function () {
Iif (self.get('needJDKCheckOnHosts')) {
// need to do JDK check on each host
self.doCheckJDK();
} else {
// no customized JDK path, so no need to check jdk
self.set('jdkCategoryWarnings', []);
self.set('isJDKWarningsLoaded', true);
}
});
},
startHostcheck: function startHostcheck(hosts) {
if (!hosts.everyProperty('bootStatus', 'FAILED')) {
this.set('isWarningsLoaded', false);
this.getHostNameResolution();
this.checkHostJDK();
} else {
this.stopHostCheck();
}
},
_submitProceed: function _submitProceed() {
this.set('confirmedHosts', this.get('bootHosts'));
App.get('router').send('next');
},
/**
* Submit-click handler
* Disable 'Next' button while it is already under process. (using Router's property 'nextBtnClickInProgress')
* @return {App.ModalPopup?}
* @method submit
*/
submit: function submit() {
var self = this;
Iif (App.get('router.nextBtnClickInProgress')) {
return;
}
if (this.get('isHostHaveWarnings')) {
return App.showConfirmationPopup(function () {
self._submitProceed();
}, Em.I18n.t('installer.step3.hostWarningsPopup.hostHasWarnings'), null, Em.I18n.t('installer.step3.hostWarningsPopup.hostHasWarnings.header'), null, 'warning');
}
this._submitProceed();
},
/**
* Show popup with host log
* @param {object} event
* @return {App.ModalPopup}
*/
hostLogPopup: function hostLogPopup(event) {
var host = event.context;
return App.ModalPopup.show({
header: Em.I18n.t('installer.step3.hostLog.popup.header').format(host.get('name')),
secondary: null,
host: host,
bodyClass: App.WizardStep3HostLogPopupBody
});
},
/**
* Open popup that contain hosts' warnings
* @return {App.ModalPopup}
* @method hostWarningsPopup
*/
hostWarningsPopup: function hostWarningsPopup() {
var self = this;
return App.ModalPopup.show({
header: Em.I18n.t('installer.step3.warnings.popup.header'),
secondary: Em.I18n.t('installer.step3.hostWarningsPopup.rerunChecks'),
primary: Em.I18n.t('common.close'),
autoHeight: false,
'data-qa': 'host-checks-modal',
onPrimary: function onPrimary() {
self.set('checksUpdateStatus', null);
this.hide();
},
onClose: function onClose() {
self.set('checksUpdateStatus', null);
this.hide();
},
onSecondary: function onSecondary() {
self.rerunChecks();
},
didInsertElement: function didInsertElement() {
this._super();
this.fitHeight();
},
footerClass: App.WizardStep3HostWarningPopupFooter.reopen({
checkHostFinished: true
}),
bodyClass: App.WizardStep3HostWarningPopupBody.reopen({
checkHostFinished: true
})
});
},
/**
* Show popup with registered hosts
* @return {App.ModalPopup}
* @method registeredHostsPopup
*/
registeredHostsPopup: function registeredHostsPopup() {
var self = this;
return App.ModalPopup.show({
header: Em.I18n.t('installer.step3.warning.registeredHosts').format(this.get('registeredHosts').length),
secondary: null,
bodyClass: Em.View.extend({
templateName: require('templates/wizard/step3/step3_registered_hosts_popup'),
message: Em.I18n.t('installer.step3.registeredHostsPopup'),
registeredHosts: self.get('registeredHosts'),
checkHostsFinished: true
})
});
}
});
}); |