w-vue-middle
Version:
统一公共服务组件
382 lines (368 loc) • 10.4 kB
JavaScript
/*
* @Author: Jason Liu
* @Date: 2023-11-29 13:37:07
* @Desc:
*/
/**
* @Author: Jason Liu
* @description: 数据集成服务
*/
const $dataIntegration = require('w-vue-middle/api/dataIntegration');
const testContent = require('./testContent').default;
let runTestTime;
export default {
components: { testContent },
props: {
value: {
type: Object,
default: () => {
return {
id: undefined,
jobType: undefined,
jsonDetail: undefined,
};
},
},
},
watch: {
value(val) {
this.nodeData = val;
},
},
data() {
return {
running: false,
nodeData: this.value,
//调试信息
debuggerProcess: {
clusterType: undefined, //集群类型
clusterId: undefined, //集群ID
limit: 100,
jobDetail: {},
},
clusters: [],
debugClusters: [], //测试集群
logList: [], //测试日志
debugSummarys: [], //数据信息
debugs: {
testId: undefined,
jobLog: [],
jobSqls: [],
executionIds: [],
failedIds: [],
finishedIds: [],
status: undefined,
}, //调试信息
qloading: false,
question: undefined, //疑难问题
pager: {
pageNum: 1,
pageSize: 10,
queryParams: {
F_backendExceptionInfo_like: undefined, //疑难问题
},
},
answerList: [],
content: undefined, //kafka XML静态调试脚本
};
},
created() {
this.geiClustersList();
this.searchProblem();
},
methods: {
/**
* @Author: Jason Liu
* @description: 搜索疑难问题
*/
searchProblem(pageNum = 1) {
this.qloading = true;
this.pager.pageNum = pageNum;
$dataIntegration
.getPagedSolutions(this.pager)
.then((req) => {
this.answerList = req.data;
})
.finally(() => {
this.qloading = false;
});
},
/**
* @Author: Jason Liu
* @description: 获取集群列表
*/
geiClustersList() {
$dataIntegration
.getClusterManager({
pageNum: 1,
pageSize: 10000,
queryParams: {
F_isDel_eq: 0,
},
})
.then((req) => {
this.clusters = req.data.map((item) => {
return {
value: item.clusterId,
label: item.name,
clusterType: item.clusterType,
};
});
this.changeClusterType();
});
},
/**
* @Author: Jason Liu
* @description: 修改测试集群
*/
changeClusterType(val) {
if (!val) {
this.debugClusters = this.clusters;
} else {
this.debugClusters = this.clusters.filter((item) => {
return item.clusterType == this.debuggerProcess.clusterType;
});
}
this.debuggerProcess.clusterId =
this.debugClusters.length > 0 ? this.debugClusters[0].value : undefined;
},
/**
* @Author: Jason Liu
* @description: 还原测试数据
*/
reductionTest() {
this.running = false;
clearTimeout(runTestTime);
this.$emit('runLoading', {
key: 'clear',
data: this.nodeData,
debugs: undefined,
});
},
/**
* @Author: Jason Liu
* @description: 获取测试的内容情况
*/
getTestResult() {
this.debugs.jobLog.forEach((log) => {
if (log) {
for (let key in log) {
if (log[key] && !this.logkeys.log[key]) {
this.logkeys.log[key] = true;
this.logList.unshift({
time: new Date(),
type: 'message',
message: `${log[key]}`,
});
}
}
}
});
/**
* @Author: Jason Liu
* @description: 执行日志解析
*/
if (this.debugs.delegate && this.debugs.delegate.jobLog2) {
this.debugs.delegate.jobLog2.forEach((log) => {
if (log) {
for (let key in log) {
if (log[key] && log[key].logMsg && !this.logkeys.log[key]) {
this.logkeys.log[key] = true;
this.logList.unshift({
time: new Date(),
type: log[key].error ? 'error' : 'message',
message: `${log[key].logMsg}`,
});
}
}
}
});
}
/**
* @Author: Jason Liu
* @description: 执行日志解析
*/
this.debugs.jobLog2.forEach((log) => {
if (log) {
for (let key in log) {
if (log[key] && log[key].logMsg && !this.logkeys.log[key]) {
this.logkeys.log[key] = true;
this.logList.unshift({
time: new Date(),
type: log[key].error ? 'error' : 'message',
message: `${log[key].logMsg}`,
});
}
}
}
});
if (this.debugs.jobSqls) {
let log = this.debugs.jobSqls;
for (let key in log) {
if (log[key] && !this.logkeys.sql[key]) {
this.logkeys.sql[key] = true;
this.logList.unshift({
time: new Date(),
type: 'message',
message: `${log[key]}`,
});
}
}
}
const { steps } = this.nodeData.jsonDetail;
this.debugs.executionIds.forEach((ele) => {
//执行中
let node = steps.find((item) => {
return item.id == ele;
});
if (node) {
this.logList.unshift({
time: new Date(),
type: 'processing',
item: node.data,
message: `[${node.data.name}]${$t('执行调试中...')}`,
});
}
});
this.debugs.finishedIds.forEach((ele) => {
//已完成
let node = steps.find((item) => {
return item.id == ele;
});
if (node) {
this.logList.unshift({
time: new Date(),
type: 'processing',
item: node.data,
message: `[${node.data.name}]${$t('执行完成')}`,
});
}
});
this.debugs.failedIds.forEach((ele) => {
//执行失败
let node = steps.find((item) => {
return item.id == ele;
});
if (node) {
this.logList.unshift({
time: new Date(),
type: 'processing',
item: node,
message: `[${node.data.name }]${$t('执行失败')}`
});
}
});
switch (this.debugs.status) {
case 'RUNNING': //启动中
if (this.debugs.jobLog.length == 0) {
this.logList.unshift({
time: new Date(),
type: this.debugs.status,
message: $t('执行中...'),
});
}
runTestTime = setTimeout(() => {
$dataIntegration.getJobTestResult(this.debugs).then((res) => {
this.debugs = res.data;
if (res.data.debugSummary) {
this.debugSummarys = res.data.debugSummary.filter((item) => {
return !!item;
});
}
this.getTestResult();
});
}, 10000);
break;
case 'SUSPENDED':
this.logList.unshift({
time: new Date(),
type: this.debugs.status,
message: $t('当前配置未能启动'),
});
this.$message.error($t('当前配置未能启动!'));
this.running = false;
clearTimeout(runTestTime);
break;
default:
this.running = false;
let message = `${$t('调试完毕')},${$t('最终给结果')}${this.debugs.status==='FINISHED' ? '【' + $t('成功') + '】' : '【' + $t('失败') + '】'}`
this.logList.unshift({
time: new Date(),
type: this.debugs.status,
message: message,
});
this.$message.success(message);
clearTimeout(runTestTime);
break;
}
this.$emit('runLoading', {
key: this.debugs.status,
data: this.nodeData,
debugs: this.debugs,
});
},
/**
* @Author: Jason Liu
* @description: 执行测试
*/
runTest() {
this.$emit('startRun');
setTimeout(() => {
if (this.nodeData.id) {
this.reductionTest();
this.$emit('runLoading', {
key: 'start',
data: this.nodeData,
debugs: undefined,
});
this.logList.unshift({
time: new Date(),
message: $t('开始调试,发送调试请求'),
type: 'start',
});
this.logkeys = { log: {}, sql: {} }; //重置历史记录
let testId = this.nodeData.id; //确保老版本兼容
if (testId.indexOf('new') > -1) {
testId = undefined;
}
let query = {
id: testId,
jobType: this.nodeData.jobType,
jsonDetail: JSON.stringify(this.nodeData.jsonDetail),
limit: this.debuggerProcess.limit,
clusterId: this.debuggerProcess.clusterId,
content: this.content, //静态脚本
};
this.running = true;
$dataIntegration
.runJobTest(query)
.then((req) => {
this.debugs = req.data;
this.logList.unshift({
time: new Date(),
type: this.debugs.status,
message: $t('系统已接受调试请求,监控状态中'),
});
this.getTestResult();
})
.catch((eorr) => {
this.running = false;
this.logList.unshift({
time: new Date(),
type: 'eorr',
message: $t('系统异常,测试失败'),
});
this.$emit('runLoading', {
key: 'eorr',
data: this.nodeData,
eorr: eorr,
debugs: undefined,
});
});
} else {
this.$message.warning($t('请设置测试job信息!'));
}
}, 300);
},
},
};