From 39ad24ea2b5c69752a4d8b13f6d2315432c053a7 Mon Sep 17 00:00:00 2001 From: vimniky Date: Wed, 28 Feb 2018 12:07:59 +0800 Subject: [PATCH] Update logging --- .../components/logging/new-edit/component.js | 40 +++++--- .../logging/target-kafka/component.js | 30 +++--- .../logging/target-kafka/template.hbs | 8 +- .../logging/target-syslog/component.js | 2 +- lib/logging/addon/logging/route.js | 41 +------- lib/logging/addon/mixins/logging-model.js | 96 ++++++------------- 6 files changed, 76 insertions(+), 141 deletions(-) diff --git a/lib/logging/addon/components/logging/new-edit/component.js b/lib/logging/addon/components/logging/new-edit/component.js index 14234370f..24829b334 100644 --- a/lib/logging/addon/components/logging/new-edit/component.js +++ b/lib/logging/addon/components/logging/new-edit/component.js @@ -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(); }, }); diff --git a/lib/logging/addon/components/logging/target-kafka/component.js b/lib/logging/addon/components/logging/target-kafka/component.js index 415ad6406..343479e02 100644 --- a/lib/logging/addon/components/logging/target-kafka/component.js +++ b/lib/logging/addon/components/logging/target-kafka/component.js @@ -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'), diff --git a/lib/logging/addon/components/logging/target-kafka/template.hbs b/lib/logging/addon/components/logging/target-kafka/template.hbs index 767c51618..15a340b95 100644 --- a/lib/logging/addon/components/logging/target-kafka/template.hbs +++ b/lib/logging/addon/components/logging/target-kafka/template.hbs @@ -22,10 +22,14 @@

{{t 'loggingPage.kafka.zookeeperHelpText'}}

{{else}} - {{#each brokerEndpoints as |item|}} + {{#each brokerEndpoints as |item idx|}}
- + {{input type="text" value=item.endpoint diff --git a/lib/logging/addon/components/logging/target-syslog/component.js b/lib/logging/addon/components/logging/target-syslog/component.js index 0e36722cf..f2d72db9d 100644 --- a/lib/logging/addon/components/logging/target-syslog/component.js +++ b/lib/logging/addon/components/logging/target-syslog/component.js @@ -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'}, diff --git a/lib/logging/addon/logging/route.js b/lib/logging/addon/logging/route.js index ae8b9456e..c882f2064 100644 --- a/lib/logging/addon/logging/route.js +++ b/lib/logging/addon/logging/route.js @@ -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, diff --git a/lib/logging/addon/mixins/logging-model.js b/lib/logging/addon/mixins/logging-model.js index 07b16b7e5..3ae117ad0 100644 --- a/lib/logging/addon/mixins/logging-model.js +++ b/lib/logging/addon/mixins/logging-model.js @@ -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() {