Commit 36cba627 authored by 智勇's avatar 智勇

getLatestSvcDB

parent 6c9f2f1d
......@@ -3,6 +3,8 @@ const bodyParser = require('koa-bodyparser')
const _ = require('lodash')
const { ProConfig } = require('../service/mongoService')
const config = require(global.configPath)
const getProjectByType = async function (ctx) {
let item = await ProConfig.findByQuery({ des: { $ne: '海外' } }, {}, { project_name: 1 })
item = _.groupBy(item, 'type')
......@@ -135,6 +137,46 @@ const getK8sConf = async function (ctx) {
ctx.body = ctx.ok(item)
}
const subSet = function (arr1, arr2) {
const set1 = new Set(arr1);
const set2 = new Set(arr2);
const subset = [];
for (const item of set1) {
if (!set2.has(item)) {
subset.push(item);
}
}
return subset;
};
const getLatestSvcDB = async (ctx) => {
const ns = ctx.request.query.namespace
const res = await ctx.curl({
uri: `${config.api.tke_api}/service?namespace=${ns}`,
method: 'get',
headers: {
cluster: ctx.request.headers.cluster || 'qa',
},
})
const allDB = []
const notLatestDB = []
const svcs = _.get(res, 'body.data.services', [])
for (const i of svcs) {
if (i.labels.type === 'java') {
const proconfig = await ProConfig.getOneProject({ project_name: i.serviceName }, { database: 1, _id: 0 })
if (proconfig.database) {
allDB.push(...proconfig.database.split(' '))
if (i.image.indexOf('latest') === -1 && i.image.indexOf(':master-') === -1) {
notLatestDB.push(...proconfig.database.split(' '))
}
}
}
}
const latestDB = subSet(allDB, notLatestDB)
ctx.body = latestDB.join(' ')
}
const router = new Router()
router
.use(bodyParser())
......@@ -148,5 +190,6 @@ router
.get('/get_type', getType)
.get('/getHostName', getDomain)
.get('/getK8sConf', getK8sConf)
.get('/getLatestSvcDB', getLatestSvcDB)
module.exports = router
......@@ -30,6 +30,7 @@ const schema = new Schema({
api: { type: String },
ddl: { type: String },
wiki: { type: String },
database: { type: String },
cpuRequest: { type: Number },
cpuLimit: { type: Number },
memRequest: { type: Number },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment