Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
TarsWeb
Commits
4185b735
Commit
4185b735
authored
7 years ago
by
clauseliu
Browse files
Options
Download
Email Patches
Plain Diff
clauseliu
parent
b44833f6
master
ETZhangSX-patch-1
czzou_dev
dcache-alpha
dependabot/npm_and_yarn/client/axios-0.21.1
dependabot/npm_and_yarn/client/elliptic-6.5.3
dependabot/npm_and_yarn/client/ini-1.3.7
dependabot/npm_and_yarn/client/lodash-4.17.21
dependabot/npm_and_yarn/client/mixin-deep-1.3.2
dependabot/npm_and_yarn/sequelize-5.21.2
feature/gateway
feature/services
k8s
kiven_dev
release/2.4
release/3.0
ruanshudong_dev
tars-alpha
1.5.1
1.5.0
1.4.2
1.4.1
1.4.0
1.3.1
1.3.0
1.2.0
1.1.1
1.1.0
1.0.0
v3.0.11
v3.0.10
v3.0.9
v3.0.8
v3.0.7
v3.0.6
v3.0.5
v3.0.4
v3.0.3
v3.0.2
v3.0.1
v3.0.0
v2.4.27
v2.4.26
v2.4.25
v2.4.24
v2.4.23
v2.4.22
v2.4.21
v2.4.20
v2.4.19
v2.4.18
v2.4.17
v2.4.16
v2.4.15
v2.4.14
v2.4.13
v2.4.12
v2.4.11
v2.4.10
v2.4.9
v2.4.8
v2.4.7
v2.4.6
v2.4.5
v2.4.4
v2.4.3
v2.4.2
v2.4.1
v2.4.0
v2.1.0
v2.0.0
No related merge requests found
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
app.js
+1
-0
app.js
app/controller/config/ConfigController.js
+138
-7
app/controller/config/ConfigController.js
app/dao/db/createModels.js
+1
-1
app/dao/db/createModels.js
app/dao/db/models/t_config_files.js
+66
-0
app/dao/db/models/t_config_files.js
app/dao/tConfigFiles.js
+55
-0
app/dao/tConfigFiles.js
app/midware/paramsMidware.js
+1
-1
app/midware/paramsMidware.js
app/router/index.js
+1
-0
app/router/index.js
app/router/routerConf.js
+13
-2
app/router/routerConf.js
app/service/config/ConfigService.js
+129
-5
app/service/config/ConfigService.js
views/index.ejs
+1
-1
views/index.ejs
with
406 additions
and
17 deletions
+406
-17
app.js
+
1
-
0
View file @
4185b735
...
...
@@ -24,6 +24,7 @@ app.use(views(__dirname + '/views', {
extension
:
'
ejs
'
}));
app
.
use
(
bodyparser
());
//前置中间件
...
...
This diff is collapsed.
Click to expand it.
app/controller/config/ConfigController.js
+
138
-
7
View file @
4185b735
...
...
@@ -8,30 +8,161 @@ const ConfigController = {};
ConfigController
.
index
=
async
(
ctx
)
=>
{
await
ctx
.
render
(
'
index
'
,
{
title
:
'
tars title#common.servername#
'
,
a
:
ctx
.
paramsObj
.
a
||
''
,
title
:
'
tars title#common.servername#
'
});
};
ConfigController
.
configFileList
=
async
(
ctx
)
=>
{
let
{
level
,
application
,
set_name
,
set_area
,
set_group
,
server_name
}
=
ctx
.
paramsObj
;
let
list
=
[];
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
;
}
try
{
ctx
.
makeResObj
(
200
,
''
,
await
ConfigService
.
getServerConfigFile
()
);
ctx
.
makeResObj
(
200
,
''
,
list
);
}
catch
(
e
){
ctx
.
makeResObj
(
500
,
e
.
toString
()
);
ctx
.
makeResObj
(
500
,
e
);
}
};
ConfigController
.
addConfigFile
=
async
(
ctx
)
=>
{
console
.
info
(
ctx
.
paramsObj
);
let
params
=
ctx
.
paramsObj
;
try
{
ctx
.
makeResObj
(
200
,
''
,
await
ConfigService
.
addConfigFile
(
params
));
}
catch
(
e
){
ctx
.
makeResObj
(
500
,
e
.
toString
());
}
};
ConfigController
.
deleteConfigFile
=
async
(
ctx
)
=>
{
let
id
=
ctx
.
paramsObj
.
id
;
try
{
ctx
.
makeResObj
(
200
,
''
,
await
ConfigService
.
deleteConfigFile
(
id
));
}
catch
(
e
)
{
ctx
.
makeResObj
(
500
,
e
.
toString
());
}
};
ConfigController
.
updateConfigFile
=
async
(
ctx
)
=>
{
let
params
=
ctx
.
paramsObj
;
try
{
ctx
.
makeResObj
(
200
,
''
,
await
ConfigService
.
updateConfigFile
(
params
));
}
catch
(
e
){
ctx
.
makeResObj
(
500
,
e
.
toString
());
}
};
ConfigController
.
configFile
=
async
(
ctx
)
=>
{
let
id
=
ctx
.
paramsObj
.
id
;
try
{
ctx
.
makeResObj
(
200
,
''
,
await
ConfigService
.
loadConfigFile
(
id
));
}
catch
(
e
){
ctx
.
makeResObj
(
500
,
e
.
toString
());
}
};
ConfigController
.
nodeConfigFileList
=
async
(
ctx
)
=>
{
let
params
=
ctx
.
paramsObj
;
try
{
ctx
.
makeResObj
(
200
,
''
,
await
ConfigService
.
getNodeConfigFile
(
params
));
}
catch
(
e
){
ctx
.
makeResObj
(
500
,
e
.
toString
());
}
};
ConfigController
.
loadConfigFileHistory
=
async
(
ctx
)
=>
{
let
id
=
ctx
.
paramsObj
.
id
;
try
{
ctx
.
makeResObj
(
200
,
''
,
await
ConfigService
.
loadConfigFileHistory
(
id
));
}
catch
(
e
){
ctx
.
makeResObj
(
500
,
e
.
toString
());
}
};
ConfigController
.
configFileHistoryList
=
async
(
ctx
)
=>
{
let
config_id
=
ctx
.
paramsObj
.
config_id
;
try
{
ctx
.
makeResObj
(
200
,
''
,
await
ConfigService
.
getConfigFileHistory
(
config_id
));
}
catch
(
e
){
ctx
.
makeResObj
(
500
,
e
.
toString
());
}
};
ConfigController
.
addConfigRef
=
async
(
ctx
)
=>
{
let
{
config_id
,
reference_id
}
=
ctx
.
paramsObj
;
try
{
ctx
.
makeResObj
(
200
,
''
,
await
ConfigService
.
addConfigRef
(
config_id
,
reference_id
));
}
catch
(
e
){
ctx
.
makeResObj
(
500
,
e
.
toString
());
}
};
ConfigController
.
deleteConfigRef
=
async
(
ctx
)
=>
{
let
id
=
ctx
.
paramsObj
.
id
;
try
{
ctx
.
makeResObj
(
200
,
''
,
await
ConfigService
.
addConfigFile
(
ctx
.
paramsObj
));
ctx
.
makeResObj
(
200
,
''
,
await
ConfigService
.
deleteConfigRef
(
id
));
}
catch
(
e
){
console
.
info
(
e
);
ctx
.
makeResObj
(
500
,
e
.
toString
());
}
};
ConfigController
.
configRefList
=
async
(
ctx
)
=>
{
let
config_id
=
ctx
.
paramsObj
.
config_id
;
try
{
ctx
.
makeResObj
(
200
,
''
,
await
ConfigService
.
getConfigRefByConfigId
(
config_id
));
}
catch
(
e
){
ctx
.
makeResObj
(
500
,
e
.
toString
());
}
};
ConfigController
.
mergedNodeConfig
=
async
(
ctx
)
=>
{
let
id
=
ctx
.
paramsObj
.
id
;
try
{
//ctx.makeResObj(200, '', await ConfigService.getConfigRefByConfigId(id));
}
catch
(
e
){
ctx
.
makeResObj
(
500
,
e
.
toString
());
}
};
ConfigController
.
pushConfigFile
=
async
(
ctx
)
=>
{
let
ids
=
ctx
.
paramsObj
.
ids
;
try
{
//ctx.makeResObj(200, '', await ConfigService.getConfigRefByConfigId(id));
}
catch
(
e
){
ctx
.
makeResObj
(
500
,
e
.
toString
());
}
};
module
.
exports
=
ConfigController
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app/dao/db/createModels.js
+
1
-
1
View file @
4185b735
var
SequelizeAuto
=
require
(
'
sequelize-auto
'
)
var
auto
=
new
SequelizeAuto
(
'
db_tars_web
'
,
'
root
'
,
''
,{
var
auto
=
new
SequelizeAuto
(
'
db_tars_web
'
,
'
root
'
,
'
admin
'
,{
host
:
'
localhost
'
,
dialect
:
'
mysql
'
,
directory
:
'
./models
'
,
// prevents the program from writing to disk
...
...
This diff is collapsed.
Click to expand it.
app/dao/db/models/t_config_files.js
0 → 100644
+
66
-
0
View file @
4185b735
/* jshint indent: 1 */
module
.
exports
=
function
(
sequelize
,
DataTypes
)
{
return
sequelize
.
define
(
'
t_config_files
'
,
{
id
:
{
type
:
DataTypes
.
INTEGER
(
11
),
allowNull
:
false
,
primaryKey
:
true
,
autoIncrement
:
true
},
server_name
:
{
type
:
DataTypes
.
STRING
(
128
),
allowNull
:
true
,
defaultValue
:
''
},
set_name
:
{
type
:
DataTypes
.
STRING
(
16
),
allowNull
:
false
,
defaultValue
:
''
},
set_area
:
{
type
:
DataTypes
.
STRING
(
16
),
allowNull
:
false
,
defaultValue
:
''
},
set_group
:
{
type
:
DataTypes
.
STRING
(
16
),
allowNull
:
false
,
defaultValue
:
''
},
host
:
{
type
:
DataTypes
.
STRING
(
20
),
allowNull
:
false
,
defaultValue
:
''
},
filename
:
{
type
:
DataTypes
.
STRING
(
128
),
allowNull
:
true
},
config
:
{
type
:
DataTypes
.
TEXT
,
allowNull
:
true
},
posttime
:
{
type
:
DataTypes
.
DATE
,
allowNull
:
true
},
lastuser
:
{
type
:
DataTypes
.
STRING
(
50
),
allowNull
:
true
},
level
:
{
type
:
DataTypes
.
INTEGER
(
11
),
allowNull
:
true
,
defaultValue
:
'
2
'
},
config_flag
:
{
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
false
,
defaultValue
:
'
0
'
}
},
{
tableName
:
'
t_config_files
'
,
timestamps
:
false
});
};
This diff is collapsed.
Click to expand it.
app/dao/tConfigFiles.js
0 → 100644
+
55
-
0
View file @
4185b735
/**
* Created by clauseliu on 2018/4/20.
*/
const
{
tConfigFiles
}
=
require
(
'
./db
'
);
const
logger
=
require
(
'
../logger
'
);
let
ConfigMapper
=
{};
ConfigMapper
.
getApplicationConfigFile
=
async
(
application
)
=>
{
try
{
return
await
tConfigFiles
.
findAll
({
where
:
{
level
:
1
,
server_name
:
application
}
});
}
catch
(
e
)
{
logger
.
error
(
e
);
return
e
;
}
};
ConfigMapper
.
getSetConfigFile
=
async
(
params
)
=>
{
try
{
let
whereObj
=
Object
.
assign
({
level
:
1
},
params
);
return
await
tConfigFiles
.
findAll
({
where
:
whereObj
});
}
catch
(
e
)
{
logger
.
error
(
e
);
return
e
;
}
};
ConfigMapper
.
getServerConfigFile
=
async
(
params
)
=>
{
for
(
var
item
in
params
)
{
if
(
!
params
[
item
]){
delete
params
[
item
];
}
}
try
{
let
whereObj
=
Object
.
assign
({
level
:
2
},
params
);
return
await
tConfigFiles
.
findAll
({
where
:
whereObj
});
}
catch
(
e
)
{
logger
.
error
(
e
);
return
e
;
}
};
module
.
exports
=
ConfigMapper
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app/midware/paramsMidware.js
+
1
-
1
View file @
4185b735
...
...
@@ -21,7 +21,7 @@ const paramsCheckMidware = async (ctx, next, checkRule) => {
var
hasError
=
false
;
_
.
each
(
checkRule
,
(
rules
,
paramName
)
=>
{
if
(
rules
){
var
value
=
params
[
paramName
]
||
''
;
var
value
=
params
[
paramName
]
!=
undefined
?
params
[
paramName
].
toString
()
:
''
;
_
.
each
(
rules
.
split
(
'
;
'
),
(
rule
)
=>
{
if
(
rule
===
'
notEmpty
'
&&
validator
.
isEmpty
(
value
)){
hasError
=
true
;
...
...
This diff is collapsed.
Click to expand it.
app/router/index.js
+
1
-
0
View file @
4185b735
...
...
@@ -30,6 +30,7 @@ const getRouter = (router, routerConf) =>{
});
};
//页面类型路由
const
pageRouter
=
new
Router
();
getRouter
(
pageRouter
,
pageConf
);
...
...
This diff is collapsed.
Click to expand it.
app/router/routerConf.js
+
13
-
2
View file @
4185b735
...
...
@@ -16,8 +16,19 @@ const apiConf = [
[
'
get
'
,
'
/getRpcData
'
,
DemoController
.
getRpcData
,
{
id
:
'
notEmpty;number
'
}],
// 服务配置接口
[
'
get
'
,
'
/config_file_list
'
,
ConfigController
.
configFileList
,
{
id
:
'
notEmpty;number
'
}],
[
'
post
'
,
'
/add_config_file
'
,
ConfigController
.
addConfigFile
],
[
'
get
'
,
'
/config_file_list
'
,
ConfigController
.
configFileList
,
{
level
:
'
number
'
,
application
:
'
notEmpty
'
}],
[
'
post
'
,
'
/add_config_file
'
,
ConfigController
.
addConfigFile
,
{
level
:
'
number
'
,
application
:
'
notEmpty
'
,
server_name
:
'
notEmpty
'
,
filename
:
'
notEmpty
'
,
config
:
'
notEmpty
'
}],
[
'
get
'
,
'
/delete_config_file
'
,
ConfigController
.
deleteConfigFile
,
{
id
:
'
number
'
}],
[
'
post
'
,
'
/update_config_file
'
,
ConfigController
.
updateConfigFile
,{
id
:
'
number
'
,
config
:
'
notEmpty
'
}],
[
'
get
'
,
'
/config_file
'
,
ConfigController
.
configFile
,
{
id
:
'
number
'
}],
[
'
post
'
,
'
/node_config_file_list
'
,
ConfigController
.
nodeConfigFileList
,
{
application
:
'
notEmpty
'
,
server_name
:
'
notEmpty
'
}],
[
'
get
'
,
'
/config_file_history
'
,
ConfigController
.
loadConfigFileHistory
,
{
id
:
'
number
'
}],
[
'
get
'
,
'
/config_file_history_list
'
,
ConfigController
.
configFileHistoryList
,
{
config_id
:
'
number
'
}],
[
'
get
'
,
'
/add_config_ref
'
,
ConfigController
.
addConfigRef
,
{
config_id
:
'
number
'
,
reference_id
:
'
number
'
}],
[
'
get
'
,
'
/delete_config_ref
'
,
ConfigController
.
deleteConfigRef
,
{
id
:
'
number
'
}],
[
'
get
'
,
'
/config_ref_list
'
,
ConfigController
.
configRefList
,
{
config_id
:
'
number
'
}]
//['get', '/merged_node_config', ConfigController.configRefList, {id: 'notEmpty;number'}],
//['get', '/push_config_file', ConfigController.configRefList, {ids: 'notEmpty;string'}],
]
module
.
exports
=
{
pageConf
,
apiConf
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app/service/config/ConfigService.js
+
129
-
5
View file @
4185b735
...
...
@@ -2,12 +2,15 @@
* Created by clauseliu on 2018/4/18.
*/
const
logger
=
require
(
`../../logger`
);
const
ConfigMapper
=
require
(
'
../../dao/tConfigFiles
'
);
const
ConfigService
=
{};
ConfigService
.
getServerConfigFile
=
async
()
=>
{
let
list
=
[{
ConfigService
.
addConfigFile
=
async
(
params
)
=>
{
return
{
id
:
0
,
server_name
:
''
,
node_name
:
''
,
...
...
@@ -18,12 +21,34 @@ ConfigService.getServerConfigFile = async() => {
config
:
''
,
level
:
1
,
posttime
:
''
}];
return
list
}
};
ConfigService
.
addConfigFile
=
async
(
params
)
=>
{
ConfigService
.
deleteConfigFile
=
async
(
id
)
=>
{
try
{
return
Promise
.
resolve
([
id
]);
}
catch
(
e
){
return
Promise
.
reject
(
e
);
}
};
ConfigService
.
updateConfigFile
=
async
(
params
)
=>
{
return
{
id
:
0
,
server_name
:
''
,
node_name
:
''
,
set_name
:
''
,
set_area
:
''
,
set_group
:
''
,
filename
:
''
,
config
:
''
,
level
:
1
,
posttime
:
''
}
};
ConfigService
.
loadConfigFile
=
async
(
id
)
=>
{
return
{
id
:
0
,
server_name
:
''
,
...
...
@@ -38,4 +63,103 @@ ConfigService.addConfigFile = async(params) => {
}
};
ConfigService
.
getServerConfigFile
=
function
(
params
)
{
return
ConfigMapper
.
getServerConfigFile
(
params
).
catch
(
function
(
e
)
{
return
e
;
});
};
ConfigService
.
getApplicationConfigFile
=
async
(
application
)
=>
{
return
await
ConfigMapper
.
getApplicationConfigFile
(
application
).
catch
(
function
(
e
)
{
return
e
;
});
};
ConfigService
.
getSetConfigFile
=
function
(
params
)
{
return
ConfigMapper
.
getSetConfigFile
(
params
).
catch
(
function
(
e
)
{
return
e
;
});
};
ConfigService
.
getNodeConfigFile
=
async
(
params
)
=>
{
let
list
=
[{
id
:
0
,
server_name
:
''
,
node_name
:
''
,
set_name
:
''
,
set_area
:
''
,
set_group
:
''
,
filename
:
''
,
config
:
''
,
level
:
1
,
posttime
:
''
}];
return
list
};
ConfigService
.
loadConfigFileHistory
=
async
(
id
)
=>
{
return
{
"
id
"
:
""
,
// 变更记录ID
"
config_id
"
:
""
,
// 配置文件ID
"
reason
"
:
""
,
// 备注
"
content
"
:
""
,
// 变更内容
"
posttime
"
:
""
,
// 更新时间
}
};
ConfigService
.
getConfigFileHistory
=
async
(
config_id
)
=>
{
return
[{
"
id
"
:
""
,
// 变更记录ID
"
config_id
"
:
""
,
// 配置文件ID
"
reason
"
:
""
,
// 备注
"
content
"
:
""
,
// 变更内容
"
posttime
"
:
""
,
// 更新时间
}]
};
/**
* 添加引用文件
* @param config_id
* @param reference_id
* @return {{id: string, config_id: string, reference_id: string}}
*/
ConfigService
.
addConfigRef
=
async
(
config_id
,
reference_id
)
=>
{
return
{
"
id
"
:
""
,
// 引用ID
"
config_id
"
:
""
,
// 配置文件ID
"
reference_id
"
:
""
// 引用配置文件ID
}
};
ConfigService
.
deleteConfigRef
=
async
(
id
)
=>
{
return
[
0
];
};
/**
* 引用列表
* @param config_id
* @return {*[]}
*/
ConfigService
.
getConfigRefByConfigId
=
async
(
config_id
)
=>
{
return
[{
"
id
"
:
0
,
// 引用ID
"
config_id
"
:
0
,
// 配置文件ID
"
reference
"
:
{
"
id
"
:
0
,
// 配置文件ID
"
server_name
"
:
""
,
// 服务
"
node_name
"
:
""
,
// 节点
"
set_name
"
:
""
,
// Set名
"
set_area
"
:
""
,
// Set取
"
set_group
"
:
""
,
// Set组
"
filename
"
:
""
,
// 文件名
"
config
"
:
""
,
// 文件内容
"
level
"
:
1
,
// 层级,1:应用或Set,2:服务,3:节点
"
posttime
"
:
""
,
// 更新时间
}
}]
};
module
.
exports
=
ConfigService
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
views/index.ejs
+
1
-
1
View file @
4185b735
...
...
@@ -19,7 +19,7 @@ this is Index Page
ajax
.
open
(
'
POST
'
,
'
/api/add_config_file
'
,
true
);
ajax
.
setRequestHeader
(
'
Content-type
'
,
'
application/x-www-form-urlencoded
'
);
ajax
.
send
(
'
id=3333
'
);
ajax
.
send
(
'
level=5&application=""
'
);
</script>
</body>
</html>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help