Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_42566577
o2oa
提交
ff4071f5
o2oa
项目概览
weixin_42566577
/
o2oa
与 Fork 源项目一致
Fork自
浙江兰德纵横网络技术股份有限公司 / o2oa
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
o2oa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ff4071f5
编写于
1月 18, 2023
作者:
Z
zhourui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sql stat 记录
上级
0d3cd751
变更
13
展开全部
隐藏空白更改
内联
并排
Showing
13 changed file
with
1642 addition
and
840 deletion
+1642
-840
o2server/x_base_core_project/src/main/java/com/x/base/core/project/Applications.java
...t/src/main/java/com/x/base/core/project/Applications.java
+2
-0
o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/DataServer.java
.../main/java/com/x/base/core/project/config/DataServer.java
+197
-171
o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/ExternalDataSource.java
...va/com/x/base/core/project/config/ExternalDataSource.java
+38
-17
o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/ExternalDataSources.java
...a/com/x/base/core/project/config/ExternalDataSources.java
+122
-122
o2server/x_base_core_project/src/main/java/com/x/base/core/project/tools/SqlTools.java
...src/main/java/com/x/base/core/project/tools/SqlTools.java
+13
-6
o2server/x_console/src/main/java/com/x/server/console/DruidStatLogger.java
...e/src/main/java/com/x/server/console/DruidStatLogger.java
+354
-0
o2server/x_console/src/main/java/com/x/server/console/ResourceFactory.java
...e/src/main/java/com/x/server/console/ResourceFactory.java
+26
-8
o2server/x_console/src/main/java/com/x/server/console/StackTraceTask.java
...le/src/main/java/com/x/server/console/StackTraceTask.java
+1
-1
o2server/x_console/src/main/java/com/x/server/console/node/RegistApplicationsEvent.java
...va/com/x/server/console/node/RegistApplicationsEvent.java
+175
-175
o2server/x_organization_assemble_express/src/main/java/com/x/organization/assemble/express/jaxrs/empower/ActionListWithIdentityObject.java
...e/express/jaxrs/empower/ActionListWithIdentityObject.java
+176
-169
o2server/x_organization_assemble_express/src/main/java/com/x/organization/assemble/express/jaxrs/empower/EmpowerAction.java
...ization/assemble/express/jaxrs/empower/EmpowerAction.java
+2
-2
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/processor/manual/ManualProcessor.java
.../service/processing/processor/manual/ManualProcessor.java
+2
-0
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/schedule/LogLongDetained.java
...platform/service/processing/schedule/LogLongDetained.java
+534
-169
未找到文件。
o2server/x_base_core_project/src/main/java/com/x/base/core/project/Applications.java
浏览文件 @
ff4071f5
...
...
@@ -4,6 +4,7 @@ import java.io.UnsupportedEncodingException;
import
java.net.URLEncoder
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Comparator
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Random
;
...
...
@@ -90,6 +91,7 @@ public class Applications extends ConcurrentHashMap<String, CopyOnWriteArrayList
this
.
put
(
className
,
list
);
}
list
.
add
(
application
);
list
.
sort
(
Comparator
.
comparing
(
Application:
:
getNode
));
}
public
ActionResponse
getQuery
(
Class
<?>
applicationClass
,
String
uri
)
throws
Exception
{
...
...
o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/DataServer.java
浏览文件 @
ff4071f5
...
...
@@ -10,176 +10,202 @@ import com.x.base.core.project.annotation.FieldDescribe;
public
class
DataServer
extends
ConfigObject
{
private
static
final
long
serialVersionUID
=
77120835343101221L
;
private
static
final
Integer
DEFAULT_TCPPORT
=
20050
;
private
static
final
Integer
DEFAULT_WEBPORT
=
null
;
private
static
final
Integer
DEFAULT_CACHESIZE
=
512
;
private
static
final
Boolean
DEFAULT_JMXENABLE
=
false
;
private
static
final
Integer
DEFAULT_MAXTOTAL
=
50
;
private
static
final
Integer
DEFAULT_MAXIDLE
=
0
;
private
static
final
Boolean
DEFAULT_STATENABLE
=
false
;
private
static
final
String
DEFAULT_STATFILTER
=
"mergeStat"
;
private
static
final
Integer
DEFAULT_SLOWSQLMILLIS
=
3000
;
private
static
final
Integer
DEFAULT_LOCKTIMEOUT
=
120000
;
private
static
final
String
DEFAULT_LOGLEVEL
=
"WARN"
;
public
static
DataServer
defaultInstance
()
{
return
new
DataServer
();
}
public
DataServer
()
{
this
.
enable
=
true
;
this
.
tcpPort
=
DEFAULT_TCPPORT
;
this
.
webPort
=
DEFAULT_WEBPORT
;
this
.
includes
=
new
ArrayList
<>();
this
.
excludes
=
new
ArrayList
<>();
this
.
cacheSize
=
DEFAULT_CACHESIZE
;
this
.
jmxEnable
=
DEFAULT_JMXENABLE
;
this
.
maxTotal
=
DEFAULT_MAXTOTAL
;
this
.
maxIdle
=
DEFAULT_MAXIDLE
;
this
.
logLevel
=
DEFAULT_LOGLEVEL
;
this
.
statEnable
=
DEFAULT_STATENABLE
;
this
.
statFilter
=
DEFAULT_STATFILTER
;
this
.
slowSqlMillis
=
DEFAULT_SLOWSQLMILLIS
;
this
.
lockTimeout
=
DEFAULT_LOCKTIMEOUT
;
}
@FieldDescribe
(
"是否启用,如果没有可用的externalDataSources.json文件,那么默认会在节点中启用本地的H2数据库作为默认的数据库."
)
private
Boolean
enable
;
@FieldDescribe
(
"H2数据库jdbc连接端口,登录的用户名:sa,密码为xadmin的密码.数据库创建在/o2server/local/repository/data/X.mv.db,一旦数据库文件被创建,那么该数据库的密码被创建."
)
private
Integer
tcpPort
;
@FieldDescribe
(
"H2数据库web端口,H2提供一个web端的client,此端口为web端client的访问端口.用户名sa,密码为xadmin数据库初始创建的密码."
)
private
Integer
webPort
;
@FieldDescribe
(
"设置此数据库存储的类,默认情况下存储所有类型,如果需要对每个类进行单独的控制以达到高性能,可以将不同的类存储到不同的节点上提高性能.可以使用通配符*"
)
private
List
<
String
>
includes
;
@FieldDescribe
(
"在此节点上不存储的类,和includes一起设置实际存储的类,可以使用通配符*"
)
private
List
<
String
>
excludes
;
@FieldDescribe
(
"是否启动jmx,如果启用,可以通过本地的jmx客户端进行访问,不支持远程jmx客户端."
)
private
Boolean
jmxEnable
;
@FieldDescribe
(
"H2数据库缓存大小,设置H2用于作为缓存的内存大小,以M作为单位,这里默认为512M."
)
private
Integer
cacheSize
;
@FieldDescribe
(
"默认日志级别,FATAL, ERROR, WARN, INFO, TRACE. 完整的配置为DefaultLevel=WARN, Tool=TRACE, Enhance=TRACE, METADATA=TRACE, Runtime=TRACE, Query=TRACE, DataCache=TRACE, JDBC=TRACE, SQL=TRACE"
)
private
String
logLevel
;
@FieldDescribe
(
"最大使用连接数"
)
private
Integer
maxTotal
;
@FieldDescribe
(
"最大空闲连接数"
)
private
Integer
maxIdle
;
@FieldDescribe
(
"启用统计,默认关闭"
)
private
Boolean
statEnable
;
@FieldDescribe
(
"统计方式配置,默认mergeStat"
)
private
String
statFilter
;
@FieldDescribe
(
"执行缓慢sql毫秒数,默认2000毫秒,执行缓慢的sql将被单独记录."
)
private
Integer
slowSqlMillis
;
@FieldDescribe
(
"默认锁超时时间()毫秒)."
)
private
Integer
lockTimeout
;
public
Integer
getLockTimeout
()
{
return
(
null
==
this
.
lockTimeout
||
this
.
lockTimeout
<
1
)
?
DEFAULT_LOCKTIMEOUT
:
this
.
lockTimeout
;
}
public
String
getLogLevel
()
{
return
StringUtils
.
isEmpty
(
this
.
logLevel
)
?
DEFAULT_LOGLEVEL
:
this
.
logLevel
;
}
public
Integer
getSlowSqlMillis
()
{
return
(
null
==
this
.
slowSqlMillis
||
this
.
slowSqlMillis
<
1
)
?
DEFAULT_SLOWSQLMILLIS
:
this
.
slowSqlMillis
;
}
public
String
getStatFilter
()
{
return
StringUtils
.
isEmpty
(
this
.
statFilter
)
?
DEFAULT_STATFILTER
:
this
.
statFilter
;
}
public
Boolean
getStatEnable
()
{
return
BooleanUtils
.
isNotFalse
(
this
.
statEnable
);
}
public
Integer
getMaxIdle
()
{
if
((
this
.
maxIdle
==
null
)
||
(
this
.
maxIdle
<
1
))
{
return
DEFAULT_MAXIDLE
;
}
else
{
return
this
.
maxTotal
;
}
}
public
Integer
getMaxTotal
()
{
if
((
this
.
maxTotal
==
null
)
||
(
this
.
maxTotal
<
0
))
{
return
DEFAULT_MAXTOTAL
;
}
else
{
return
this
.
maxTotal
;
}
}
public
Boolean
getJmxEnable
()
{
return
BooleanUtils
.
isTrue
(
this
.
jmxEnable
);
}
public
Integer
getCacheSize
()
{
return
(
this
.
cacheSize
==
null
||
this
.
cacheSize
<
DEFAULT_CACHESIZE
)
?
DEFAULT_CACHESIZE
:
this
.
cacheSize
;
}
public
Integer
getTcpPort
()
{
if
(
null
!=
this
.
tcpPort
&&
this
.
tcpPort
>
0
)
{
return
this
.
tcpPort
;
}
return
DEFAULT_TCPPORT
;
}
public
Integer
getWebPort
()
{
if
(
null
!=
this
.
webPort
&&
this
.
webPort
>
0
)
{
return
this
.
webPort
;
}
return
DEFAULT_WEBPORT
;
}
public
Boolean
getEnable
()
{
return
BooleanUtils
.
isTrue
(
this
.
enable
);
}
public
List
<
String
>
getIncludes
()
{
if
(
null
!=
this
.
includes
)
{
return
this
.
includes
;
}
return
new
ArrayList
<>();
}
public
List
<
String
>
getExcludes
()
{
if
(
null
!=
this
.
excludes
)
{
return
this
.
excludes
;
}
return
new
ArrayList
<>();
}
public
void
setTcpPort
(
Integer
tcpPort
)
{
this
.
tcpPort
=
tcpPort
;
}
public
void
setWebPort
(
Integer
webPort
)
{
this
.
webPort
=
webPort
;
}
public
void
setEnable
(
Boolean
enable
)
{
this
.
enable
=
enable
;
}
public
void
setIncludes
(
List
<
String
>
includes
)
{
this
.
includes
=
includes
;
}
public
void
setExcludes
(
List
<
String
>
excludes
)
{
this
.
excludes
=
excludes
;
}
public
void
setJmxEnable
(
Boolean
jmxEnable
)
{
this
.
jmxEnable
=
jmxEnable
;
}
public
void
setCacheSize
(
Integer
cacheSize
)
{
this
.
cacheSize
=
cacheSize
;
}
public
void
setLogLevel
(
String
logLevel
)
{
this
.
logLevel
=
logLevel
;
}
private
static
final
long
serialVersionUID
=
77120835343101221L
;
private
static
final
Integer
DEFAULT_TCPPORT
=
20050
;
private
static
final
Integer
DEFAULT_WEBPORT
=
null
;
private
static
final
Integer
DEFAULT_CACHESIZE
=
512
;
private
static
final
Boolean
DEFAULT_JMXENABLE
=
false
;
private
static
final
Integer
DEFAULT_MAXTOTAL
=
50
;
private
static
final
Integer
DEFAULT_MAXIDLE
=
0
;
private
static
final
Boolean
DEFAULT_STATENABLE
=
true
;
private
static
final
String
DEFAULT_STATFILTER
=
"mergeStat"
;
private
static
final
Boolean
DEFAULT_SLOWSQLENABLE
=
true
;
private
static
final
Integer
DEFAULT_SLOWSQLTHRESHOLD
=
3000
;
private
static
final
Boolean
DEFAULT_LOGSTATENABLE
=
false
;
private
static
final
Integer
DEFAULT_LOGSTATINTERVAL
=
180
;
private
static
final
Integer
DEFAULT_LOCKTIMEOUT
=
120000
;
private
static
final
String
DEFAULT_LOGLEVEL
=
"WARN"
;
public
static
DataServer
defaultInstance
()
{
return
new
DataServer
();
}
public
DataServer
()
{
this
.
enable
=
true
;
this
.
tcpPort
=
DEFAULT_TCPPORT
;
this
.
webPort
=
DEFAULT_WEBPORT
;
this
.
includes
=
new
ArrayList
<>();
this
.
excludes
=
new
ArrayList
<>();
this
.
cacheSize
=
DEFAULT_CACHESIZE
;
this
.
jmxEnable
=
DEFAULT_JMXENABLE
;
this
.
maxTotal
=
DEFAULT_MAXTOTAL
;
this
.
maxIdle
=
DEFAULT_MAXIDLE
;
this
.
logLevel
=
DEFAULT_LOGLEVEL
;
this
.
statEnable
=
DEFAULT_STATENABLE
;
this
.
statFilter
=
DEFAULT_STATFILTER
;
this
.
slowSqlEnable
=
DEFAULT_SLOWSQLENABLE
;
this
.
slowSqlThreshold
=
DEFAULT_SLOWSQLTHRESHOLD
;
this
.
lockTimeout
=
DEFAULT_LOCKTIMEOUT
;
this
.
logStatEnable
=
DEFAULT_LOGSTATENABLE
;
this
.
logStatInterval
=
DEFAULT_LOGSTATINTERVAL
;
}
@FieldDescribe
(
"是否启用,如果没有可用的externalDataSources.json文件,那么默认会在节点中启用本地的H2数据库作为默认的数据库."
)
private
Boolean
enable
;
@FieldDescribe
(
"H2数据库jdbc连接端口,登录的用户名:sa,密码为xadmin的密码.数据库创建在/o2server/local/repository/data/X.mv.db,一旦数据库文件被创建,那么该数据库的密码被创建."
)
private
Integer
tcpPort
;
@FieldDescribe
(
"H2数据库web端口,H2提供一个web端的client,此端口为web端client的访问端口.用户名sa,密码为xadmin数据库初始创建的密码."
)
private
Integer
webPort
;
@FieldDescribe
(
"设置此数据库存储的类,默认情况下存储所有类型,如果需要对每个类进行单独的控制以达到高性能,可以将不同的类存储到不同的节点上提高性能.可以使用通配符*"
)
private
List
<
String
>
includes
;
@FieldDescribe
(
"在此节点上不存储的类,和includes一起设置实际存储的类,可以使用通配符*"
)
private
List
<
String
>
excludes
;
@FieldDescribe
(
"是否启动jmx,如果启用,可以通过本地的jmx客户端进行访问,不支持远程jmx客户端."
)
private
Boolean
jmxEnable
;
@FieldDescribe
(
"H2数据库缓存大小,设置H2用于作为缓存的内存大小,以M作为单位,这里默认为512M."
)
private
Integer
cacheSize
;
@FieldDescribe
(
"默认日志级别,FATAL, ERROR, WARN, INFO, TRACE. 完整的配置为DefaultLevel=WARN, Tool=TRACE, Enhance=TRACE, METADATA=TRACE, Runtime=TRACE, Query=TRACE, DataCache=TRACE, JDBC=TRACE, SQL=TRACE"
)
private
String
logLevel
;
@FieldDescribe
(
"最大使用连接数"
)
private
Integer
maxTotal
;
@FieldDescribe
(
"最大空闲连接数"
)
private
Integer
maxIdle
;
@FieldDescribe
(
"启用统计,默认关闭"
)
private
Boolean
statEnable
;
@FieldDescribe
(
"统计方式配置,默认mergeStat"
)
private
String
statFilter
;
@FieldDescribe
(
"默认锁超时时间毫秒)."
)
private
Integer
lockTimeout
;
@FieldDescribe
(
"启用记录统计日志."
)
private
Boolean
logStatEnable
;
@FieldDescribe
(
"统计日志输出间隔."
)
private
Integer
logStatInterval
;
@FieldDescribe
(
"是否启用执行慢sql记录."
)
private
Boolean
slowSqlEnable
;
@FieldDescribe
(
"执行慢sql记录阈值,毫秒数,默认3000毫秒."
)
private
Integer
slowSqlThreshold
;
public
Boolean
getLogStatEnable
()
{
return
BooleanUtils
.
isTrue
(
this
.
logStatEnable
);
}
public
Integer
getLogStatInterval
()
{
return
(
null
==
this
.
logStatInterval
||
this
.
logStatInterval
<
1
)
?
DEFAULT_LOGSTATINTERVAL
:
this
.
logStatInterval
;
}
public
Integer
getLockTimeout
()
{
return
(
null
==
this
.
lockTimeout
||
this
.
lockTimeout
<
1
)
?
DEFAULT_LOCKTIMEOUT
:
this
.
lockTimeout
;
}
public
String
getLogLevel
()
{
return
StringUtils
.
isEmpty
(
this
.
logLevel
)
?
DEFAULT_LOGLEVEL
:
this
.
logLevel
;
}
public
Boolean
getSlowSqlEnable
()
{
return
BooleanUtils
.
isTrue
(
this
.
slowSqlEnable
);
}
public
Integer
getSlowSqlThreshold
()
{
return
(
null
==
this
.
slowSqlThreshold
||
this
.
slowSqlThreshold
<
1
)
?
DEFAULT_SLOWSQLTHRESHOLD
:
this
.
slowSqlThreshold
;
}
public
String
getStatFilter
()
{
return
StringUtils
.
isEmpty
(
this
.
statFilter
)
?
DEFAULT_STATFILTER
:
this
.
statFilter
;
}
public
Boolean
getStatEnable
()
{
return
BooleanUtils
.
isNotFalse
(
this
.
statEnable
);
}
public
Integer
getMaxIdle
()
{
if
((
this
.
maxIdle
==
null
)
||
(
this
.
maxIdle
<
1
))
{
return
DEFAULT_MAXIDLE
;
}
else
{
return
this
.
maxTotal
;
}
}
public
Integer
getMaxTotal
()
{
if
((
this
.
maxTotal
==
null
)
||
(
this
.
maxTotal
<
0
))
{
return
DEFAULT_MAXTOTAL
;
}
else
{
return
this
.
maxTotal
;
}
}
public
Boolean
getJmxEnable
()
{
return
BooleanUtils
.
isTrue
(
this
.
jmxEnable
);
}
public
Integer
getCacheSize
()
{
return
(
this
.
cacheSize
==
null
||
this
.
cacheSize
<
DEFAULT_CACHESIZE
)
?
DEFAULT_CACHESIZE
:
this
.
cacheSize
;
}
public
Integer
getTcpPort
()
{
if
(
null
!=
this
.
tcpPort
&&
this
.
tcpPort
>
0
)
{
return
this
.
tcpPort
;
}
return
DEFAULT_TCPPORT
;
}
public
Integer
getWebPort
()
{
if
(
null
!=
this
.
webPort
&&
this
.
webPort
>
0
)
{
return
this
.
webPort
;
}
return
DEFAULT_WEBPORT
;
}
public
Boolean
getEnable
()
{
return
BooleanUtils
.
isTrue
(
this
.
enable
);
}
public
List
<
String
>
getIncludes
()
{
if
(
null
!=
this
.
includes
)
{
return
this
.
includes
;
}
return
new
ArrayList
<>();
}
public
List
<
String
>
getExcludes
()
{
if
(
null
!=
this
.
excludes
)
{
return
this
.
excludes
;
}
return
new
ArrayList
<>();
}
public
void
setTcpPort
(
Integer
tcpPort
)
{
this
.
tcpPort
=
tcpPort
;
}
public
void
setWebPort
(
Integer
webPort
)
{
this
.
webPort
=
webPort
;
}
public
void
setEnable
(
Boolean
enable
)
{
this
.
enable
=
enable
;
}
public
void
setIncludes
(
List
<
String
>
includes
)
{
this
.
includes
=
includes
;
}
public
void
setExcludes
(
List
<
String
>
excludes
)
{
this
.
excludes
=
excludes
;
}
public
void
setJmxEnable
(
Boolean
jmxEnable
)
{
this
.
jmxEnable
=
jmxEnable
;
}
public
void
setCacheSize
(
Integer
cacheSize
)
{
this
.
cacheSize
=
cacheSize
;
}
public
void
setLogLevel
(
String
logLevel
)
{
this
.
logLevel
=
logLevel
;
}
}
o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/ExternalDataSource.java
浏览文件 @
ff4071f5
...
...
@@ -3,6 +3,7 @@ package com.x.base.core.project.config;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.apache.commons.lang3.BooleanUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
com.x.base.core.container.factory.SlicePropertiesBuilder
;
...
...
@@ -37,12 +38,18 @@ public class ExternalDataSource extends ConfigObject {
public
static
final
String
DEFAULT_STATFILTER
=
"mergeStat"
;
private
static
final
Boolean
DEFAULT_SLOWSQLENABLE
=
true
;
private
static
final
Integer
DEFAULT_SLOWSQLTHRESHOLD
=
3000
;
private
static
final
Boolean
DEFAULT_LOGSTATENABLE
=
false
;
private
static
final
Integer
DEFAULT_LOGSTATINTERVAL
=
180
;
public
static
final
List
<
String
>
DEFAULT_INCLUDES
=
new
ArrayList
<>();
public
static
final
List
<
String
>
DEFAULT_EXCLUDES
=
new
ArrayList
<>();
public
static
final
Integer
DEFAULT_SLOWSQLMILLIS
=
3000
;
public
static
final
String
DEFAULT_LOGLEVEL
=
"ERROR"
;
public
static
final
String
DEFAULT_TRANSACTIONISOLATION
=
"read-committed"
;
...
...
@@ -55,8 +62,6 @@ public class ExternalDataSource extends ConfigObject {
public
static
final
Boolean
DEFAULT_AUTOCOMMIT
=
false
;
// public static final Boolean DEFAULT_TRACESQLENABLE = false;
public
static
final
String
DEFAULT_SCHEMA
=
"X"
;
public
static
ExternalDataSource
defaultInstance
()
{
...
...
@@ -72,7 +77,10 @@ public class ExternalDataSource extends ConfigObject {
o
.
maxIdle
=
DEFAULT_MAXIDLE
;
o
.
statEnable
=
DEFAULT_STATENABLE
;
o
.
statFilter
=
DEFAULT_STATFILTER
;
o
.
slowSqlMillis
=
DEFAULT_SLOWSQLMILLIS
;
o
.
slowSqlEnable
=
DEFAULT_SLOWSQLENABLE
;
o
.
slowSqlThreshold
=
DEFAULT_SLOWSQLTHRESHOLD
;
o
.
logStatEnable
=
DEFAULT_LOGSTATENABLE
;
o
.
logStatInterval
=
DEFAULT_LOGSTATINTERVAL
;
o
.
includes
=
DEFAULT_INCLUDES
;
o
.
excludes
=
DEFAULT_EXCLUDES
;
o
.
logLevel
=
DEFAULT_LOGLEVEL
;
...
...
@@ -81,7 +89,6 @@ public class ExternalDataSource extends ConfigObject {
o
.
testConnectionOnCheckout
=
DEFAULT_TESTCONNECTIONONCHECKOUT
;
o
.
maxIdleTime
=
DEFAULT_MAXIDLETIME
;
o
.
autoCommit
=
DEFAULT_AUTOCOMMIT
;
// o.traceSqlEnable = DEFAULT_TRACESQLENABLE;
return
o
;
}
...
...
@@ -105,8 +112,6 @@ public class ExternalDataSource extends ConfigObject {
private
Boolean
statEnable
;
@FieldDescribe
(
"统计方式配置,默认mergeStat."
)
private
String
statFilter
;
@FieldDescribe
(
"执行缓慢sql毫秒数,默认2000毫秒,执行缓慢的sql将被单独记录."
)
private
Integer
slowSqlMillis
;
@FieldDescribe
(
"设置此数据库存储的类,默认情况下存储所有类型,如果需要对每个类进行单独的控制以达到高性能,可以将不同的类存储到不同的节点上提高性能.可以使用通配符*."
)
private
List
<
String
>
includes
;
@FieldDescribe
(
"在此节点上不存储的类,和includes一起设置实际存储的类,可以使用通配符*."
)
...
...
@@ -123,14 +128,34 @@ public class ExternalDataSource extends ConfigObject {
private
Integer
maxIdleTime
;
@FieldDescribe
(
"自动提交,默认为false."
)
private
Boolean
autoCommit
=
DEFAULT_AUTOCOMMIT
;
// @FieldDescribe("启用sql跟踪.")
// private Boolean traceSqlEnable = DEFAULT_TRACESQLENABLE;
@FieldDescribe
(
"模式."
)
private
String
schema
=
DEFAULT_SCHEMA
;
@FieldDescribe
(
"启用记录统计日志."
)
private
Boolean
logStatEnable
;
@FieldDescribe
(
"统计日志输出间隔,单位分钟,默认180."
)
private
Integer
logStatInterval
;
@FieldDescribe
(
"是否启用执行慢sql记录."
)
private
Boolean
slowSqlEnable
;
@FieldDescribe
(
"执行慢sql记录阈值,毫秒数,默认3000毫秒."
)
private
Integer
slowSqlThreshold
;
// public Boolean getTraceSqlEnable() {
// return (null == this.traceSqlEnable) ? DEFAULT_TRACESQLENABLE : this.traceSqlEnable;
// }
public
Boolean
getLogStatEnable
()
{
return
BooleanUtils
.
isTrue
(
this
.
logStatEnable
);
}
public
Integer
getLogStatInterval
()
{
return
(
null
==
this
.
logStatInterval
||
this
.
logStatInterval
<
1
)
?
DEFAULT_LOGSTATINTERVAL
:
this
.
logStatInterval
;
}
public
Boolean
getSlowSqlEnable
()
{
return
BooleanUtils
.
isTrue
(
this
.
slowSqlEnable
);
}
public
Integer
getSlowSqlThreshold
()
{
return
(
null
==
this
.
slowSqlThreshold
||
this
.
slowSqlThreshold
<
1
)
?
DEFAULT_SLOWSQLTHRESHOLD
:
this
.
slowSqlThreshold
;
}
public
Boolean
getAutoCommit
()
{
return
(
null
==
this
.
autoCommit
)
?
DEFAULT_AUTOCOMMIT
:
this
.
autoCommit
;
...
...
@@ -167,10 +192,6 @@ public class ExternalDataSource extends ConfigObject {
:
this
.
dictionary
;
}
public
Integer
getSlowSqlMillis
()
{
return
(
null
==
this
.
slowSqlMillis
||
this
.
slowSqlMillis
<
1
)
?
DEFAULT_SLOWSQLMILLIS
:
this
.
slowSqlMillis
;
}
public
String
getStatFilter
()
{
return
StringUtils
.
isEmpty
(
this
.
statFilter
)
?
DEFAULT_STATFILTER
:
this
.
statFilter
;
}
...
...
o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/ExternalDataSources.java
浏览文件 @
ff4071f5
...
...
@@ -13,91 +13,91 @@ import com.x.base.core.project.tools.ListTools;
public
class
ExternalDataSources
extends
CopyOnWriteArrayList
<
ExternalDataSource
>
{
private
static
final
long
serialVersionUID
=
4502077979125945875L
;
public
static
ExternalDataSources
defaultInstance
()
{
return
new
ExternalDataSources
();
}
public
ExternalDataSources
()
{
super
();
}
public
Boolean
enable
()
{
if
(
this
.
isEmpty
())
{
return
false
;
}
for
(
ExternalDataSource
o
:
this
)
{
if
(
BooleanUtils
.
isTrue
(
o
.
getEnable
()))
{
return
true
;
}
}
return
false
;
}
public
String
name
(
ExternalDataSource
externalDataSource
)
throws
Exception
{
String
name
=
""
;
int
idx
=
0
;
for
(
ExternalDataSource
o
:
this
)
{
idx
++;
if
(
BooleanUtils
.
isTrue
(
o
.
getEnable
())
&&
Objects
.
equals
(
o
,
externalDataSource
))
{
name
=
"s"
+
(
""
+
(
1000
+
idx
)).
substring
(
1
);
break
;
}
}
if
(
StringUtils
.
isEmpty
(
name
))
{
throw
new
Exception
(
"externalDataSource not in externalDataSources."
+
externalDataSource
);
}
return
name
;
}
public
List
<
String
>
names
()
throws
Exception
{
List
<
String
>
names
=
new
ArrayList
<>();
int
idx
=
0
;
for
(
ExternalDataSource
o
:
this
)
{
idx
++;
if
(
BooleanUtils
.
isTrue
(
o
.
getEnable
()))
{
names
.
add
(
"s"
+
(
""
+
(
1000
+
idx
)).
substring
(
1
));
}
}
return
names
;
}
public
List
<
String
>
findNamesOfContainerEntity
(
String
className
)
throws
Exception
{
List
<
String
>
names
=
new
ArrayList
<>();
for
(
ExternalDataSource
o
:
this
)
{
if
(
BooleanUtils
.
isTrue
(
o
.
getEnable
()))
{
List
<
String
>
list
=
ListTools
.
toList
(
className
);
list
=
ListTools
.
includesExcludesWildcard
(
list
,
o
.
getIncludes
(),
o
.
getExcludes
());
if
(!
list
.
isEmpty
())
{
names
.
add
(
this
.
name
(
o
));
}
}
}
return
names
;
}
public
String
log
(
String
name
)
{
int
idx
=
0
;
for
(
ExternalDataSource
o
:
this
)
{
idx
++;
if
(
BooleanUtils
.
isTrue
(
o
.
getEnable
()))
{
String
n
=
"s"
+
(
""
+
(
1000
+
idx
)).
substring
(
1
);
if
(
StringUtils
.
equals
(
n
,
name
))
{
String
value
=
o
.
getLogLevel
();
if
(
StringUtils
.
contains
(
value
,
"="
))
{
return
value
;
}
else
{
return
"DefaultLevel=WARN, Tool="
+
value
+
", Enhance="
+
value
+
", METADATA="
+
value
+
", Runtime="
+
value
+
", Query="
+
value
+
", DataCache="
+
value
+
", JDBC="
+
value
+
", SQL="
+
value
;
}
}
}
}
return
"DefaultLevel=WARN, Tool=WARN, Enhance=WARN, METADATA=WARN, Runtime=WARN, Query=WARN, DataCache=WARN, JDBC=ERROR, SQL=WARN"
;
}
private
static
final
long
serialVersionUID
=
4502077979125945875L
;
public
static
ExternalDataSources
defaultInstance
()
{
return
new
ExternalDataSources
();
}
public
ExternalDataSources
()
{
super
();
}
public
Boolean
enable
()
{
if
(
this
.
isEmpty
())
{
return
false
;
}
for
(
ExternalDataSource
o
:
this
)
{
if
(
BooleanUtils
.
isTrue
(
o
.
getEnable
()))
{
return
true
;
}
}
return
false
;
}
public
String
name
(
ExternalDataSource
externalDataSource
)
throws
Exception
{
String
name
=
""
;
int
idx
=
0
;
for
(
ExternalDataSource
o
:
this
)
{
idx
++;
if
(
BooleanUtils
.
isTrue
(
o
.
getEnable
())
&&
Objects
.
equals
(
o
,
externalDataSource
))
{
name
=
"s"
+
(
""
+
(
1000
+
idx
)).
substring
(
1
);
break
;
}
}
if
(
StringUtils
.
isEmpty
(
name
))
{
throw
new
Exception
(
"externalDataSource not in externalDataSources."
+
externalDataSource
);
}
return
name
;
}
public
List
<
String
>
names
()
throws
Exception
{
List
<
String
>
names
=
new
ArrayList
<>();
int
idx
=
0
;
for
(
ExternalDataSource
o
:
this
)
{
idx
++;
if
(
BooleanUtils
.
isTrue
(
o
.
getEnable
()))
{
names
.
add
(
"s"
+
(
""
+
(
1000
+
idx
)).
substring
(
1
));
}
}
return
names
;
}
public
List
<
String
>
findNamesOfContainerEntity
(
String
className
)
throws
Exception
{
List
<
String
>
names
=
new
ArrayList
<>();
for
(
ExternalDataSource
o
:
this
)
{
if
(
BooleanUtils
.
isTrue
(
o
.
getEnable
()))
{
List
<
String
>
list
=
ListTools
.
toList
(
className
);
list
=
ListTools
.
includesExcludesWildcard
(
list
,
o
.
getIncludes
(),
o
.
getExcludes
());
if
(!
list
.
isEmpty
())
{
names
.
add
(
this
.
name
(
o
));
}
}
}
return
names
;
}
public
String
log
(
String
name
)
{
int
idx
=
0
;
for
(
ExternalDataSource
o
:
this
)
{
idx
++;
if
(
BooleanUtils
.
isTrue
(
o
.
getEnable
()))
{
String
n
=
"s"
+
(
""
+
(
1000
+
idx
)).
substring
(
1
);
if
(
StringUtils
.
equals
(
n
,
name
))
{
String
value
=
o
.
getLogLevel
();
if
(
StringUtils
.
contains
(
value
,
"="
))
{
return
value
;
}
else
{
return
"DefaultLevel=WARN, Tool="
+
value
+
", Enhance="
+
value
+
", METADATA="
+
value
+
", Runtime="
+
value
+
", Query="
+
value
+
", DataCache="
+
value
+
", JDBC="
+
value
+
", SQL="
+
value
;
}
}
}
}
return
"DefaultLevel=WARN, Tool=WARN, Enhance=WARN, METADATA=WARN, Runtime=WARN, Query=WARN, DataCache=WARN, JDBC=ERROR, SQL=WARN"
;
}
public
String
dictionary
()
throws
Exception
{
for
(
ExternalDataSource
o
:
this
)
{
...
...
@@ -107,7 +107,7 @@ public class ExternalDataSources extends CopyOnWriteArrayList<ExternalDataSource
}
throw
new
IllegalStateException
(
"get dictionary error."
);
}
public
String
schema
()
throws
Exception
{
for
(
ExternalDataSource
o
:
this
)
{
if
(
BooleanUtils
.
isTrue
(
o
.
getEnable
()))
{
...
...
@@ -117,41 +117,41 @@ public class ExternalDataSources extends CopyOnWriteArrayList<ExternalDataSource
throw
new
IllegalStateException
(
"get schema error."
);
}
public
boolean
hasSchema
()
throws
Exception
{
for
(
ExternalDataSource
o
:
this
)
{
if
(
BooleanUtils
.
isTrue
(
o
.
getEnable
()))
{
return
SlicePropertiesBuilder
.
hasSchemaOfUrl
(
o
.
getUrl
());
}
}
throw
new
Exception
(
"hasSchema error."
);
}
public
String
getTransactionIsolation
()
{
for
(
ExternalDataSource
o
:
this
)
{
return
o
.
getTransactionIsolation
();
}
return
null
;
}
public
Boolean
getTestConnectionOnCheckin
()
{
for
(
ExternalDataSource
o
:
this
)
{
return
o
.
getTestConnectionOnCheckin
();
}
return
null
;
}
public
Boolean
getTestConnectionOnCheckout
()
{
for
(
ExternalDataSource
o
:
this
)
{
return
o
.
getTestConnectionOnCheckout
();
}
return
null
;
}
public
Integer
getMaxIdleTime
()
{
for
(
ExternalDataSource
o
:
this
)
{
return
o
.
getMaxIdleTime
();
}
return
null
;
}
public
boolean
hasSchema
()
throws
Exception
{
for
(
ExternalDataSource
o
:
this
)
{
if
(
BooleanUtils
.
isTrue
(
o
.
getEnable
()))
{
return
SlicePropertiesBuilder
.
hasSchemaOfUrl
(
o
.
getUrl
());
}
}
throw
new
Exception
(
"hasSchema error."
);
}
public
String
getTransactionIsolation
()
{
for
(
ExternalDataSource
o
:
this
)
{
return
o
.
getTransactionIsolation
();
}
return
null
;
}
public
Boolean
getTestConnectionOnCheckin
()
{
for
(
ExternalDataSource
o
:
this
)
{
return
o
.
getTestConnectionOnCheckin
();
}
return
null
;
}
public
Boolean
getTestConnectionOnCheckout
()
{
for
(
ExternalDataSource
o
:
this
)
{
return
o
.
getTestConnectionOnCheckout
();
}
return
null
;
}
public
Integer
getMaxIdleTime
()
{
for
(
ExternalDataSource
o
:
this
)
{
return
o
.
getMaxIdleTime
();
}
return
null
;
}
}
o2server/x_base_core_project/src/main/java/com/x/base/core/project/tools/SqlTools.java
浏览文件 @
ff4071f5
...
...
@@ -4,12 +4,19 @@ import org.apache.commons.lang3.StringUtils;
public
class
SqlTools
{
private
SqlTools
()
{
// nothing
}
private
SqlTools
()
{
// nothing
}
public
static
String
removeLikePatternEscapeCharacter
(
String
query
)
{
return
StringUtils
.
remove
(
StringUtils
.
remove
(
StringUtils
.
remove
(
query
,
"%"
),
"_"
),
"\\"
);
}
public
static
String
removeLikePatternEscapeCharacter
(
String
query
)
{
return
StringUtils
.
remove
(
StringUtils
.
remove
(
StringUtils
.
remove
(
query
,
"%"
),
"_"
),
"\\"
);
}
public
static
String
escape
(
String
str
)
{
if
(
str
==
null
)
{
return
null
;
}
return
StringUtils
.
replace
(
str
,
"'"
,
"''"
);
}
}
o2server/x_console/src/main/java/com/x/server/console/DruidStatLogger.java
0 → 100644
浏览文件 @
ff4071f5
package
com.x.server.console
;
import
static
com
.
alibaba
.
druid
.
util
.
JdbcSqlStatUtils
.
rtrim
;
import
java.io.File
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
import
java.util.Date
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.io.filefilter.FalseFileFilter
;
import
org.apache.commons.io.filefilter.RegexFileFilter
;
import
com.alibaba.druid.pool.DruidDataSourceStatLoggerAdapter
;
import
com.alibaba.druid.pool.DruidDataSourceStatValue
;
import
com.alibaba.druid.stat.JdbcSqlStatValue
;
import
com.x.base.core.project.config.Config
;
import
com.x.base.core.project.gson.XGsonBuilder
;
import
com.x.base.core.project.logger.Logger
;
import
com.x.base.core.project.logger.LoggerFactory
;
import
com.x.base.core.project.tools.DateTools
;
public
class
DruidStatLogger
extends
DruidDataSourceStatLoggerAdapter
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
DruidStatLogger
.
class
);
private
static
final
String
FILE_NAME_PREFIX
=
"sqlStat_"
;
private
static
final
String
FILE_NAME_EXTENSION
=
".json"
;
private
static
final
Integer
MAXSIZE
=
50
;
@Override
public
void
log
(
DruidDataSourceStatValue
statValue
)
{
Map
<
String
,
Object
>
map
=
new
LinkedHashMap
<>();
setBase
(
map
,
statValue
);
setConnection
(
statValue
,
map
);
setWaitThreadCount
(
map
,
statValue
);
setNotEmptyWaitCount
(
map
,
statValue
);
setNotEmptyWaitMillis
(
map
,
statValue
);
setLogicConnectErrorCount
(
map
,
statValue
);
setPhysicalConnectCount
(
map
,
statValue
);
setPhysicalCloseCount
(
map
,
statValue
);
setPhysicalConnectErrorCount
(
map
,
statValue
);
setExecuteCount
(
map
,
statValue
);
setErrorCount
(
map
,
statValue
);
setCommitCount
(
map
,
statValue
);
setRollbackCount
(
map
,
statValue
);
setPstmtCacheHitCount
(
map
,
statValue
);
setPstmtCacheMissCount
(
map
,
statValue
);
setStartTransactionCount
(
map
,
statValue
);
setConnectCount
(
map
,
statValue
);
setClobOpenCount
(
map
,
statValue
);
setBlobOpenCount
(
map
,
statValue
);
setSqlSkipCount
(
map
,
statValue
);
setSqlList
(
map
,
statValue
);
setKeepAliveCheckCount
(
map
,
statValue
);
write
(
XGsonBuilder
.
toJson
(
map
));
}
private
void
write
(
String
text
)
{
try
{
File
dir
=
Config
.
dir_logs
();
if
(
dir
.
exists
()
&&
dir
.
isDirectory
())
{
List
<
File
>
list
=
new
ArrayList
<>();
for
(
File
f
:
FileUtils
.
listFilesAndDirs
(
dir
,
FalseFileFilter
.
FALSE
,
new
RegexFileFilter
(
"^"
+
FILE_NAME_PREFIX
+
"[1,2][0,9][0-9][0-9][0,1][0-9][0-3][0-9][0-5][0-9][0-5][0-9][0-5][0-9]"
+
FILE_NAME_EXTENSION
+
"$"
)))
{
if
(
dir
!=
f
)
{
list
.
add
(
f
);
}
}
list
=
list
.
stream
().
sorted
(
Comparator
.
comparing
(
File:
:
getName
).
reversed
())
.
collect
(
Collectors
.
toList
());
if
(
list
.
size
()
>
MAXSIZE
)
{
for
(
int
i
=
MAXSIZE
;
i
<
list
.
size
();
i
++)
{
File
file
=
list
.
get
(
i
);
FileUtils
.
forceDelete
(
file
);
}
}
}
Path
path
=
dir
.
toPath
().
resolve
(
FILE_NAME_PREFIX
+
DateTools
.
compact
(
new
Date
())
+
FILE_NAME_EXTENSION
);
Files
.
writeString
(
path
,
text
,
StandardCharsets
.
UTF_8
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
private
void
setWaitThreadCount
(
Map
<
String
,
Object
>
map
,
DruidDataSourceStatValue
statValue
)
{
if
(
statValue
.
getWaitThreadCount
()
>
0
)
{
map
.
put
(
"waitThreadCount"
,
statValue
.
getWaitThreadCount
());
}
}
private
void
setNotEmptyWaitCount
(
Map
<
String
,
Object
>
map
,
DruidDataSourceStatValue
statValue
)
{
if
(
statValue
.
getNotEmptyWaitCount
()
>
0
)
{
map
.
put
(
"notEmptyWaitCount"
,
statValue
.
getNotEmptyWaitCount
());
}
}
private
void
setNotEmptyWaitMillis
(
Map
<
String
,
Object
>
map
,
DruidDataSourceStatValue
statValue
)
{
if
(
statValue
.
getNotEmptyWaitMillis
()
>
0
)
{
map
.
put
(
"notEmptyWaitMillis"
,
statValue
.
getNotEmptyWaitMillis
());
}
}
private
void
setLogicConnectErrorCount
(
Map
<
String
,
Object
>
map
,
DruidDataSourceStatValue
statValue
)
{
if
(
statValue
.
getLogicConnectErrorCount
()
>
0
)
{
map
.
put
(
"logicConnectErrorCount"
,
statValue
.
getLogicConnectErrorCount
());
}
}
private
void
setPhysicalConnectCount
(
Map
<
String
,
Object
>
map
,
DruidDataSourceStatValue
statValue
)
{
if
(
statValue
.
getPhysicalConnectCount
()
>
0
)
{
map
.
put
(
"physicalConnectCount"
,
statValue
.
getPhysicalConnectCount
());
}
}
private
void
setPhysicalCloseCount
(
Map
<
String
,
Object
>
map
,
DruidDataSourceStatValue
statValue
)
{
if
(
statValue
.
getPhysicalCloseCount
()
>
0
)
{
map
.
put
(
"physicalCloseCount"
,
statValue
.
getPhysicalCloseCount
());
}
}
private
void
setPhysicalConnectErrorCount
(
Map
<
String
,
Object
>
map
,
DruidDataSourceStatValue
statValue
)
{
if
(
statValue
.
getPhysicalConnectErrorCount
()
>
0
)
{
map
.
put
(
"physicalConnectErrorCount"
,
statValue
.
getPhysicalConnectErrorCount
());
}
}
private
void
setExecuteCount
(
Map
<
String
,
Object
>
map
,
DruidDataSourceStatValue
statValue
)
{
if
(
statValue
.
getExecuteCount
()
>
0
)
{
map
.
put
(
"executeCount"
,
statValue
.
getExecuteCount
());
}
}
private
void
setErrorCount
(
Map
<
String
,
Object
>
map
,
DruidDataSourceStatValue
statValue
)
{
if
(
statValue
.
getErrorCount
()
>
0
)
{
map
.
put
(
"errorCount"
,
statValue
.
getErrorCount
());
}
}
private
void
setCommitCount
(
Map
<
String
,
Object
>
map
,
DruidDataSourceStatValue
statValue
)
{
if
(
statValue
.
getCommitCount
()
>
0
)
{
map
.
put
(
"commitCount"
,
statValue
.
getCommitCount
());
}
}
private
void
setRollbackCount
(
Map
<
String
,
Object
>
map
,
DruidDataSourceStatValue
statValue
)
{
if
(
statValue
.
getRollbackCount
()
>
0
)
{
map
.
put
(
"rollbackCount"
,
statValue
.
getRollbackCount
());
}
}
private
void
setPstmtCacheHitCount
(
Map
<
String
,
Object
>
map
,
DruidDataSourceStatValue
statValue
)
{
if
(
statValue
.
getPstmtCacheHitCount
()
>
0
)
{
map
.
put
(
"pstmtCacheHitCount"
,
statValue
.
getPstmtCacheHitCount
());
}
}
private
void
setPstmtCacheMissCount
(
Map
<
String
,
Object
>
map
,
DruidDataSourceStatValue
statValue
)
{
if
(
statValue
.
getPstmtCacheMissCount
()
>
0
)
{
map
.
put
(
"pstmtCacheMissCount"
,
statValue
.
getPstmtCacheMissCount
());
}
}
private
void
setStartTransactionCount
(
Map
<
String
,
Object
>
map
,
DruidDataSourceStatValue
statValue
)
{
if
(
statValue
.
getStartTransactionCount
()
>
0
)
{
map
.
put
(
"startTransactionCount"
,
statValue
.
getStartTransactionCount
());
map
.
put
(
"transactionHistogram"
,
rtrim
(
statValue
.
getTransactionHistogram
()));
}
}
private
void
setConnectCount
(
Map
<
String
,
Object
>
map
,
DruidDataSourceStatValue
statValue
)
{
if
(
statValue
.
getConnectCount
()
>
0
)
{
map
.
put
(
"connectionHoldTimeHistogram"
,
rtrim
(
statValue
.
getConnectionHoldTimeHistogram
()));
}
}
private
void
setClobOpenCount
(
Map
<
String
,
Object
>
map
,
DruidDataSourceStatValue
statValue
)
{
if
(
statValue
.
getClobOpenCount
()
>
0
)
{
map
.
put
(
"clobOpenCount"
,
statValue
.
getClobOpenCount
());
}
}
private
void
setBlobOpenCount
(
Map
<
String
,
Object
>
map
,
DruidDataSourceStatValue
statValue
)
{
if
(
statValue
.
getBlobOpenCount
()
>
0
)
{
map
.
put
(
"blobOpenCount"
,
statValue
.
getBlobOpenCount
());
}
}
private
void
setSqlSkipCount
(
Map
<
String
,
Object
>
map
,
DruidDataSourceStatValue
statValue
)
{
if
(
statValue
.
getSqlSkipCount
()
>
0
)
{
map
.
put
(
"sqlSkipCount"
,
statValue
.
getSqlSkipCount
());
}
}
private
void
setKeepAliveCheckCount
(
Map
<
String
,
Object
>
map
,
DruidDataSourceStatValue
statValue
)
{
if
(
statValue
.
getKeepAliveCheckCount
()
>
0
)
{
map
.
put
(
"keepAliveCheckCount"
,
statValue
.
getKeepAliveCheckCount
());
}
}
private
void
setSqlList
(
Map
<
String
,
Object
>
map
,
DruidDataSourceStatValue
statValue
)
{
ArrayList
<
Map
<
String
,
Object
>>
sqlList
=
new
ArrayList
<>();
if
(!
statValue
.
getSqlList
().
isEmpty
())
{
for
(
JdbcSqlStatValue
sqlStat
:
statValue
.
getSqlList
())
{
Map
<
String
,
Object
>
sqlStatMap
=
new
LinkedHashMap
<>();
sqlStatMap
.
put
(
"sql"
,
sqlStat
.
getSql
());
setSqlListSetExecuteCount
(
sqlStatMap
,
sqlStat
);
setSqlListSetExecuteErrorCount
(
sqlStatMap
,
sqlStat
);
setSqlListSetRunningCount
(
sqlStatMap
,
sqlStat
);
setSqlListSetConcurrentMax
(
sqlStatMap
,
sqlStat
);
setSqlListSetFetchRowCount
(
sqlStatMap
,
sqlStat
);
setSqlListSetUpdateCount
(
sqlStatMap
,
sqlStat
);
setSqlListSetInTransactionCount
(
sqlStatMap
,
sqlStat
);
setSqlListSetClobOpenCount
(
sqlStatMap
,
sqlStat
);
setSqlListSetBlobOpenCount
(
sqlStatMap
,
sqlStat
);
sqlList
.
add
(
sqlStatMap
);
}
map
.
put
(
"sqlList"
,
sqlList
);
}
}
private
void
setSqlListSetBlobOpenCount
(
Map
<
String
,
Object
>
sqlStatMap
,
JdbcSqlStatValue
sqlStat
)
{
if
(
sqlStat
.
getBlobOpenCount
()
>
0
)
{
sqlStatMap
.
put
(
"blobOpenCount"
,
sqlStat
.
getBlobOpenCount
());
}
}
private
void
setSqlListSetClobOpenCount
(
Map
<
String
,
Object
>
sqlStatMap
,
JdbcSqlStatValue
sqlStat
)
{
if
(
sqlStat
.
getClobOpenCount
()
>
0
)
{
sqlStatMap
.
put
(
"clobOpenCount"
,
sqlStat
.
getClobOpenCount
());
}
}
private
void
setSqlListSetInTransactionCount
(
Map
<
String
,
Object
>
sqlStatMap
,
JdbcSqlStatValue
sqlStat
)
{
if
(
sqlStat
.
getInTransactionCount
()
>
0
)
{
sqlStatMap
.
put
(
"inTransactionCount"
,
sqlStat
.
getInTransactionCount
());
}
}
private
void
setSqlListSetUpdateCount
(
Map
<
String
,
Object
>
sqlStatMap
,
JdbcSqlStatValue
sqlStat
)
{
if
(
sqlStat
.
getUpdateCount
()
>
0
)
{
sqlStatMap
.
put
(
"updateCount"
,
sqlStat
.
getUpdateCount
());
sqlStatMap
.
put
(
"updateCountMax"
,
sqlStat
.
getUpdateCountMax
());
sqlStatMap
.
put
(
"updateHistogram"
,
rtrim
(
sqlStat
.
getUpdateHistogram
()));
}
}
private
void
setSqlListSetFetchRowCount
(
Map
<
String
,
Object
>
sqlStatMap
,
JdbcSqlStatValue
sqlStat
)
{
if
(
sqlStat
.
getFetchRowCount
()
>
0
)
{
sqlStatMap
.
put
(
"fetchRowCount"
,
sqlStat
.
getFetchRowCount
());
sqlStatMap
.
put
(
"fetchRowCountMax"
,
sqlStat
.
getFetchRowCountMax
());
sqlStatMap
.
put
(
"fetchRowHistogram"
,
rtrim
(
sqlStat
.
getFetchRowHistogram
()));
}
}
private
void
setSqlListSetConcurrentMax
(
Map
<
String
,
Object
>
sqlStatMap
,
JdbcSqlStatValue
sqlStat
)
{
int
concurrentMax
=
sqlStat
.
getConcurrentMax
();
if
(
concurrentMax
>
0
)
{
sqlStatMap
.
put
(
"concurrentMax"
,
concurrentMax
);
}
}
private
void
setSqlListSetRunningCount
(
Map
<
String
,
Object
>
sqlStatMap
,
JdbcSqlStatValue
sqlStat
)
{
int
runningCount
=
sqlStat
.
getRunningCount
();
if
(
runningCount
>
0
)
{
sqlStatMap
.
put
(
"runningCount"
,
runningCount
);
}
}
private
void
setSqlListSetExecuteErrorCount
(
Map
<
String
,
Object
>
sqlStatMap
,
JdbcSqlStatValue
sqlStat
)
{
long
executeErrorCount
=
sqlStat
.
getExecuteErrorCount
();
if
(
executeErrorCount
>
0
)
{
sqlStatMap
.
put
(
"executeErrorCount"
,
executeErrorCount
);
}
}
private
void
setSqlListSetExecuteCount
(
Map
<
String
,
Object
>
sqlStatMap
,
JdbcSqlStatValue
sqlStat
)
{
if
(
sqlStat
.
getExecuteCount
()
>
0
)
{
sqlStatMap
.
put
(
"executeCount"
,
sqlStat
.
getExecuteCount
());
sqlStatMap
.
put
(
"executeMillisMax"
,
sqlStat
.
getExecuteMillisMax
());
sqlStatMap
.
put
(
"executeMillisTotal"
,
sqlStat
.
getExecuteMillisTotal
());
sqlStatMap
.
put
(
"executeHistogram"
,
rtrim
(
sqlStat
.
getExecuteHistogram
()));
sqlStatMap
.
put
(
"executeAndResultHoldHistogram"
,
rtrim
(
sqlStat
.
getExecuteAndResultHoldHistogram
()));
}
}
private
void
setConnection
(
DruidDataSourceStatValue
statValue
,
Map
<
String
,
Object
>
map
)
{
if
(
statValue
.
getActivePeak
()
>
0
)
{
map
.
put
(
"activePeak"
,
statValue
.
getActivePeak
());
map
.
put
(
"activePeakTime"
,
statValue
.
getActivePeakTime
());
}
map
.
put
(
"poolingCount"
,
statValue
.
getPoolingCount
());
if
(
statValue
.
getPoolingPeak
()
>
0
)
{
map
.
put
(
"poolingPeak"
,
statValue
.
getPoolingPeak
());
map
.
put
(
"poolingPeakTime"
,
statValue
.
getPoolingPeakTime
());
}
map
.
put
(
"connectCount"
,
statValue
.
getConnectCount
());
map
.
put
(
"closeCount"
,
statValue
.
getCloseCount
());
}
private
void
setBase
(
Map
<
String
,
Object
>
map
,
DruidDataSourceStatValue
statValue
)
{
map
.
put
(
"url"
,
statValue
.
getUrl
());
map
.
put
(
"dbType"
,
statValue
.
getDbType
());
map
.
put
(
"name"
,
statValue
.
getName
());
map
.
put
(
"activeCount"
,
statValue
.
getActiveCount
());
}
}
\ No newline at end of file
o2server/x_console/src/main/java/com/x/server/console/ResourceFactory.java
浏览文件 @
ff4071f5
...
...
@@ -29,8 +29,10 @@ import org.apache.commons.io.FilenameUtils;
import
org.apache.commons.io.filefilter.WildcardFileFilter
;
import
org.apache.commons.lang3.BooleanUtils
;
import
org.apache.commons.lang3.concurrent.BasicThreadFactory
;
import
org.apache.commons.lang3.reflect.FieldUtils
;
import
org.eclipse.jetty.plus.jndi.Resource
;
import
com.alibaba.druid.pool.DruidDataSource
;
import
com.alibaba.druid.pool.DruidDataSourceC3P0Adapter
;
import
com.google.common.util.concurrent.ThreadFactoryBuilder
;
import
com.google.gson.JsonElement
;
...
...
@@ -209,13 +211,21 @@ public class ResourceFactory {
dataSource
.
setTestConnectionOnCheckout
(
ds
.
getTestConnectionOnCheckout
());
dataSource
.
setMaxIdleTime
(
ds
.
getMaxIdleTime
());
dataSource
.
setAcquireIncrement
(
2
);
Properties
properties
=
new
Properties
(
);
DruidDataSource
druidDataSource
=
(
DruidDataSource
)
FieldUtils
.
readField
(
dataSource
,
"dataSource"
,
true
);
if
(
BooleanUtils
.
isTrue
(
ds
.
getStatEnable
()))
{
dataSource
.
setFilters
(
ds
.
getStatFilter
());
properties
.
setProperty
(
"druid.stat.slowSqlMillis"
,
ds
.
getSlowSqlMillis
().
toString
());
properties
.
setProperty
(
"druid.stat.logSlowSql"
,
"true"
);
if
(
BooleanUtils
.
isTrue
(
ds
.
getSlowSqlEnable
()))
{
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
"druid.stat.slowSqlMillis"
,
ds
.
getSlowSqlThreshold
().
toString
());
properties
.
setProperty
(
"druid.stat.logSlowSql"
,
"true"
);
dataSource
.
setProperties
(
properties
);
}
if
(
BooleanUtils
.
isTrue
(
ds
.
getLogStatEnable
()))
{
druidDataSource
.
setStatLogger
(
new
DruidStatLogger
());
druidDataSource
.
setTimeBetweenLogStatsMillis
(
60000L
*
ds
.
getLogStatInterval
());
}
}
dataSource
.
setProperties
(
properties
);
// 增加autoCommit设置
dataSource
.
setAutoCommitOnClose
(
ds
.
getAutoCommit
());
String
name
=
Config
.
externalDataSources
().
name
(
ds
);
...
...
@@ -259,13 +269,21 @@ public class ResourceFactory {
dataSource
.
setMaxPoolSize
(
entry
.
getValue
().
getMaxTotal
());
dataSource
.
setMinPoolSize
(
entry
.
getValue
().
getMaxIdle
());
dataSource
.
setAcquireIncrement
(
2
);
Properties
properties
=
new
Properties
(
);
DruidDataSource
druidDataSource
=
(
DruidDataSource
)
FieldUtils
.
readField
(
dataSource
,
"dataSource"
,
true
);
if
(
BooleanUtils
.
isTrue
(
entry
.
getValue
().
getStatEnable
()))
{
dataSource
.
setFilters
(
entry
.
getValue
().
getStatFilter
());
properties
.
setProperty
(
"druid.stat.slowSqlMillis"
,
entry
.
getValue
().
getSlowSqlMillis
().
toString
());
properties
.
setProperty
(
"druid.stat.logSlowSql"
,
"true"
);
if
(
BooleanUtils
.
isTrue
(
entry
.
getValue
().
getSlowSqlEnable
()))
{
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
"druid.stat.slowSqlMillis"
,
entry
.
getValue
().
getSlowSqlThreshold
().
toString
());
properties
.
setProperty
(
"druid.stat.logSlowSql"
,
"true"
);
dataSource
.
setProperties
(
properties
);
}
if
(
BooleanUtils
.
isTrue
(
entry
.
getValue
().
getLogStatEnable
()))
{
druidDataSource
.
setStatLogger
(
new
DruidStatLogger
());
druidDataSource
.
setTimeBetweenLogStatsMillis
(
60000L
*
entry
.
getValue
().
getLogStatInterval
());
}
}
dataSource
.
setProperties
(
properties
);
// 增加autoCommit设置
dataSource
.
setAutoCommitOnClose
(
false
);
String
name
=
Config
.
nodes
().
dataServers
().
name
(
entry
.
getValue
());
...
...
o2server/x_console/src/main/java/com/x/server/console/StackTraceTask.java
浏览文件 @
ff4071f5
...
...
@@ -41,7 +41,7 @@ public class StackTraceTask implements Job {
}
Process
p
=
processBuilder
.
start
();
String
resp
=
IOUtils
.
toString
(
p
.
getErrorStream
(),
DefaultCharset
.
charset_utf_8
);
LOGGER
.
print
(
"schedule stack trace to {}
.{}
"
,
file
,
resp
);
LOGGER
.
print
(
"schedule stack trace to {}
, {}.
"
,
file
,
resp
);
p
.
destroy
();
clean
(
now
);
}
catch
(
Exception
e
)
{
...
...
o2server/x_console/src/main/java/com/x/server/console/node/RegistApplicationsEvent.java
浏览文件 @
ff4071f5
...
...
@@ -36,180 +36,180 @@ import com.x.server.console.server.Servers;
public
class
RegistApplicationsEvent
implements
Event
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
RegistApplicationsEvent
.
class
);
private
static
final
Gson
gson
=
XGsonBuilder
.
instance
();
public
final
String
type
=
Event
.
TYPE_REGISTAPPLICATIONS
;
@Override
public
void
execute
()
{
this
.
execute
(
Servers
.
applicationServer
);
}
public
void
execute
(
Server
applicationServer
)
{
try
{
if
(
BooleanUtils
.
isTrue
(
Servers
.
applicationServerIsStarted
())
&&
(
null
!=
Config
.
resource_node_applications
()))
{
List
<
Application
>
list
=
listApplication
(
applicationServer
);
if
(
ListTools
.
isEmpty
(
list
))
{
logger
.
warn
(
"applications on node:{} is empty."
,
Config
.
node
());
}
if
(
BooleanUtils
.
isTrue
(
Config
.
currentNode
().
getSelfHealthCheckEnable
())
&&
(!
this
.
healthCheck
(
list
)))
{
logger
.
warn
(
"health check result is false."
);
list
.
clear
();
}
Req
req
=
new
Req
();
req
.
setServerTime
(
new
Date
());
req
.
setNode
(
Config
.
node
());
req
.
setValue
(
gson
.
toJson
(
list
));
for
(
Entry
<
String
,
CenterServer
>
entry
:
Config
.
nodes
().
centerServers
().
orderedEntry
())
{
toCenter
(
entry
,
req
);
}
}
}
catch
(
Exception
e
)
{
logger
.
error
(
e
);
}
}
private
void
toCenter
(
Entry
<
String
,
CenterServer
>
entry
,
Req
req
)
{
try
{
CipherConnectionAction
.
put
(
false
,
2000
,
4000
,
Config
.
url_x_program_center_jaxrs
(
entry
,
"center"
,
"regist"
,
"applications"
),
req
)
.
getData
(
WrapBoolean
.
class
);
}
catch
(
Exception
e
)
{
logger
.
warn
(
"registerToCenter error:{}"
,
e
.
getMessage
());
}
}
private
List
<
Application
>
listApplication
(
Server
applicationServer
)
throws
Exception
{
List
<
Application
>
list
=
new
ArrayList
<>();
GzipHandler
gzipHandler
=
(
GzipHandler
)
applicationServer
.
getHandler
();
HandlerList
hanlderList
=
(
HandlerList
)
gzipHandler
.
getHandler
();
for
(
Handler
handler
:
hanlderList
.
getHandlers
())
{
if
(
QuickStartWebApp
.
class
.
isAssignableFrom
(
handler
.
getClass
()))
{
QuickStartWebApp
app
=
(
QuickStartWebApp
)
handler
;
if
(
app
.
isStarted
()
&&
(!
StringUtils
.
equalsIgnoreCase
(
app
.
getContextPath
(),
"/x_program_center"
))
&&
(!
StringUtils
.
equalsIgnoreCase
(
app
.
getContextPath
(),
"/"
)))
{
try
{
list
.
add
(
gson
.
fromJson
(
app
.
getServletContext
()
.
getAttribute
(
AbstractContext
.
SERVLETCONTEXT_ATTRIBUTE_APPLICATION
).
toString
(),
Application
.
class
));
}
catch
(
Exception
e
)
{
logger
.
error
(
new
RunningException
(
"cannot read application attribute contextPath:{}."
,
app
.
getContextPath
()));
}
}
}
}
return
list
;
}
private
boolean
healthCheck
(
List
<
Application
>
list
)
{
List
<
CompletableFuture
<
Long
>>
futures
=
new
ArrayList
<>();
try
{
for
(
Application
o
:
list
)
{
futures
.
add
(
healthCheckTask
(
o
));
}
long
max
=
Long
.
MIN_VALUE
;
for
(
CompletableFuture
<
Long
>
future
:
futures
)
{
long
difference
=
future
.
get
(
3000
,
TimeUnit
.
MILLISECONDS
);
if
(
difference
<
0
)
{
return
false
;
}
max
=
Math
.
max
(
max
,
difference
);
}
if
(
max
>
2
*
1000
)
{
logger
.
warn
(
"response time is too long: {}ms."
,
max
);
}
}
catch
(
Exception
e
)
{
logger
.
error
(
new
RunningException
(
e
,
"health check error."
));
Thread
.
currentThread
().
interrupt
();
return
false
;
}
return
true
;
}
private
CompletableFuture
<
Long
>
healthCheckTask
(
Application
application
)
{
return
CompletableFuture
.
supplyAsync
(()
->
{
try
{
Resp
resp
=
CipherConnectionAction
.
get
(
false
,
2000
,
4000
,
application
,
"echo"
).
getData
(
Resp
.
class
);
Date
date
=
resp
.
getServerTime
();
return
Math
.
abs
(
date
.
getTime
()
-
((
new
Date
()).
getTime
()));
}
catch
(
Exception
e
)
{
logger
.
error
(
new
RunningException
(
e
,
"health check failure:{},{}."
,
application
.
getNode
(),
application
.
getContextPath
()));
}
return
-
1L
;
},
Inner
.
executorService
);
}
private
static
class
Inner
{
private
static
final
ExecutorService
executorService
=
Executors
.
newFixedThreadPool
(
2
,
new
BasicThreadFactory
.
Builder
().
namingPattern
(
"RegistApplicationsEvent-healthCheck-%d"
).
daemon
(
true
)
.
build
());
}
public
static
class
Resp
{
@FieldDescribe
(
"上下文根"
)
private
String
servletContextName
;
@FieldDescribe
(
"服务器时间"
)
private
Date
serverTime
;
public
String
getServletContextName
()
{
return
servletContextName
;
}
public
void
setServletContextName
(
String
servletContextName
)
{
this
.
servletContextName
=
servletContextName
;
}
public
Date
getServerTime
()
{
return
serverTime
;
}
public
void
setServerTime
(
Date
serverTime
)
{
this
.
serverTime
=
serverTime
;
}
}
public
static
class
Req
extends
WrapString
{
private
static
final
long
serialVersionUID
=
-
2855209663719641934L
;
@FieldDescribe
(
"节点名"
)
private
String
node
;
@FieldDescribe
(
"服务器时间"
)
private
Date
serverTime
;
public
String
getNode
()
{
return
node
;
}
public
void
setNode
(
String
node
)
{
this
.
node
=
node
;
}
public
Date
getServerTime
()
{
return
serverTime
;
}
public
void
setServerTime
(
Date
serverTime
)
{
this
.
serverTime
=
serverTime
;
}
}
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
RegistApplicationsEvent
.
class
);
private
static
final
Gson
gson
=
XGsonBuilder
.
instance
();
public
final
String
type
=
Event
.
TYPE_REGISTAPPLICATIONS
;
@Override
public
void
execute
()
{
this
.
execute
(
Servers
.
applicationServer
);
}
public
void
execute
(
Server
applicationServer
)
{
try
{
if
(
BooleanUtils
.
isTrue
(
Servers
.
applicationServerIsStarted
())
&&
(
null
!=
Config
.
resource_node_applications
()))
{
List
<
Application
>
list
=
listApplication
(
applicationServer
);
if
(
ListTools
.
isEmpty
(
list
))
{
logger
.
warn
(
"applications on node:{} is empty."
,
Config
.
node
());
}
if
(
BooleanUtils
.
isTrue
(
Config
.
currentNode
().
getSelfHealthCheckEnable
())
&&
(!
this
.
healthCheck
(
list
)))
{
logger
.
warn
(
"health check result is false."
);
list
.
clear
();
}
Req
req
=
new
Req
();
req
.
setServerTime
(
new
Date
());
req
.
setNode
(
Config
.
node
());
req
.
setValue
(
gson
.
toJson
(
list
));
for
(
Entry
<
String
,
CenterServer
>
entry
:
Config
.
nodes
().
centerServers
().
orderedEntry
())
{
toCenter
(
entry
,
req
);
}
}
}
catch
(
Exception
e
)
{
logger
.
error
(
e
);
}
}
private
void
toCenter
(
Entry
<
String
,
CenterServer
>
entry
,
Req
req
)
{
try
{
CipherConnectionAction
.
put
(
false
,
2000
,
4000
,
Config
.
url_x_program_center_jaxrs
(
entry
,
"center"
,
"regist"
,
"applications"
),
req
)
.
getData
(
WrapBoolean
.
class
);
}
catch
(
Exception
e
)
{
logger
.
warn
(
"registerToCenter error, node:{}, message:{}."
,
entry
.
getKey
()
,
e
.
getMessage
());
}
}
private
List
<
Application
>
listApplication
(
Server
applicationServer
)
throws
Exception
{
List
<
Application
>
list
=
new
ArrayList
<>();
GzipHandler
gzipHandler
=
(
GzipHandler
)
applicationServer
.
getHandler
();
HandlerList
hanlderList
=
(
HandlerList
)
gzipHandler
.
getHandler
();
for
(
Handler
handler
:
hanlderList
.
getHandlers
())
{
if
(
QuickStartWebApp
.
class
.
isAssignableFrom
(
handler
.
getClass
()))
{
QuickStartWebApp
app
=
(
QuickStartWebApp
)
handler
;
if
(
app
.
isStarted
()
&&
(!
StringUtils
.
equalsIgnoreCase
(
app
.
getContextPath
(),
"/x_program_center"
))
&&
(!
StringUtils
.
equalsIgnoreCase
(
app
.
getContextPath
(),
"/"
)))
{
try
{
list
.
add
(
gson
.
fromJson
(
app
.
getServletContext
()
.
getAttribute
(
AbstractContext
.
SERVLETCONTEXT_ATTRIBUTE_APPLICATION
).
toString
(),
Application
.
class
));
}
catch
(
Exception
e
)
{
logger
.
error
(
new
RunningException
(
"cannot read application attribute contextPath:{}."
,
app
.
getContextPath
()));
}
}
}
}
return
list
;
}
private
boolean
healthCheck
(
List
<
Application
>
list
)
{
List
<
CompletableFuture
<
Long
>>
futures
=
new
ArrayList
<>();
try
{
for
(
Application
o
:
list
)
{
futures
.
add
(
healthCheckTask
(
o
));
}
long
max
=
Long
.
MIN_VALUE
;
for
(
CompletableFuture
<
Long
>
future
:
futures
)
{
long
difference
=
future
.
get
(
3000
,
TimeUnit
.
MILLISECONDS
);
if
(
difference
<
0
)
{
return
false
;
}
max
=
Math
.
max
(
max
,
difference
);
}
if
(
max
>
2
*
1000
)
{
logger
.
warn
(
"response time is too long: {}ms."
,
max
);
}
}
catch
(
Exception
e
)
{
logger
.
error
(
new
RunningException
(
e
,
"health check error."
));
Thread
.
currentThread
().
interrupt
();
return
false
;
}
return
true
;
}
private
CompletableFuture
<
Long
>
healthCheckTask
(
Application
application
)
{
return
CompletableFuture
.
supplyAsync
(()
->
{
try
{
Resp
resp
=
CipherConnectionAction
.
get
(
false
,
2000
,
4000
,
application
,
"echo"
).
getData
(
Resp
.
class
);
Date
date
=
resp
.
getServerTime
();
return
Math
.
abs
(
date
.
getTime
()
-
((
new
Date
()).
getTime
()));
}
catch
(
Exception
e
)
{
logger
.
error
(
new
RunningException
(
e
,
"health check failure:{},{}."
,
application
.
getNode
(),
application
.
getContextPath
()));
}
return
-
1L
;
},
Inner
.
executorService
);
}
private
static
class
Inner
{
private
static
final
ExecutorService
executorService
=
Executors
.
newFixedThreadPool
(
2
,
new
BasicThreadFactory
.
Builder
().
namingPattern
(
"RegistApplicationsEvent-healthCheck-%d"
).
daemon
(
true
)
.
build
());
}
public
static
class
Resp
{
@FieldDescribe
(
"上下文根"
)
private
String
servletContextName
;
@FieldDescribe
(
"服务器时间"
)
private
Date
serverTime
;
public
String
getServletContextName
()
{
return
servletContextName
;
}
public
void
setServletContextName
(
String
servletContextName
)
{
this
.
servletContextName
=
servletContextName
;
}
public
Date
getServerTime
()
{
return
serverTime
;
}
public
void
setServerTime
(
Date
serverTime
)
{
this
.
serverTime
=
serverTime
;
}
}
public
static
class
Req
extends
WrapString
{
private
static
final
long
serialVersionUID
=
-
2855209663719641934L
;
@FieldDescribe
(
"节点名"
)
private
String
node
;
@FieldDescribe
(
"服务器时间"
)
private
Date
serverTime
;
public
String
getNode
()
{
return
node
;
}
public
void
setNode
(
String
node
)
{
this
.
node
=
node
;
}
public
Date
getServerTime
()
{
return
serverTime
;
}
public
void
setServerTime
(
Date
serverTime
)
{
this
.
serverTime
=
serverTime
;
}
}
}
o2server/x_organization_assemble_express/src/main/java/com/x/organization/assemble/express/jaxrs/empower/ActionListWithIdentityObject.java
浏览文件 @
ff4071f5
...
...
@@ -26,6 +26,8 @@ import com.x.base.core.project.connection.ActionResponse;
import
com.x.base.core.project.gson.GsonPropertyObject
;
import
com.x.base.core.project.http.ActionResult
;
import
com.x.base.core.project.http.EffectivePerson
;
import
com.x.base.core.project.logger.Logger
;
import
com.x.base.core.project.logger.LoggerFactory
;
import
com.x.base.core.project.tools.ListTools
;
import
com.x.organization.assemble.express.Business
;
import
com.x.organization.assemble.express.ThisApplication
;
...
...
@@ -36,182 +38,187 @@ import com.x.organization.core.entity.accredit.Filter;
class
ActionListWithIdentityObject
extends
BaseAction
{
ActionResult
<
List
<
Wo
>>
execute
(
EffectivePerson
effectivePerson
,
JsonElement
jsonElement
)
throws
Exception
{
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
Wi
wi
=
this
.
convertToWrapIn
(
jsonElement
,
Wi
.
class
);
ActionResult
<
List
<
Wo
>>
result
=
new
ActionResult
<>();
Business
business
=
new
Business
(
emc
);
List
<
Wo
>
wos
=
this
.
convert
(
business
,
wi
);
result
.
setData
(
wos
);
return
result
;
}
}
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ActionListWithIdentityObject
.
class
);
public
static
class
Wi
extends
GsonPropertyObject
{
ActionResult
<
List
<
Wo
>>
execute
(
EffectivePerson
effectivePerson
,
JsonElement
jsonElement
)
throws
Exception
{
@FieldDescribe
(
"应用"
)
private
String
application
;
LOGGER
.
debug
(
"execute:{}."
,
effectivePerson:
:
getDistinguishedName
);
@FieldDescribe
(
"流程版本"
)
private
String
edition
;
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
Wi
wi
=
this
.
convertToWrapIn
(
jsonElement
,
Wi
.
class
);
ActionResult
<
List
<
Wo
>>
result
=
new
ActionResult
<>();
Business
business
=
new
Business
(
emc
);
List
<
Wo
>
wos
=
this
.
convert
(
business
,
wi
);
result
.
setData
(
wos
);
return
result
;
}
}
@FieldDescribe
(
"流程"
)
private
String
process
;
public
static
class
Wi
extends
GsonPropertyObject
{
@FieldDescribe
(
"工作
"
)
private
String
work
;
@FieldDescribe
(
"应用
"
)
private
String
application
;
@FieldDescribe
(
"身份
"
)
private
List
<
String
>
identityList
=
new
ArrayList
<>()
;
@FieldDescribe
(
"流程版本
"
)
private
String
edition
;
public
List
<
String
>
getIdentityList
()
{
return
identityList
;
}
@FieldDescribe
(
"流程"
)
private
String
process
;
public
void
setIdentityList
(
List
<
String
>
identityList
)
{
this
.
identityList
=
identityList
;
}
public
String
getApplication
()
{
return
application
;
}
public
void
setApplication
(
String
application
)
{
this
.
application
=
application
;
}
public
String
getProcess
()
{
return
process
;
}
public
void
setProcess
(
String
process
)
{
this
.
process
=
process
;
}
public
String
getWork
()
{
return
work
;
}
public
void
setWork
(
String
work
)
{
this
.
work
=
work
;
}
public
String
getEdition
()
{
return
edition
;
}
public
void
setEdition
(
String
edition
)
{
this
.
edition
=
edition
;
}
}
public
static
class
Wo
extends
Empower
{
private
static
final
long
serialVersionUID
=
1559687446726204650L
;
public
Wo
()
{
}
public
Wo
(
String
fromIdentity
,
String
toIdentity
)
{
this
.
setFromIdentity
(
fromIdentity
);
this
.
setToIdentity
(
toIdentity
);
}
}
private
List
<
Wo
>
convert
(
Business
business
,
Wi
wi
)
throws
Exception
{
List
<
Wo
>
wos
=
new
ArrayList
<>();
Map
<
String
,
List
<
Empower
>>
map
=
this
.
list
(
business
,
wi
).
stream
()
.
collect
(
Collectors
.
groupingBy
(
o
->
o
.
getFromIdentity
()));
for
(
String
str
:
wi
.
getIdentityList
())
{
List
<
Empower
>
list
=
map
.
get
(
str
);
if
(
ListTools
.
isNotEmpty
(
list
))
{
list
.
sort
(
new
EmpowerComparator
());
Empower
empower
=
this
.
pick
(
business
,
list
,
wi
.
getWork
());
if
(
null
!=
empower
)
{
Wo
wo
=
new
Wo
(
str
,
str
);
wo
.
setToIdentity
(
list
.
get
(
0
).
getToIdentity
());
wos
.
add
(
wo
);
}
}
}
return
wos
;
}
private
Empower
pick
(
Business
business
,
List
<
Empower
>
list
,
String
work
)
throws
Exception
{
for
(
Empower
empower
:
list
)
{
if
(
StringUtils
.
equals
(
Empower
.
TYPE_FILTER
,
empower
.
getType
())
&&
StringUtils
.
isNotEmpty
(
empower
.
getFilterListData
()))
{
List
<
Filter
>
filters
=
gson
.
fromJson
(
empower
.
getFilterListData
(),
Filter
.
LISTTYPE
);
Filter
filter
=
filters
.
get
(
0
);
ActionResponse
response
=
ThisApplication
.
context
().
applications
().
getQuery
(
x_processplatform_assemble_surface
.
class
,
Applications
.
joinQueryUri
(
"data"
,
"work"
,
work
)
+
"/"
+
StringUtils
.
replace
(
filter
.
path
,
"."
,
"/"
));
if
(
null
!=
response
.
getData
())
{
if
(
StringUtils
.
equals
(
filter
.
value
,
response
.
getData
().
getAsString
()))
{
return
empower
;
}
}
else
{
return
empower
;
}
}
}
return
list
.
get
(
0
);
}
private
class
EmpowerComparator
implements
Comparator
<
Empower
>
{
public
int
compare
(
Empower
o1
,
Empower
o2
)
{
if
(
StringUtils
.
equals
(
Empower
.
TYPE_FILTER
,
o1
.
getType
()))
{
return
-
1
;
}
else
if
(
StringUtils
.
equals
(
Empower
.
TYPE_FILTER
,
o2
.
getType
()))
{
return
1
;
}
else
if
(
StringUtils
.
equals
(
Empower
.
TYPE_PROCESS
,
o1
.
getType
()))
{
return
-
1
;
}
else
if
(
StringUtils
.
equals
(
Empower
.
TYPE_PROCESS
,
o2
.
getType
()))
{
return
1
;
}
else
if
(
StringUtils
.
equals
(
Empower
.
TYPE_APPLICATION
,
o1
.
getType
()))
{
return
-
1
;
}
else
if
(
StringUtils
.
equals
(
Empower
.
TYPE_APPLICATION
,
o2
.
getType
()))
{
return
1
;
}
else
{
return
0
;
}
}
}
private
List
<
Empower
>
list
(
Business
business
,
Wi
wi
)
throws
Exception
{
List
<
Identity
>
identities
=
business
.
identity
().
pick
(
wi
.
getIdentityList
());
List
<
String
>
names
=
ListTools
.
extractProperty
(
identities
,
JpaObject
.
DISTINGUISHEDNAME
,
String
.
class
,
true
,
true
);
EntityManager
em
=
business
.
entityManagerContainer
().
get
(
Empower
.
class
);
CriteriaBuilder
cb
=
em
.
getCriteriaBuilder
();
CriteriaQuery
<
Empower
>
cq
=
cb
.
createQuery
(
Empower
.
class
);
Root
<
Empower
>
root
=
cq
.
from
(
Empower
.
class
);
Predicate
p
=
cb
.
or
(
cb
.
equal
(
root
.
get
(
Empower_
.
type
),
Empower
.
TYPE_ALL
),
cb
.
and
(
cb
.
equal
(
root
.
get
(
Empower_
.
type
),
Empower
.
TYPE_APPLICATION
),
cb
.
equal
(
root
.
get
(
Empower_
.
application
),
wi
.
getApplication
())),
cb
.
and
(
cb
.
equal
(
root
.
get
(
Empower_
.
type
),
Empower
.
TYPE_PROCESS
),
cb
.
or
(
cb
.
and
(
cb
.
isNotNull
(
root
.
get
(
Empower_
.
edition
)),
cb
.
notEqual
(
root
.
get
(
Empower_
.
edition
),
""
),
cb
.
equal
(
root
.
get
(
Empower_
.
edition
),
wi
.
getEdition
())),
cb
.
equal
(
root
.
get
(
Empower_
.
process
),
wi
.
getProcess
()))),
cb
.
and
(
cb
.
equal
(
root
.
get
(
Empower_
.
type
),
Empower
.
TYPE_FILTER
),
cb
.
or
(
cb
.
and
(
cb
.
isNotNull
(
root
.
get
(
Empower_
.
edition
)),
cb
.
notEqual
(
root
.
get
(
Empower_
.
edition
),
""
),
cb
.
equal
(
root
.
get
(
Empower_
.
edition
),
wi
.
getEdition
())),
cb
.
equal
(
root
.
get
(
Empower_
.
process
),
wi
.
getProcess
()))));
p
=
cb
.
and
(
p
,
root
.
get
(
Empower_
.
fromIdentity
).
in
(
names
));
p
=
cb
.
and
(
p
,
cb
.
equal
(
root
.
get
(
Empower_
.
enable
),
true
));
p
=
cb
.
and
(
p
,
cb
.
lessThan
(
root
.
get
(
Empower_
.
startTime
),
new
Date
()),
cb
.
greaterThan
(
root
.
get
(
Empower_
.
completedTime
),
new
Date
()));
return
em
.
createQuery
(
cq
.
select
(
root
).
where
(
p
)).
getResultList
().
stream
().
distinct
().
collect
(
Collectors
.
toList
());
}
@FieldDescribe
(
"工作"
)
private
String
work
;
@FieldDescribe
(
"身份"
)
private
List
<
String
>
identityList
=
new
ArrayList
<>();
public
List
<
String
>
getIdentityList
()
{
return
identityList
;
}
public
void
setIdentityList
(
List
<
String
>
identityList
)
{
this
.
identityList
=
identityList
;
}
public
String
getApplication
()
{
return
application
;
}
public
void
setApplication
(
String
application
)
{
this
.
application
=
application
;
}
public
String
getProcess
()
{
return
process
;
}
public
void
setProcess
(
String
process
)
{
this
.
process
=
process
;
}
public
String
getWork
()
{
return
work
;
}
public
void
setWork
(
String
work
)
{
this
.
work
=
work
;
}
public
String
getEdition
()
{
return
edition
;
}
public
void
setEdition
(
String
edition
)
{
this
.
edition
=
edition
;
}
}
public
static
class
Wo
extends
Empower
{
private
static
final
long
serialVersionUID
=
1559687446726204650L
;
public
Wo
()
{
}
public
Wo
(
String
fromIdentity
,
String
toIdentity
)
{
this
.
setFromIdentity
(
fromIdentity
);
this
.
setToIdentity
(
toIdentity
);
}
}
private
List
<
Wo
>
convert
(
Business
business
,
Wi
wi
)
throws
Exception
{
List
<
Wo
>
wos
=
new
ArrayList
<>();
Map
<
String
,
List
<
Empower
>>
map
=
this
.
list
(
business
,
wi
).
stream
()
.
collect
(
Collectors
.
groupingBy
(
Empower:
:
getFromIdentity
));
for
(
String
str
:
wi
.
getIdentityList
())
{
List
<
Empower
>
list
=
map
.
get
(
str
);
if
(
ListTools
.
isNotEmpty
(
list
))
{
list
.
sort
(
new
EmpowerComparator
());
Empower
empower
=
this
.
pick
(
business
,
list
,
wi
.
getWork
());
if
(
null
!=
empower
)
{
Wo
wo
=
new
Wo
(
str
,
str
);
wo
.
setToIdentity
(
list
.
get
(
0
).
getToIdentity
());
wos
.
add
(
wo
);
}
}
}
return
wos
;
}
private
Empower
pick
(
Business
business
,
List
<
Empower
>
list
,
String
work
)
throws
Exception
{
for
(
Empower
empower
:
list
)
{
if
(
StringUtils
.
equals
(
Empower
.
TYPE_FILTER
,
empower
.
getType
())
&&
StringUtils
.
isNotEmpty
(
empower
.
getFilterListData
()))
{
List
<
Filter
>
filters
=
gson
.
fromJson
(
empower
.
getFilterListData
(),
Filter
.
LISTTYPE
);
Filter
filter
=
filters
.
get
(
0
);
ActionResponse
response
=
ThisApplication
.
context
().
applications
().
getQuery
(
x_processplatform_assemble_surface
.
class
,
Applications
.
joinQueryUri
(
"data"
,
"work"
,
work
)
+
"/"
+
StringUtils
.
replace
(
filter
.
path
,
"."
,
"/"
));
if
(
null
!=
response
.
getData
())
{
if
(
StringUtils
.
equals
(
filter
.
value
,
response
.
getData
().
getAsString
()))
{
return
empower
;
}
}
else
{
return
empower
;
}
}
}
return
list
.
get
(
0
);
}
private
class
EmpowerComparator
implements
Comparator
<
Empower
>
{
public
int
compare
(
Empower
o1
,
Empower
o2
)
{
if
(
StringUtils
.
equals
(
Empower
.
TYPE_FILTER
,
o1
.
getType
()))
{
return
-
1
;
}
else
if
(
StringUtils
.
equals
(
Empower
.
TYPE_FILTER
,
o2
.
getType
()))
{
return
1
;
}
else
if
(
StringUtils
.
equals
(
Empower
.
TYPE_PROCESS
,
o1
.
getType
()))
{
return
-
1
;
}
else
if
(
StringUtils
.
equals
(
Empower
.
TYPE_PROCESS
,
o2
.
getType
()))
{
return
1
;
}
else
if
(
StringUtils
.
equals
(
Empower
.
TYPE_APPLICATION
,
o1
.
getType
()))
{
return
-
1
;
}
else
if
(
StringUtils
.
equals
(
Empower
.
TYPE_APPLICATION
,
o2
.
getType
()))
{
return
1
;
}
else
{
return
0
;
}
}
}
private
List
<
Empower
>
list
(
Business
business
,
Wi
wi
)
throws
Exception
{
List
<
Identity
>
identities
=
business
.
identity
().
pick
(
wi
.
getIdentityList
());
List
<
String
>
names
=
ListTools
.
extractProperty
(
identities
,
JpaObject
.
DISTINGUISHEDNAME
,
String
.
class
,
true
,
true
);
EntityManager
em
=
business
.
entityManagerContainer
().
get
(
Empower
.
class
);
CriteriaBuilder
cb
=
em
.
getCriteriaBuilder
();
CriteriaQuery
<
Empower
>
cq
=
cb
.
createQuery
(
Empower
.
class
);
Root
<
Empower
>
root
=
cq
.
from
(
Empower
.
class
);
Predicate
p
=
cb
.
or
(
cb
.
equal
(
root
.
get
(
Empower_
.
type
),
Empower
.
TYPE_ALL
),
cb
.
and
(
cb
.
equal
(
root
.
get
(
Empower_
.
type
),
Empower
.
TYPE_APPLICATION
),
cb
.
equal
(
root
.
get
(
Empower_
.
application
),
wi
.
getApplication
())),
cb
.
and
(
cb
.
equal
(
root
.
get
(
Empower_
.
type
),
Empower
.
TYPE_PROCESS
),
cb
.
or
(
cb
.
and
(
cb
.
isNotNull
(
root
.
get
(
Empower_
.
edition
)),
cb
.
notEqual
(
root
.
get
(
Empower_
.
edition
),
""
),
cb
.
equal
(
root
.
get
(
Empower_
.
edition
),
wi
.
getEdition
())),
cb
.
equal
(
root
.
get
(
Empower_
.
process
),
wi
.
getProcess
()))),
cb
.
and
(
cb
.
equal
(
root
.
get
(
Empower_
.
type
),
Empower
.
TYPE_FILTER
),
cb
.
or
(
cb
.
and
(
cb
.
isNotNull
(
root
.
get
(
Empower_
.
edition
)),
cb
.
notEqual
(
root
.
get
(
Empower_
.
edition
),
""
),
cb
.
equal
(
root
.
get
(
Empower_
.
edition
),
wi
.
getEdition
())),
cb
.
equal
(
root
.
get
(
Empower_
.
process
),
wi
.
getProcess
()))));
p
=
cb
.
and
(
p
,
root
.
get
(
Empower_
.
fromIdentity
).
in
(
names
));
p
=
cb
.
and
(
p
,
cb
.
equal
(
root
.
get
(
Empower_
.
enable
),
true
));
p
=
cb
.
and
(
p
,
cb
.
lessThan
(
root
.
get
(
Empower_
.
startTime
),
new
Date
()),
cb
.
greaterThan
(
root
.
get
(
Empower_
.
completedTime
),
new
Date
()));
List
<
Empower
>
os
=
em
.
createQuery
(
cq
.
select
(
root
).
where
(
p
)).
getResultList
().
stream
().
distinct
()
.
collect
(
Collectors
.
toList
());
return
os
;
}
}
\ No newline at end of file
o2server/x_organization_assemble_express/src/main/java/com/x/organization/assemble/express/jaxrs/empower/EmpowerAction.java
浏览文件 @
ff4071f5
...
...
@@ -27,7 +27,7 @@ import com.x.base.core.project.logger.LoggerFactory;
@JaxrsDescribe
(
"授权接口"
)
public
class
EmpowerAction
extends
StandardJaxrsAction
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
EmpowerAction
.
class
);
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
EmpowerAction
.
class
);
@JaxrsMethodDescribe
(
value
=
"查找指定人员的委托办理."
,
action
=
ActionListWithIdentityObject
.
class
)
@POST
...
...
@@ -41,7 +41,7 @@ public class EmpowerAction extends StandardJaxrsAction {
try
{
result
=
new
ActionListWithIdentityObject
().
execute
(
effectivePerson
,
jsonElement
);
}
catch
(
Exception
e
)
{
logger
.
error
(
e
,
effectivePerson
,
request
,
jsonElement
);
LOGGER
.
error
(
e
,
effectivePerson
,
request
,
jsonElement
);
result
.
error
(
e
);
}
asyncResponse
.
resume
(
ResponseFactory
.
getEntityTagActionResultResponse
(
request
,
result
,
jsonElement
));
...
...
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/processor/manual/ManualProcessor.java
浏览文件 @
ff4071f5
...
...
@@ -330,7 +330,9 @@ public class ManualProcessor extends AbstractManualProcessor {
if
(!(
StringUtils
.
equals
(
aeiObjects
.
getWork
().
getWorkCreateType
(),
Work
.
WORKCREATETYPE_SURFACE
)
&&
BooleanUtils
.
isFalse
(
aeiObjects
.
getWork
().
getWorkThroughManual
())))
{
List
<
String
>
values
=
taskIdentities
.
identities
();
values
=
ListUtils
.
subtract
(
values
,
aeiObjects
.
getProcessingAttributes
().
getIgnoreEmpowerIdentityList
());
taskIdentities
.
empower
(
aeiObjects
.
business
().
organization
().
empower
().
listWithIdentityObject
(
aeiObjects
.
getWork
().
getApplication
(),
aeiObjects
.
getProcess
().
getEdition
(),
aeiObjects
.
getWork
().
getProcess
(),
aeiObjects
.
getWork
().
getId
(),
values
));
...
...
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/schedule/LogLongDetained.java
浏览文件 @
ff4071f5
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录