| 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 |
1
1
1
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
10
10
10
10
10
10
64
10
20
20
20
20
3
15
15
3
3
53
53
123
123
123
55
68
68
15
15
6
6
6
6
6
6
6
6
6
3
2
2
2
2
1
1
1
1
1
3
1
1
2
1
1
1
1
1
1
1
1
15
15
15
15
12
12
22
12
12
12
17
12
12
12
2
2
2
2
2
18
7
18
18
5
5
4
1
| 'use strict';
;require.register("mixins/wizard/wizardProgressPageController", 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');
/**
* Mixin for wizard controller for showing command progress on wizard pages
* This should
* @type {Ember.Mixin}
*/
App.wizardProgressPageControllerMixin = Em.Mixin.create(App.InstallComponent, {
controllerName: '',
clusterDeployState: 'WIZARD_DEPLOY',
status: 'IN_PROGRESS',
tasks: [],
commands: [],
currentRequestIds: [], //todo: replace with using requestIds from tasks
logs: [],
currentTaskId: null,
POLL_INTERVAL: 4000,
isSubmitDisabled: true,
isBackButtonDisabled: true,
stages: [],
/**
* List of statuses that inform about the end of request progress.
* @type {String[]}
*/
completedStatuses: ['COMPLETED', 'FAILED', 'TIMEDOUT', 'ABORTED'],
currentPageRequestId: null,
isSingleRequestPage: false,
isCommandLevelRetry: Em.computed.not('isSingleRequestPage'),
showRetry: false,
/**
* Show whether tasks data was loaded
* @type {Boolean}
*/
isLoading: false,
k: Em.K,
/**
* tasksMessagesPrefix should be overloaded by any controller including the mixin
*/
tasksMessagesPrefix: '',
loadStep: function loadStep() {
this.clearStep();
var self = this;
Eif (!self.isSingleRequestPage) {
this.initStep();
} else {
var requestIds = this.get('content.tasksRequestIds');
var currentRequestId = requestIds && requestIds[0][0];
if (!currentRequestId) {
this.set('isLoaded', false);
this.submitRequest();
} else {
self.set('currentPageRequestId', currentRequestId);
self.doPollingForPageRequest();
}
}
},
initStep: function initStep() {
this.initializeTasks();
Eif (!this.isSingleRequestPage) {
this.loadTasks();
}
this.addObserver('tasks.@each.status', this, 'onTaskStatusChange');
Iif (this.isSingleRequestPage) {
var dfd = $.Deferred();
var dfdObject = {
deferred: dfd,
isJqueryPromise: true
};
this.onTaskStatusChange(dfdObject);
return dfd.promise();
} else {
this.onTaskStatusChange();
}
},
clearStep: function clearStep() {
this.removeObserver('tasks.@each.status', this, 'onTaskStatusChange');
this.set('isSubmitDisabled', true);
this.set('isBackButtonDisabled', true);
this.set('tasks', []);
this.set('currentRequestIds', []);
this.set('isLoaded', false);
},
/**
* Clear stages info for single page request.
*/
clearStage: function clearStage() {
this.setDBProperties({
tasksRequestIds: null,
tasksStatuses: null
});
this.set('showRetry', false);
this.set('content.tasksRequestIds', null);
this.set('content.tasksStatuses', null);
this.set('content.currentTaskId', null);
this.get('stages').clear();
},
retry: function retry() {
this.set('showRetry', false);
this.get('tasks').setEach('status', 'PENDING');
this.loadStep();
},
submitRequest: function submitRequest() {
var self = this;
return App.ajax.send({
name: this.get('request.ajaxName'),
data: this.get('request.ajaxData'),
sender: this,
error: 'onSingleRequestError',
success: 'submitRequestSuccess',
kdcCancelHandler: function kdcCancelHandler() {
self.set('status', 'FAILED');
self.set('isLoaded', true);
self.set('showRetry', true);
}
});
},
submitRequestSuccess: function submitRequestSuccess(data, result, request) {
if (data) {
this.set('currentPageRequestId', data.Requests.id);
this.doPollingForPageRequest();
} else {
//Step has been successfully completed
if (request.status === 200) {
this.set('status', 'COMPLETED');
this.set('isSubmitDisabled', false);
this.set('isLoaded', true);
}
}
},
doPollingForPageRequest: function doPollingForPageRequest() {
App.ajax.send({
name: 'admin.poll.kerberize.cluster.request',
sender: this,
data: {
requestId: this.get('currentPageRequestId')
},
success: 'initializeStages'
});
},
initializeStages: function initializeStages(data) {
var self = this;
var stages = [];
this.set('logs', []);
data.stages.forEach(function (_stage) {
stages.pushObject(Em.Object.create(_stage.Stage));
}, this);
if (!this.get('stages').length) {
this.get('stages').pushObjects(stages);
this.initStep().done(function () {
self.updatePageWithPolledData(data);
});
} else {
this.updatePageWithPolledData(data);
}
},
updatePageWithPolledData: function updatePageWithPolledData(data) {
// If all tasks completed no need to update each task status.
// Preferable to skip polling of data for completed tasks after page refresh.
if (this.get('status') === 'COMPLETED') return;
var self = this;
var tasks = [];
var currentPageRequestId = this.get('currentPageRequestId');
var currentTaskId = this.get('currentTaskId');
var currentTask = this.get('tasks').findProperty('id', currentTaskId);
var currentStage = data.stages.findProperty('Stage.stage_id', currentTask.get('stageId'));
var tasksInCurrentStage = currentStage.tasks;
this.set('logs', tasksInCurrentStage);
this.setRequestIds(this.get('currentTaskId'), [this.get('currentPageRequestId')]);
if (!tasksInCurrentStage.someProperty('Tasks.status', 'PENDING') && !tasksInCurrentStage.someProperty('Tasks.status', 'QUEUED') && !tasksInCurrentStage.someProperty('Tasks.status', 'IN_PROGRESS')) {
this.set('currentRequestIds', []);
if (tasksInCurrentStage.someProperty('Tasks.status', 'FAILED') || tasksInCurrentStage.someProperty('Tasks.status', 'TIMEDOUT') || tasksInCurrentStage.someProperty('Tasks.status', 'ABORTED')) {
this.setTaskStatus(currentTaskId, 'FAILED');
} else {
this.setTaskStatus(currentTaskId, 'COMPLETED');
}
} else {
var completedActions = tasksInCurrentStage.filterProperty('Tasks.status', 'COMPLETED').length + tasksInCurrentStage.filterProperty('Tasks.status', 'FAILED').length + tasksInCurrentStage.filterProperty('Tasks.status', 'ABORTED').length + tasksInCurrentStage.filterProperty('Tasks.status', 'TIMEDOUT').length;
var queuedActions = tasksInCurrentStage.filterProperty('Tasks.status', 'QUEUED').length;
var inProgressActions = tasksInCurrentStage.filterProperty('Tasks.status', 'IN_PROGRESS').length;
var progress = Math.floor((queuedActions * 0.09 + inProgressActions * 0.35 + completedActions) / tasksInCurrentStage.length * 100);
this.get('tasks').findProperty('id', currentTaskId).set('progress', progress);
}
// start polling if current request not completed
if (!this.get('completedStatuses').contains(this.get('status'))) {
window.setTimeout(function () {
self.doPollingForPageRequest();
}, self.POLL_INTERVAL);
}
},
initializeTasks: function initializeTasks() {
var self = this;
var commands = this.isSingleRequestPage ? this.get('stages') : this.get('commands');
var currentStep = App.router.get(this.get('content.controllerName') + '.currentStep');
var tasksMessagesPrefix = this.get('tasksMessagesPrefix');
// check that all stages have been completed for single request type
var allStagesCompleted = commands.everyProperty('status', 'COMPLETED');
for (var i = 0; i < commands.length; i++) {
this.get('tasks').pushObject(Ember.Object.create({
title: self.isSingleRequestPage ? commands[i].get('context') : Em.I18n.t(tasksMessagesPrefix + currentStep + '.task' + i + '.title'),
// set COMPLETED status for task if all stages completed successfully
status: allStagesCompleted ? 'COMPLETED' : 'PENDING',
id: i,
stageId: self.isSingleRequestPage ? commands[i].get('stage_id') : null,
command: self.isSingleRequestPage ? 'k' : commands[i],
showRetry: false,
showRollback: false,
name: self.isSingleRequestPage ? commands[i].get('context') : Em.I18n.t(tasksMessagesPrefix + currentStep + '.task' + i + '.title'),
displayName: self.isSingleRequestPage ? commands[i].get('context') : Em.I18n.t(tasksMessagesPrefix + currentStep + '.task' + i + '.title'),
progress: 0,
isRunning: false,
requestIds: self.isSingleRequestPage ? [this.get('stages')[0].request_id] : []
}));
}
this.set('isLoaded', true);
},
loadTasks: function loadTasks() {
var self = this;
var loadedStatuses = this.get('content.tasksStatuses');
var loadedRequestIds = this.get('content.tasksRequestIds');
if (loadedStatuses && loadedStatuses.length === this.get('tasks').length) {
this.get('tasks').forEach(function (task, i) {
self.setTaskStatus(task.get('id'), loadedStatuses[i]);
self.setRequestIds(task.get('id'), loadedRequestIds[i]);
});
Iif (loadedStatuses.contains('IN_PROGRESS')) {
var curTaskId = this.get('tasks')[loadedStatuses.indexOf('IN_PROGRESS')].get('id');
this.set('currentRequestIds', this.get('content.requestIds'));
this.set('currentTaskId', curTaskId);
this.doPolling();
} else Iif (loadedStatuses.contains('QUEUED')) {
var curTaskId = this.get('tasks')[loadedStatuses.indexOf('QUEUED')].get('id');
this.set('currentTaskId', curTaskId);
this.runTask(curTaskId);
}
}
},
/**
* remove tasks by command name
*/
removeTasks: function removeTasks(commands) {
var tasks = this.get('tasks');
commands.forEach(function (command) {
var cmd = tasks.filterProperty('command', command);
var index = null;
if (cmd.length === 0) {
return false;
} else {
index = tasks.indexOf(cmd[0]);
}
tasks.splice(index, 1);
});
},
setTaskStatus: function setTaskStatus(taskId, status) {
this.get('tasks').findProperty('id', taskId).set('status', status);
},
setTaskCanSkip: function setTaskCanSkip(taskId, canSkip) {
this.get('tasks').findProperty('id', taskId).set('canSkip', true);
},
setRequestIds: function setRequestIds(taskId, requestIds) {
this.get('tasks').findProperty('id', taskId).set('requestIds', requestIds);
},
retryTask: function retryTask() {
var task = this.get('tasks').findProperty('status', 'FAILED');
task.set('showRetry', false);
task.set('showRollback', false);
this.set('isSubmitDisabled', true);
this.set('isBackButtonDisabled', true);
task.set('status', 'PENDING');
},
onTaskStatusChange: function onTaskStatusChange(dfdObject) {
var statuses = this.get('tasks').mapProperty('status');
var tasksRequestIds = this.get('tasks').mapProperty('requestIds');
var requestIds = this.get('currentRequestIds');
// save task info
App.router.get(this.get('content.controllerName')).saveTasksStatuses(statuses);
App.router.get(this.get('content.controllerName')).saveTasksRequestIds(tasksRequestIds);
App.router.get(this.get('content.controllerName')).saveRequestIds(requestIds);
// call saving of cluster status asynchronous
// synchronous executing cause problems in Firefox
var successCallbackData;
Iif (dfdObject && dfdObject.isJqueryPromise) {
successCallbackData = { deferred: dfdObject.deferred };
}
App.clusterStatus.setClusterStatus({
clusterName: App.router.getClusterName(),
clusterState: this.get('clusterDeployState'),
wizardControllerName: this.get('content.controllerName'),
localdb: App.db.data
}, { successCallback: this.statusChangeCallback, sender: this, successCallbackData: successCallbackData });
},
/**
* Method that called after saving persist data to server.
* Switch task according its status.
*/
statusChangeCallback: function statusChangeCallback(data) {
if (!this.get('tasks').someProperty('status', 'IN_PROGRESS') && !this.get('tasks').someProperty('status', 'QUEUED') && !this.get('tasks').someProperty('status', 'FAILED')) {
var nextTask = this.get('tasks').findProperty('status', 'PENDING');
if (nextTask) {
this.set('status', 'IN_PROGRESS');
var taskStatus = this.isSingleRequestPage ? 'IN_PROGRESS' : 'QUEUED';
this.setTaskStatus(nextTask.get('id'), taskStatus);
this.set('currentTaskId', nextTask.get('id'));
this.runTask(nextTask.get('id'));
} else {
this.set('status', 'COMPLETED');
this.set('isSubmitDisabled', false);
this.set('isBackButtonDisabled', false);
}
} else if (this.get('tasks').someProperty('status', 'FAILED')) {
this.set('status', 'FAILED');
this.set('isBackButtonDisabled', false);
if (this.get('isCommandLevelRetry')) {
this.get('tasks').findProperty('status', 'FAILED').set('showRetry', true);
} else {
this.set('showRetry', true);
}
if (this.get('tasks').someProperty('canSkip', true)) {
this.get('tasks').findProperty('canSkip', true).set('showSkip', true);
}
if (App.supports.autoRollbackHA) {
this.get('tasks').findProperty('status', 'FAILED').set('showRollback', true);
}
}
this.get('tasks').filterProperty('status', 'COMPLETED').setEach('showRetry', false);
this.get('tasks').filterProperty('status', 'COMPLETED').setEach('showRollback', false);
this.get('tasks').filterProperty('status', 'COMPLETED').setEach('showSkip', false);
this.get('tasks').filterProperty('status', 'IN_PROGRESS').setEach('showSkip', false);
if (data && data.deferred) {
data.deferred.resolve();
}
},
/**
* Run command of appropriate task
*/
runTask: function runTask(taskId) {
this[this.get('tasks').findProperty('id', taskId).get('command')]();
},
onTaskError: function onTaskError() {
this.setTaskStatus(this.get('currentTaskId'), 'FAILED');
},
onTaskErrorWithSkip: function onTaskErrorWithSkip() {
this.onTaskError();
this.setTaskCanSkip(this.get('currentTaskId'), true);
},
onSingleRequestError: function onSingleRequestError(jqXHR, ajaxOptions, error, opt) {
App.ajax.defaultErrorHandler(jqXHR, opt.url, opt.type, jqXHR.status);
this.set('status', 'FAILED');
this.set('isLoaded', true);
this.set('showRetry', true);
},
onTaskCompleted: function onTaskCompleted() {
this.setTaskStatus(this.get('currentTaskId'), 'COMPLETED');
},
/**
* check whether component installed on specified hosts
* @param {string} componentName
* @param {string[]} hostNames
* @return {$.ajax}
*/
checkInstalledComponents: function checkInstalledComponents(componentName, hostNames) {
return App.ajax.send({
name: 'host_component.installed.on_hosts',
sender: this,
data: {
componentName: componentName,
hostNames: hostNames.join(',')
}
});
},
/**
* make server call to stop services
* if stopListedServicesFlag == false; stop all services excluding the services passed as parameters
* if stopListedServicesFlag == true; stop only services passed as parameters
* if namenode or secondary namenode then stop all services
* @param services, stopListedServicesFlag, stopAllServices
* @returns {$.ajax}
*/
stopServices: function stopServices(services, stopListedServicesFlag, stopAllServices) {
var stopAllServices = stopAllServices || false;
var stopListedServicesFlag = stopListedServicesFlag || false;
var data = {
'ServiceInfo': {
'state': 'INSTALLED'
}
};
if (stopAllServices) {
data.context = "Stop all services";
} else {
Iif (!services || !services.length) {
services = App.Service.find().mapProperty('serviceName').filter(function (service) {
return service != 'HDFS';
});
}
var servicesList;
Iif (stopListedServicesFlag) {
servicesList = services.join(',');
} else {
servicesList = App.Service.find().mapProperty("serviceName").filter(function (s) {
return !services.contains(s);
}).join(',');
}
data.context = "Stop required services";
data.urlParams = "ServiceInfo/service_name.in(" + servicesList + ")";
}
return App.ajax.send({
name: 'common.services.update',
sender: this,
data: data,
success: 'startPolling',
error: 'onTaskError'
});
},
/*tep4
* make server call to start services
* if startListedServicesFlag == false; start all services excluding the services passed as parameters
* if startListedServicesFlag == true; start only services passed as parameters
* if no parameters are passed; start all services
* and run smoke tests if runSmokeTest is true
* @param runSmokeTest
* @param services
* @param startListedServicesFlag
* @returns {$.ajax}
*/
startServices: function startServices(runSmokeTest, services, startListedServicesFlag) {
var startListedServicesFlag = startListedServicesFlag || false;
var skipServiceCheck = App.router.get('clusterController.ambariProperties')['skip.service.checks'] === "true";
var data = {
'ServiceInfo': {
'state': 'STARTED'
}
};
var servicesList;
Iif (services && services.length) {
if (startListedServicesFlag) {
servicesList = services.join(',');
} else {
servicesList = App.Service.find().mapProperty("serviceName").filter(function (s) {
return !services.contains(s);
}).join(',');
}
data.context = "Start required services";
data.urlParams = "ServiceInfo/service_name.in(" + servicesList + ")";
} else {
data.context = "Start all services";
}
Iif (runSmokeTest) {
data.urlParams = data.urlParams ? data.urlParams + '&' : '';
data.urlParams += 'params/run_smoke_test=' + !skipServiceCheck;
}
return App.ajax.send({
name: 'common.services.update',
sender: this,
data: data,
success: 'startPolling',
error: 'startServicesErrorCallback'
});
},
startServicesErrorCallback: function startServicesErrorCallback(jqXHR, ajaxOptions, error, opt) {
App.ajax.defaultErrorHandler(jqXHR, opt.url, opt.type, jqXHR.status);
this.onTaskError(jqXHR, ajaxOptions, error, opt);
},
/**
* Create component on single or multiple hosts.
*
* @method createComponent
* @param {string} componentName - name of the component
* @param {(string|string[])} hostName - host/hosts where components should be installed
* @param {string} serviceName - name of the services
*/
createComponent: function createComponent(componentName, hostName, serviceName) {
var hostNames = Array.isArray(hostName) ? hostName : [hostName];
var self = this;
this.set('showRetry', false);
this.checkInstalledComponents(componentName, hostNames).then(function (data) {
var hostsWithComponents = data.items.mapProperty('HostRoles.host_name');
var result = hostNames.map(function (item) {
return {
componentName: componentName,
hostName: item,
hasComponent: hostsWithComponents.contains(item)
};
});
var hostsWithoutComponents = result.filterProperty('hasComponent', false).mapProperty('hostName');
var taskNum = 1;
var requestData = {
"RequestInfo": {
"query": hostsWithoutComponents.map(function (item) {
return 'Hosts/host_name=' + item;
}).join('|')
},
"Body": {
"host_components": [{
"HostRoles": {
"component_name": componentName
}
}]
}
};
Eif (!!hostsWithoutComponents.length) {
self.updateAndCreateServiceComponent(componentName).done(function () {
App.ajax.send({
name: 'wizard.step8.register_host_to_component',
sender: self,
data: {
data: JSON.stringify(requestData),
hostName: result.mapProperty('hostName'),
componentName: componentName,
serviceName: serviceName,
taskNum: taskNum,
cluster: App.get('clusterName')
},
success: 'onCreateComponent',
error: 'onCreateComponent'
});
});
} else {
self.onCreateComponent(null, null, {
hostName: result.mapProperty('hostName'),
componentName: componentName,
serviceName: serviceName,
taskNum: taskNum
}, self);
}
});
},
onCreateComponent: function onCreateComponent() {
var hostName = arguments[2].hostName;
var componentName = arguments[2].componentName;
var taskNum = arguments[2].taskNum;
var serviceName = arguments[2].serviceName;
this.updateComponent(componentName, hostName, serviceName, "Install", taskNum);
},
onCreateComponentError: function onCreateComponentError(error) {
if (error.responseText.indexOf('org.apache.ambari.server.controller.spi.ResourceAlreadyExistsException') !== -1) {
this.onCreateComponent();
} else {
this.onTaskError();
}
},
/**
* Update component status on selected hosts.
*
* @param {string} componentName
* @param {(string|string[]|null)} hostName - use null to update components on all hosts
* @param {string} serviceName
* @param {string} context
* @param {number} taskNum
* @returns {$.ajax}
*/
updateComponent: function updateComponent(componentName, hostName, serviceName, context, taskNum) {
if (hostName && !(hostName instanceof Array)) {
hostName = [hostName];
}
var state = context.toLowerCase() == "start" ? "STARTED" : "INSTALLED";
return App.ajax.send({
name: 'common.host_components.update',
sender: this,
data: {
HostRoles: {
state: state
},
query: 'HostRoles/component_name=' + componentName + (hostName ? '&HostRoles/host_name.in(' + hostName.join(',') + ')' : '') + '&HostRoles/maintenance_state=OFF',
context: context + " " + App.format.role(componentName, false),
hostName: hostName,
taskNum: taskNum || 1,
componentName: componentName,
serviceName: serviceName
},
success: 'startPolling',
error: 'onTaskError'
});
},
/**
* Update state for array of components of different services and on different hosts
*
* @param {Array} components - array of components object with fields serviceName, hostName and componentName
* @param {String} state - new state to update
*/
updateComponentsState: function updateComponentsState(components, state) {
components.forEach(function (component) {
App.ajax.send({
name: 'common.host.host_component.update',
sender: this,
data: {
hostName: component.hostName,
serviceName: component.serviceName,
componentName: component.componentName,
HostRoles: {
state: state
},
taskNum: components.length
},
success: 'startPolling',
error: 'onTaskError'
});
}, this);
},
startPolling: function startPolling(data) {
if (data) {
this.get('currentRequestIds').push(data.Requests.id);
var tasksCount = arguments[2].taskNum || 1;
if (tasksCount === this.get('currentRequestIds').length) {
this.setRequestIds(this.get('currentTaskId'), this.get('currentRequestIds'));
this.doPolling();
}
} else {
this.onTaskCompleted();
}
},
doPolling: function doPolling() {
this.setTaskStatus(this.get('currentTaskId'), 'IN_PROGRESS');
var requestIds = this.get('currentRequestIds');
this.set('logs', []);
for (var i = 0; i < requestIds.length; i++) {
App.ajax.send({
name: 'background_operations.get_by_request',
sender: this,
data: {
requestId: requestIds[i]
},
success: 'parseLogs',
error: 'onTaskError'
});
}
},
parseLogs: function parseLogs(logs) {
this.get('logs').pushObject(logs.tasks);
if (this.get('currentRequestIds').length === this.get('logs').length) {
var tasks = [];
this.get('logs').forEach(function (logs) {
tasks.pushObjects(logs);
}, this);
var self = this;
var currentTaskId = this.get('currentTaskId');
if (!tasks.someProperty('Tasks.status', 'PENDING') && !tasks.someProperty('Tasks.status', 'QUEUED') && !tasks.someProperty('Tasks.status', 'IN_PROGRESS')) {
this.set('currentRequestIds', []);
if (tasks.someProperty('Tasks.status', 'FAILED') || tasks.someProperty('Tasks.status', 'TIMEDOUT') || tasks.someProperty('Tasks.status', 'ABORTED')) {
this.setTaskStatus(currentTaskId, 'FAILED');
} else {
this.setTaskStatus(currentTaskId, 'COMPLETED');
}
} else {
var actionsPerHost = tasks.length;
var completedActions = tasks.filterProperty('Tasks.status', 'COMPLETED').length + tasks.filterProperty('Tasks.status', 'FAILED').length + tasks.filterProperty('Tasks.status', 'ABORTED').length + tasks.filterProperty('Tasks.status', 'TIMEDOUT').length;
var queuedActions = tasks.filterProperty('Tasks.status', 'QUEUED').length;
var inProgressActions = tasks.filterProperty('Tasks.status', 'IN_PROGRESS').length;
var progress = Math.floor((queuedActions * 0.09 + inProgressActions * 0.35 + completedActions) / actionsPerHost * 100);
this.get('tasks').findProperty('id', currentTaskId).set('progress', progress);
window.setTimeout(function () {
self.doPolling();
}, self.POLL_INTERVAL);
}
}
},
showHostProgressPopup: function showHostProgressPopup(event) {
if (!['IN_PROGRESS', 'FAILED', 'COMPLETED'].contains(Em.get(event.context, 'status')) || !event.contexts[0].requestIds.length) {
return;
}
var popupTitle = event.contexts[0].title,
requestIds = event.contexts[0].requestIds,
stageId = event.contexts[0].stageId,
hostProgressPopupController = App.router.get('highAvailabilityProgressPopupController');
hostProgressPopupController.initPopup(popupTitle, requestIds, this, true, stageId);
},
done: function done() {
if (!this.get('isSubmitDisabled')) {
this.set('isSubmitDisabled', true);
this.removeObserver('tasks.@each.status', this, 'onTaskStatusChange');
App.router.send('next');
}
},
back: function back() {
if (!this.get('isBackButtonDisabled')) {
this.set('isBackButtonDisabled', true);
this.removeObserver('tasks.@each.status', this, 'onTaskStatusChange');
App.router.send('back');
}
},
/**
* Delete component on single hosts.
*
* @method deleteComponent
* @param {string} componentName - name of the component
* @param {string} hostName - host from where components should be deleted
*/
deleteComponent: function deleteComponent(componentName, hostName) {
App.ajax.send({
name: 'common.delete.host_component',
sender: this,
data: {
componentName: componentName,
hostName: hostName
},
success: 'onTaskCompleted',
error: 'onDeleteHostComponentsError'
});
},
onDeleteHostComponentsError: function onDeleteHostComponentsError(error) {
// If the component does not exist on the host, NoSuchResourceException is thrown.
// If NoSuchResourceException is thrown, there is no action required and operation should continue.
if (error.responseText.indexOf('org.apache.ambari.server.controller.spi.NoSuchResourceException') !== -1) {
this.onTaskCompleted();
} else {
this.onTaskError();
}
},
/**
* Same as <code>createComponent</code> but with kdc session check and status changes
* when KDC auth dialog dissmised.
*
* @see createComponent
*/
createInstallComponentTask: function createInstallComponentTask(componentName, hostName, serviceName, options) {
var self = this;
App.get('router.mainAdminKerberosController').getKDCSessionState(function () {
self.createComponent(componentName, hostName, serviceName);
}, function () {
self.onTaskError();
});
}
});
}); |