Commit 937e580f authored by windwei(魏佳新)'s avatar windwei(魏佳新)
Browse files

first

parents
Showing with 2152 additions and 0 deletions
+2152 -0
app.js 0 → 100644
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
const Koa = require('koa');
const app = new Koa();
const path = require('path');
const views = require('koa-views');
const json = require('koa-json');
const onerror = require('koa-onerror');
const bodyparser = require('koa-bodyparser');
const multer = require('koa-multer');
const static = require('koa-static');
const {pageRouter, apiRouter} = require('./app/router');
const preMidware = require('./app/midware/preMidware');
const postMidware = require('./app/midware/postMidware');
const localeMidware = require('./app/midware/localeMidware');
const helmet = require("koa-helmet");
// const compress = require('koa-compress')
const loginMidware = require('yami-sso-client').koa;
console.log(loginMidware);
const limitMidware = require('./app/midware/limitMidware');
const WebConf = require('./config/webConf');
const upload = multer({dest: WebConf.pkgUploadPath.path+'/'});
//信任proxy头部,支持 X-Forwarded-Host
app.proxy = true;
// error handler
onerror(app);
//防洪水攻击
app.use(limitMidware());
//安全防护
app.use(helmet());
//设置ejs模板
// app.use(views(__dirname + '/views', {
// extension: 'ejs'
// }));
app.use(bodyparser());
app.use(upload.single('suse')); //这里决定了上传包的name只能叫suse。
//国际化多语言中间件
app.use(localeMidware);
//前置中间件
preMidware.forEach((midware)=>{
app.use(midware);
});
//登录校验
let loginConf = require('./config/loginConf.js');
loginConf.ignore =loginConf.ignore.concat(['/static', '/tarsnode.tar.gz', '/favicon.ico', '/pages/server/api/get_locale']);
app.use(loginMidware(loginConf));
//激活router
app.use(pageRouter.routes(), pageRouter.allowedMethods());
app.use(apiRouter.routes(), apiRouter.allowedMethods());
//激活静态资源中间件
app.use(static(path.join(__dirname, './client/dist'), {maxage: 7 * 24 * 60 * 60 * 1000}));
app.use(static(path.join(__dirname, './files'), {maxage: 7 * 24 * 60 * 60 * 1000}));
//后置中间件
postMidware.forEach((midware)=>{
app.use(midware);
});
module.exports = app;
\ No newline at end of file
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
const logger = require('../../logger');
const AdapterService = require('../../service/adapter/AdapterService');
const AuthService = require('../../service/auth/AuthService');
const _ = require('lodash');
const util = require('../../tools/util');
const adapterConfStruct = {
id: '',
application: '',
server_name: '',
node_name: '',
adapter_name: '',
thread_num: '',
endpoint: '',
max_connections: '',
allow_ip: '',
servant: '',
queuecap: '',
queuetimeout: '',
posttime: {formatter: util.formatTimeStamp},
protocol: '',
handlegroup: ''
};
const AdapterController = {};
AdapterController.getAdapterConfById = async(ctx) => {
let id = ctx.paramsObj.id;
try {
var rst = await AdapterService.getAdapterConfById(id);
if (!_.isEmpty(rst)) {
if (!await AuthService.hasDevAuth(rst.application, rst.server_name, ctx.uid)) {
ctx.makeNotAuthResObj();
} else {
ctx.makeResObj(200, '', util.viewFilter(rst, adapterConfStruct));
}
} else {
logger.error('[getAdapterConfById]', '未查询到id=' + id + '相应的Adapter', ctx);
ctx.makeErrResObj();
}
} catch (e) {
logger.error('[getAdapterConfById]', e, ctx);
ctx.makeErrResObj();
}
};
AdapterController.getAdapterConfListByServerConfId = async(ctx) => {
let id = ctx.paramsObj.id;
try {
let rst = await AdapterService.getAdapterConfList(id);
if(!_.isEmpty(rst)){
let adapter = rst[0].dataValues;
if (!await AuthService.hasDevAuth(adapter.application, adapter.server_name, ctx.uid)) {
ctx.makeNotAuthResObj();
return;
}
}
ctx.makeResObj(200, '', util.viewFilter(rst, adapterConfStruct));
} catch (e) {
logger.error('[getAdapterConfListByServerConfId]', e, ctx);
ctx.makeErrResObj();
}
};
AdapterController.addAdapterConf = async(ctx) => {
let addAdapter = ctx.paramsObj;
try {
if (!await AuthService.hasDevAuth(addAdapter.application, addAdapter.server_name, ctx.uid)) {
ctx.makeNotAuthResObj();
}else{
addAdapter.adapter_name = addAdapter.servant + 'Adapter';
addAdapter.posttime = new Date();
let rst = await AdapterService.addAdapterConf(addAdapter);
ctx.makeResObj(200, '', util.viewFilter(rst, adapterConfStruct));
}
} catch (e) {
logger.error('[addAdapterConf]', e, ctx);
ctx.makeErrResObj();
}
};
AdapterController.deleteAdapterConf = async(ctx) => {
let id = ctx.paramsObj.id;
try {
var adapterParams = await AdapterService.getAdapterConfById(id);
if (!await AuthService.hasDevAuth(adapterParams.application, adapterParams.server_name, ctx.uid)) {
ctx.makeNotAuthResObj();
}else{
await AdapterService.deleteAdapterConf(id);
ctx.makeResObj(200, '', [id]);
}
} catch (e) {
logger.error('[addAdapterConf]', e, ctx);
ctx.makeErrResObj();
}
};
AdapterController.updateAdapterConf = async(ctx) => {
let updateAdapter = ctx.paramsObj;
try {
var adapterParams = await AdapterService.getAdapterConfById(updateAdapter.id);
if (!await AuthService.hasDevAuth(adapterParams.application, adapterParams.server_name, ctx.uid)) {
ctx.makeNotAuthResObj();
}else{
updateAdapter.adapter_name = updateAdapter.servant + 'Adapter';
updateAdapter.posttime = new Date();
await AdapterService.updateAdapterConf(updateAdapter);
let rst = await AdapterService.getAdapterConfById(updateAdapter.id);
if (!_.isEmpty(rst)) {
ctx.makeResObj(200, '', util.viewFilter(rst, adapterConfStruct));
} else {
logger.error('[getAdapterConfById]', '未查询到id=' + updateAdapter.id + '相应的Adapter', ctx);
ctx.makeErrResObj();
}
}
} catch (e) {
logger.error('[updateAdapterConf]', e, ctx);
ctx.makeErrResObj();
}
};
AdapterController.getAvaliablePort = async(ctx) => {
try {
let nodeNames = ctx.paramsObj.node_name;
nodeNames = nodeNames ? nodeNames.split(/;|,/) : [];
let rst = await AdapterService.getAvaliablePort(nodeNames);
ctx.makeResObj(200, '', rst);
} catch (e) {
logger.error('[updateAdapterConf]', e, ctx);
ctx.makeErrResObj();
}
};
module.exports = AdapterController;
\ No newline at end of file
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
const logger = require('../../logger');
const _ = require('lodash');
const util = require('../../tools/util');
const AuthService = require('../../service/auth/AuthService');
const authConf = require('../../../config/authConf');
const AuthController = {};
AuthController.isEnableAuth = async(ctx) =>{
try{
ctx.makeResObj(200, '', {enableAuth: authConf.enableAuth});
}catch(e){
logger.error('[isEnableAuth]', e, ctx);
ctx.makeErrResObj();
}
};
AuthController.hasAuth = async(ctx) => {
try{
let application = ctx.paramsObj.application;
let serverName = ctx.paramsObj.server_name;
let role = ctx.paramsObj.role;
let func = '';
switch (role){
case 'developer':
func = AuthService.hasDevAuth;
break;
case 'operator':
func = AuthService.hasOpeAuth;
break;
default:
func = AuthService.hasAdminAuth;
break;
}
ctx.makeResObj(200, '', {has_auth: await func(application, serverName, ctx.uid)});
}catch(e){
logger.error('[isEnableAuth]', e, ctx);
ctx.makeErrResObj();
}
};
AuthController.getAuthList = async(ctx) => {
try{
let application = ctx.paramsObj.application;
let serverName = ctx.paramsObj.server_name;
let rst = await AuthService.getAuthList(application, serverName);
ctx.makeResObj(200, '', rst);
}catch(e){
logger.error('[getUidList]', e, ctx);
ctx.makeErrResObj();
}
};
AuthController.updateAuth = async(ctx) => {
try{
let application = ctx.paramsObj.application;
let serverName = ctx.paramsObj.server_name;
let operator = ctx.paramsObj.operator || '';
let developer = ctx.paramsObj.developer || '';
await AuthService.updateAuth(application, serverName, operator, developer);
ctx.makeResObj(200, '', {});
}catch(e){
logger.error('[getUidList]', e, ctx);
ctx.makeErrResObj();
}
};
module.exports = AuthController;
\ No newline at end of file
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
const logger = require('../../logger');
const ConfigService = require('../../service/config/ConfigService');
const AdminService = require('../../service/admin/AdminService');
const util = require('../../tools/util');
const ConfigController = {};
const configListStruct = {id:'',server_name:'',set_name:'',set_area:'',host:{key:'node_name'},set_group:'',filename:'',config:'',level:'',posttime:{formatter:util.formatTimeStamp},lastuser:''};
const AuthService = require('../../service/auth/AuthService');
ConfigController.getUnusedApplicationConfigFile = async(ctx) => {
let {config_id, application} = ctx.paramsObj;
try{
ctx.makeResObj(200, '', await ConfigService.getUnusedApplicationConfigFile(application, config_id));
}catch(e){
logger.error('[getUnusedApplicationConfigFile]', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
ConfigController.configFileList = async(ctx) => {
let {level, application, set_name, set_area, set_group, server_name} = ctx.paramsObj;
let list = [];
try{
if(!await AuthService.checkHasParentAuth({application: application, setName: set_name, setArea: set_area, setGroup: set_group, serverName: server_name, uid: ctx.uid})){
ctx.makeNotAuthResObj();
}else{
switch(level) {
case '1' :
list = await ConfigService.getApplicationConfigFile(application);
break;
case '2' :
if(!set_name) {
return ctx.makeResObj(500, 'set_name #common.notempty#');
}
list = await ConfigService.getSetConfigFile({server_name:application, set_name:set_name});
break;
case '3' :
if(!set_name || !set_area){
return ctx.makeResObj(500, 'set_name,set_area #common.notempty#');
}
list = await ConfigService.getSetConfigFile({server_name:application, set_name:set_name, set_area:set_area});
break;
case '4' :
if(!set_name || !set_area || !set_group){
return ctx.makeResObj(500, 'set_name,set_area,set_group #common.notempty#');
}
list = await ConfigService.getSetConfigFile({server_name:application, set_name:set_name, set_area:set_area, set_group:set_group});
break;
case '5' :
if(!server_name){
return ctx.makeResObj(500, 'server_name #common.notempty#');
}
list = await ConfigService.getServerConfigFile({server_name:`${application}.${server_name}`, set_name:set_name, set_area:set_area, set_group:set_group});
break;
}
ctx.makeResObj(200, '', util.viewFilter(list,configListStruct));
}
}catch(e){
logger.error('[configFileList]', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
ConfigController.addConfigFile = async(ctx) => {
let params = ctx.paramsObj;
try{
if(!await AuthService.checkHasParentAuth({application: params.application, setName: params.set_name, setArea: params.set_area, setGroup: params.set_group, serverName: params.server_name, uid: ctx.uid})){
ctx.makeNotAuthResObj();
}else{
let ret = await ConfigService.addConfigFile(params);
ctx.makeResObj(200, '', util.viewFilter(ret,configListStruct));
}
}catch(e){
logger.error('[addConfigFile]', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
ConfigController.deleteConfigFile = async(ctx) => {
let id = ctx.paramsObj.id;
try{
let serverParams = await ConfigService.getServerInfoByConfigId(id);
if(!await AuthService.checkHasParentAuth(Object.assign(serverParams, {uid: ctx.uid}))){
ctx.makeNotAuthResObj();
}else{
ctx.makeResObj(200, '', await ConfigService.deleteConfigFile(id));
}
}catch(e) {
logger.error('[deleteConfigFile]', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
ConfigController.updateConfigFile = async(ctx) => {
let params = ctx.paramsObj;
try{
let serverParams = await ConfigService.getServerInfoByConfigId(params.id);
if(!await AuthService.checkHasParentAuth(Object.assign(serverParams, {uid: ctx.uid}))){
ctx.makeNotAuthResObj();
}else{
let ret = await ConfigService.updateConfigFile(params);
ctx.makeResObj(200, '', util.viewFilter(ret,configListStruct));
}
}catch(e){
logger.error('[updateConfigFile]', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
ConfigController.configFile = async(ctx) => {
let id = ctx.paramsObj.id;
try{
let serverParams = await ConfigService.getServerInfoByConfigId(id);
if(!await AuthService.checkHasParentAuth(Object.assign(serverParams, {uid: ctx.uid}))){
ctx.makeNotAuthResObj();
}else{
let ret = await ConfigService.getConfigFile(id);
ctx.makeResObj(200, '', util.viewFilter(ret,configListStruct));
}
}catch(e){
logger.error('[configFile]', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
ConfigController.nodeConfigFileList = async(ctx) => {
let {application, set_name, set_area, set_group, server_name, config_id} = ctx.paramsObj;
try{
if(!await AuthService.checkHasParentAuth({application: application, setName: set_name, setArea: set_area, setGroup: set_group, serverName: server_name, uid: ctx.uid})){
ctx.makeNotAuthResObj();
}else{
let list = await ConfigService.getNodeConfigFile({
application:application,
server_name:server_name,
set_name:set_name,
set_area:set_area,
set_group:set_group,
config_id:config_id
});
ctx.makeResObj(200, '', util.viewFilter(list,configListStruct));
}
}catch(e){
logger.error('[nodeConfigFileList]', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
ConfigController.getConfigFileHistory = async(ctx) => {
let id = ctx.paramsObj.id;
try{
let ret = await ConfigService.getConfigFileHistory(id);
if(ret && ret.configid != undefined){
let serverParams = await ConfigService.getServerInfoByConfigId(ret.configid);
if(!await AuthService.checkHasParentAuth(Object.assign(serverParams, {uid: ctx.uid}))){
ctx.makeNotAuthResObj();
return;
}
}
ctx.makeResObj(200, '', util.viewFilter(ret,{id:'',configid:{key: 'config_id'},reason:'',content:'',posttime:{formatter:util.formatTimeStamp}}));
}catch(e){
logger.error('[getConfigFileHistory]', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
ConfigController.configFileHistoryList = async(ctx) => {
let {config_id, currPage = 0, pageSize = 0} = ctx.paramsObj;
try{
let serverParams = await ConfigService.getServerInfoByConfigId(config_id);
if(!await AuthService.checkHasParentAuth(Object.assign(serverParams, {uid: ctx.uid}))){
ctx.makeNotAuthResObj();
}else{
let ret = await ConfigService.getConfigFileHistoryList(config_id, currPage, pageSize);
ctx.makeResObj(200, '', {count:ret.count,rows:util.viewFilter(ret.rows,{id:'',config_id:'',reason:'',content:'',posttime:{formatter:util.formatTimeStamp}})});
}
}catch(e){
logger.error('[configFileHistoryList]', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
ConfigController.addConfigRef = async(ctx) => {
let {config_id, reference_id} = ctx.paramsObj;
try{
let serverParams = await ConfigService.getServerInfoByConfigId(config_id);
if(!await AuthService.checkHasParentAuth(Object.assign(serverParams, {uid: ctx.uid}))){
ctx.makeNotAuthResObj();
}else{
let ret = await ConfigService.addConfigRef(config_id, reference_id);
ctx.makeResObj(200, '', util.viewFilter(ret,{id:'',config_id:'',reference_id:''}));
}
}catch(e){
logger.error('[addConfigRef]', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
ConfigController.deleteConfigRef = async(ctx) => {
let id = ctx.paramsObj.id;
try{
let serverParams = await ConfigService.getServerInfoByConfigId(id, 'refId');
if(!await AuthService.checkHasParentAuth(Object.assign(serverParams, {uid: ctx.uid}))){
ctx.makeNotAuthResObj();
}else{
ctx.makeResObj(200, '', await ConfigService.deleteConfigRef(id));
}
}catch(e){
logger.error('[deleteConfigRef]', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
ConfigController.configRefList = async(ctx) => {
let config_id = ctx.paramsObj.config_id;
try{
let serverParams = await ConfigService.getServerInfoByConfigId(config_id);
if(!await AuthService.checkHasParentAuth(Object.assign(serverParams, {uid: ctx.uid}))){
ctx.makeNotAuthResObj();
}else{
ctx.makeResObj(200, '', await ConfigService.getConfigRefByConfigId(config_id));
}
}catch(e){
logger.error('[configRefList]', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
ConfigController.mergedNodeConfig = async(ctx) => {
let id = ctx.paramsObj.id;
try{
let serverParams = await ConfigService.getServerInfoByConfigId(id);
if(!await AuthService.checkHasParentAuth(Object.assign(serverParams, {uid: ctx.uid}))){
ctx.makeNotAuthResObj();
}else{
let configFile = await ConfigService.getConfigFile(id);
ctx.makeResObj(200, '', await AdminService.loadConfigByHost(configFile.server_name, configFile.filename, configFile.host));
}
}catch(e){
logger.error('[mergedNodeConfig]', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
ConfigController.pushConfigFile = async(ctx) => {
let ids = ctx.paramsObj.ids;
try{
ids = ids.split(/[,;]/);
let list = await ConfigService.getConfigFileList(ids);
let filename = '';
let targets = list.map(configFile => {
let [application, server_name] = configFile.server_name.split('.');
filename = configFile.filename;
return {
application : application,
serverName : server_name,
nodeName : configFile.host
};
});
ctx.makeResObj(200, '', await AdminService.doCommand(targets, `tars.loadconfig ${filename}`));
}catch(e){
logger.error('[pushConfigFile]', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
module.exports = ConfigController;
\ No newline at end of file
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
const logger = require('../../logger');
const ServerService = require('../../service/server/ServerService');
const DeployServerController = {};
const util = require('../../tools/util');
const serverConfStruct = {
id: '',
application: '',
server_name: '',
node_name: '',
server_type: '',
enable_set: {formatter: (value)=>{return value == 'Y' ? true : false;}},
set_name: '',
set_area: '',
set_group: '',
setting_state: '',
present_state: '',
bak_flag: {formatter: (value)=>{return value == 0 ? false : true;}},
template_name: '',
profile: '',
async_thread_num: '',
base_path: '',
exe_path: '',
start_script_path: '',
stop_script_path: '',
monitor_script_path: '',
patch_time: util.formatTimeStamp,
patch_version: "",
process_id: '',
posttime: {formatter: util.formatTimeStamp}
};
DeployServerController.deployServer = async(ctx) => {
var params = ctx.paramsObj;
try {
let rst = await ServerService.addServerConf(params);
rst.server_conf = util.viewFilter(rst.server_conf, serverConfStruct)
ctx.makeResObj(200, '', rst);
} catch (e) {
logger.error('[getServerNotifyList]', e, ctx);
ctx.makeErrResObj();
}
};
DeployServerController.serverTypeList = async(ctx) => {
try {
let ServerTypeList = ['tars_cpp', 'tars_java', 'tars_nodejs', 'tars_php'];
ctx.makeResObj(200, '', ServerTypeList);
} catch (e) {
logger.error('[serverTypeList]', e, ctx);
ctx.makeErrResObj();
}
};
module.exports = DeployServerController;
\ No newline at end of file
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
const logger = require('../../logger');
const ExpandService = require('../../service/expand/ExpandService');
const util = require('../../tools/util');
const AuthService = require('../../service/auth/AuthService');
const expandStruct = {
application: '',
server_name: '',
set: '',
obj_name: '',
node_name: '',
bind_ip: '',
port: '',
template_name: '',
status: '',
auth: ''
};
const serverConfStruct = {
id: '',
application: '',
server_name: '',
node_name: '',
server_type: '',
enable_set: {
formatter: (value)=> {
return value == 'Y' ? true : false;
}
},
set_name: '',
set_area: '',
set_group: '',
setting_state: '',
present_state: '',
bak_flag: {
formatter: (value)=> {
return value == 0 ? false : true;
}
},
template_name: '',
profile: '',
async_thread_num: '',
base_path: '',
exe_path: '',
start_script_path: '',
stop_script_path: '',
monitor_script_path: '',
patch_time: util.formatTimeStamp,
patch_version: "",
process_id: '',
posttime: {formatter: util.formatTimeStamp}
};
const ExpandServerController = {};
ExpandServerController.selectAppServer = async(ctx) => {
try{
let params = ctx.paramsObj;
let level = params.level;
let application = params.application;
let serverName = params.server_name;
let set = params.set;
let rst = [];
let uid = ctx.uid;
switch(parseInt(level)){
case 1:
rst = await ExpandService.getApplication(uid);
break;
case 2:
rst = await ExpandService.getServerName(application, uid);
break;
case 3:
rst = await ExpandService.getSet(application, serverName);
break;
case 4:
rst = await ExpandService.getNodeName(application, serverName, set);
break;
default:
break;
}
ctx.makeResObj(200, '', rst);
}catch(e){
logger.error('[selectAppServer]', e, ctx);
ctx.makeErrResObj();
}
};
ExpandServerController.expandServerPreview = async(ctx) => {
var params = ctx.paramsObj;
try {
if (!await AuthService.hasDevAuth(params.application, params.server_name, ctx.uid)) {
ctx.makeNotAuthResObj();
} else {
let rst = await ExpandService.preview(params);
ctx.makeResObj(200, '', util.viewFilter(rst, expandStruct));
}
} catch (e) {
logger.error('[expandServerPreview]', e, ctx);
ctx.makeErrResObj();
}
};
ExpandServerController.expandServer = async(ctx) => {
var params = ctx.paramsObj;
try {
if (!await AuthService.hasDevAuth(params.application, params.server_name, ctx.uid)) {
ctx.makeNotAuthResObj();
} else {
let rst = await ExpandService.expand(params);
ctx.makeResObj(200, '', {
server_conf: util.viewFilter(rst.server_conf, serverConfStruct),
tars_node_rst: rst.tars_node_rst
});
}
} catch (e) {
logger.error('[expandServerPreview]', e, ctx);
ctx.makeErrResObj();
}
};
module.exports = ExpandServerController;
\ No newline at end of file
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
const logger = require('../../logger');
const fs = require('fs-extra');
const util = require('../../tools/util');
const path = require('path');
let fileNames = fs.readdirSync(path.join(__dirname, '../../../locale'));
let locale = {};
fileNames.forEach((fileName) => {
let content = require(path.join(__dirname, '../../../locale/', fileName));
locale[content.localeCode] = content;
});
const LocaleController = {};
LocaleController.getLocale = async(ctx) => {
ctx.makeResObj(200, '', locale || {});
};
module.exports = LocaleController;
\ No newline at end of file
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
const logger = require('../../logger');
const loginConf = require('../../../config/loginConf');
const LoginController = {};
LoginController.isEnableLogin = async(ctx) =>{
try{
ctx.makeResObj(200, '', {enableLogin: loginConf.enableLogin || false});
}catch(e){
logger.error('[getLoginUid]', e, ctx);
ctx.makeErrResObj();
}
};
LoginController.getLoginUid = async(ctx) =>{
try{
ctx.makeResObj(200, '', {uid: ctx.uid || ''});
}catch(e){
logger.error('[getLoginUid]', e, ctx);
ctx.makeErrResObj();
}
};
module.exports = LoginController;
\ No newline at end of file
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
const logger = require('../../logger');
const util = require('../../tools/util');
const MonitorStatService = require('../../service/monitor/MonitorStatService');
const MonitorPropertyService = require('../../service/monitor/MonitorPropertyService');
const MonitorController = {};
MonitorController.tarsstat = async (ctx) => {
let {thedate, predate, startshowtime, endshowtime, master_name, slave_name, interface_name, master_ip, slave_ip, group_by} = ctx.paramsObj;
try {
let list = await MonitorStatService.getTARSStatMonitorData({thedate, predate, startshowtime, endshowtime, master_name, slave_name, interface_name, master_ip, slave_ip, group_by});
ctx.makeResObj(200,'',util.viewFilter(list, {
show_date: '',
show_time: '',
master_name: '',
slave_name: '',
interface_name: '',
master_ip: '',
slave_ip: '',
the_total_count: '',
pre_total_count: '',
total_count_wave: '',
the_avg_time: '',
pre_avg_time: '',
the_fail_rate: '',
pre_fail_rate: '',
the_timeout_rate: '',
pre_timeout_rate: '',
}));
}catch(e) {
logger.error(e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
MonitorController.tarsproperty = async (ctx) => {
let {thedate, predate, startshowtime, endshowtime, master_name, master_ip, property_name, policy} = ctx.paramsObj;
try {
let list = await MonitorPropertyService.getTARSPropertyMonitorData({thedate, predate, startshowtime, endshowtime, master_name, master_ip, property_name, policy});
ctx.makeResObj(200,'',util.viewFilter(list,{show_date:'',show_time:'',master_name:'',master_ip:'',property_name:'',policy:'',the_value:'',pre_value:''}));
}catch(e) {
logger.error(e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
module.exports = MonitorController;
\ No newline at end of file
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
const logger = require('../../logger');
const ServerController = require('../../controller/server/ServerController');
const NotifyService = require('../../service/notify/NotifyService');
const AuthService = require('../../service/auth/AuthService');
const NotifyController = {};
const util = require('../../tools/util');
const serverNotifyStruct = {
notifytime: {formatter: util.formatTimeStamp},
server_id: '',
thread_id: '',
command: '',
result: ''
};
NotifyController.getServerNotifyList = async(ctx) => {
let treeNodeId = ctx.paramsObj.tree_node_id;
let curPage = parseInt(ctx.paramsObj.curr_page) || 0;
let pageSize = parseInt(ctx.paramsObj.page_size) || 0;
try {
let params = ServerController.formatTreeNodeId(treeNodeId);
if (!await AuthService.hasDevAuth(params.application, params.serverName, ctx.uid)) {
ctx.makeNotAuthResObj();
} else {
let rst = await NotifyService.getServerNotifyList(params, curPage, pageSize);
ctx.makeResObj(200, '', {count:rst.count,rows:util.viewFilter(rst.rows, serverNotifyStruct)});
}
} catch (e) {
logger.error('[getServerNotifyList]', e, ctx);
ctx.makeErrResObj();
}
};
module.exports = NotifyController;
\ No newline at end of file
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
const PageController = {
};
PageController.index = async (ctx) => {
await ctx.redirect('/index.html');
};
module.exports = PageController;
\ No newline at end of file
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
const logger = require('../../logger');
const PatchService = require('../../service/patch/PatchService');
const CompileService = require('../../service/patch/CompileService');
const AuthService = require('../../service/auth/AuthService');
const WebConf = require('../../../config/webConf');
const util = require('../../tools/util');
const fs = require('fs-extra');
const md5Sum = require('md5-file').sync;
const PatchController = {};
PatchController.uploadPatchPackage = async (ctx) => {
try{
let {application, module_name, md5, task_id, comment} = ctx.req.body;
if (!await AuthService.hasDevAuth(application, module_name, ctx.uid)) {
ctx.makeNotAuthResObj();
} else {
let file = ctx.req.file;
if(!file) {
logger.error('[uploadPatchPackage]:','no files');
return ctx.makeErrResObj(500,'no files');
}
let baseUploadPath = WebConf.pkgUploadPath.path;
// 发布包上传目录
let updateTgzPath = `${baseUploadPath}/${application}/${module_name}`;
console.info('updateTgzPath:',updateTgzPath);
await fs.ensureDirSync(updateTgzPath);
let hash = md5Sum(`${baseUploadPath}/${file.filename}`);
if(md5 && md5!=hash) {
return ctx.makeErrResObj(500,'#patch.md5#');
}
let uploadTgzName = `${application}.${module_name}_${file.fieldname}_${new Date().getTime()}.tgz`;
logger.info('[newTgzName]:',`${updateTgzPath}/${uploadTgzName}`);
logger.info('[orgTgzName]:',`${baseUploadPath}/${file.filename}`);
await fs.rename(`${baseUploadPath}/${file.filename}`, `${updateTgzPath}/${uploadTgzName}`);
let paramsObj = {
server : `${application}.${module_name}`,
tgz : uploadTgzName,
md5 : hash,
update_text : comment || '',
task_id : task_id,
posttime : new Date()
};
logger.info('[addServerPatch:]',paramsObj);
let ret = await PatchService.addServerPatch(paramsObj);
await CompileService.addPatchTask(paramsObj).catch((err) => {
logger.error('[CompileService.addPatchTask]:',err);
});
ctx.makeResObj(200,'',util.viewFilter(ret,{id:'',server:'',tgz:'',update_text:{key:'comment'},posttime:{formatter:util.formatTimeStamp}}));
}
}catch (e) {
logger.error('[PatchController.uploadPatchPackage]:', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
PatchController.serverPatchList = async (ctx) => {
let {application, module_name, curr_page = 0, page_size = 0} = ctx.paramsObj;
try{
if (!await AuthService.hasDevAuth(application, module_name, ctx.uid)) {
ctx.makeNotAuthResObj();
} else {
let ret = await PatchService.getServerPatch(application, module_name, parseInt(curr_page), parseInt(page_size));
ctx.makeResObj(200,'',{count:ret.count,rows:util.viewFilter(ret.rows,{id:'',server:'',tgz:'',update_text:{key:'comment'},posttime:{formatter:util.formatTimeStamp}})});
}
}catch(e) {
logger.error('[PatchController.serverPatchList]:', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
PatchController.getServerPatchByTaskId = async (ctx) => {
let {task_id} = ctx.paramsObj;
try{
let ret = await CompileService.getServerPatchByTaskId(task_id);
ctx.makeResObj(200,'',util.viewFilter(ret,{id:'',server:'',tgz:'',update_text:{key:'comment'},posttime:{formatter:util.formatTimeStamp}}));
}catch(e) {
logger.error('[PatchController.getServerPatchByTaskId]:', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
PatchController.getTagList = async (ctx) => {
let {application, server_name} = ctx.paramsObj;
try{
if (!await AuthService.hasDevAuth(application, server_name, ctx.uid)) {
ctx.makeNotAuthResObj();
} else {
let list = await CompileService.getTagList(application, server_name);
ctx.makeResObj(200,'',util.viewFilter(list,{path:'',version:'',commitMessage:''}));
}
}catch(e) {
logger.error('[PatchController.getTagList]:', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
PatchController.getCompilerConf = (ctx) => {
try {
ctx.makeResObj(200,'',CompileService.getCompilerConf());
}catch(e) {
logger.error('[PatchController.getCompilerConf]:', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
PatchController.getCodeInfConf = async (ctx) => {
let {application, server_name} = ctx.paramsObj;
try{
if (!await AuthService.hasDevAuth(application, server_name, ctx.uid)) {
ctx.makeNotAuthResObj();
} else {
let ret = await CompileService.getCodeInfConf(application, server_name);
ctx.makeResObj(200,'',ret);
}
}catch(e) {
logger.error('[PatchController.getCodeInfConf]:', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
PatchController.setCodeInfConf = async (ctx) => {
let {application, server_name, path} = ctx.paramsObj;
try{
let ret = await CompileService.setCodeInfConf({application, server_name, path});
ctx.makeResObj(200,'',ret);
}catch(e) {
logger.error('[PatchController.setCodeInfConf]:', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
PatchController.doCompile = async (ctx) => {
let {application, server_name, node, path, version, comment, compileUrl} = ctx.paramsObj;
try{
if (!await AuthService.hasDevAuth(application, server_name, ctx.uid)) {
ctx.makeNotAuthResObj();
} else {
let ret = await CompileService.doCompile({application, server_name, node, path, version, comment, compileUrl});
ctx.makeResObj(200,'',ret);
}
}catch(e) {
logger.error('[PatchController.doCompile]:', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
PatchController.compilerTask = async (ctx) => {
let {taskNo} = ctx.paramsObj;
try {
let ret = await CompileService.compilerTask(taskNo);
ctx.makeResObj(200, '', ret);
}catch(e) {
logger.error('[PatchController.compilerTask]:', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
module.exports = PatchController;
\ No newline at end of file
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
const logger = require('../../logger');
const ResourceService = require('../../service/resource/ResourceService');
const AdminService = require('../../service/admin/AdminService');
const _ = require('lodash');
const util = require('../../tools/util');
const send = require('koa-send');
const ResourceController = {};
ResourceController.installTarsNode = async(ctx) => {
try {
let ips = ctx.paramsObj.ips;
ips = _.trim(ips, /;|,/).split(';');
let rst = await ResourceService.installTarsNodes(ips);
ctx.makeResObj(200, '', rst);
} catch (e) {
logger.error('[installTarsNode]', e, ctx);
ctx.makeErrResObj();
}
};
ResourceController.uninstallTarsNode = async(ctx) => {
try {
let ips = ctx.paramsObj.ips;
ips = _.trim(ips, /;|,/).split(';');
let rst = await ResourceService.uninstallTarsNode(ips);
ctx.makeResObj(200, '', rst);
} catch (e) {
logger.error('[installTarsNode]', e, ctx);
ctx.makeErrResObj();
}
};
module.exports = ResourceController;
\ No newline at end of file
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
const logger = require('../../logger');
const ServerService = require('../../service/server/ServerService');
const AdminService = require('../../service/admin/AdminService');
const _ = require('lodash');
const util = require('../../tools/util');
const AuthService = require('../../service/auth/AuthService');
const serverConfStruct = {
id: '',
application: '',
server_name: '',
node_name: '',
server_type: '',
enable_set: {
formatter: (value)=> {
return value == 'Y' ? true : false;
}
},
set_name: '',
set_area: '',
set_group: '',
setting_state: '',
present_state: '',
bak_flag: {
formatter: (value)=> {
return value == 0 ? false : true;
}
},
template_name: '',
profile: '',
async_thread_num: '',
base_path: '',
exe_path: '',
start_script_path: '',
stop_script_path: '',
monitor_script_path: '',
patch_time: {formatter: util.formatTimeStamp},
patch_version: "",
process_id: '',
posttime: {formatter: util.formatTimeStamp}
};
const ServerController = {};
ServerController.getServerConfById = async(ctx) => {
let id = ctx.paramsObj.id;
try {
var rst = await ServerService.getServerConfById(id);
if (!_.isEmpty(rst)) {
rst = rst.dataValues;
if (!await AuthService.hasDevAuth(rst.application, rst.server_name, ctx.uid)) {
ctx.makeNotAuthResObj();
} else {
ctx.makeResObj(200, '', util.viewFilter(rst, serverConfStruct));
}
} else {
logger.error('[getServerConfById]', '未查询到id=' + id + '相应的服务', ctx);
ctx.makeErrResObj();
}
} catch (e) {
logger.error('[getServerConfById]', e, ctx);
ctx.makeErrResObj();
}
};
ServerController.serverExist = async(ctx) => {
let application = ctx.paramsObj.application;
let serverName = ctx.paramsObj.server_name;
let nodeName = ctx.paramsObj.node_name;
try {
ctx.makeResObj(200, '', (await ServerService.getServerConf(application, serverName, nodeName)).length > 0);
} catch (e) {
logger.error('[serverExist]', e, ctx);
ctx.makeErrResObj();
}
};
ServerController.getServerConfList4Tree = async(ctx) => {
let treeNodeId = ctx.paramsObj.tree_node_id;
let curPage = parseInt(ctx.paramsObj.cur_page) || 0;
let pageSize = parseInt(ctx.paramsObj.page_size) || 0;
try {
let params = ServerController.formatTreeNodeId(treeNodeId);
if(await AuthService.hasAdminAuth(ctx.uid)){
ctx.makeResObj(200, '', util.viewFilter(await ServerService.getServerConfList4Tree({
application: params.application,
serverName: params.serverName,
enableSet: params.enableSet,
setName: params.setName,
setArea: params.setArea,
setGroup: params.setGroup,
curPage: curPage || 0,
pageSize: pageSize || 0
}), serverConfStruct));
}else if (params.application && params.serverName) { //若在服务页面,则直接检测是否有权限
if (!await AuthService.hasDevAuth(params.application, params.serverName, ctx.uid)) {
ctx.makeNotAuthResObj();
} else {
ctx.makeResObj(200, '', util.viewFilter(await ServerService.getServerConfList4Tree({
application: params.application,
serverName: params.serverName,
enableSet: params.enableSet,
setName: params.setName,
setArea: params.setArea,
setGroup: params.setGroup,
curPage: curPage || 0,
pageSize: pageSize || 0
}), serverConfStruct));
}
} else { //若非服务页面,比如应用页面,set页面,需先获取用户相关权限进行合并
let serverList = await ServerService.getServerConfList4Tree({
application: params.application,
setName: params.setName,
setArea: params.setArea,
setGroup: params.setGroup,
curPage: curPage || 0,
pageSize: pageSize || 0
});
let authList = await AuthService.getAuthListByUid(ctx.uid);
let rst = [];
_.each(authList, (auth)=> {
let application = auth.application;
let serverName = auth.serverName;
if (!serverName && application == params.application) {
rst = serverList;
return false;
}
serverList.forEach((server)=>{
if(server.application == application && server.server_name == serverName){
rst.push(server);
}
});
});
ctx.makeResObj(200, '', util.viewFilter(rst, serverConfStruct));
}
} catch (e) {
logger.error('[getServerConfList4Tree]', e, ctx);
ctx.makeErrResObj();
}
};
ServerController.formatTreeNodeId = (treeNodeId) => {
let serverConf = {};
treeNodeId = treeNodeId.split('.');
treeNodeId.forEach((s)=> {
let i = parseInt(s.substring(0, 1));
let v = s.substring(1);
switch (i) {
case 1:
serverConf.application = v;
break;
case 2:
serverConf.setName = v;
serverConf.enableSet = 'Y';
break;
case 3:
serverConf.setArea = v;
serverConf.enableSet = 'Y';
break;
case 4:
serverConf.setGroup = v;
serverConf.enableSet = 'Y';
break;
case 5:
serverConf.serverName = v;
break;
default:
break;
}
});
return serverConf;
};
ServerController.getInactiveServerConfList = async(ctx) => {
let application = ctx.paramsObj.application || '';
let serverName = ctx.paramsObj.server_name || '';
let nodeName = ctx.paramsObj.node_name || '';
let curPage = parseInt(ctx.paramsObj.cur_page) || 0;
let pageSize = parseInt(ctx.paramsObj.page_size) || 0;
try {
if (!await AuthService.hasDevAuth(application, serverName, ctx.uid)) {
ctx.makeNotAuthResObj();
} else {
let rst = await ServerService.getInactiveServerConfList(application, serverName, nodeName, curPage, pageSize);
ctx.makeResObj(200, '', util.viewFilter(rst, serverConfStruct));
}
} catch (e) {
logger.error('[getInactiveServerConfList]', e, ctx);
ctx.makeErrResObj();
}
};
ServerController.getRealtimeState = async(ctx)=> {
let id = ctx.paramsObj.id;
try {
let rst = await ServerService.getServerConfById(id);
if (!_.isEmpty(rst)) {
rst = rst.dataValues;
if (!await AuthService.hasDevAuth(rst.application, rst.server_name, ctx.uid)) {
ctx.makeNotAuthResObj();
} else {
ctx.makeResObj(200, '', {realtime_state: rst['present_state']});
}
} else {
logger.error('[getRealtimeState]', '未查询到id=' + id + '相应的服务', ctx);
ctx.makeErrResObj();
}
} catch (e) {
logger.error('[getRealtimeState]', e, ctx);
ctx.makeErrResObj();
}
};
ServerController.updateServerConf = async(ctx) => {
try {
let updateServer = ctx.paramsObj;
let server = await ServerService.getServerConfById(updateServer.id);
if (!_.isEmpty(server)) {
if (!await AuthService.hasDevAuth(server.application, server.server_name, ctx.uid)) {
ctx.makeNotAuthResObj();
return;
}
Object.assign(server, updateServer);
server.bak_flag = server.isBak ? 1 : 0;
server.enable_set = server.enable_set ? 'Y' : 'N';
if(server.enable_set == 'Y' && parseInt(server.set_group) != server.set_group){
ctx.makeResObj(500, '#serverList.dlg.errMsg.setGroup#');
return;
}
server.posttime = new Date();
await ServerService.updateServerConf(server);
ctx.makeResObj(200, '', util.viewFilter(await ServerService.getServerConfById(updateServer.id), serverConfStruct));
} else {
logger.error('[updateServerConf]', '未查询到id=' + updateServer.id + '相应的服务', ctx);
ctx.makeErrResObj();
}
} catch (e) {
logger.error('[updateServerConf]', e, ctx);
ctx.makeErrResObj();
}
};
ServerController.loadServer = async(ctx) => {
let application = ctx.paramsObj.application;
let serverName = ctx.paramsObj.server_name;
let nodeName = ctx.paramsObj.node_name;
try {
if (!await AuthService.hasDevAuth(application, serverName, ctx.uid)) {
ctx.makeNotAuthResObj();
} else {
let ret = await AdminService.loadServer(application, serverName, nodeName);
ctx.makeResObj(200, '', ret);
}
} catch (e) {
logger.error('[loadServer]', e, ctx);
ctx.makeErrResObj();
}
};
module.exports = ServerController;
\ No newline at end of file
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
const logger = require('../../logger');
const TreeService = require('../../service/server/TreeService');
const AdminService = require('../../service/admin/AdminService');
const _ = require('lodash');
const util = require('../../tools/util');
const AuthService = require('../../service/auth/AuthService');
const TreeController = {};
TreeController.listTree = async(ctx)=> {
try {
ctx.makeResObj(200, '', await TreeService.getTreeNodes(ctx.uid));
} catch (e) {
logger.error('[listTree]', e, ctx);
ctx.makeErrResObj();
}
};
module.exports = TreeController;
\ No newline at end of file
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
const logger = require('../../logger');
const TaskService = require('../../service/task/TaskService');
const util = require('../../tools/util');
const kafkaConf = require('../../../config/webConf').kafkaConf;
const AuthService = require('../../service/auth/AuthService');
const TaskController = {
};
let kafkaProducer;
let kafkaConsumer;
if(kafkaConf.enable) {
const kafka = require('kafka-node');
kafkaProducer = require('../../service/task/KafkaProducer');
kafkaConsumer = require('../../service/task/KafkaConsumer');
kafkaConsumer.consume();
}
TaskController.getTasks = async (ctx) => {
try{
let {application, server_name, command, from, to, curr_page = 0, page_size = 0} = ctx.paramsObj;
if (!await AuthService.hasDevAuth(application, server_name, ctx.uid)) {
ctx.makeNotAuthResObj();
} else {
let ret = [];
let tasks = await TaskService.getTasks({application, server_name, command, from, to, curr_page, page_size}).catch(function (e) {
logger.error('[getTasks]:',e);
return e;
});
for(let i=0,len=tasks.rows.length;i<len;i++) {
let task = tasks.rows[i];
try {
ret.push(await TaskService.getTaskRsp(task.task_no));
}catch(e){
ret.push({
task_no : task.task_no,
serial : !!task.serial,
status : -1,
items : [{}]
});
}
}
ctx.makeResObj(200, '', {count:tasks.count,rows:ret});
}
}catch(e) {
logger.error('[TaskController.getTasks]:', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
TaskController.getTask = async (ctx) => {
try{
let ret;
if(kafkaConf.enable) {
let task = await TaskService.getTaskStatus(ctx.paramsObj.task_no);
logger.info(task);
if(task.status=='waiting') {
ret = {status: 0};
}else{
ret = await TaskService.getTaskRsp(ctx.paramsObj.task_no);
}
}else {
ret = await TaskService.getTaskRsp(ctx.paramsObj.task_no);
}
ctx.makeResObj(200, '', ret);
}catch(e) {
logger.error('[TaskController.getTask]:', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
TaskController.addTask = async (ctx) => {
let {serial, items} = ctx.paramsObj;
if(!items.length) {
return ctx.makeResObj(500, '#task.params#');
}
try {
let task_no = util.getUUID().toString();
if(kafkaConf.enable) {
await kafkaProducer.produce(JSON.stringify({serial, items, task_no}), () => {
logger.info('task produce success!');
});
} else {
await TaskService.addTask({serial, items, task_no});
}
ctx.makeResObj(200, '', task_no);
}catch(e) {
logger.error('[TaskController.addTask]:', e, ctx);
ctx.makeErrResObj(500, e.toString());
}
};
module.exports = TaskController;
\ No newline at end of file
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
const logger = require('../../logger');
const TemplateService = require('../../service/template/TemplateService');
const _ = require('lodash');
const util = require('../../tools/util');
const AuthService = require('../../service/auth/AuthService');
const templateStruct = {
id: '',
template_name: '',
parents_name: '',
profile: '',
posttime: {formatter: util.formatTimeStamp}
};
const TemplateController = {};
TemplateController.addTemplate = async(ctx) => {
try {
let templateName = ctx.paramsObj.template_name;
let parentsName = ctx.paramsObj.parents_name;
let profile = ctx.paramsObj.profile;
ctx.makeResObj(200, '', util.viewFilter(await TemplateService.addTemplate(templateName, parentsName, profile), templateStruct));
} catch (e) {
logger.error('[addTemplate]', e, ctx);
ctx.makeErrResObj();
}
};
TemplateController.deleteTemplate = async(ctx) => {
try {
let id = ctx.paramsObj.id;
await TemplateService.deleteTemplate(id);
ctx.makeResObj(200, '', [id]);
} catch (e) {
logger.error('[addTemplate]', e, ctx);
ctx.makeErrResObj();
}
};
TemplateController.updateTemplate = async(ctx) => {
try {
let params = ctx.paramsObj;
await TemplateService.updateTemplate(params);
ctx.makeResObj(200, '', util.viewFilter(await TemplateService.getTemplateById(params.id), templateStruct));
} catch (e) {
logger.error('[addTemplate]', e, ctx);
ctx.makeErrResObj();
}
};
TemplateController.getTemplate = async(ctx) => {
try {
let templateName = ctx.paramsObj.template_name;
ctx.makeResObj(200, '', util.viewFilter(await TemplateService.getTemplateByName(templateName), templateStruct));
} catch (e) {
logger.error('[getTemplate]', e, ctx);
ctx.makeErrResObj();
}
};
TemplateController.getTemplateList = async(ctx) => {
try {
let templateName = ctx.paramsObj.template_name || '';
let parentsName = ctx.paramsObj.parents_name || '';
ctx.makeResObj(200, '', util.viewFilter(await TemplateService.getTemplateList(templateName, parentsName), templateStruct));
} catch (e) {
logger.error('[getTemplateList]', e, ctx);
ctx.makeErrResObj();
}
};
TemplateController.getTemplateNameList = async(ctx)=> {
try {
let templateList = await TemplateService.getTemplateList('', '');
let templateNameList = [];
templateList.forEach((template)=> {
templateNameList.push(template.dataValues.template_name);
});
ctx.makeResObj(200, '', templateNameList);
} catch (e) {
logger.error('[getTemplateNameList]', e, ctx);
ctx.makeErrResObj();
}
};
module.exports = TemplateController;
\ No newline at end of file
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
const {tAdapterConf, sequelize} = require('./db').db_tars;
const AdapterDao = {};
AdapterDao.getAdapterConfById = async(id) => {
return await tAdapterConf.findOne({
where: {
id: id
}
});
};
AdapterDao.getAdapterConf = async(application, serverName, nodeName) => {
return await tAdapterConf.findAll({
where: {
application: application,
server_name: serverName,
node_name: nodeName
}
});
};
AdapterDao.getAdapterConfByObj = async(params) => {
return await tAdapterConf.findOne({
where: {
application: params.application,
server_name: params.serverName,
node_name: params.nodeName,
adapter_name: params.application + '.' + params.serverName + '.' + params.objName + 'Adapter'
}
});
};
AdapterDao.getAdapterConfByNodeName = async(nodeNames) => {
return await tAdapterConf.findAll({
where: {
node_name: nodeNames
}
});
};
AdapterDao.insertAdapterConf = async(params, transaction) => {
if(transaction){
return await tAdapterConf.create(params, {transaction: transaction});
}else{
return await tAdapterConf.create(params);
}
};
AdapterDao.deleteAdapterConf = async(id) => {
return await tAdapterConf.destroy({
where: {id: id}
});
};
AdapterDao.updateAdapterConf = async(params) => {
return await tAdapterConf.update(params, {where: {id: params.id}});
};
module.exports = AdapterDao;
\ No newline at end of file
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
const {tConfigFiles,tConfigHistoryFiles,tConfigReferences} = require('./db').db_tars;
let ConfigDao = {};
ConfigDao.getUnusedApplicationConfigFile = async(application, configId) => {
let referenceIds = await tConfigReferences.findAll({
raw : true,
attributes : ['reference_id'],
where : {config_id : configId}
});
let arr = [];
referenceIds.forEach(function (ref) {
arr.push(ref.reference_id);
});
return await tConfigFiles.findAll({
raw : true,
where : {
level : 1,
server_name : application,
set_name : '',
set_area : '',
set_group : '',
id : {
'$notIn' : arr
}
}
});
};
ConfigDao.getApplicationConfigFile = async (application) => {
return await tConfigFiles.findAll({
where : {
level : 1,
server_name : application,
set_name : '',
set_area : '',
set_group : '',
}
});
};
ConfigDao.getSetConfigFile = async (params) => {
let whereObj = Object.assign({level:1},filterParams(params));
return await tConfigFiles.findAll({
where : whereObj
});
};
ConfigDao.getServerConfigFile = async (params) => {
let whereObj = Object.assign({level:2},filterParams(params));
return await tConfigFiles.findAll({
where : whereObj
});
};
ConfigDao.insertConfigFile = async (params, transaction) => {
if(transaction){
return await tConfigFiles.create(params, {transaction: transaction});
}else{
return await tConfigFiles.create(params);
}
};
ConfigDao.insertConfigFileHistory = async (params) => {
return await tConfigHistoryFiles.create(params);
};
ConfigDao.getConfigFile = async (id) => {
return await tConfigFiles.findOne({
raw : true,
where : {id : id}
});
};
ConfigDao.getConfigFileByRefTableId = async (id) => {
tConfigFiles.belongsTo(tConfigReferences, {foreignKey: 'id', targetKey: 'config_id'});
return await tConfigFiles.findOne({
raw : true,
include: [{
model : tConfigReferences,
where: {id: id}
}]
});
};
ConfigDao.getConfigFileList = async (ids) => {
return await tConfigFiles.findAll({
where : {
id : {
'$in' : ids
}
}
});
};
ConfigDao.getNodeConfigFile = async (params) => {
let whereObj = Object.assign({},{level:3},filterParams(params));
return await tConfigFiles.findAll({
order : [
['id','desc']
],
where : whereObj
});
};
ConfigDao.deleteConfigFile = async (id) => {
return await tConfigFiles.destroy({where: {id:id}});
};
ConfigDao.getConfigRefList = async (id) => {
return await tConfigReferences.findAll({where: {reference_id:id}});
};
ConfigDao.updateConfigFile = async (params) => {
return await tConfigFiles.update(
params,
{where : {id : params.id}}
);
};
ConfigDao.getConfigFileHistory = async (id) => {
return await tConfigHistoryFiles.findOne({
raw : true,
where : {
id : id
}
});
};
ConfigDao.getConfigFileHistoryList = async (id, curPage, pageSize) => {
var opts = {
order : [
['id','desc']
],
where : {
configId : id
}
};
if(curPage && pageSize){
Object.assign(opts,{
limit: pageSize,
offset: pageSize * (curPage - 1)
})
}
return await tConfigHistoryFiles.findAndCountAll(opts);
};
ConfigDao.insertConfigRef = async (configId, refId) => {
return await tConfigReferences.create({
config_id : configId,
reference_id: refId
});
};
ConfigDao.getConfigRef = async (refId) => {
return await tConfigReferences.findOne({
raw : true,
where : {id: refId}
});
};
ConfigDao.deleteConfigRef = async (id) => {
return await tConfigReferences.destroy({
where : {id : id}
});
};
ConfigDao.getConfigRefByConfigId = async (configId) => {
tConfigReferences.belongsTo(tConfigFiles,{foreignKey:'reference_id'});
return await tConfigReferences.findAll({
order : [
['id','desc']
],
where : {
config_id : configId
},
include : {
model : tConfigFiles
},
});
};
function filterParams(obj) {
for(var item in obj) {
if(!obj[item] && obj[item]!== ''){
delete obj[item];
}
}
return obj;
}
module.exports = ConfigDao;
\ No newline at end of file
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
const {
tAdapterConf
} = require('./db').db_tars;
const logger = require('../logger');
var DemoDao = function(){}
DemoDao.getAdapterConfById = async (id) => {
try{
return await tAdapterConf.findAll({
where: {
id: id
}
});
} catch(e){
logger.error(e);
throw(e);
}
}
DemoDao.insertAdapterConf = async(adapterConf)=>{
}
DemoDao.updateAdapterConf = async(id, adapterConf)=>{
}
module.exports = DemoDao;
\ No newline at end of file
Supports Markdown
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