Commit aa528eff authored by 智勇's avatar 智勇

增加接口getK8sConf

parent 4a378e0c
...@@ -55,6 +55,9 @@ const save = async (ctx) => { ...@@ -55,6 +55,9 @@ const save = async (ctx) => {
} }
} }
// 处理多个空格
data.table_list = data.table_list.split(/ +/).join(' ')
// let db = await DBConfig.getOne({ "_id": data._id }) // let db = await DBConfig.getOne({ "_id": data._id })
// if (db && db.updatedAt && JSON.stringify(db.updatedAt).replace(/"/g, '') !== data.updatedAt) { // if (db && db.updatedAt && JSON.stringify(db.updatedAt).replace(/"/g, '') !== data.updatedAt) {
// ctx.body = ctx.fail('停留时间太长导致时间戳不正确,请刷新后再试~') // ctx.body = ctx.fail('停留时间太长导致时间戳不正确,请刷新后再试~')
......
const Router = require('koa-router') const Router = require('koa-router')
const bodyParser = require('koa-bodyparser') const bodyParser = require('koa-bodyparser')
const _ = require('lodash') const _ = require('lodash')
const { ProConfig } = require('../service/mongoService') const { ProConfig } = require('../service/mongoService')
const getProjectByType = async function (ctx) { const getProjectByType = async function (ctx) {
let item = await ProConfig.getQgProjects() let item = await ProConfig.findByQuery({ des: { $ne: '海外' } }, { is_active: -1, project_name: 1 })
item = _.groupBy(item, 'type') item = _.groupBy(item, 'type')
const arr = [] const arr = []
...@@ -56,20 +54,20 @@ const save = async function (ctx) { ...@@ -56,20 +54,20 @@ const save = async function (ctx) {
data[prop] = data[prop].trim() data[prop] = data[prop].trim()
} }
} }
await ProConfig.saveProject(data) await ProConfig.saveProject(data)
ctx.body = ctx.ok() ctx.body = ctx.ok()
} }
const getNewPort = async function (ctx) { const getNewPort = async function (ctx) {
const port = await ProConfig.getNewPort() const port = await ProConfig.getNewPort()
ctx.body = ctx.ok(port + 1) ctx.body = ctx.ok(port + 1)
} }
const findByQuery = async function (ctx) { // const findByQuery = async function (ctx) {
const item = await ProConfig.findByQuery(ctx.request.body) // const item = await ProConfig.findByQuery(ctx.request.body)
ctx.body = ctx.ok(item) // ctx.body = ctx.ok(item)
} // }
const remove = async function (ctx) { const remove = async function (ctx) {
const rule = { const rule = {
...@@ -97,7 +95,7 @@ const getInfo = async function (ctx) { ...@@ -97,7 +95,7 @@ const getInfo = async function (ctx) {
data.system_name = 'xjfq-ui' data.system_name = 'xjfq-ui'
} }
const item = await ProConfig.getDomain(data.system_name) const item = await ProConfig.getOneProject({ project_name: data.system_name })
if (data.key && item[data.key]) { if (data.key && item[data.key]) {
ctx.body = item[data.key] ctx.body = item[data.key]
return return
...@@ -109,8 +107,9 @@ const getType = async function (ctx) { ...@@ -109,8 +107,9 @@ const getType = async function (ctx) {
const item = await ProConfig.getType() const item = await ProConfig.getType()
ctx.body = ctx.ok(item) ctx.body = ctx.ok(item)
} }
const getDomain = async function (ctx) { const getDomain = async function (ctx) {
const item = await ProConfig.getDomain(ctx.request.query.project_name) const item = await ProConfig.getOneProject({ project_name: ctx.request.query.project_name })
if (item && item.project_name === 'recruiting-management') { if (item && item.project_name === 'recruiting-management') {
item.host_name = 'recruitui.liangkebang.net' item.host_name = 'recruitui.liangkebang.net'
} }
...@@ -119,6 +118,14 @@ const getDomain = async function (ctx) { ...@@ -119,6 +118,14 @@ const getDomain = async function (ctx) {
} }
ctx.body = ctx.ok(item) ctx.body = ctx.ok(item)
} }
const getK8sConf = async function (ctx) {
const item = await ProConfig.getOneProject({ project_name: ctx.request.query.project_name }, {
cpuRequest: 1, cpuLimit: 1, memRequest: 1, memLimit: 1, _id: 0,
})
ctx.body = ctx.ok(item)
}
const router = new Router() const router = new Router()
router router
...@@ -129,9 +136,9 @@ router ...@@ -129,9 +136,9 @@ router
.get('/get_new_port', getNewPort) .get('/get_new_port', getNewPort)
.get('/delete', remove) .get('/delete', remove)
.post('/save', save) .post('/save', save)
.post('/find_by_query', findByQuery) // .post('/find_by_query', findByQuery)
.get('/get_type', getType) .get('/get_type', getType)
.get('/getHostName', getDomain) .get('/getHostName', getDomain)
.get('/getK8sConf', getK8sConf)
module.exports = router module.exports = router
...@@ -8,6 +8,7 @@ module.exports = function () { ...@@ -8,6 +8,7 @@ module.exports = function () {
'/user/get_station', '/user/get_station',
'/user/check_token', '/user/check_token',
'/proconfig/get_info', '/proconfig/get_info',
'/proconfig/getK8sConf',
'/harborHook/endpoint', '/harborHook/endpoint',
'/k8s/namespace/get_namespace_for_jenkins', '/k8s/namespace/get_namespace_for_jenkins',
'/k8s/namespace', '/k8s/namespace',
......
...@@ -23,16 +23,16 @@ const schema = new Schema({ ...@@ -23,16 +23,16 @@ const schema = new Schema({
auth: { type: String }, auth: { type: String },
jar_path: { type: String }, jar_path: { type: String },
command1: { type: String }, command1: { type: String },
command2: { type: String },
command3: { type: String },
command4: { type: String },
command5: { type: String },
build_command: { type: String }, build_command: { type: String },
start_command: { type: String }, start_command: { type: String },
stop_command: { type: String }, stop_command: { type: String },
api: { type: String }, api: { type: String },
ddl: { type: String }, ddl: { type: String },
wiki: { type: String }, wiki: { type: String },
cpuRequest: { type: Number },
cpuLimit: { type: Number },
memRequest: { type: Number },
memLimit: { type: Number },
}, { }, {
versionKey: false, versionKey: false,
collection: 'proconfigs', // 表名 collection: 'proconfigs', // 表名
...@@ -55,16 +55,15 @@ schema.statics.getActiveProjectsHostName = function () { ...@@ -55,16 +55,15 @@ schema.statics.getActiveProjectsHostName = function () {
}) })
} }
schema.statics.getQgProjects = function () { schema.statics.findByQuery = function (query, sort) {
return this.find({ des: { $ne: '海外' } }).sort({ is_active: -1, project_name: 1 }) if (query.project_name) {
} query.project_name = new RegExp(query.project_name)
}
schema.statics.getActiveProjects = function () { return this.find(query).sort(sort).lean()
return this.find({ des: { $ne: '海外' }, is_active: 1 }).sort({ project_name: 1 })
} }
schema.statics.getDomain = function (name) { schema.statics.getOneProject = function (query, column, sort) {
return this.findOne({ project_name: name }) return this.findOne(query, column).sort(sort)
} }
schema.statics.saveProject = function (doc) { schema.statics.saveProject = function (doc) {
...@@ -75,6 +74,7 @@ schema.statics.saveProject = function (doc) { ...@@ -75,6 +74,7 @@ schema.statics.saveProject = function (doc) {
} }
return this.create(doc) return this.create(doc)
} }
schema.statics.getNewPort = async function () { schema.statics.getNewPort = async function () {
const item = await this.findOne().select('port').sort({ port: -1 }) const item = await this.findOne().select('port').sort({ port: -1 })
if (!item || (item.port < initPort)) { if (!item || (item.port < initPort)) {
...@@ -82,16 +82,7 @@ schema.statics.getNewPort = async function () { ...@@ -82,16 +82,7 @@ schema.statics.getNewPort = async function () {
} }
return item.port return item.port
} }
schema.statics.hostName = async function (projectName) {
return this.find({ project_name: projectName })
}
schema.statics.findByQuery = function (query, sort) {
if (query.project_name) {
query.project_name = new RegExp(query.project_name)
}
// query = Object.assign(query, { des: { $ne: '海外' } })
return this.find(query).sort(sort).lean()
}
schema.statics.delete = function (id) { schema.statics.delete = function (id) {
return this.findByIdAndRemove(id) return this.findByIdAndRemove(id)
} }
......
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