| 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 |
1
1
1
3
8
8
5
2
2
2
1
5
5
5
5
4
4
4
4
4
4
4
4
4
10
10
10
10
10
10
5
5
5
5
5
5
2
3
3
5
9
9
9
9
9
9
9
8
8
1
3
3
3
3
3
4
4
3
1
| 'use strict';
;require.register("mixins/common/configs/configs_loader", 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');
App.ConfigsLoader = Em.Mixin.create(App.GroupsMappingMixin, {
/**
* version of default config group, configs of which currently applied
*/
currentDefaultVersion: null,
/**
* defines if service config versions are loaded to model
* @type {boolean}
*/
allVersionsLoaded: false,
/**
* this method should be used in clear step method
* @method clearLoadInfo
*/
clearLoadInfo: function clearLoadInfo() {
this.set('allVersionsLoaded', false);
},
/**
* loads all versions that is not saved on UI for current moment
* @returns {$.ajax}
*/
loadServiceConfigVersions: function loadServiceConfigVersions() {
this.set('allVersionsLoaded', false);
return App.ajax.send({
name: 'service.serviceConfigVersions.get',
data: {
serviceName: this.get('content.serviceName')
},
sender: this,
success: 'loadServiceConfigVersionsSuccess'
});
},
/**
* success handler for <code>loadServiceConfigVersions<code>
* @param data
*/
loadServiceConfigVersionsSuccess: function loadServiceConfigVersionsSuccess(data) {
if (Em.get(data, 'items.length')) {
App.serviceConfigVersionsMapper.map(data);
var currentDefault = data.items.filterProperty('group_name', App.ServiceConfigGroup.defaultGroupName).findProperty('is_current');
if (currentDefault) {
this.set('currentDefaultVersion', currentDefault.service_config_version);
}
}
this.set('allVersionsLoaded', true);
Eif (!this.get('preSelectedConfigVersion')) {
this.set('selectedVersion', this.get('currentDefaultVersion'));
}
this.set('preSelectedConfigVersion', null);
},
/**
* @method loadPreSelectedConfigVersion
*/
loadPreSelectedConfigVersion: function loadPreSelectedConfigVersion() {
var preSelectedVersion = this.get('preSelectedConfigVersion');
this.set('selectedVersion', this.get('preSelectedConfigVersion.version'));
/** handling redirecting from config history page **/
var self = this;
this.loadConfigGroups(this.get('servicesToLoad')).done(function () {
var selectedGroup = App.ServiceConfigGroup.find().find(function (g) {
return g.get('serviceName') === preSelectedVersion.get('serviceName') && (g.get('name') === preSelectedVersion.get('groupName') || preSelectedVersion.get('groupName') === App.ServiceConfigGroup.defaultGroupName && g.get('isDefault'));
});
self.set('selectedConfigGroup', selectedGroup);
self.loadSelectedVersion(preSelectedVersion.get('version'), selectedGroup);
preSelectedVersion = null;
});
},
/**
* loads current versions of current and dependent services
* and all current version for config groups
* @method loadCurrentVersions
*/
loadCurrentVersions: function loadCurrentVersions() {
this.set('isCompareMode', false);
this.set('compareServiceVersion', null);
this.set('versionLoaded', false);
this.set('selectedVersion', this.get('currentDefaultVersion'));
this.set('preSelectedConfigVersion', null);
this.trackRequestChain(App.ajax.send({
name: 'service.serviceConfigVersions.get.current',
sender: this,
data: {
serviceNames: this.get('servicesToLoad').join(',')
},
success: 'loadCurrentVersionsSuccess'
}));
},
/**
* success handler for <code>loadCurrentVersions<code>
* @param data
* @param opt
* @param params
*/
loadCurrentVersionsSuccess: function loadCurrentVersionsSuccess(data, opt, params) {
var self = this;
var serviceGroups;
App.configGroupsMapper.map(data, true, params.serviceNames.split(','));
this.loadConfigGroups(params.serviceNames.split(',')).done(function () {
serviceGroups = App.ServiceConfigGroup.find().filterProperty('serviceName', self.get('content.serviceName'));
if (self.get('isHostsConfigsPage')) {
self.set('selectedConfigGroup', serviceGroups.find(function (cg) {
return !cg.get('isDefault') && cg.get('hosts').contains(self.get('host.hostName'));
}) || serviceGroups.findProperty('isDefault'));
} else {
self.set('selectedConfigGroup', serviceGroups.findProperty('isDefault'));
}
self.parseConfigData(data);
});
},
/**
* loads selected versions of current service
* @method loadSelectedVersion
*/
loadSelectedVersion: function loadSelectedVersion(version, switchToGroup, stayInCompare) {
Eif (!stayInCompare) {
this.set('isCompareMode', false);
this.set('compareServiceVersion', null);
}
this.set('versionLoaded', false);
version = version || this.get('currentDefaultVersion');
this.clearRecommendationsInfo();
if (version === this.get('currentDefaultVersion') && (!switchToGroup || switchToGroup.get('isDefault'))) {
// current version with default group
this.set('selectedVersion', this.get('currentDefaultVersion'));
this.loadCurrentVersions();
} else {
// - version with DEFAULT config group but not CURRENT
// - ANY version with NON_DEFAULT config group
this.loadDefaultGroupVersion(version, switchToGroup);
}
},
/**
* version with NON_DEFAULT group require properties from CURRENT version of DEFAULT group to correctly display page
* @param {string} version
* @param {?Em.Object} switchToGroup
*/
loadDefaultGroupVersion: function loadDefaultGroupVersion(version, switchToGroup) {
var versions = this.isVersionDefault(version) ? [version] : [this.get('currentDefaultVersion'), version];
var selectedVersion = versions.length > 1 ? versions[1] : versions[0];
this.setSelectedConfigGroup(version, switchToGroup);
this.set('selectedVersion', selectedVersion);
this.trackRequest(App.ajax.send({
name: 'service.serviceConfigVersions.get.multiple',
sender: this,
data: {
serviceName: this.get('content.serviceName'),
serviceConfigVersions: versions,
additionalParams: this.get('dependentServiceNames.length') ? '|(service_name.in(' + this.get('dependentServiceNames') + ')&is_current=true)' : ''
},
success: 'loadSelectedVersionsSuccess'
}));
},
/**
*
* @param {string} version
* @param {?Em.Object} switchToGroup
*/
setSelectedConfigGroup: function setSelectedConfigGroup(version, switchToGroup) {
switchToGroup = this.isVersionDefault(version) && !switchToGroup ? this.get('configGroups').findProperty('isDefault') : switchToGroup;
if (this.get('dataIsLoaded') && switchToGroup) {
this.set('selectedConfigGroup', switchToGroup);
}
},
/**
* success handler for <code>loadSelectedVersionsSuccess<code>
* @param data
*/
loadSelectedVersionsSuccess: function loadSelectedVersionsSuccess(data) {
this.parseConfigData(data);
}
});
}); |