Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sqlrest
Overview
Overview
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
comm
sqlrest
Commits
6d764c30
Commit
6d764c30
authored
Jun 27, 2025
by
inrgihc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
补充代码逻辑
parent
b369724d
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
111 additions
and
7 deletions
+111
-7
build-docker/sqlrest/sqlrest-release/conf/executor/application.yaml
+0
-1
build-docker/sqlrest/sqlrest-release/conf/gateway/application.yaml
+0
-1
sqlrest-common/src/main/java/com/gitee/sqlrest/common/util/PomVersionUtils.java
+9
-1
sqlrest-core/src/main/java/com/gitee/sqlrest/core/executor/DataSourceCleanService.java
+48
-0
sqlrest-core/src/main/java/com/gitee/sqlrest/core/servlet/ClientTokenService.java
+5
-1
sqlrest-core/src/main/java/com/gitee/sqlrest/core/util/DataSourceUtils.java
+6
-0
sqlrest-executor/src/main/resources/application.yaml
+0
-1
sqlrest-gateway/src/main/resources/application.yaml
+0
-1
sqlrest-manager/src/main/java/com/gitee/sqlrest/manager/config/AuthenticationConfiguration.java
+2
-0
sqlrest-manager/src/main/java/com/gitee/sqlrest/manager/config/McpServerConfiguration.java
+1
-1
sqlrest-manager/src/main/java/com/gitee/sqlrest/manager/controller/AliveHealthController.java
+30
-0
sqlrest-persistence/src/main/java/com/gitee/sqlrest/persistence/dao/DataSourceDao.java
+10
-0
No files found.
build-docker/sqlrest/sqlrest-release/conf/executor/application.yaml
View file @
6d764c30
...
@@ -34,7 +34,6 @@ logging:
...
@@ -34,7 +34,6 @@ logging:
eureka
:
eureka
:
instance
:
instance
:
ip-address
:
${MANAGER_HOST}
prefer-ip-address
:
true
prefer-ip-address
:
true
secure-port-enabled
:
false
secure-port-enabled
:
false
non-secure-port-enabled
:
true
non-secure-port-enabled
:
true
...
...
build-docker/sqlrest/sqlrest-release/conf/gateway/application.yaml
View file @
6d764c30
...
@@ -67,7 +67,6 @@ logging:
...
@@ -67,7 +67,6 @@ logging:
eureka
:
eureka
:
instance
:
instance
:
ip-address
:
${MANAGER_HOST}
prefer-ip-address
:
true
prefer-ip-address
:
true
secure-port-enabled
:
false
secure-port-enabled
:
false
non-secure-port-enabled
:
true
non-secure-port-enabled
:
true
...
...
sqlrest-common/src/main/java/com/gitee/sqlrest/common/util/PomVersionUtils.java
View file @
6d764c30
...
@@ -20,6 +20,8 @@ import java.nio.file.Paths;
...
@@ -20,6 +20,8 @@ import java.nio.file.Paths;
import
java.security.CodeSource
;
import
java.security.CodeSource
;
import
java.security.ProtectionDomain
;
import
java.security.ProtectionDomain
;
import
java.util.Enumeration
;
import
java.util.Enumeration
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.jar.JarEntry
;
import
java.util.jar.JarEntry
;
import
java.util.jar.JarFile
;
import
java.util.jar.JarFile
;
import
lombok.experimental.UtilityClass
;
import
lombok.experimental.UtilityClass
;
...
@@ -34,7 +36,13 @@ public final class PomVersionUtils {
...
@@ -34,7 +36,13 @@ public final class PomVersionUtils {
private
static
final
String
PREFIX
=
"version="
;
private
static
final
String
PREFIX
=
"version="
;
public
static
String
getProjectVersion
()
{
private
static
final
Map
<
String
,
String
>
persistCache
=
new
ConcurrentHashMap
<>();
public
static
String
getCachedProjectVersion
()
{
return
persistCache
.
computeIfAbsent
(
PREFIX
,
key
->
getProjectVersion
());
}
private
static
String
getProjectVersion
()
{
Class
<?>
clazz
=
PomVersionUtils
.
class
;
Class
<?>
clazz
=
PomVersionUtils
.
class
;
String
resourcePath
=
clazz
.
getResource
(
""
).
toString
();
String
resourcePath
=
clazz
.
getResource
(
""
).
toString
();
if
(
resourcePath
.
startsWith
(
"file:"
))
{
if
(
resourcePath
.
startsWith
(
"file:"
))
{
...
...
sqlrest-core/src/main/java/com/gitee/sqlrest/core/executor/DataSourceCleanService.java
0 → 100644
View file @
6d764c30
// Copyright tang. All rights reserved.
// https://gitee.com/inrgihc/sqlrest
//
// Use of this source code is governed by a BSD-style license
//
// Author: tang (inrgihc@126.com)
// Date : 2024/3/31
// Location: beijing , china
/////////////////////////////////////////////////////////////
package
com
.
gitee
.
sqlrest
.
core
.
executor
;
import
com.gitee.sqlrest.core.util.DataSourceUtils
;
import
com.gitee.sqlrest.persistence.dao.DataSourceDao
;
import
java.util.Set
;
import
javax.annotation.Resource
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.boot.context.event.ApplicationReadyEvent
;
import
org.springframework.context.event.EventListener
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Service
;
@Slf4j
@Service
public
class
DataSourceCleanService
{
@Resource
private
DataSourceDao
dataSourceDao
;
/*每小时执行一次*/
@EventListener
(
ApplicationReadyEvent
.
class
)
@Scheduled
(
cron
=
"${cron.datasource.clean.expression:0 0 0/1 * * ? }"
)
public
void
autoClean
()
{
log
.
info
(
"Start check deleted datasource for close it ..."
);
try
{
Set
<
Long
>
running
=
DataSourceUtils
.
getAllDataSourceIdSet
();
Set
<
Long
>
exists
=
dataSourceDao
.
getAllIdList
();
for
(
Long
id
:
running
)
{
if
(!
exists
.
contains
(
id
))
{
DataSourceUtils
.
dropHikariDataSource
(
id
);
}
}
}
catch
(
Exception
e
)
{
log
.
warn
(
"Failed to auto clean deleted datasource,error: {}"
,
e
.
getMessage
(),
e
);
}
}
}
sqlrest-core/src/main/java/com/gitee/sqlrest/core/servlet/ClientTokenService.java
View file @
6d764c30
...
@@ -132,7 +132,11 @@ public class ClientTokenService {
...
@@ -132,7 +132,11 @@ public class ClientTokenService {
}
else
if
(
appClient
.
getExpireAt
()
==
0
)
{
}
else
if
(
appClient
.
getExpireAt
()
==
0
)
{
clientToken
.
setExpireSeconds
(
0L
);
clientToken
.
setExpireSeconds
(
0L
);
}
else
{
}
else
{
clientToken
.
setExpireSeconds
(-
1L
);
if
(
AliveTimeEnum
.
LONGEVITY
.
equals
(
appClient
.
getTokenAlive
()))
{
clientToken
.
setExpireSeconds
(-
1L
);
}
else
{
clientToken
.
setExpireSeconds
(
Constants
.
CLIENT_TOKEN_DURATION_SECONDS
);
}
}
}
// 将token持久化到数据库中,以备重启服务器后原token继续可用
// 将token持久化到数据库中,以备重启服务器后原token继续可用
...
...
sqlrest-core/src/main/java/com/gitee/sqlrest/core/util/DataSourceUtils.java
View file @
6d764c30
...
@@ -18,8 +18,10 @@ import com.zaxxer.hikari.HikariDataSource;
...
@@ -18,8 +18,10 @@ import com.zaxxer.hikari.HikariDataSource;
import
java.net.URLClassLoader
;
import
java.net.URLClassLoader
;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.Statement
;
import
java.sql.Statement
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Properties
;
import
java.util.Properties
;
import
java.util.Set
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
lombok.experimental.UtilityClass
;
import
lombok.experimental.UtilityClass
;
...
@@ -80,6 +82,10 @@ public final class DataSourceUtils {
...
@@ -80,6 +82,10 @@ public final class DataSourceUtils {
}
}
}
}
public
static
Set
<
Long
>
getAllDataSourceIdSet
()
{
return
new
HashSet
<>(
datasourceMap
.
keySet
());
}
public
static
HikariDataSource
createDataSource
(
DataSourceEntity
properties
,
String
driverPath
)
{
public
static
HikariDataSource
createDataSource
(
DataSourceEntity
properties
,
String
driverPath
)
{
Properties
parameters
=
new
Properties
();
Properties
parameters
=
new
Properties
();
HikariDataSource
ds
=
new
HikariDataSource
();
HikariDataSource
ds
=
new
HikariDataSource
();
...
...
sqlrest-executor/src/main/resources/application.yaml
View file @
6d764c30
...
@@ -34,7 +34,6 @@ logging:
...
@@ -34,7 +34,6 @@ logging:
eureka
:
eureka
:
instance
:
instance
:
ip-address
:
${MANAGER_HOST}
prefer-ip-address
:
true
prefer-ip-address
:
true
secure-port-enabled
:
false
secure-port-enabled
:
false
non-secure-port-enabled
:
true
non-secure-port-enabled
:
true
...
...
sqlrest-gateway/src/main/resources/application.yaml
View file @
6d764c30
...
@@ -67,7 +67,6 @@ logging:
...
@@ -67,7 +67,6 @@ logging:
eureka
:
eureka
:
instance
:
instance
:
ip-address
:
${MANAGER_HOST}
prefer-ip-address
:
true
prefer-ip-address
:
true
secure-port-enabled
:
false
secure-port-enabled
:
false
non-secure-port-enabled
:
true
non-secure-port-enabled
:
true
...
...
sqlrest-manager/src/main/java/com/gitee/sqlrest/manager/config/AuthenticationConfiguration.java
View file @
6d764c30
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
package
com
.
gitee
.
sqlrest
.
manager
.
config
;
package
com
.
gitee
.
sqlrest
.
manager
.
config
;
import
com.gitee.sqlrest.common.consts.Constants
;
import
com.gitee.sqlrest.common.exception.CommonException
;
import
com.gitee.sqlrest.common.exception.CommonException
;
import
com.gitee.sqlrest.common.exception.ResponseErrorCode
;
import
com.gitee.sqlrest.common.exception.ResponseErrorCode
;
import
com.gitee.sqlrest.common.util.CacheUtils
;
import
com.gitee.sqlrest.common.util.CacheUtils
;
...
@@ -53,6 +54,7 @@ public class AuthenticationConfiguration implements WebMvcConfigurer {
...
@@ -53,6 +54,7 @@ public class AuthenticationConfiguration implements WebMvcConfigurer {
"/actuator/**"
,
"/actuator/**"
,
"/eureka/**"
,
"/eureka/**"
,
"/error**"
,
"/error**"
,
Constants
.
MANGER_API_V1
+
"/health/**"
,
"/dashboard"
,
"/dashboard"
,
"/dashboard/**"
"/dashboard/**"
))
))
...
...
sqlrest-manager/src/main/java/com/gitee/sqlrest/manager/config/McpServerConfiguration.java
View file @
6d764c30
...
@@ -62,7 +62,7 @@ public class McpServerConfiguration {
...
@@ -62,7 +62,7 @@ public class McpServerConfiguration {
@Bean
@Bean
public
McpSyncServer
mcpSyncServer
(
WebMvcSseServerTransportProvider
transportProvider
)
{
public
McpSyncServer
mcpSyncServer
(
WebMvcSseServerTransportProvider
transportProvider
)
{
McpSyncServer
syncServer
=
McpServer
.
sync
(
transportProvider
)
McpSyncServer
syncServer
=
McpServer
.
sync
(
transportProvider
)
.
serverInfo
(
Constants
.
MCP_SERVER_NAME
,
PomVersionUtils
.
getProjectVersion
())
.
serverInfo
(
Constants
.
MCP_SERVER_NAME
,
PomVersionUtils
.
get
Cached
ProjectVersion
())
.
capabilities
(
.
capabilities
(
ServerCapabilities
.
builder
()
ServerCapabilities
.
builder
()
.
resources
(
true
,
true
)
.
resources
(
true
,
true
)
...
...
sqlrest-manager/src/main/java/com/gitee/sqlrest/manager/controller/AliveHealthController.java
0 → 100644
View file @
6d764c30
// Copyright tang. All rights reserved.
// https://gitee.com/inrgihc/sqlrest
//
// Use of this source code is governed by a BSD-style license
//
// Author: tang (inrgihc@126.com)
// Date : 2024/3/31
// Location: beijing , china
/////////////////////////////////////////////////////////////
package
com
.
gitee
.
sqlrest
.
manager
.
controller
;
import
com.gitee.sqlrest.common.consts.Constants
;
import
com.gitee.sqlrest.common.dto.ResultEntity
;
import
com.gitee.sqlrest.common.util.PomVersionUtils
;
import
io.swagger.annotations.Api
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@Api
(
tags
=
{
"存活健康接口"
})
@RestController
@RequestMapping
(
value
=
Constants
.
MANGER_API_V1
+
"/health"
)
public
class
AliveHealthController
{
@GetMapping
(
value
=
"/version"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
ResultEntity
<
String
>
queryFirewallRules
()
{
return
ResultEntity
.
success
(
PomVersionUtils
.
getCachedProjectVersion
());
}
}
sqlrest-persistence/src/main/java/com/gitee/sqlrest/persistence/dao/DataSourceDao.java
View file @
6d764c30
...
@@ -9,11 +9,14 @@
...
@@ -9,11 +9,14 @@
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
package
com
.
gitee
.
sqlrest
.
persistence
.
dao
;
package
com
.
gitee
.
sqlrest
.
persistence
.
dao
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.gitee.sqlrest.persistence.entity.DataSourceEntity
;
import
com.gitee.sqlrest.persistence.entity.DataSourceEntity
;
import
com.gitee.sqlrest.persistence.mapper.DataSourceMapper
;
import
com.gitee.sqlrest.persistence.mapper.DataSourceMapper
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
org.springframework.stereotype.Repository
;
import
org.springframework.stereotype.Repository
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
...
@@ -46,6 +49,13 @@ public class DataSourceDao {
...
@@ -46,6 +49,13 @@ public class DataSourceDao {
);
);
}
}
public
Set
<
Long
>
getAllIdList
()
{
LambdaQueryWrapper
<
DataSourceEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<>();
queryWrapper
.
select
(
DataSourceEntity:
:
getId
);
return
dataSourceMapper
.
selectList
(
queryWrapper
).
stream
().
map
(
DataSourceEntity:
:
getId
)
.
collect
(
Collectors
.
toSet
());
}
public
void
updateById
(
DataSourceEntity
databaseConnectionEntity
)
{
public
void
updateById
(
DataSourceEntity
databaseConnectionEntity
)
{
dataSourceMapper
.
updateById
(
databaseConnectionEntity
);
dataSourceMapper
.
updateById
(
databaseConnectionEntity
);
}
}
...
...
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