Merge pull request #2718 from n313893254/18551

Fix logging issue about swtich project
This commit is contained in:
Westly Wright 2019-03-05 09:13:42 -07:00 committed by GitHub
commit c1ee95464e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 30 deletions

View File

@ -9,6 +9,7 @@ import parseUri from 'shared/utils/parse-uri';
import { resolve } from 'rsvp'; import { resolve } from 'rsvp';
import { next, later } from '@ember/runloop'; import { next, later } from '@ember/runloop';
import C from 'ui/utils/constants'; import C from 'ui/utils/constants';
import { on } from '@ember/object/evented';
const INVALID_PREFIX_CHAR = ['\\', '/', '*', '?', '"', '<', '>', '|', ` `, ',', '#']; const INVALID_PREFIX_CHAR = ['\\', '/', '*', '?', '"', '<', '>', '|', ` `, ',', '#'];
@ -32,11 +33,6 @@ export default Component.extend(NewOrEdit, {
cluster: reads('scope.currentCluster'), cluster: reads('scope.currentCluster'),
project: reads('scope.currentProject'), project: reads('scope.currentProject'),
clusterTargetType: reads('clusterLogging.targetType'), clusterTargetType: reads('clusterLogging.targetType'),
originalModelTargetType: reads('originalModel.targetType'),
didReceiveAttrs() {
this.initCustomContent()
},
actions: { actions: {
test() { test() {
@ -112,27 +108,13 @@ export default Component.extend(NewOrEdit, {
}), }),
pasteOrUploadChange: observer('pasteOrUpload', function() { pasteOrUploadChange: observer('pasteOrUpload', function() {
const { fileObj, deepStrs = [] } = get(this, 'parseValue') const { fileObj, deepStrs = [] } = this.parseValue(get(this, 'customContent'))
const preTargetType = get(this, 'preTargetType') const preTargetType = get(this, 'preTargetType')
if (!get(this, 'pasteOrUpload')) { if (!get(this, 'pasteOrUpload')) {
const type = fileObj['@type'] const type = fileObj['@type']
let targetType = type const targetType = this.fileToFormType(type)
switch (type) {
case 'splunk_hec':
targetType = 'splunk'
break;
case 'remote_syslog':
targetType = 'syslog'
break;
case 'kafka_buffered':
targetType = 'kafka'
break;
case 'forward':
targetType = 'fluentForwarder'
break;
}
set(this, 'targetType', targetType) set(this, 'targetType', targetType)
} else { } else {
let type = preTargetType let type = preTargetType
@ -191,9 +173,13 @@ export default Component.extend(NewOrEdit, {
&& !get(this, 'pasteOrUpload'); && !get(this, 'pasteOrUpload');
}), }),
parseValue: computed('customContent', function() { pageChange: on('init', observer('originalModel.customTargetConfig.content', function() {
this.initCustomContent()
})),
parseValue(value) {
let fileObj = {} let fileObj = {}
const removeMacth = get(this, 'customContent').replace(/.*<match.*>.*(\r\n|\n|\r) {2}/ig, '').replace(/(\r\n|\n|\r).*<\/match.*>/ig, '') const removeMacth = value.replace(/.*<match.*>.*(\r\n|\n|\r) {2}/ig, '').replace(/(\r\n|\n|\r).*<\/match.*>/ig, '')
const deepStrs = removeMacth.match(/<(.|\r\n|\n|\r)*<\/.*>/ig, '') || [] const deepStrs = removeMacth.match(/<(.|\r\n|\n|\r)*<\/.*>/ig, '') || []
const removedDeep = removeMacth.replace(/<(.|\r\n|\n|\r)*<\/.*>/ig, '') const removedDeep = removeMacth.replace(/<(.|\r\n|\n|\r)*<\/.*>/ig, '')
@ -212,7 +198,7 @@ export default Component.extend(NewOrEdit, {
fileObj, fileObj,
deepStrs deepStrs
} }
}), },
willSave() { willSave() {
const { const {
@ -240,7 +226,7 @@ export default Component.extend(NewOrEdit, {
const errors = set(this, 'errors', []) const errors = set(this, 'errors', [])
if (get(this, 'pasteOrUpload')) { if (get(this, 'pasteOrUpload')) {
const { fileObj } = get(this, 'parseValue') const { fileObj } = this.parseValue(get(this, 'customContent'))
const targetType = fileObj['@type'] const targetType = fileObj['@type']
const types = Object.keys(C.LOGGING_TPYE_TO_CONFIG) || [] const types = Object.keys(C.LOGGING_TPYE_TO_CONFIG) || []
@ -360,13 +346,21 @@ export default Component.extend(NewOrEdit, {
}, },
initCustomContent() { initCustomContent() {
if (get(this, 'originalModelTargetType') === 'customTarget') { if (get(this, 'originalModel.targetType') === 'customTarget') {
const { fileObj } = this.parseValue(get(this, 'originalModel.customTargetConfig.content'))
const type = fileObj['@type']
let preTargetType = this.fileToFormType(type)
setProperties(this, { setProperties(this, {
pasteOrUpload: true, pasteOrUpload: true,
customContent: `<match *>\n ${ get(this, 'model.customTargetConfig.content') }\n</match>`, customContent: `<match *>\n ${ get(this, 'originalModel.customTargetConfig.content') }\n</match>`,
preTargetType,
}) })
} else { } else {
set(this, 'customContent', get(this, 'model.customTarget.config.content')) setProperties(this, {
pasteOrUpload: false,
customContent: get(this, 'model.customTarget.config.content'),
})
} }
}, },
@ -547,4 +541,25 @@ export default Component.extend(NewOrEdit, {
return errors return errors
}, },
fileToFormType(type) {
let formType = type
switch (type) {
case 'splunk_hec':
formType = 'splunk'
break;
case 'remote_syslog':
formType = 'syslog'
break;
case 'kafka_buffered':
formType = 'kafka'
break;
case 'forward':
formType = 'fluentForwarder'
break;
}
return formType
},
}); });

View File

@ -25,7 +25,7 @@
{{#if (not-eq targetType "none")}} {{#if (not-eq targetType "none")}}
<section class="header has-tabs clearfix p-0"> <section class="header has-tabs clearfix p-0">
<ul class="tab-nav"> <ul class="tab-nav">
{{#if pasteOrUpload}} {{#if (eq targetType "customTarget")}}
<li> <li>
<button class={{concat (if testing "btn-disabled-transparent") " btn bg-transparent"}} {{action "cancel"}} disabled={{testing}}>{{t "loggingPage.advanced.cancel"}}</button> <button class={{concat (if testing "btn-disabled-transparent") " btn bg-transparent"}} {{action "cancel"}} disabled={{testing}}>{{t "loggingPage.advanced.cancel"}}</button>
</li> </li>
@ -38,7 +38,7 @@
</section> </section>
{{/if}} {{/if}}
{{#if pasteOrUpload}} {{#if (eq targetType "customTarget")}}
<div class="mt-25"> <div class="mt-25">
{{logging/input-logging-config {{logging/input-logging-config
showDownload=false showDownload=false