| 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 |
1
1
1
1
536
56
480
2
1
1
4
3
3
3
2
3
2
1
1
3
1
2
1
1
2
2
7
4
3
3
3
1
2
3
3
1
1
4
4
4
2
2
2
2
2
2
2
2
5
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
2
2
1
1
1
1
1
1
1
| 'use strict';
;require.register("controllers/main/service", 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 misc = require('utils/misc');
App.MainServiceController = Em.ArrayController.extend(App.SupportClientConfigsDownload, {
name: 'mainServiceController',
/**
* @type {Ember.Object[]}
*/
content: function () {
if (!App.router.get('clusterController.isLoaded')) {
return [];
}
return misc.sortByOrder(App.StackService.find().mapProperty('serviceName'), App.Service.find().toArray());
}.property('App.router.clusterController.isLoaded').volatile(),
/**
* Current cluster
* @type {Ember.Object}
*/
cluster: function () {
if (!App.router.get('clusterController.isClusterDataLoaded')) {
return null;
}
return App.Cluster.find().objectAt(0);
}.property('App.router.clusterController.isClusterDataLoaded'),
/**
* Check if all services are installed
* true - all installed, false - not all
* @type {bool}
*/
isAllServicesInstalled: function () {
if (!this.get('content')) return false;
var notAvailableServices = App.ServiceSimple.find().filterProperty('doNotShowAndInstall').mapProperty('name');
var availableServices = App.ServiceSimple.find().filterProperty('doNotShowAndInstall', false);
var installedServices = this.get('content').filter(function (service) {
return !notAvailableServices.contains(service.get('serviceName'));
});
return installedServices.length == availableServices.length;
}.property('content.@each', 'content.length'),
/**
* Should "Start All"-button be disabled
* @type {bool}
*/
isStartAllDisabled: function () {
if (this.get('isStartStopAllClicked') == true) {
return true;
}
var stoppedServices = this.get('content').filter(function (_service) {
return _service.get('healthStatus') === 'red' && !App.get('services.clientOnly').contains(_service.get('serviceName'));
});
return stoppedServices.length === 0; // all green status
}.property('isStartStopAllClicked', 'content.@each.healthStatus'),
/**
* Should "Stop All"-button be disabled
* @type {bool}
*/
isStopAllDisabled: function () {
if (this.get('isStartStopAllClicked') == true) {
return true;
}
return !this.get('content').someProperty('healthStatus', 'green');
}.property('isStartStopAllClicked', 'content.@each.healthStatus'),
/**
* Should "Refresh All"-button be disabled
* @type {bool}
*/
isRestartAllRequiredDisabled: Em.computed.everyBy('content', 'isRestartRequired', false),
/**
* @type {bool}
*/
isStartStopAllClicked: Em.computed.notEqual('App.router.backgroundOperationsController.runningOperationsCount', 0),
/**
* Callback for <code>start all service</code> button
* @return {App.ModalPopup|null}
* @method startAllService
*/
startAllService: function startAllService(event) {
return this.startStopAllService(event, 'STARTED');
},
/**
* Callback for <code>stop all service</code> button
* @return {App.ModalPopup|null}
* @method stopAllService
*/
stopAllService: function stopAllService(event) {
return this.startStopAllService(event, 'INSTALLED');
},
/**
* Common method for "start-all", "stop-all" calls
* @param {object} event
* @param {string} state 'STARTED|INSTALLED'
* @returns {App.ModalPopup|null}
* @method startStopAllService
*/
startStopAllService: function startStopAllService(event, state) {
if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
return null;
}
var self = this;
var bodyMessage = Em.Object.create({
confirmMsg: state == 'INSTALLED' ? Em.I18n.t('services.service.stopAll.confirmMsg') : Em.I18n.t('services.service.startAll.confirmMsg'),
confirmButton: state == 'INSTALLED' ? Em.I18n.t('services.service.stop.confirmButton') : Em.I18n.t('services.service.start.confirmButton')
});
if (state == 'INSTALLED' && App.Service.find().filterProperty('serviceName', 'HDFS').someProperty('workStatus', App.HostComponentStatus.started)) {
App.router.get('mainServiceItemController').checkNnLastCheckpointTime(function () {
return App.showConfirmationFeedBackPopup(function (query) {
self.allServicesCall(state, query);
}, bodyMessage);
});
} else {
return App.showConfirmationFeedBackPopup(function (query) {
self.allServicesCall(state, query);
}, bodyMessage);
}
},
/**
* Download client configs for all services
*/
downloadAllClientConfigs: function downloadAllClientConfigs() {
this.downloadClientConfigsCall({ resourceType: this.resourceTypeEnum.CLUSTER });
},
/**
* Do request to server for "start|stop" all services
* @param {string} state "STARTED|INSTALLED"
* @param {object} query
* @method allServicesCall
* @return {$.ajax}
*/
allServicesCall: function allServicesCall(state, query) {
var context = state == 'INSTALLED' ? App.BackgroundOperationsController.CommandContexts.STOP_ALL_SERVICES : App.BackgroundOperationsController.CommandContexts.START_ALL_SERVICES;
return App.ajax.send({
name: 'common.services.update',
sender: this,
data: {
context: context,
ServiceInfo: {
state: state
},
query: query
},
success: 'allServicesCallSuccessCallback',
error: 'allServicesCallErrorCallback',
showLoadingPopup: true
});
},
/**
* Restart all services - restarts by sending one RESTART command
*/
restartAllServices: function restartAllServices() {
App.ajax.send({
name: 'restart.allServices',
sender: this,
showLoadingPopup: true
});
},
/**
* Restart all services - stops all services, then starts them back
*/
stopAndStartAllServices: function stopAndStartAllServices() {
this.silentStopAllServices();
},
/**
* Silent stop all services - without user confirmation
* @returns {$.ajax}
*/
silentStopAllServices: function silentStopAllServices() {
return App.ajax.send({
name: 'common.services.update',
sender: this,
data: {
context: App.BackgroundOperationsController.CommandContexts.STOP_ALL_SERVICES,
ServiceInfo: {
state: 'INSTALLED'
}
},
success: 'silentStopSuccess',
showLoadingPopup: true
});
},
isStopAllServicesFailed: function isStopAllServicesFailed() {
var workStatuses = App.Service.find().mapProperty('workStatus');
for (var i = 0; i < workStatuses.length; i++) {
if (workStatuses[i] !== 'INSTALLED' && workStatuses[i] !== 'STOPPING') {
return true;
}
}
return false;
},
/**
* Success callback for silent stop
*/
silentStopSuccess: function silentStopSuccess() {
var self = this;
App.router.get('userSettingsController').dataLoading('show_bg').done(function (initValue) {
Eif (initValue) {
App.router.get('backgroundOperationsController').showPopup();
}
Em.run.later(function () {
self.set('shouldStart', true);
}, App.bgOperationsUpdateInterval);
});
},
/**
* Silent start all services - without user confirmation
*/
silentStartAllServices: function () {
if (!App.router.get('backgroundOperationsController').get('runningOperationsCount') && this.get('shouldStart') && !this.isStopAllServicesFailed()) {
this.set('shouldStart', false);
return App.ajax.send({
name: 'common.services.update',
sender: this,
data: {
context: App.BackgroundOperationsController.CommandContexts.START_ALL_SERVICES,
ServiceInfo: {
state: 'STARTED'
}
},
success: 'silentCallSuccessCallback',
showLoadingPopup: true
});
}
}.observes('shouldStart', 'controllers.backgroundOperationsController.runningOperationsCount'),
/**
* Success callback for silent start
*/
silentCallSuccessCallback: function silentCallSuccessCallback() {
// load data (if we need to show this background operations popup) from persist
App.router.get('userSettingsController').dataLoading('show_bg').done(function (initValue) {
Eif (initValue) {
App.router.get('backgroundOperationsController').showPopup();
}
});
},
/**
* Success-callback for all-services request
* @param {object} data
* @param {object} xhr
* @param {object} params
* @method allServicesCallSuccessCallback
*/
allServicesCallSuccessCallback: function allServicesCallSuccessCallback(data, xhr, params) {
params.query.set('status', 'SUCCESS');
// load data (if we need to show this background operations popup) from persist
App.router.get('userSettingsController').dataLoading('show_bg').done(function (initValue) {
Eif (initValue) {
App.router.get('backgroundOperationsController').showPopup();
}
});
},
/**
* Error-callback for all-services request
* @param {object} request
* @param {object} ajaxOptions
* @param {string} error
* @param {object} opt
* @param {object} params
* @method allServicesCallErrorCallback
*/
allServicesCallErrorCallback: function allServicesCallErrorCallback(request, ajaxOptions, error, opt, params) {
params.query.set('status', 'FAIL');
App.ajax.defaultErrorHandler(request, opt.url, opt.type, request.status);
},
/**
* "Add-service"-click handler
* @method gotoAddService
*/
gotoAddService: function gotoAddService() {
if (this.get('isAllServicesInstalled')) {
return;
}
App.router.get('addServiceController').setDBProperty('onClosePath', 'main.services.index');
App.router.transitionTo('main.serviceAdd');
},
/**
* Show confirmation popup and send request to restart all host components with stale_configs=true
*/
restartAllRequired: function restartAllRequired() {
var self = this;
if (!this.get('isRestartAllRequiredDisabled')) {
return App.showConfirmationPopup(function () {
self.restartHostComponents();
}, Em.I18n.t('services.service.refreshAll.confirmMsg').format(App.Service.find().filterProperty('isRestartRequired').mapProperty('displayName').uniq().join(', ')), null, null, Em.I18n.t('services.service.restartAll.confirmButton'));
} else {
return null;
}
},
/**
* Send request restart host components from hostComponentsToRestart
* @returns {$.ajax}
*/
restartHostComponents: function restartHostComponents() {
App.ajax.send({
name: 'restart.staleConfigs',
sender: this,
success: 'restartAllRequiredSuccessCallback',
showLoadingPopup: true
});
},
/**
* Success callback for restartAllRequired
*/
restartAllRequiredSuccessCallback: function restartAllRequiredSuccessCallback() {
// load data (if we need to show this background operations popup) from persist
App.router.get('userSettingsController').dataLoading('show_bg').done(function (initValue) {
Eif (initValue) {
App.router.get('backgroundOperationsController').showPopup();
}
});
}
});
}); |