| 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
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306 |
1
1
1
1
1
1
1
1
1
4
6
1
4
6
1
6
1
6
6
6
6
6
6
6
6
6
6
6
6
1
1
50
43
7
7
3
3
3
2
1
1
2
4
4
4
2
5
5
5
5
5
5
5
5
20
35
20
10
5
5
5
5
5
5
5
3
3
177
50
7
7
7
7
5
5
5
5
5
5
2
2
2
5
5
20
20
14
5
5
5
9
36
23
11
12
13
2
2
12
12
12
6
2
6
2
6
6
6
11
11
11
11
11
11
11
11
1
1
1
1
10
10
2
14
14
14
14
14
14
14
14
14
14
6
6
6
1
6
6
6
18
6
18
18
36
36
36
36
6
6
1
19
19
19
19
19
20
20
20
20
20
20
20
20
20
20
20
20
20
19
19
19
18
18
4
4
24
6
4
4
6
1
3
3
3
7
2
1
21
21
21
21
76
74
74
74
91
91
91
4
4
4
4
2
2
2
10
15
2
4
4
4
2
2
4
4
4
15
4
4
3
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
3
1
1
1
1
1
1
1
14
14
4
10
10
10
10
10
10
10
10
10
| 'use strict';
;require.register("mixins/wizard/assign_master_components", 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.
*/
require('mixins/common/hosts/host_component_recommendation_mixin');
require('mixins/common/hosts/host_component_validation_mixin');
var App = require('app');
var blueprintUtils = require('utils/blueprint');
var numberUtils = require('utils/number_utils');
var validationUtils = require('utils/validator');
/**
* Mixin for assign master-to-host step in wizards
* Implements basic logic of assign masters page
* Should be used with controller linked with App.AssignMasterComponentsView
* @type {Ember.Mixin}
*/
App.AssignMasterComponents = Em.Mixin.create(App.HostComponentValidationMixin, App.HostComponentRecommendationMixin, {
/**
* Array of master component names to show on the page
* By default is empty, this means that masters of all selected services should be shown
* @type {Array}
*/
mastersToShow: [],
/**
* Array of master component names to show on the service config assign master page
* @type {Array}
*/
mastersToCreate: [],
/**
* Array of master component names to add for install
* @type {Array}
*/
mastersToAdd: [],
/**
* Array of master component names, that are already installed, but should have ability to change host
* @type {Array}
*/
mastersToMove: [],
/**
* Array of master component names, that should be addable
* Are used in HA wizards to add components, that are not addable for other wizards
* @type {Array}
*/
mastersAddableInHA: [],
/**
* Array of master component names to show 'Current' prefix in label before component name
* Prefix will be shown only for installed instances
* @type {Array}
*/
showCurrentPrefix: [],
/**
* Array of master component names to show 'Additional' prefix in label before component name
* Prefix will be shown only for not installed instances
* @type {Array}
*/
showAdditionalPrefix: [],
/**
* Array of objects with label and host keys to show specific hosts on the page
* @type {Array}
* format:
* [
* {
* label: 'Current',
* host: 'c6401.ambari.apache.org'
* },
* {
* label: 'Additional',
* host: function () {
* return 'c6402.ambari.apache.org';
* }.property()
* }
* ]
*/
additionalHostsList: [],
/**
* Define whether show already installed masters first
* @type {Boolean}
*/
showInstalledMastersFirst: false,
/**
* Map of component name to list of hostnames for that component
* format:
* {
* NAMENODE: [
* 'c6401.ambari.apache.org'
* ],
* DATANODE: [
* 'c6402.ambari.apache.org',
* 'c6403.ambari.apache.org',
* ]
* }
* @type {Object}
*/
recommendedHostsForComponents: {},
recommendations: null,
markSavedComponentsAsInstalled: false,
/**
* @type {boolean}
* @default false
*/
validationInProgress: false,
/**
* run validation call which was skipped
* validation should be always ran after last change
* @type {boolean}
* @default false
*/
runQueuedValidation: false,
/**
* Array of <code>servicesMasters</code> objects, that will be shown on the page
* Are filtered using <code>mastersToShow</code>
* @type {Array}
*/
servicesMastersToShow: function () {
var mastersToShow = this.get('mastersToShow');
var servicesMasters = this.get('servicesMasters');
var result = [];
if (!mastersToShow.length) {
result = servicesMasters;
} else {
mastersToShow.forEach(function (master) {
result = result.concat(servicesMasters.filterProperty('component_name', master));
});
}
if (this.get('showInstalledMastersFirst')) {
result = this.sortMasterComponents(result);
}
return result;
}.property('servicesMasters.length', 'mastersToShow.length', 'showInstalledMastersFirst'),
/**
* Sort masters, installed masters will be first.
* @param masters
* @returns {Array}
*/
sortMasterComponents: function sortMasterComponents(masters) {
return [].concat(masters.filterProperty('isInstalled'), masters.filterProperty('isInstalled', false));
},
/**
* Check if <code>installerWizard</code> used
* @type {bool}
*/
isInstallerWizard: Em.computed.equal('content.controllerName', 'installerController'),
/**
* Master components which could be assigned to multiple hosts
* @type {string[]}
*/
multipleComponents: Em.computed.alias('App.components.multipleMasters'),
/**
* Master components which could be assigned to multiple hosts
* @type {string[]}
*/
addableComponents: function () {
return App.get('components.addableMasterInstallerWizard').concat(this.get('mastersAddableInHA')).uniq();
}.property('App.components.addableMasterInstallerWizard', 'mastersAddableInHA'),
/**
* Define state for submit button
* @type {bool}
*/
submitDisabled: false,
/**
* Is Submit-click processing now
* @type {bool}
*/
submitButtonClicked: false,
/**
* Either use or not use server validation in this controller
* @type {bool}
*/
useServerValidation: true,
/**
* Trigger for executing host names check for components
* Should de "triggered" when host changed for some component and when new multiple component is added/removed
* @type {bool}
*/
hostNameCheckTrigger: false,
/**
* List of hosts
* @type {Array}
*/
hosts: [],
/**
* Name of multiple component which host name was changed last
* @type {Object|null}
*/
componentToRebalance: null,
/**
* Name of component which host was changed last
* @type {string}
*/
lastChangedComponent: null,
/**
* Flag for rebalance multiple components
* @type {number}
*/
rebalanceComponentHostsCounter: 0,
/**
* @type {Ember.Enumerable}
*/
servicesMasters: [],
/**
* @type {Ember.Enumerable}
*/
selectedServicesMasters: [],
/**
* Is hosts data loaded
* @type {bool}
*/
isHostsLoaded: false,
/**
* Are recommendations loaded
* @type {bool}
*/
isRecommendationsLoaded: false,
/**
* Is data for current step loaded
* @type {bool}
*/
isLoaded: Em.computed.and('isHostsLoaded', 'isRecommendationsLoaded'),
/**
* Is back from the next step
* @type {bool}
*/
backFromNextStep: false,
/**
* Validation error messages which don't related with any master
*/
generalErrorMessages: [],
/**
* Validation warning messages which don't related with any master
*/
generalWarningMessages: [],
/**
* Is masters-hosts layout initial one
* @type {bool}
*/
isInitialLayout: true,
/**
* true if any error exists
*/
anyError: function () {
return this.get('servicesMasters').some(function (m) {
return m.get('errorMessage');
}) || this.get('generalErrorMessages').some(function (m) {
return m;
});
}.property('servicesMasters.@each.errorMessage', 'generalErrorMessages'),
/**
* true if any warning exists
*/
anyWarning: function () {
return this.get('servicesMasters').some(function (m) {
return m.get('warnMessage');
}) || this.get('generalWarningMessages').some(function (m) {
return m;
});
}.property('servicesMasters.@each.warnMessage', 'generalWarningMessages'),
/**
* Clear loaded recommendations
*/
clearRecommendations: function clearRecommendations() {
if (this.get('content.recommendations')) {
this.set('content.recommendations', null);
}
Iif (this.get('recommendations')) {
this.set('recommendations', null);
}
},
/**
* List of host with assigned masters
* Format:
* <code>
* [
* {
* host_name: '',
* hostInfo: {},
* masterServices: [],
* masterServicesToDisplay: [] // used only in template
* },
* ....
* ]
* </code>
* @type {Ember.Enumerable}
*/
masterHostMapping: function () {
var mapping = [],
mappingObject,
mappedHosts,
hostObj;
//get the unique assigned hosts and find the master services assigned to them
mappedHosts = this.get("selectedServicesMasters").mapProperty("selectedHost").uniq();
mappedHosts.forEach(function (item) {
hostObj = this.get("hosts").findProperty("host_name", item);
// User may input invalid host name (this is handled in hostname checker). Here we just skip it
Iif (!hostObj) return;
var masterServices = this.get("selectedServicesMasters").filterProperty("selectedHost", item),
masterServicesToDisplay = [];
masterServices.mapProperty('display_name').uniq().forEach(function (n) {
masterServicesToDisplay.pushObject(masterServices.findProperty('display_name', n));
});
mappingObject = Em.Object.create({
host_name: item,
hostInfo: hostObj.host_info,
masterServices: masterServices,
masterServicesToDisplay: masterServicesToDisplay
});
mapping.pushObject(mappingObject);
}, this);
return mapping.sortProperty('host_name');
}.property('selectedServicesMasters.@each.selectedHost', 'selectedServicesMasters.@each.isHostNameValid', 'isLoaded'),
/**
* Count of hosts without masters
* @type {number}
*/
remainingHosts: function () {
Iif (this.get('content.controllerName') === 'installerController') {
return 0;
} else {
return this.get("hosts.length") - this.get("masterHostMapping.length");
}
}.property('masterHostMapping.length', 'selectedServicesMasters.@each.selectedHost'),
/**
* Update submit button status
* @method updateIsSubmitDisabled
*/
updateIsSubmitDisabled: function () {
if (this.thereIsNoMasters()) {
return false;
}
var isSubmitDisabled = this.get('servicesMasters').someProperty('isHostNameValid', false);
if (this.get('useServerValidation')) {
this.set('submitDisabled', true);
Iif (this.get('servicesMasters').length === 0) {
return;
}
if (!isSubmitDisabled) {
if (!this.get('isInitialLayout')) {
this.clearRecommendations(); // reset previous recommendations
} else {
this.set('isInitialLayout', false);
}
this.recommendAndValidate();
}
} else {
isSubmitDisabled = isSubmitDisabled || !this.customClientSideValidation();
this.set('submitDisabled', isSubmitDisabled);
return isSubmitDisabled;
}
}.observes('servicesMasters.@each.selectedHost'),
/**
* Function to validate master-to-host assignments
* Should be defined in controller
* @returns {boolean}
*/
customClientSideValidation: function customClientSideValidation() {
return true;
},
/**
* Success-callback for validations request
* @param {object} data
* @method updateValidationsSuccessCallback
*/
updateValidationsSuccessCallback: function updateValidationsSuccessCallback(data) {
var self = this;
var generalErrorMessages = [];
var generalWarningMessages = [];
this.get('servicesMasters').setEach('warnMessage', null);
this.get('servicesMasters').setEach('errorMessage', null);
var anyErrors = false;
var validationData = validationUtils.filterNotInstalledComponents(data);
validationData.filterProperty('type', 'host-component').forEach(function (item) {
var master = self.get('servicesMasters').find(function (m) {
return m.component_name === item['component-name'] && m.selectedHost === item.host;
});
if (master) {
if (item.level === 'ERROR') {
anyErrors = true;
master.set('errorMessage', item.message);
} else Eif (item.level === 'WARN') {
master.set('warnMessage', item.message);
}
}
});
this.set('generalErrorMessages', generalErrorMessages);
this.set('generalWarningMessages', generalWarningMessages);
// use this.set('submitDisabled', anyErrors); is validation results should block next button
// It's because showValidationIssuesAcceptBox allow use accept validation issues and continue
this.set('submitDisabled', false); //this.set('submitDisabled', anyErrors);
},
/**
* Error-callback for validations request
* @param {object} jqXHR
* @param {object} ajaxOptions
* @param {string} error
* @param {object} opt
* @method updateValidationsErrorCallback
*/
updateValidationsErrorCallback: function updateValidationsErrorCallback(jqXHR, ajaxOptions, error, opt) {},
/**
* @override App.HostComponentRecommendationMixin
*/
getRecommendationRequestData: function getRecommendationRequestData(options) {
var res = this._super(options);
res.services = this.getCurrentServiceNames();
if (!this.get('isInstallerWizard')) {
res.recommendations = this.getCurrentMasterSlaveBlueprint();
}
return res;
},
/**
* @override App.HostComponentRecommendationMixin
*/
getHostComponentValidationParams: function getHostComponentValidationParams(options) {
var res = this._super(options);
res.services = this.getCurrentServiceNames();
return res;
},
/**
* Returns selected and installed service names
* @return {string[]}
*/
getCurrentServiceNames: function getCurrentServiceNames() {
return App.StackService.find().filter(function (i) {
return i.get('isSelected') || i.get('isInstalled');
}).mapProperty('serviceName').uniq();
},
/**
* Clear controller data (hosts, masters etc)
* @method clearStep
*/
clearStep: function clearStep() {
this.setProperties({
hosts: [],
isHostsLoaded: false,
isRecommendationsLoaded: false,
backFromNextStep: false,
selectedServicesMasters: [],
servicesMasters: []
});
App.StackServiceComponent.find().forEach(function (stackComponent) {
stackComponent.set('serviceComponentId', 1);
}, this);
},
clearStepOnExit: function clearStepOnExit() {
this.clearStep();
},
/**
* Load controller data (hosts, host components etc)
* @method loadStep
*/
loadStep: function loadStep() {
var self = this;
this.clearStep();
if (this._additionalClearSteps) {
this._additionalClearSteps();
}
this.renderHostInfo().done(function () {
//when returning from step Assign Slaves and Clients, recommendations are already available
//set the flag so that recommendations AJAX call is not made unnecessarily
if (self.get('recommendations')) {
self.set('backFromNextStep', true);
}
self.getRecommendedHosts({
hosts: self.getHosts()
}).then(function () {
self.loadStepCallback(self.createComponentInstallationObjects(), self);
});
});
},
/**
* Callback after load controller data (hosts, host components etc)
* @method loadStepCallback
*/
loadStepCallback: function loadStepCallback(components, self) {
self.renderComponents(components);
self.get('addableComponents').forEach(function (componentName) {
self.updateComponent(componentName);
}, self);
self.set('isRecommendationsLoaded', true);
if (self.thereIsNoMasters() && !self.get('mastersToCreate').length) {
App.router.send('next');
}
},
/**
* Returns true if there is no new master components which need assigment to host
*/
thereIsNoMasters: function thereIsNoMasters() {
return !this.get("selectedServicesMasters").filterProperty('isInstalled', false).length;
},
/**
* Used to set showAddControl flag for installer wizard
* @method updateComponent
*/
updateComponent: function updateComponent(componentName) {
var component = this.last(componentName);
Iif (!component) {
return;
}
var showControl = !App.StackServiceComponent.find().findProperty('componentName', componentName).get('stackService').get('isInstalled') || this.get('mastersAddableInHA').contains(componentName);
if (showControl) {
var mastersLength = this.get("selectedServicesMasters").filterProperty("component_name", componentName).length;
Iif (mastersLength < this.getMaxNumberOfMasters(componentName)) {
component.set('showAddControl', true);
} else {
component.set('showRemoveControl', mastersLength != 1);
}
}
},
/**
* Count max number of instances for masters <code>componentName</code>, according to their cardinality and number of hosts
* @param componentName
* @returns {Number}
*/
getMaxNumberOfMasters: function getMaxNumberOfMasters(componentName) {
var maxByCardinality = App.StackServiceComponent.find().findProperty('componentName', componentName).get('maxToInstall');
var hostsNumber = this.get("hosts.length");
return Math.min(maxByCardinality, hostsNumber);
},
/**
* Load active host list to <code>hosts</code> variable
* @method renderHostInfo
*/
renderHostInfo: function renderHostInfo() {
var self = this;
var isInstaller = this.get('wizardController.name') === 'installerController' || this.get('content.controllerName') === 'installerController';
return App.ajax.send({
name: isInstaller ? 'hosts.info.install' : 'hosts.high_availability.wizard',
sender: this,
data: {
hostNames: isInstaller ? this.getHosts().join() : null
}
}).success(function (data) {
self.loadWizardHostsSuccessCallback(data);
});
},
loadWizardHostsSuccessCallback: function loadWizardHostsSuccessCallback(data) {
var hostInfo = this.get('content.hosts'),
result = [];
data.items.forEach(function (host) {
var hostName = host.Hosts.host_name,
_host = hostInfo[hostName],
cpu = host.Hosts.cpu_count,
memory = host.Hosts.total_mem.toFixed(2);
if (_host.bootStatus === 'REGISTERED') {
result.push(Em.Object.create({
host_name: hostName,
cpu: cpu,
memory: memory,
disk_info: host.Hosts.disk_info,
maintenance_state: host.Hosts.maintenance_state,
isInstalled: _host.isInstalled,
host_info: Em.I18n.t('installer.step5.hostInfo').fmt(hostName, numberUtils.bytesToSize(memory, 1, 'parseFloat', 1024), cpu)
}));
}
}, this);
this.set('hosts', result);
this.sortHosts(this.get('hosts'));
this.set('isHostsLoaded', true);
},
/**
* Sort list of host-objects by properties (memory - desc, cpu - desc, hostname - asc)
* @param {object[]} hosts
*/
sortHosts: function sortHosts(hosts) {
hosts.sort(function (a, b) {
if (a.get('memory') == b.get('memory')) {
if (a.get('cpu') == b.get('cpu')) {
return a.get('host_name').localeCompare(b.get('host_name')); // hostname asc
}
return b.get('cpu') - a.get('cpu'); // cores desc
}
return b.get('memory') - a.get('memory'); // ram desc
});
},
/**
* Get recommendations info from API
* @param {object} recommendationBlueprint
* @method loadComponentsRecommendationsFromServer
* @override App.HostComponentRecommendationMixin
*/
loadComponentsRecommendationsFromServer: function loadComponentsRecommendationsFromServer(recommendationBlueprint) {
var self = this;
//when returning from step Assign Slaves and Clients, backFromNextStep will be true
if (this.get('recommendations') && this.get('backFromNextStep')) {
// Don't do AJAX call if recommendations has been already received
// But if user returns to previous step (selecting services), stored recommendations will be cleared in routers' next handler and AJAX call will be made again
return $.Deferred().resolve().promise();
} else {
return this._super(recommendationBlueprint);
}
},
/**
* Create components for displaying component-host comboboxes in UI assign dialog
* expects content.recommendations will be filled with recommendations API call result
* @return {Object[]}
*/
createComponentInstallationObjects: function createComponentInstallationObjects() {
var stackMasterComponentsMap = {},
masterHosts = this.get('content.masterComponentHosts') || this.get('masterComponentHosts'),
//saved to local storage info
servicesToAdd = (this.get('content.services') || []).filterProperty('isSelected').filterProperty('isInstalled', false).mapProperty('serviceName'),
recommendations = this.get('recommendations'),
resultComponents = [],
multipleComponentHasBeenAdded = {},
hostGroupsMap = {};
App.StackServiceComponent.find().forEach(function (component) {
var isMasterCreateOnConfig = this.get('mastersToCreate').contains(component.get('componentName'));
Iif (this.get('isInstallerWizard') && (component.get('isShownOnInstallerAssignMasterPage') || isMasterCreateOnConfig)) {
stackMasterComponentsMap[component.get('componentName')] = component;
} else if (component.get('isShownOnAddServiceAssignMasterPage') || this.get('mastersToShow').contains(component.get('componentName')) || isMasterCreateOnConfig) {
stackMasterComponentsMap[component.get('componentName')] = component;
}
}, this);
recommendations.blueprint_cluster_binding.host_groups.forEach(function (group) {
hostGroupsMap[group.name] = group;
});
recommendations.blueprint.host_groups.forEach(function (host_group) {
var hosts = hostGroupsMap[host_group.name] ? hostGroupsMap[host_group.name].hosts : [];
hosts.forEach(function (host) {
host_group.components.forEach(function (component) {
var willBeDisplayed = true;
var stackMasterComponent = stackMasterComponentsMap[component.name];
Eif (stackMasterComponent) {
var isMasterCreateOnConfig = this.get('mastersToCreate').contains(component.name);
// If service is already installed and not being added as a new service then render on UI only those master components
// that have already installed hostComponents.
// NOTE: On upgrade there might be a prior installed service with non-installed newly introduced serviceComponent
Iif (!servicesToAdd.contains(stackMasterComponent.get('serviceName')) && !isMasterCreateOnConfig) {
willBeDisplayed = masterHosts.someProperty('component', component.name);
}
Eif (willBeDisplayed) {
var savedComponents = masterHosts.filterProperty('component', component.name);
if (this.get('multipleComponents').contains(component.name) && savedComponents.length > 0) {
Eif (!multipleComponentHasBeenAdded[component.name]) {
multipleComponentHasBeenAdded[component.name] = true;
savedComponents.forEach(function (saved) {
resultComponents.push(this.createComponentInstallationObject(stackMasterComponent, host.fqdn.toLowerCase(), saved));
}, this);
}
} else {
var savedComponent = masterHosts.findProperty('component', component.name);
resultComponents.push(this.createComponentInstallationObject(stackMasterComponent, host.fqdn.toLowerCase(), savedComponent));
}
}
}
}, this);
}, this);
}, this);
return resultComponents;
},
/**
* Create component for displaying component-host comboboxes in UI assign dialog
* @param fullComponent - full component description
* @param hostName - host fqdn where component will be installed
* @param savedComponent - the same object which function returns but created before
* @return {Object}
*/
createComponentInstallationObject: function createComponentInstallationObject(fullComponent, hostName, savedComponent) {
var componentName = fullComponent.get('componentName'),
resultingHostName = savedComponent ? savedComponent.hostName : hostName;
var componentObj = {};
componentObj.component_name = componentName;
componentObj.display_name = App.format.role(fullComponent.get('componentName'), false);
componentObj.serviceId = fullComponent.get('serviceName');
componentObj.isServiceCoHost = App.StackServiceComponent.find().findProperty('componentName', componentName).get('isCoHostedComponent') && !this.get('mastersToMove').contains(componentName);
componentObj.selectedHost = resultingHostName;
componentObj.isInstalled = savedComponent ? savedComponent.isInstalled || this.get('markSavedComponentsAsInstalled') && !this.get('mastersToCreate').contains(fullComponent.get('componentName')) : false;
Iif (this.get('content.controllerName') === 'reassignMasterController' && componentName === 'NAMENODE' && App.get('hasNameNodeFederation')) {
componentObj.nameSpace = App.HostComponent.find(componentName + '_' + resultingHostName).get('haNameSpace');
}
return componentObj;
},
/**
* Success-callback for recommendations request
* @param {object} data
* @method loadRecommendationsSuccessCallback
*/
loadRecommendationsSuccessCallback: function loadRecommendationsSuccessCallback(data) {
var recommendations = data.resources[0].recommendations;
this.set('recommendations', recommendations);
if (this.get('content.controllerName')) {
this.set('content.recommendations', recommendations);
}
var recommendedHostsForComponent = {};
var hostsForHostGroup = {};
recommendations.blueprint_cluster_binding.host_groups.forEach(function (hostGroup) {
hostsForHostGroup[hostGroup.name] = hostGroup.hosts.mapProperty('fqdn');
});
recommendations.blueprint.host_groups.forEach(function (hostGroup) {
var components = hostGroup.components.mapProperty('name');
components.forEach(function (componentName) {
var hostList = recommendedHostsForComponent[componentName] || [];
var hostNames = hostsForHostGroup[hostGroup.name] || [];
hostList.pushObjects(hostNames);
recommendedHostsForComponent[componentName] = hostList;
});
});
this.set('recommendedHostsForComponents', recommendedHostsForComponent);
if (this.get('content.controllerName')) {
this.set('content.recommendedHostsForComponents', recommendedHostsForComponent);
}
},
/**
* Error-callback for recommendations request
* @param {object} jqXHR
* @param {object} ajaxOptions
* @param {string} error
* @param {object} opt
* @method loadRecommendationsErrorCallback
*/
loadRecommendationsErrorCallback: function loadRecommendationsErrorCallback(jqXHR, ajaxOptions, error, opt) {
App.ajax.defaultErrorHandler(jqXHR, opt.url, opt.type, jqXHR.status);
},
/**
* Put master components to <code>selectedServicesMasters</code>, which will be automatically rendered in template
* @param {Ember.Enumerable} masterComponents
* @method renderComponents
*/
renderComponents: function renderComponents(masterComponents) {
var installedServices = App.StackService.find().filterProperty('isSelected').filterProperty('isInstalled', false).mapProperty('serviceName'); //list of shown services
var result = [];
var serviceComponentId, previousComponentName;
this.addNewMasters(masterComponents);
masterComponents.forEach(function (item) {
var masterComponent = App.StackServiceComponent.find().findProperty('componentName', item.component_name);
var componentObj = Em.Object.create(item, item.nameSpace ? {
allMasters: result,
/**
* Namespace of NameNode for enabled HDFS federation.
* If a new host is assigned to component, looking for other NameNodes
* to find which namespace has a 'free' host after this assignment.
* NameNodes with new host assigned are excluded from this process
* since moving more than one component at once is not allowed.
*/
nameSpace: function () {
var _this = this;
var hostComponent = App.HostComponent.find(this.get('component_name') + '_' + this.get('selectedHost'));
if (hostComponent.get('isLoaded')) {
return hostComponent.get('haNameSpace');
} else {
var nameSpacesCounts = {};
var allNameSpaces = this.get('allMasters').filter(function (masterComponent) {
return masterComponent.get('serviceComponentId') !== _this.get('serviceComponentId') && App.HostComponent.find(masterComponent.get('component_name') + '_' + masterComponent.get('selectedHost')).get('isLoaded') && masterComponent.get('nameSpace');
}).mapProperty('nameSpace');
allNameSpaces.forEach(function (nameSpace) {
var currentCount = nameSpacesCounts[nameSpace];
nameSpacesCounts[nameSpace] = currentCount ? currentCount + 1 : 1;
});
var nameSpacesWithMissingHost = Object.keys(nameSpacesCounts).filter(function (key) {
return nameSpacesCounts[key] === 1;
});
if (nameSpacesWithMissingHost.length === 1) {
return nameSpacesWithMissingHost[0];
}
}
}.property('allMasters.@each.selectedHost')
} : {});
var showRemoveControl;
Eif (masterComponent.get('isMasterWithMultipleInstances')) {
showRemoveControl = installedServices.contains(masterComponent.get('stackService.serviceName')) && masterComponents.filterProperty('component_name', item.component_name).length > 1;
previousComponentName = item.component_name;
componentObj.set('serviceComponentId', result.filterProperty('component_name', item.component_name).length + 1);
componentObj.set("showRemoveControl", showRemoveControl);
}
componentObj.set('isHostNameValid', true);
componentObj.set('showCurrentPrefix', this.get('showCurrentPrefix').contains(item.component_name) && item.isInstalled);
componentObj.set('showAdditionalPrefix', this.get('showAdditionalPrefix').contains(item.component_name) && !item.isInstalled);
Iif (this.get('mastersToMove').contains(item.component_name)) {
componentObj.set('isInstalled', false);
}
result.push(componentObj);
}, this);
result = this.sortComponentsByServiceName(result);
this.set("selectedServicesMasters", result);
this.set('servicesMasters', result);
},
/**
* Add new master components from <code>mastersToAdd</code> list
* @param masterComponents
* @returns {masterComponents[]}
*/
addNewMasters: function addNewMasters(masterComponents) {
this.get('mastersToAdd').forEach(function (masterName, index, mastersToAdd) {
var toBeAddedNumber = mastersToAdd.filter(function (name) {
return name === masterName;
}).length,
alreadyAddedNumber = masterComponents.filterProperty('component_name', masterName).rejectProperty('isInstalled').length;
if (toBeAddedNumber > alreadyAddedNumber) {
var hostName = this.getHostForMaster(masterName, masterComponents),
serviceName = this.getServiceByMaster(masterName);
masterComponents.push(this.createComponentInstallationObject(Em.Object.create({
componentName: masterName,
serviceName: serviceName
}), hostName));
}
}, this);
return masterComponents;
},
/**
* Find available host for master and return it
* If there is no available hosts returns false
* @param master
* @param allMasters
* @returns {*}
*/
getHostForMaster: function getHostForMaster(master, allMasters) {
var masterHostList = [];
allMasters.forEach(function (component) {
if (component.component_name === master) {
masterHostList.push(component.selectedHost);
}
});
var recommendedHostsForMaster = this.get('recommendedHostsForComponents')[master] || [];
for (var k = 0; k < recommendedHostsForMaster.length; k++) {
if (!masterHostList.contains(recommendedHostsForMaster[k])) {
return recommendedHostsForMaster[k];
}
}
var usedHosts = allMasters.filterProperty('component_name', master).mapProperty('selectedHost');
var allHosts = this.get('hosts');
for (var i = 0; i < allHosts.length; i++) {
if (!usedHosts.contains(allHosts[i].get('host_name'))) {
return allHosts[i].get('host_name');
}
}
return false;
},
/**
* Find serviceName for master by it's componentName
* @param master
* @returns {*}
*/
getServiceByMaster: function getServiceByMaster(master) {
return App.StackServiceComponent.find().findProperty('componentName', master).get('serviceName');
},
/**
* Sort components by their service (using <code>App.StackService.displayOrder</code>)
* Services not in App.StackService.displayOrder are moved to the end of the list
*
* @param components
* @returns {*}
*/
sortComponentsByServiceName: function sortComponentsByServiceName(components) {
var displayOrder = App.StackService.displayOrder;
var componentsOrderForService = App.StackService.componentsOrderForService;
var indexForUnordered = Math.max(displayOrder.length, components.length);
return components.sort(function (a, b) {
if (a.serviceId === b.serviceId && a.serviceId in componentsOrderForService) return componentsOrderForService[a.serviceId].indexOf(a.component_name) - componentsOrderForService[b.serviceId].indexOf(b.component_name);
var aValue = displayOrder.indexOf(a.serviceId) != -1 ? displayOrder.indexOf(a.serviceId) : indexForUnordered;
var bValue = displayOrder.indexOf(b.serviceId) != -1 ? displayOrder.indexOf(b.serviceId) : indexForUnordered;
return aValue - bValue;
});
},
/**
* Update dependent co-hosted components according to the change in the component host
* @method updateCoHosts
*/
updateCoHosts: function () {
var components = App.StackServiceComponent.find().filterProperty('isOtherComponentCoHosted');
var selectedServicesMasters = this.get('selectedServicesMasters');
components.forEach(function (component) {
var componentName = component.get('componentName');
var hostComponent = selectedServicesMasters.findProperty('component_name', componentName);
var dependentCoHosts = component.get('coHostedComponents');
dependentCoHosts.forEach(function (coHostedComponent) {
var dependentHostComponent = selectedServicesMasters.findProperty('component_name', coHostedComponent);
if (!this.get('mastersToMove').contains(coHostedComponent) && hostComponent && dependentHostComponent) dependentHostComponent.set('selectedHost', hostComponent.get('selectedHost'));
}, this);
}, this);
}.observes('selectedServicesMasters.@each.selectedHost'),
/**
* On change callback for inputs
* @param {string} componentName
* @param {string} selectedHost
* @param {number} serviceComponentId
* @method assignHostToMaster
*/
assignHostToMaster: function assignHostToMaster(componentName, selectedHost, serviceComponentId) {
var flag = this.isHostNameValid(componentName, selectedHost);
var component;
this.updateIsHostNameValidFlag(componentName, serviceComponentId, flag);
if (serviceComponentId) {
component = this.get('selectedServicesMasters').filterProperty('component_name', componentName).findProperty("serviceComponentId", serviceComponentId);
Eif (component) component.set("selectedHost", selectedHost);
} else {
this.get('selectedServicesMasters').findProperty("component_name", componentName).set("selectedHost", selectedHost);
}
},
/**
* Determines if hostName is valid for component:
* <ul>
* <li>host name shouldn't be empty</li>
* <li>host should exist</li>
* <li>if host installed maintenance state should be 'OFF'</li>
* <li>host should have only one component with <code>componentName</code></li>
* </ul>
* @param {string} componentName
* @param {string} selectedHost
* @returns {boolean} true - valid, false - invalid
* @method isHostNameValid
*/
isHostNameValid: function isHostNameValid(componentName, selectedHost) {
return selectedHost.trim() !== '' && this.get('hosts').filter(function (host) {
return host.host_name === selectedHost && (!host.isInstalled || host.maintenance_state === 'OFF');
}).length > 0 && this.get('selectedServicesMasters').filterProperty('component_name', componentName).mapProperty('selectedHost').filter(function (h) {
return h === selectedHost;
}).length <= 1;
},
/**
* Update <code>isHostNameValid</code> property with <code>flag</code> value
* for component with name <code>componentName</code> and
* <code>serviceComponentId</code>-property equal to <code>serviceComponentId</code>-parameter value
* @param {string} componentName
* @param {number} serviceComponentId
* @param {bool} flag
* @method updateIsHostNameValidFlag
*/
updateIsHostNameValidFlag: function updateIsHostNameValidFlag(componentName, serviceComponentId, flag) {
var component;
Eif (componentName) {
if (serviceComponentId) {
component = this.get('selectedServicesMasters').filterProperty('component_name', componentName).findProperty("serviceComponentId", serviceComponentId);
} else {
component = this.get('selectedServicesMasters').findProperty("component_name", componentName);
}
Eif (component) {
component.set("isHostNameValid", flag);
component.set("errorMessage", flag ? null : Em.I18n.t('installer.step5.error.host.invalid'));
}
}
},
/**
* Returns last component of selected type
* @param {string} componentName
* @return {Em.Object|null}
* @method last
*/
last: function last(componentName) {
return this.get("selectedServicesMasters").filterProperty("component_name", componentName).get("lastObject");
},
/**
* Add new component to ZooKeeper Server and Hbase master
* @param {string} componentName
* @return {bool} true - added, false - not added
* @method addComponent
*/
addComponent: function addComponent(componentName) {
/*
* Logic: If ZooKeeper or Hbase service is selected then there can be
* minimum 1 ZooKeeper or Hbase master in total, and
* maximum 1 ZooKeeper or Hbase on every host
*/
var maxNumMasters = this.getMaxNumberOfMasters(componentName),
currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName).sortProperty('serviceComponentId'),
newMaster = null,
masterHosts = null,
suggestedHost = null,
i = 0,
lastMaster = null;
if (!currentMasters.length) {
return false;
}
Eif (currentMasters.get("length") < maxNumMasters) {
currentMasters.set("lastObject.showAddControl", false);
currentMasters.set("lastObject.showRemoveControl", true);
//create a new master component host based on an existing one
newMaster = Em.Object.create({});
lastMaster = currentMasters.get("lastObject");
newMaster.set("display_name", lastMaster.get("display_name"));
newMaster.set("component_name", lastMaster.get("component_name"));
newMaster.set("selectedHost", lastMaster.get("selectedHost"));
newMaster.set("serviceId", lastMaster.get("serviceId"));
newMaster.set("isInstalled", false);
newMaster.set('showAdditionalPrefix', this.get('showAdditionalPrefix').contains(lastMaster.get("component_name")));
Iif (currentMasters.get("length") === maxNumMasters - 1) {
newMaster.set("showAddControl", false);
} else {
newMaster.set("showAddControl", true);
}
newMaster.set("showRemoveControl", true);
//get recommended host for the new Zookeeper server
masterHosts = currentMasters.mapProperty("selectedHost").uniq();
for (i = 0; i < this.get("hosts.length"); i++) {
Iif (!masterHosts.contains(this.get("hosts")[i].get("host_name"))) {
suggestedHost = this.get("hosts")[i].get("host_name");
break;
}
}
newMaster.set("selectedHost", suggestedHost);
newMaster.set("serviceComponentId", currentMasters.get("lastObject.serviceComponentId") + 1);
this.get("selectedServicesMasters").insertAt(this.get("selectedServicesMasters").indexOf(lastMaster) + 1, newMaster);
this.setProperties({
componentToRebalance: componentName,
lastChangedComponent: componentName
});
this.incrementProperty('rebalanceComponentHostsCounter');
this.toggleProperty('hostNameCheckTrigger');
return true;
}
return false; //if no more zookeepers can be added
},
/**
* Remove component from ZooKeeper server or Hbase Master
* @param {string} componentName
* @param {number} serviceComponentId
* @return {bool} true - removed, false - no
* @method removeComponent
*/
removeComponent: function removeComponent(componentName, serviceComponentId) {
var currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName);
//work only if the multiple master service is selected in previous step
if (currentMasters.length <= 1) {
return false;
}
this.get("selectedServicesMasters").removeAt(this.get("selectedServicesMasters").indexOf(currentMasters.findProperty("serviceComponentId", serviceComponentId)));
currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName);
Eif (currentMasters.get("length") < this.getMaxNumberOfMasters(componentName)) {
currentMasters.set("lastObject.showAddControl", true);
}
Iif (currentMasters.filterProperty('isInstalled', false).get("length") === 1) {
currentMasters.set("lastObject.showRemoveControl", false);
}
this.setProperties({
componentToRebalance: componentName,
lastChangedComponent: componentName
});
this.incrementProperty('rebalanceComponentHostsCounter');
this.toggleProperty('hostNameCheckTrigger');
return true;
},
recommendAndValidate: function recommendAndValidate(callback) {
var self = this,
hostNames = this.getHosts();
if (this.get('validationInProgress')) {
this.set('runQueuedValidation', true);
return;
}
this.set('validationInProgress', true);
// load recommendations with partial request
this.getRecommendedHosts({
hosts: hostNames,
components: this.getCurrentComponentHostMap()
}).done(function () {
self.validateSelectedHostComponents({
hosts: hostNames,
blueprint: self.get('recommendations')
}).always(function () {
if (callback) {
callback();
}
self.set('validationInProgress', false);
if (self.get('runQueuedValidation')) {
self.set('runQueuedValidation', false);
self.recommendAndValidate(callback);
}
});
});
},
getCurrentComponentHostMap: function getCurrentComponentHostMap() {
return this.get('masterHostMapping').reduce(function (acc, i) {
var components = Em.getWithDefault(i, 'masterServices', []);
var hostName = Em.get(i, 'host_name');
components.forEach(function (i) {
var componentName = Em.get(i, 'component_name');
var component = acc.findProperty('componentName', componentName);
if (component) {
Em.set(component, 'hosts', Em.getWithDefault(component, 'hosts', []).concat(hostName).uniq());
Em.set(component, 'size', Em.getWithDefault(component, 'hosts.length', 0));
} else {
acc.push({
componentName: componentName,
hosts: [hostName],
size: 1
});
}
});
return acc;
}, []);
},
_goNextStepIfValid: function _goNextStepIfValid() {
if (!this.get('submitDisabled')) {
App.router.send('next');
} else {
App.set('router.nextBtnClickInProgress', false);
}
},
nextButtonDisabled: Em.computed.or('App.router.btnClickInProgress', 'submitDisabled', 'validationInProgress', '!isLoaded'),
/**
* Submit button click handler
* Disable 'Next' button while it is already under process. (using Router's property 'nextBtnClickInProgress')
* @method submit
*/
submit: function submit() {
var self = this;
if (this.get('submitDisabled')) {
return;
}
if (!this.get('submitButtonClicked') && !App.get('router.nextBtnClickInProgress')) {
this.set('submitButtonClicked', true);
App.router.set('nextBtnClickInProgress', true);
if (this.get('useServerValidation')) {
self.recommendAndValidate(function () {
self.showValidationIssuesAcceptBox(self._goNextStepIfValid.bind(self));
});
} else {
this.updateIsSubmitDisabled();
this._goNextStepIfValid();
this.set('submitButtonClicked', false);
}
}
},
/**
* In case of any validation issues shows accept dialog box for user which allow cancel and fix issues or continue anyway
* @method showValidationIssuesAcceptBox
*/
showValidationIssuesAcceptBox: function showValidationIssuesAcceptBox(callback) {
var self = this;
// If there are no warnings and no errors, return
if (!self.get('anyWarning') && !self.get('anyError')) {
callback();
self.set('submitButtonClicked', false);
return;
}
App.ModalPopup.show({
'data-qa': 'validation-issues-modal',
primary: Em.I18n.t('common.continueAnyway'),
header: Em.I18n.t('installer.step5.validationIssuesAttention.header'),
body: Em.I18n.t('installer.step5.validationIssuesAttention'),
onPrimary: function onPrimary() {
this._super();
callback();
self.set('submitButtonClicked', false);
},
onSecondary: function onSecondary() {
this._super();
App.router.set('nextBtnClickInProgress', false);
self.set('submitButtonClicked', false);
},
onClose: function onClose() {
this._super();
self.set('submitButtonClicked', false);
}
});
},
getHosts: function getHosts() {
return Em.keys(this.get('content.hosts'));
}
});
}); |