| 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 |
1
1
1
10
10
2
10
82
60
60
78
60
183
58
43
58
183
60
52
60
60
60
36
2
59
55
55
66
46
46
53
53
53
53
1
| 'use strict';
;require.register("models/configs/objects/service_config", 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.ServiceConfig = Ember.Object.extend({
serviceName: '',
configCategories: [],
configCategoriesMap: function () {
var categoriesMap = {};
this.get('configCategories').forEach(function (c) {
Eif (!categoriesMap[c.get('name')]) categoriesMap[c.get('name')] = c;
});
return categoriesMap;
}.property('configCategories.[]'),
configs: [],
restartRequired: false,
restartRequiredMessage: '',
restartRequiredHostsAndComponents: {},
configGroups: [],
dependentServiceNames: [],
initConfigsLength: 0, // configs length after initialization in order to watch changes
errorCount: Em.computed.alias('configsWithErrors.length'),
/**
* Properties for which some aggregations should be calculated
* like <code>configsWithErrors<code>, <code>changedConfigProperties<code> etc.
*
* @type {Object[]}
*/
activeProperties: [],
configsWithErrors: [],
/**
* Collection of properties that were changed:
* for saved properties use - <code>isNotDefaultValue<code>
* for not saved properties (on wizards, for new services) use
* - <code>isNotInitialValue<code>
* for added properties use - <code>isNotSaved<code>
* @type {Object[]}
*/
changedConfigProperties: [],
setActiveProperties: function () {
Em.run.once(this, 'setActivePropertiesOnce');
}.observes('configs.@each.isActive', 'configs.@each.isRequiredByAgent', 'configs.@each.value', 'configs.@each.isUndefinedLabel'),
setActivePropertiesOnce: function setActivePropertiesOnce() {
Iif (this.get('isDestroyed')) return false;
var activeProperties = this.get('configs').filter(function (c) {
return (c.get('isActive') || c.get('isUndefinedLabel')) && (c.get('isRequiredByAgent') || c.get('isRequired'));
});
this.set('activeProperties', activeProperties);
},
setChangedConfigProperties: function () {
Em.run.once(this, 'setChangedConfigPropertiesOnce');
}.observes('activeProperties.@each.isNotDefaultValue', 'activeProperties.@each.isNotSaved', 'activeProperties.@each.isNotInitialValue'),
setChangedConfigPropertiesOnce: function setChangedConfigPropertiesOnce() {
var changedConfigProperties = this.get('activeProperties').filter(function (c) {
return c.get('isNotDefaultValue') || c.get('isNotSaved') || c.get('isNotInitialValue');
}, this);
this.set('changedConfigProperties', changedConfigProperties);
},
setConfigsWithErrors: function () {
Em.run.once(this, 'setConfigsWithErrorsOnce');
}.observes('activeProperties.@each.isValid', 'activeProperties.@each.isValidOverride', 'activeProperties.length'),
setConfigsWithErrorsOnce: function setConfigsWithErrorsOnce() {
var configsWithErrors = this.get('activeProperties').filter(function (c) {
return !c.get('isValid') || !c.get('isValidOverride');
});
this.set('configsWithErrors', configsWithErrors);
},
observeErrors: function () {
this.get('configCategories').setEach('errorCount', 0);
this.get('configsWithErrors').forEach(function (c) {
//configurations with widget shouldn't affect advanced category error counter
if (this.get('configCategoriesMap')[c.get('category')] && !c.get('isInDefaultTheme')) {
this.get('configCategoriesMap')[c.get('category')].incrementProperty('errorCount');
}
}, this);
}.observes('configsWithErrors'),
configTypes: function () {
return App.StackService.find(this.get('serviceName')).get('configTypeList') || [];
}.property('serviceName'),
radioConfigs: Em.computed.filterBy('configs', 'displayType', 'radio button'),
observeForeignKeys: function () {
//TODO refactor or move this logic to other place
Em.run.once(this, 'updateVisibilityByForeignKeys');
}.observes('radioConfigs.@each.value'),
updateVisibilityByForeignKeys: function updateVisibilityByForeignKeys() {
var configs = this.get('configs');
configs.forEach(function (item) {
if (item.get('isVisible')) {
var options = item.get('options');
Iif (options && options.someProperty('foreignKeys')) {
var options = options.filterProperty('foreignKeys');
options.forEach(function (opt) {
opt.foreignKeys.forEach(function (key) {
var config = configs.findProperty('name', key);
if (config) {
config.set('isVisible', item.get('value') === opt.displayName);
}
});
});
}
}
});
},
/**
* Config with overrides that has values that differs from saved
*
* @type {Object[]}
*/
configsWithChangedOverrides: Em.computed.filterBy('activeProperties', 'isOverrideChanged', true),
/**
* Defines if some configs were added/removed
* @type {boolean}
*/
configsLengthWasChanged: Em.computed.notEqualProperties('configs.length', 'initConfigsLength'),
/**
* @type {boolean}
*/
isPropertiesChanged: Em.computed.or('configsLengthWasChanged', 'changedConfigProperties.length', 'configsWithChangedOverrides.length'),
init: function init() {
this._super();
this.set('dependentServiceNames', App.StackService.find(this.get('serviceName')).get('dependentServiceNames') || []);
this.observeForeignKeys();
this.setActiveProperties();
},
hasConfigIssues: Em.computed.someBy('activeProperties', 'hasIssues', true)
});
App.ConfigSiteTag = Ember.Object.extend({
site: DS.attr('string'),
tag: DS.attr('string'),
/**
* Object map of hostname->override-tag for overrides.
* <b>Creators should set new object here.<b>
*/
hostOverrides: null
});
}); |