Update logging

This commit is contained in:
vimniky 2018-02-28 12:07:59 +08:00
parent 1c72bda7ce
commit 39ad24ea2b
6 changed files with 76 additions and 141 deletions

View File

@ -128,6 +128,18 @@ export default Ember.Component.extend(NewOrEdit, {
}.property('originalModel.{id,targetType}', 'targetType'),
validate() {
const targetType = get(this, 'targetType');
const config = get(this, `primaryResource.${targetType}Config`);
const errors = config.validationErrors();
if (errors.get('length')) {
set(this, 'errors', errors);
return false;
}
set(this, 'errors', null);
return true;
},
actions: {
save(cb) {
const targetType = get(this, 'targetType');
@ -148,15 +160,26 @@ export default Ember.Component.extend(NewOrEdit, {
}
// set kafka config
if (targetType === 'kafka') {
const kt = get(model, 'kafka.config.brokerType');
let kt;
const brokerEndpoints = get(model, 'kafka.config.brokerEndpoints');
const zookeeperEndpoint = get(model, 'kafka.config.zookeeperEndpoint');
if (brokerEndpoints && brokerEndpoints.length > 0) {
kt = 'broker';
} else if (zookeeperEndpoint) {
kt = 'zookeeper';
} else {
set(this, 'errors', ['"Endpoint" is required']);
cb();
return;
}
if (kt === 'broker') {
set(model, 'kafkaConfig', {
zookeeperEndpoint: null,
brokerEndpoints: get(model, 'kafka.config.brokerEndpoints'),
brokerEndpoints,
});
} else if (kt === 'zookeeper') {
set(model, 'kafkaConfig', {
zookeeperEndpoint: get(model, 'kafka.config.zookeeperEndpoint'),
zookeeperEndpoint,
brokerEndpoints: null,
});
}
@ -175,20 +198,11 @@ export default Ember.Component.extend(NewOrEdit, {
set(model, `${targetType}Config`, get(model, `${targetType}.config`));
this._super(cb);
// model.save().then(nue => {
// this.setProperties({
// model: nue,
// originalModel: nue.clone(),
// });
// cb(true);
// }).catch(err => {
// console.log(err);
// cb();
// });
},
},
doneSaving(nue) {
set(this, 'model', nue.patch());
return this.pollLogging();
},
});

View File

@ -7,20 +7,15 @@ export default Component.extend({
brokerType: 'zookeeper',
brokerEndpoints: null,
cachedBrokerEndpoints: null,
cachedZookeeper: null,
cachedZookeeperEndpoint: null,
init() {
this._super();
const endpoints = get(this, 'config.brokerEndpoints');
if (endpoints) {
set(this, 'brokerEndpoints', endpoints.map(endpoint => ({endpoint})));
}
const brokerEndpoints = get(this, 'config.brokerEndpoints');
const zookeeperEndpoint = get(this, 'config.zookeeperEndpoint')
if (brokerEndpoints) {
set(this, 'brokerType', 'broker')
}
if (zookeeperEndpoint) {
set(this, 'brokerType', 'broker');
set(this, 'brokerEndpoints', brokerEndpoints.map(endpoint => ({endpoint})));
} else {
set(this, 'brokerType', 'zookeeper');
}
},
@ -56,22 +51,21 @@ ${str}
brokerTypeChange: function() {
const t = get(this, 'brokerType');
const brokerEndpoints = get(this, 'brokerEndpoints');
const zookeeper = get(this, 'config.zookeeper');
const cachedZookeeper = get(this, 'cachedZookeeper');
const cachedBrokerEndpoint = get(this, 'cachedBrokerEndpoints');
set(this, 'config.brokerType', t);
const zookeeperEndpoint = get(this, 'config.zookeeperEndpoint');
const cachedZookeeperEndpoint = get(this, 'cachedZookeeperEndpoint');
const cachedBrokerEndpoints = get(this, 'cachedBrokerEndpoints');
if (t === 'zookeeper') {
set(this, 'cachedBrokerEndpoints', brokerEndpoints);
set(this, 'config.zookeeper', cachedZookeeper);
set(this, 'config.zookeeperEndpoint', cachedZookeeperEndpoint);
set(this, 'brokerEndpoints', null);
} else if (t === 'broker') {
if (!cachedBrokerEndpoint) {
if (!cachedBrokerEndpoints) {
this.send('add');
} else {
set(this, 'brokerEndpoints', cachedBrokerEndpoint);
set(this, 'brokerEndpoints', cachedBrokerEndpoints);
}
set(this, 'cachedZookeeper', zookeeper);
set(this, 'config.zookeeper', null);
set(this, 'cachedZookeeperEndpoint', zookeeperEndpoint);
set(this, 'config.zookeeperEndpoint', null);
}
}.observes('brokerType'),

View File

@ -22,10 +22,14 @@
</div>
<p class="text-info text-small mb-0">{{t 'loggingPage.kafka.zookeeperHelpText'}}</p>
{{else}}
{{#each brokerEndpoints as |item|}}
{{#each brokerEndpoints as |item idx|}}
<div class="row">
<div class="col span-11">
<label class="acc-label" for="">{{t 'loggingPage.endpoint'}}{{field-required}}</label>
<label class="acc-label" for="">{{t 'loggingPage.endpoint'}}
{{#if (eq idx 0)}}
{{field-required}}
{{/if}}
</label>
{{input
type="text"
value=item.endpoint

View File

@ -5,7 +5,7 @@ import { get, set } from '@ember/object'
const SEVERITIES = [
{value: 'emerg', label: 'emergency'},
{value: 'alert', label: 'alert'},
{value: 'critical', label: 'critical'},
{value: 'crit', label: 'critical'},
{value: 'err', label: 'error'},
{value: 'warning', label: 'warning'},
{value: 'notice', label: 'notice'},

View File

@ -22,45 +22,6 @@ export default Route.extend({
return newLogging;
},
// patchLogging(logging) {
// const t = get(logging, 'targetType');
// const gs = get(this, 'globalStore');
// const nue = gs.createRecord({
// type: logging.get('type'),
// });
// const loggingTagets = [
// 'embedded',
// 'kafka',
// 'elasticsearch',
// 'splunk',
// 'syslog',
// ];
// const map = {};
// loggingTagets.forEach(key => {
// const config = gs.createRecord({
// type: `${key}Config`
// });
// const clone = nue.clone();
// clone.set('config', config);
// map[key] = clone;
// });
// // why can't set props on logging ???????????????
// logging.set('a', 1);
// logging.get('a') // ===> undefined
// logging.setProperties(map);
// if (t && t !== 'none') {
// set(logging, `${t}.config`, get(logging, `${t}Config`));
// set(logging, `${t}.outputFlushInterval`, get(logging, 'outputFlushInterval'));
// set(logging, `${t}.outputTags`, get(logging, 'outputTags'));
// }
// console.log('------logging', logging);
// return logging;
// },
model(/*params, transition*/) {
const globalStore = this.get('globalStore');
const pageScope = this.get('pageScope');
@ -77,6 +38,7 @@ export default Route.extend({
logging = this.createLogging('clusterlogging');
}
const originalLogging = logging.clone();
logging = logging.clone().patch();
return {
logging,
originalLogging,
@ -104,6 +66,7 @@ export default Route.extend({
logging = this.createLogging('projectlogging');
}
const originalLogging = logging.clone();
logging = logging.clone().patch();
const clusterLogging = hash.clusterLogging.get('firstObject');
return {
logging,

View File

@ -1,84 +1,44 @@
import { get, set } from '@ember/object'
import { inject as service } from '@ember/service'
import { alias } from '@ember/object/computed'
import Mixin from '@ember/object/mixin';
const DEFAULT_TARGET_TYPE = 'none';
export default Mixin.create({
// needs to override this type
// needs to override the type props
type: null,
scope: service(),
globalStore: service(),
pageScope: alias('scope.currentPageScope'),
cluster: alias('scope.currentCluster'),
project: alias('scope.currentProject'),
modalService: service('modal'),
init(...args) {
this._super(...args);
patch() {
const t = get(this, 'targetType');
const store = get(this, 'store');
const kafka = {
outputTags: null,
outputFlushInterval: 3,
config: {
topic: null,
// comma separated enpoints string
brokerEndpoints: null,
zookeeperEndpoint: null,
},
};
const elasticsearch = {
outputTags: null,
outputFlushInterval: 3,
config: {
authUsername: null,
authPassword: null,
dateFormat: 'YYYY-MM-DD',
indexPrefix: null,
endpoint: null,
},
};
const splunk = {
outputTags: null,
outputFlushInterval: 3,
config: {
endpoint: null,
source: null,
token: null,
},
};
const embedded = {
outputTags: null,
outputFlushInterval: 3,
config: {
dateFormat: 'YYYY-MM-DD',
indexPrefix: null,
},
};
const syslog = {
outputTags: null,
outputFlushInterval: 3,
config: {
severity: 'info',
program: null,
endpoint: null,
protocol: 'tcp',
},
};
this.setProperties({
embedded,
elasticsearch,
splunk,
kafka,
syslog,
const nue = store.createRecord({
type: this.get('type'),
});
if (t && get(this, t)) {
const loggingTagets = [
'embedded',
'kafka',
'elasticsearch',
'splunk',
'syslog',
];
const map = {};
loggingTagets.forEach(key => {
const config = store.createRecord({
type: `${key}Config`
});
const clone = nue.clone();
clone.set('config', config);
map[key] = clone;
});
this.setProperties(map);
if (t && t !== 'none') {
set(this, `${t}.config`, get(this, `${t}Config`));
set(this, `${t}.outputFlushInterval`, get(this, 'outputFlushInterval'));
set(this, `${t}.outputTags`, get(this, 'outputTags'));
}
return this;
},
targetType: function() {