[Pipeline] Add logging

This commit is contained in:
qianmoQ 2023-09-06 15:32:42 +08:00
parent 8840dbd8b2
commit 74feb5e665
6 changed files with 143 additions and 4 deletions

View File

@ -33,6 +33,7 @@ import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.core.env.Environment;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Service;
import java.io.File;
@ -309,6 +310,33 @@ public class PipelineServiceImpl
return CommonResponse.success(lines);
}
@Override
public CommonResponse<Long> deleteById(PagingAndSortingRepository repository, Long id)
{
Optional<PipelineEntity> pipelineOptional = this.repository.findById(id);
if (!pipelineOptional.isPresent()) {
return CommonResponse.failure(String.format("Pipeline [ %s ] not found", id));
}
PipelineEntity entity = pipelineOptional.get();
log.info("Delete pipeline [ {} ] work home", entity.getName());
try {
FileUtils.deleteDirectory(new File(entity.getWork()));
}
catch (IOException e) {
log.warn("Failed to delete pipeline [ {} ] work home {}", entity.getName(), e);
}
return PipelineService.super.deleteById(repository, id);
}
/**
* Merges the properties of a source entity with a list of fields and a configuration.
*
* @param entity the source entity
* @param fields the list of fields
* @param configure the configuration
* @return the merged properties
*/
private Properties merge(SourceEntity entity, List<IConfigureExecutorField> fields, Properties configure)
{
Properties properties = new Properties();
@ -324,6 +352,13 @@ public class PipelineServiceImpl
return properties;
}
/**
* Sets the property value for the given field.
*
* @param field the field to set the property value for
* @param properties the properties object to store the property
* @param configure the configuration properties object
*/
private void setProperty(IConfigureExecutorField field, Properties properties, Properties configure)
{
Object value = "None";

View File

@ -18,6 +18,7 @@
"@types/watermark-dom": "^2.3.1",
"ag-grid-community": "^29.3.5",
"ag-grid-vue3": "^29.3.5",
"ansi_up": "^6.0.2",
"axios": "^0.27.2",
"core-js": "^3.8.3",
"echarts": "^5.4.0",

View File

@ -21,6 +21,11 @@ class PipelineService
return new HttpCommon().post(`${baseUrl}/submit`, configure);
}
logger(id: number): Promise<ResponseModel>
{
return new HttpCommon().get(`${baseUrl}/log/${id}`);
}
getByName<T>(name: string): Promise<ResponseModel>
{
return Promise.resolve(undefined);

View File

@ -62,7 +62,7 @@
type="primary"
size="small"
icon="md-bulb"
@click="handlerVisibleMarkdownPreview(row.message, true)">
@click="handlerLogger(row, true)">
</Button>
</Tooltip>
<Tooltip :content="$t('common.stop')"
@ -123,6 +123,12 @@
:info="info"
@close="handlerStop(null, false)">
</StopPipeline>
<LoggerPipeline v-if="logger"
:is-visible="logger"
:info="info"
@close="handlerLogger(null, false)">
</LoggerPipeline>
</div>
</template>
@ -138,13 +144,14 @@ import MarkdownPreview from "@/components/common/MarkdownPreview.vue";
import DeletePipeline from "@/views/admin/pipeline/DeletePipeline.vue";
import DetailsPipeline from "@/views/admin/pipeline/DetailPipeline.vue";
import StopPipeline from "@/views/admin/pipeline/StopPipeline.vue";
import LoggerPipeline from "@/views/admin/pipeline/components/LoggerPipeline.vue";
const filter: Filter = new Filter();
const pagination: Pagination = PaginationBuilder.newInstance();
export default defineComponent({
name: 'UserPipelineHome',
components: {StopPipeline, DetailsPipeline, DeletePipeline, MarkdownPreview},
components: {LoggerPipeline, StopPipeline, DetailsPipeline, DeletePipeline, MarkdownPreview},
setup()
{
const i18n = useI18n();
@ -167,7 +174,8 @@ export default defineComponent({
info: null,
// Pipeline detail
detail: false,
stopped: false
stopped: false,
logger: false
}
},
created()
@ -239,6 +247,11 @@ export default defineComponent({
this.handlerInitialize(this.filter);
}
},
handlerLogger(row: any, isOpen: boolean)
{
this.logger = isOpen
this.info = row
},
getStateText(origin: string): string
{
return getText(this.i18n, origin);

View File

@ -0,0 +1,85 @@
<template>
<div>
<Modal v-model="visible"
:title="title"
width="80%"
:closable="false"
:maskClosable="false">
<Scroll>
<div v-for="(log, index) in logs" :key="index">
<div v-html="log" style="margin-bottom: 5px; font-size: 16px"></div>
</div>
</Scroll>
<template #footer>
<Button @click="handlerCancel()">
{{ $t('common.cancel') }}
</Button>
</template>
</Modal>
</div>
</template>
<script lang="ts">
import PipelineService from '@/services/user/PipelineService';
import {AnsiUp} from 'ansi_up';
import {defineComponent} from 'vue';
export default defineComponent({
name: 'LoggerPipeline',
props: {
isVisible: {
type: Boolean,
default: () => false
},
info: {
type: Object,
default: () => null
}
},
created()
{
this.handlerInitialize();
},
data()
{
return {
title: null,
logs: []
}
},
methods: {
handlerInitialize()
{
this.title = `[ ${this.info.name} ] ${this.$t('common.log')}`
PipelineService.logger(this.info.id)
.then(response => {
if (response.status) {
const ansi_up = new AnsiUp()
const array = response.data
for (const i in array) {
this.logs[i] = ansi_up.ansi_to_html(array[i])
}
}
else {
this.$Message.error(response.message);
}
})
},
handlerCancel()
{
this.visible = false;
}
},
computed: {
visible: {
get(): boolean
{
return this.isVisible
},
set(value: boolean)
{
this.$emit('close', value)
}
}
},
});
</script>

View File

@ -76,7 +76,7 @@ public class LogbackExecutor
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
ENCODER_CONTAINER.put(this.name, encoder);
encoder.setContext(context);
String pattern = "%date %level [%thread] %logger{10} [%file:%line] %msg%n";
String pattern = "%date %highlight(%-5level) %boldMagenta([%thread]) %cyan([%file:%line]) %msg%n";
encoder.setPattern(pattern);
encoder.setCharset(Charset.forName("utf-8"));
encoder.start();