Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
项目统一框架
amos-boot-biz
Commits
3abcd2d5
Commit
3abcd2d5
authored
Mar 01, 2024
by
liguofu@yeejoin.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化:【空工大】maas数据源新增时,名称重复得问题
parent
64db854a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
37 deletions
+30
-37
ClientHandler.java
.../main/java/com/yeejoin/amos/kgd/config/ClientHandler.java
+30
-37
No files found.
amos-boot-module/amos-boot-module-api/amos-boot-module-kgd-api/src/main/java/com/yeejoin/amos/kgd/config/ClientHandler.java
View file @
3abcd2d5
...
@@ -146,7 +146,7 @@ public class ClientHandler<path> implements Runnable {
...
@@ -146,7 +146,7 @@ public class ClientHandler<path> implements Runnable {
// String product = robotAuthentication.getProduct();
// String product = robotAuthentication.getProduct();
// String appKey = robotAuthentication.getAppKey();
// String appKey = robotAuthentication.getAppKey();
String
token
=
"
f5f5ebba-f68a-4093-a78e-388c925a6eaa
"
;
// 如果token、失效,就去浏览器复制最新的token、
String
token
=
"
a1bae8ec-6ef4-40f3-94b0-78f16a249b0e
"
;
// 如果token、失效,就去浏览器复制最新的token、
String
product
=
"AMOS_STUDIO_WEB"
;
String
product
=
"AMOS_STUDIO_WEB"
;
String
appKey
=
"AMOS_STUDIO"
;
String
appKey
=
"AMOS_STUDIO"
;
...
@@ -254,57 +254,60 @@ public class ClientHandler<path> implements Runnable {
...
@@ -254,57 +254,60 @@ public class ClientHandler<path> implements Runnable {
// String product = robotAuthentication.getProduct();
// String product = robotAuthentication.getProduct();
// String appKey = robotAuthentication.getAppKey();
// String appKey = robotAuthentication.getAppKey();
String
token
=
"
f5f5ebba-f68a-4093-a78e-388c925a6eaa
"
;
// 如果token、失效,就去浏览器复制最新的token、
String
token
=
"
a1bae8ec-6ef4-40f3-94b0-78f16a249b0e
"
;
// 如果token、失效,就去浏览器复制最新的token、
String
product
=
"AMOS_STUDIO_WEB"
;
String
product
=
"AMOS_STUDIO_WEB"
;
String
appKey
=
"AMOS_STUDIO"
;
String
appKey
=
"AMOS_STUDIO"
;
String
[]
parts
=
url
.
split
(
"/|:"
);
String
[]
parts
=
url
.
split
(
"/|:"
);
String
dbIp
=
parts
[
2
];
String
dbIp
=
parts
[
4
];
int
dbPort
=
Integer
.
parseInt
(
parts
[
3
]);
int
dbPort
=
Integer
.
parseInt
(
parts
[
5
]);
String
dbName
=
parts
[
4
];
String
dbName
=
parts
[
6
].
split
(
"\\?"
)[
0
];
RestTemplate
restTemplate
=
new
RestTemplate
();
RestTemplate
restTemplate
=
new
RestTemplate
();
String
defaultDatabaseName
=
"空工大_"
+
dbName
;
String
defaultDatabaseName
=
"空工大_"
+
dbName
;
//查询数据库是否已创建
//查询数据库是否已创建
String
connId
=
""
;
String
connId
=
""
;
String
datasourcesUrl
=
"http://"
+
hostAndPort
+
"/maas/
dsm/datasources/query
"
;
String
datasourcesUrl
=
"http://"
+
hostAndPort
+
"/maas/
maas/desktop/conns-jdbc
"
;
Map
<
String
,
String
>
datasourcesParams
=
new
HashMap
<>();
Map
<
String
,
String
>
datasourcesParams
=
new
HashMap
<>();
datasourcesParams
.
put
(
"pid"
,
dataSourcesGroupId
);
HttpEntity
<
Map
<
String
,
String
>>
datasourcesRequestEntity
=
new
HttpEntity
<>(
datasourcesParams
,
getHeader
(
token
,
product
,
appKey
,
hostAndPort
,
false
));
HttpEntity
<
Map
<
String
,
String
>>
datasourcesRequestEntity
=
new
HttpEntity
<>(
datasourcesParams
,
getHeader
(
token
,
product
,
appKey
,
hostAndPort
,
false
));
ResponseEntity
<
String
>
datasourcesResponse
=
restTemplate
.
exchange
(
datasourcesUrl
,
HttpMethod
.
POS
T
,
datasourcesRequestEntity
,
String
.
class
);
ResponseEntity
<
String
>
datasourcesResponse
=
restTemplate
.
exchange
(
datasourcesUrl
,
HttpMethod
.
GE
T
,
datasourcesRequestEntity
,
String
.
class
);
String
datasourcesBody
=
datasourcesResponse
.
getBody
();
String
datasourcesBody
=
datasourcesResponse
.
getBody
();
JSONObject
datasourcesJsonObject
=
JSONObject
.
parseObject
(
datasourcesBody
);
JSONObject
datasourcesJsonObject
=
JSONObject
.
parseObject
(
datasourcesBody
);
JSONArray
datasourcesResult
=
datasourcesJsonObject
.
getJSONArray
(
"result"
);
JSONArray
datasourcesResult
=
datasourcesJsonObject
.
getJSONArray
(
"result"
);
if
(
datasourcesResult
!=
null
)
{
if
(
datasourcesResult
!=
null
&&
datasourcesResult
.
size
()
>
0
)
{
for
(
int
i
=
0
;
i
<
datasourcesResult
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
datasourcesResult
.
size
();
i
++)
{
Map
<
String
,
Object
>
stringObjectMap
=
(
Map
<
String
,
Object
>)
datasourcesResult
.
get
(
i
);
Map
<
String
,
Object
>
stringObjectMap
=
(
Map
<
String
,
Object
>)
datasourcesResult
.
get
(
i
);
if
(
defaultDatabaseName
.
equals
(
stringObjectMap
.
get
(
"name"
)))
{
if
(
defaultDatabaseName
.
equals
(
stringObjectMap
.
get
(
"name"
)))
{
connId
=
(
String
)
stringObjectMap
.
get
(
"id"
);
connId
=
(
String
)
stringObjectMap
.
get
(
"id"
);
break
;
}
}
}
}
}
}
//查询数据库表是否已创建
//查询数据库表是否已创建
boolean
isCreateTable
=
false
;
boolean
isCreateTable
=
false
;
String
jdbcTablesUrl
=
"http://"
+
hostAndPort
+
"/maas/dsm/jdbc/tables"
;
if
(
StringUtil
.
isNotEmpty
(
connId
))
{
Map
<
String
,
String
>
jdbcTablesParams
=
new
HashMap
<>();
datasourcesParams
.
put
(
"dsId"
,
connId
);
String
tablelistUrl
=
"http://"
+
hostAndPort
+
"/maas/maas/desktop/tablelist"
;
datasourcesParams
.
put
(
"dsType"
,
"mysql"
);
Map
<
String
,
String
>
tablelistParams
=
new
HashMap
<>();
datasourcesParams
.
put
(
"resourceType"
,
"mysql"
);
tablelistParams
.
put
(
"connId"
,
connId
);
datasourcesParams
.
put
(
"dsdetail"
,
"{\"hostname\":\""
+
dbIp
+
"\",\"port\":"
+
dbPort
+
",\"name\":\""
+
defaultDatabaseName
+
"\",\"database\":\""
+
dbName
+
"\",\"username\":\""
+
username
+
"\",\"password\":\""
+
DesUtil
.
encode
(
password
,
passwordSecretKey
)
+
"\",\"dbtype\":\"mysql\"}"
);
tablelistParams
.
put
(
"subcjectId"
,
dataSourcesGroupId
);
HttpEntity
<
Map
<
String
,
String
>>
jdbcTablesRequestEntity
=
new
HttpEntity
<>(
jdbcTablesParams
,
getHeader
(
token
,
product
,
appKey
,
hostAndPort
,
false
));
HttpEntity
<
Map
<
String
,
String
>>
tablelistRequestEntity
=
new
HttpEntity
<>(
tablelistParams
,
getHeader
(
token
,
product
,
appKey
,
hostAndPort
,
false
));
ResponseEntity
<
String
>
jdbcTablesResponse
=
restTemplate
.
exchange
(
jdbcTablesUrl
,
HttpMethod
.
POST
,
jdbcTablesRequestEntity
,
String
.
class
);
ResponseEntity
<
String
>
tablelistResponse
=
restTemplate
.
exchange
(
tablelistUrl
,
HttpMethod
.
POST
,
tablelistRequestEntity
,
String
.
class
);
String
jdbcTablesBody
=
jdbcTablesResponse
.
getBody
();
String
tablelistBody
=
tablelistResponse
.
getBody
();
JSONObject
jdbcTablesJsonObject
=
JSONObject
.
parseObject
(
jdbcTablesBody
);
JSONObject
tablelistJsonObject
=
JSONObject
.
parseObject
(
tablelistBody
);
JSONArray
jdbcTablesResult
=
jdbcTablesJsonObject
.
getJSONArray
(
"result"
);
JSONArray
tablelistResult
=
tablelistJsonObject
.
getJSONArray
(
"result"
);
if
(
jdbcTablesResult
!=
null
)
{
if
(
tablelistResult
!=
null
&&
tablelistResult
.
size
()
>
0
)
{
for
(
int
i
=
0
;
i
<
jdbcTablesResult
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
tablelistResult
.
size
();
i
++)
{
Map
<
String
,
Object
>
stringObjectMap
=
(
Map
<
String
,
Object
>)
jdbcTablesResult
.
get
(
i
);
Map
<
String
,
Object
>
stringObjectMap
=
(
Map
<
String
,
Object
>)
tablelistResult
.
get
(
i
);
if
(
tableName
.
equals
(
stringObjectMap
.
get
(
"name"
)))
{
if
(
tableName
.
equals
(
stringObjectMap
.
get
(
"name"
)))
{
isCreateTable
=
true
;
isCreateTable
=
true
;
break
;
}
}
}
}
}
}
}
//3. 调用conn接口,数据库已创建过就不在创建
//3. 调用conn接口,数据库已创建过就不在创建
if
(
StringUtil
.
isEmpty
(
connId
))
{
if
(
StringUtil
.
isEmpty
(
connId
))
{
String
connsUrl
=
"http://"
+
hostAndPort
+
"/maas/maas/desktop/conns"
;
String
connsUrl
=
"http://"
+
hostAndPort
+
"/maas/maas/desktop/conns"
;
...
@@ -312,7 +315,7 @@ public class ClientHandler<path> implements Runnable {
...
@@ -312,7 +315,7 @@ public class ClientHandler<path> implements Runnable {
connsParams
.
put
(
"name"
,
defaultDatabaseName
);
connsParams
.
put
(
"name"
,
defaultDatabaseName
);
connsParams
.
put
(
"connType"
,
"mysql"
);
connsParams
.
put
(
"connType"
,
"mysql"
);
connsParams
.
put
(
"subjectid"
,
dataSourcesGroupId
);
connsParams
.
put
(
"subjectid"
,
dataSourcesGroupId
);
connsParams
.
put
(
"detail"
,
"{\"hostname\":\""
+
dbIp
+
"\",\"port\":"
+
dbPort
+
",\"username\":\""
+
username
+
"\",\"password\":\""
+
DesUtil
.
encode
(
password
,
passwordSecretKey
)
+
"\",\"name\":\""
+
defaultDatabaseName
+
"\",\"database\":\""
+
dbName
+
"\",\"dbtype\":\"mysql\"}"
);
connsParams
.
put
(
"detail"
,
"{\"hostname\":\""
+
dbIp
+
"\",\"port\":"
+
dbPort
+
",\"username\":\""
+
username
+
"\",\"password\":\""
+
DesUtil
.
encode
(
password
,
passwordSecretKey
)
+
"\",\"name\":\""
+
defaultDatabaseName
+
"\",\"database\":\""
+
dbName
+
"\",\"dbtype\":\"mysql\"}"
);
HttpEntity
<
Map
<
String
,
String
>>
connsRequestEntity
=
new
HttpEntity
<>(
connsParams
,
getHeader
(
token
,
product
,
appKey
,
hostAndPort
,
false
));
HttpEntity
<
Map
<
String
,
String
>>
connsRequestEntity
=
new
HttpEntity
<>(
connsParams
,
getHeader
(
token
,
product
,
appKey
,
hostAndPort
,
false
));
ResponseEntity
<
String
>
connsResponse
=
restTemplate
.
exchange
(
connsUrl
,
HttpMethod
.
POST
,
connsRequestEntity
,
String
.
class
);
ResponseEntity
<
String
>
connsResponse
=
restTemplate
.
exchange
(
connsUrl
,
HttpMethod
.
POST
,
connsRequestEntity
,
String
.
class
);
...
@@ -336,16 +339,6 @@ public class ClientHandler<path> implements Runnable {
...
@@ -336,16 +339,6 @@ public class ClientHandler<path> implements Runnable {
JSONObject
tablesJsonObject
=
JSONObject
.
parseObject
(
tablesBody
);
JSONObject
tablesJsonObject
=
JSONObject
.
parseObject
(
tablesBody
);
String
tablesResult
=
tablesJsonObject
.
getString
(
"result"
);
String
tablesResult
=
tablesJsonObject
.
getString
(
"result"
);
String
tablelistUrl
=
"http://"
+
hostAndPort
+
"/maas/maas/desktop/tablelist"
;
Map
<
String
,
String
>
tablelistParams
=
new
HashMap
<>();
tablesParams
.
put
(
"connId"
,
connId
);
tablesParams
.
put
(
"subcjectId"
,
dataSourcesGroupId
);
HttpEntity
<
Map
<
String
,
String
>>
tablelistRequestEntity
=
new
HttpEntity
<>(
tablelistParams
,
getHeader
(
token
,
product
,
appKey
,
hostAndPort
,
false
));
ResponseEntity
<
String
>
tablelistResponse
=
restTemplate
.
exchange
(
tablelistUrl
,
HttpMethod
.
POST
,
tablelistRequestEntity
,
String
.
class
);
String
tablelistBody
=
tablelistResponse
.
getBody
();
JSONObject
tablelistJsonObject
=
JSONObject
.
parseObject
(
tablelistBody
);
String
tablelistResult
=
tablelistJsonObject
.
getString
(
"result"
);
}
}
}
}
}
}
...
...
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