Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qa-deploy-utils
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QA
qa-deploy-utils
Commits
51eea2ef
Commit
51eea2ef
authored
Mar 25, 2018
by
智勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get db config from mongodb
parent
ab546dab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
24 deletions
+48
-24
get_project_config_server.js
qa_shell_script/config_server/get_project_config_server.js
+36
-24
dbconfig.js
qa_shell_script/config_server/model/dbconfig.js
+12
-0
No files found.
qa_shell_script/config_server/get_project_config_server.js
View file @
51eea2ef
var
express
=
require
(
'
express
'
);
var
express
=
require
(
'
express
'
);
var
cproc
=
require
(
'
child_process
'
);
var
cproc
=
require
(
'
child_process
'
);
var
bodyParser
=
require
(
'
body-parser
'
);
var
bodyParser
=
require
(
'
body-parser
'
);
var
db_config
=
require
(
'
./config/db
'
);
var
request
=
require
(
'
request
'
);
var
request
=
require
(
'
request
'
);
// const mongodb = require('mongodb');
const
mongoose
=
require
(
'
mongoose
'
);
const
mongoose
=
require
(
'
mongoose
'
);
var
ProConfig
=
require
(
'
./model/proconfig.js
'
);
var
ProConfig
=
require
(
'
./model/proconfig.js
'
);
var
DBconfig
=
require
(
'
./model/dbconfig.js
'
);
// return
// return
var
execSync
=
cproc
.
execSync
;
var
execSync
=
cproc
.
execSync
;
var
options
=
{
var
options
=
{
...
@@ -13,6 +13,7 @@ var options = {
...
@@ -13,6 +13,7 @@ var options = {
limit
:
'
100kb
'
,
limit
:
'
100kb
'
,
type
:
'
application/octet-stream
'
type
:
'
application/octet-stream
'
};
};
// 同步进行接口转发
// 同步进行接口转发
function
requestPromise
(
option
)
{
function
requestPromise
(
option
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
...
@@ -25,10 +26,9 @@ function requestPromise(option) {
...
@@ -25,10 +26,9 @@ function requestPromise(option) {
})
})
})
})
}
}
// mongoose.connect('mongodb://
localhost/my_databas
e');
// mongoose.connect('mongodb://
192.168.28.179:27017/qaHom
e');
mongoose
.
connect
(
'
mongodb://172.30.220.22:27017/qaHome
'
)
mongoose
.
connect
(
'
mongodb://172.30.220.22:27017/qaHome
'
)
var
app
=
express
();
var
app
=
express
();
var
admin
=
express
();
// the sub app
var
admin
=
express
();
// the sub app
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}))
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}))
...
@@ -88,10 +88,9 @@ function parseJson2Str(json) {
...
@@ -88,10 +88,9 @@ function parseJson2Str(json) {
}
}
return
a
.
join
(
"
"
)
return
a
.
join
(
"
"
)
}
}
// ------------UTILS----------
// ------------UTILS----------
// DB 维护数据
let
db_conf
=
db_config
.
db_config
();
let
db_conf_keys
=
Object
.
keys
(
db_conf
);
// 从mongo中获取配置
// 从mongo中获取配置
function
getProjectConfigPromise
()
{
function
getProjectConfigPromise
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
...
@@ -106,9 +105,6 @@ function getProjectConfigPromise() {
...
@@ -106,9 +105,6 @@ function getProjectConfigPromise() {
}
else
if
(
pro
[
"
project_name
"
]
==
"
new-paycenter-ui
"
)
{
}
else
if
(
pro
[
"
project_name
"
]
==
"
new-paycenter-ui
"
)
{
hosts
[
"
paycenter-ui--new-paycenter-ui
"
]
=
pro
[
"
host_name
"
];
hosts
[
"
paycenter-ui--new-paycenter-ui
"
]
=
pro
[
"
host_name
"
];
}
}
// else if(pro["project_name"] == "new-spider-center-ui"){
// hosts["spider-center-ui--new-spider-center-ui"] = pro["host_name"];
// }
let
temp
=
{
let
temp
=
{
project_group
:
""
,
project_group
:
""
,
...
@@ -152,11 +148,29 @@ function getProjectConfigPromise() {
...
@@ -152,11 +148,29 @@ function getProjectConfigPromise() {
})
})
}
}
// let db_conf = db_config.db_config();
// let db_conf_keys = Object.keys(db_conf);
// 从mongo中获取DB配置
function
getDBConfigPromise
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
DBconfig
.
find
({}).
exec
().
then
(
res
=>
{
let
re
=
{}
let
_dbs
=
JSON
.
parse
(
JSON
.
stringify
(
res
))
for
(
let
db
of
_dbs
)
{
re
[
db
[
"
dbname
"
]]
=
db
}
resolve
(
re
)
}).
catch
((
err
)
=>
{
reject
(
err
)
});
})
}
//
//
admin
.
get
(
'
/get_db_config/:name/:attr
'
,
function
(
req
,
res
)
{
admin
.
get
(
'
/get_db_config/:name/:attr
'
,
async
function
(
req
,
res
)
{
let
str
=
""
let
db_conf
=
await
getDBConfigPromise
();
let
db_conf_keys
=
Object
.
keys
(
db_conf
);
if
(
req
.
params
.
name
==
"
all
"
)
{
if
(
req
.
params
.
name
==
"
all
"
)
{
if
(
req
.
params
.
attr
==
"
name
"
)
{
if
(
req
.
params
.
attr
==
"
name
"
)
{
res
.
send
(
db_conf_keys
.
join
(
"
"
));
res
.
send
(
db_conf_keys
.
join
(
"
"
));
...
@@ -167,27 +181,29 @@ admin.get('/get_db_config/:name/:attr', function (req, res) {
...
@@ -167,27 +181,29 @@ admin.get('/get_db_config/:name/:attr', function (req, res) {
}
else
{
}
else
{
let
item
=
db_conf
[
req
.
params
.
name
]
let
item
=
db_conf
[
req
.
params
.
name
]
// res.send(JSON.stringify(db_conf[req.params.name]))
// res.send(JSON.stringify(db_conf[req.params.name]))
res
.
send
(
`
${
item
.
host
}
${
item
.
port
}
${
item
.
user
}
${
item
.
pwd
}
${
item
.
sys_
table_list
}
`
)
res
.
send
(
`
${
item
.
ip
}
${
item
.
port
}
${
item
.
username
}
${
item
.
passwd
}
${
item
.
table_list
}
`
)
}
}
}
}
});
});
admin
.
get
(
'
/get_db_dump_command/:name/:opt
'
,
function
(
req
,
res
)
{
admin
.
get
(
'
/get_db_dump_command/:name/:opt
'
,
async
function
(
req
,
res
)
{
let
db_conf
=
await
getDBConfigPromise
();
let
db_conf_keys
=
Object
.
keys
(
db_conf
);
if
(
req
.
params
.
opt
!=
"
opt
"
)
{
if
(
req
.
params
.
opt
!=
"
opt
"
)
{
res
.
send
(
db_config
.
get_mysql_dump_table
(
req
.
params
.
name
));
res
.
send
(
db_config
.
get_mysql_dump_table
(
req
.
params
.
name
));
}
else
{
}
else
{
res
.
send
(
db_config
.
get_mysql_dump_opt
(
req
.
params
.
name
));
res
.
send
(
db_config
.
get_mysql_dump_opt
(
req
.
params
.
name
));
}
}
});
});
admin
.
get
(
'
/get_db_config/refersh
'
,
function
()
{
admin
.
get
(
'
/get_db_config/refersh
'
,
async
function
(
req
,
res
)
{
let
db_conf
=
await
getDBConfigPromise
();
let
db_conf_keys
=
Object
.
keys
(
db_conf
);
res
.
setHeader
(
"
Content-Type
"
,
"
application/json
"
);
res
.
setHeader
(
"
Content-Type
"
,
"
application/json
"
);
db_conf
=
db_config
.
db_config
();
db_conf_keys
=
Object
.
keys
(
db_conf
);
res
.
send
({
code
:
"
OK
"
})
res
.
send
({
code
:
"
OK
"
})
})
})
// 获取节点命令
// 获取节点命令
admin
.
get
(
'
/get_node_command/:name
'
,
async
function
(
req
,
res
)
{
admin
.
get
(
'
/get_node_command/:name
'
,
async
function
(
req
,
res
)
{
res
.
setHeader
(
"
Content-Type
"
,
"
application/json
"
);
res
.
setHeader
(
"
Content-Type
"
,
"
application/json
"
);
let
configs
=
await
getProjectConfigPromise
();
let
configs
=
await
getProjectConfigPromise
();
...
@@ -196,7 +212,6 @@ admin.get('/get_node_command/:name', async function (req, res) {
...
@@ -196,7 +212,6 @@ admin.get('/get_node_command/:name', async function (req, res) {
res
.
send
({
configPath
:
pro
.
config_file
,
buildCmd
:
pro
.
command
,
gitPath
:
pro
.
git_path
});
res
.
send
({
configPath
:
pro
.
config_file
,
buildCmd
:
pro
.
command
,
gitPath
:
pro
.
git_path
});
});
});
// 获取项目配置
// 获取项目配置
admin
.
get
(
'
/get_project_attr/:name
'
,
async
function
(
req
,
res
)
{
admin
.
get
(
'
/get_project_attr/:name
'
,
async
function
(
req
,
res
)
{
res
.
setHeader
(
"
Content-Type
"
,
"
application/json
"
);
res
.
setHeader
(
"
Content-Type
"
,
"
application/json
"
);
...
@@ -376,9 +391,6 @@ admin.get('/get_proxy', function (req, res) {
...
@@ -376,9 +391,6 @@ admin.get('/get_proxy', function (req, res) {
res
.
send
({
namespace
:
String
(
str
)
});
res
.
send
({
namespace
:
String
(
str
)
});
});
});
app
.
use
(
'
/config_server
'
,
admin
)
app
.
use
(
'
/config_server
'
,
admin
)
console
.
log
(
"
http://192.168.4.3:10088/config_server/get_node_command
"
)
console
.
log
(
"
http://192.168.4.3:10088/config_server/get_node_command
"
)
app
.
listen
(
10088
)
app
.
listen
(
10088
)
\ No newline at end of file
qa_shell_script/config_server/model/dbconfig.js
0 → 100644
View file @
51eea2ef
var
mongoose
=
require
(
'
mongoose
'
);
var
Schema
=
mongoose
.
Schema
;
var
DBConfigSchema
=
new
Schema
({
dbname
:
String
,
ip
:
String
,
port
:
Number
,
username
:
String
,
passwd
:
String
,
table_list
:
String
});
module
.
exports
=
mongoose
.
model
(
'
Dbconfig
'
,
DBConfigSchema
);
\ No newline at end of file
Write
Preview
Markdown
is supported
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