Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
platform
/
platform-process-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 2d9b00fc
authored
Sep 15, 2023
by
zhouhaibao
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]admin监控添加
1 parent
733e47f0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
222 additions
and
188 deletions
platform-process/pom.xml
platform-process/src/main/java/cn/com/glsx/Application.java
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/core/XxlJobUtil.java
platform-process/src/main/java/cn/com/glsx/process/modules/controller/TestXXLJobController.java
platform-process/src/main/java/cn/com/glsx/process/modules/service/UserDemoService.java
platform-process/pom.xml
View file @
2d9b00f
...
@@ -95,7 +95,27 @@
...
@@ -95,7 +95,27 @@
<groupId>
com.glsx
</groupId>
<groupId>
com.glsx
</groupId>
<artifactId>
rest-admin-redis
</artifactId>
<artifactId>
rest-admin-redis
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
<dependency>
<groupId>
de.codecentric
</groupId>
<artifactId>
spring-boot-admin-starter-client
</artifactId>
<version>
2.6.11
</version>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<version>
1.16.14
</version>
<scope>
provided
</scope>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
platform-process/src/main/java/cn/com/glsx/Application.java
View file @
2d9b00f
...
@@ -34,6 +34,8 @@ public class Application implements CommandLineRunner {
...
@@ -34,6 +34,8 @@ public class Application implements CommandLineRunner {
SpringApplication
.
run
(
Application
.
class
,
args
);
SpringApplication
.
run
(
Application
.
class
,
args
);
}
}
@PostConstruct
@PostConstruct
void
started
()
{
void
started
()
{
TimeZone
.
setDefault
(
getTimeZone
(
of
(
"Asia/Shanghai"
)));
TimeZone
.
setDefault
(
getTimeZone
(
of
(
"Asia/Shanghai"
)));
...
...
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/core/XxlJobUtil.java
View file @
2d9b00f
...
@@ -20,186 +20,192 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -20,186 +20,192 @@ import lombok.extern.slf4j.Slf4j;
@Component
@Component
@Slf4j
@Slf4j
public
class
XxlJobUtil
{
public
class
XxlJobUtil
{
public
static
final
int
SUCCESS_CODE
=
200
;
public
static
final
int
SUCCESS_CODE
=
200
;
private
static
String
adminAddresses
;
private
static
String
adminAddresses
;
private
static
String
appname
;
private
static
String
appname
;
private
static
Integer
groupId
;
private
static
Integer
groupId
;
private
static
String
accessToken
;
private
static
String
accessToken
;
private
static
String
cookie
=
""
;
private
static
String
cookie
=
""
;
@Value
(
"${xxl.job.admin.addresses}"
)
@Value
(
"${xxl.job.admin.addresses}"
)
public
void
setAdminAddresses
(
String
adminAddresses
)
{
public
void
setAdminAddresses
(
String
adminAddresses
)
{
XxlJobUtil
.
adminAddresses
=
adminAddresses
;
XxlJobUtil
.
adminAddresses
=
adminAddresses
;
}
}
@Value
(
"${xxl.job.accessToken}"
)
@Value
(
"${xxl.job.accessToken}"
)
public
void
setAccessToken
(
String
accessToken
)
{
public
void
setAccessToken
(
String
accessToken
)
{
XxlJobUtil
.
accessToken
=
accessToken
;
XxlJobUtil
.
accessToken
=
accessToken
;
}
}
@Value
(
"${xxl.job.executor.appname}"
)
@Value
(
"${xxl.job.executor.appname}"
)
public
void
setAppname
(
String
appname
)
{
public
void
setAppname
(
String
appname
)
{
XxlJobUtil
.
appname
=
appname
;
XxlJobUtil
.
appname
=
appname
;
}
}
@Value
(
"${xxl.job.executor.groupId}"
)
@Value
(
"${xxl.job.executor.groupId}"
)
public
void
setGroupId
(
Integer
groupId
)
{
public
void
setGroupId
(
Integer
groupId
)
{
XxlJobUtil
.
groupId
=
groupId
;
XxlJobUtil
.
groupId
=
groupId
;
}
}
private
static
final
String
ADD_URL
=
"/jobinfo/postadd"
;
private
static
final
String
ADD_URL
=
"/jobinfo/postadd"
;
private
static
final
String
UPDATE_URL
=
"/jobinfo/postupdate"
;
private
static
final
String
UPDATE_URL
=
"/jobinfo/postupdate"
;
private
static
final
String
REMOVE_URL
=
"/jobinfo/remove"
;
private
static
final
String
REMOVE_URL
=
"/jobinfo/remove"
;
private
static
final
String
PAUSE_URL
=
"/jobinfo/stop"
;
private
static
final
String
PAUSE_URL
=
"/jobinfo/stop"
;
private
static
final
String
START_URL
=
"/jobinfo/start"
;
private
static
final
String
START_URL
=
"/jobinfo/start"
;
private
static
final
String
ADD_AND_START_URL
=
"/jobinfo/trigger"
;
private
static
final
String
ADD_AND_START_URL
=
"/jobinfo/trigger"
;
private
static
final
String
FINDBYBUSKEY
=
"/jobinfo/findByBusKey"
;
private
static
final
String
FINDBYBUSKEY
=
"/jobinfo/findByBusKey"
;
private
static
final
String
GET_GROUP_ID
=
"/jobgroup/pageList"
;
private
static
final
String
GET_GROUP_ID
=
"/jobgroup/pageList"
;
private
static
final
String
LOGIN
=
"/login"
;
private
static
final
String
LOGIN
=
"/login"
;
/**
/**
* 添加任务
* 添加任务
*
*
* @param jobInfo 任务信息
* @param jobInfo 任务信息
* @return {@link String} 任务id
* @return {@link String} 任务id
**/
**/
public
static
String
add
(
XxlJobInfo
jobInfo
)
{
public
static
String
add
(
XxlJobInfo
jobInfo
)
{
jobInfo
.
setJobGroup
(
groupId
);
jobInfo
.
setJobGroup
(
groupId
);
jobInfo
.
setGlueType
(
"BEAN"
);
jobInfo
.
setGlueType
(
"BEAN"
);
jobInfo
.
setExecutorBlockStrategy
(
"SERIAL_EXECUTION"
);
jobInfo
.
setExecutorBlockStrategy
(
"SERIAL_EXECUTION"
);
jobInfo
.
setExecutorRouteStrategy
(
"FIRST"
);
jobInfo
.
setExecutorRouteStrategy
(
"FIRST"
);
jobInfo
.
setMisfireStrategy
(
"DO_NOTHING"
);
jobInfo
.
setMisfireStrategy
(
"DO_NOTHING"
);
jobInfo
.
setScheduleType
(
ScheduleTypeEnum
.
CRON
.
name
());
jobInfo
.
setScheduleType
(
ScheduleTypeEnum
.
CRON
.
name
());
return
doPost
(
adminAddresses
+
ADD_URL
,
jobInfo
,
String
.
class
);
return
doPost
(
adminAddresses
+
ADD_URL
,
jobInfo
,
String
.
class
);
}
}
/**
/**
* 修改执行时间
* 修改执行时间
*
*
* @return {@link String}
* @return {@link String}
**/
**/
public
static
String
update
(
XxlJobInfo
jobInfo
)
{
public
static
String
update
(
XxlJobInfo
jobInfo
)
{
return
doPost
(
adminAddresses
+
UPDATE_URL
,
jobInfo
,
String
.
class
);
String
busKey
=
jobInfo
.
getBusKey
();
}
XxlJobInfo
byBusKey
=
findByBusKey
(
busKey
);
if
(
byBusKey
!=
null
)
{
/**
jobInfo
.
setId
(
byBusKey
.
getId
());
* 删除任务
return
doPost
(
adminAddresses
+
UPDATE_URL
,
jobInfo
,
String
.
class
);
*
}
* @param buskey 业务key
return
null
;
* @return {@link String}
}
**/
public
static
String
remove
(
String
buskey
)
{
/**
XxlJobInfo
byBusKey
=
findByBusKey
(
buskey
);
* 删除任务
if
(
byBusKey
!=
null
)
{
*
return
doPost
(
adminAddresses
+
REMOVE_URL
+
"?id="
+
byBusKey
.
getId
(),
null
,
String
.
class
);
* @param buskey 业务key
}
* @return {@link String}
return
null
;
**/
}
public
static
String
remove
(
String
buskey
)
{
XxlJobInfo
byBusKey
=
findByBusKey
(
buskey
);
/**
if
(
byBusKey
!=
null
)
{
* 暂停任务
return
doPost
(
adminAddresses
+
REMOVE_URL
+
"?id="
+
byBusKey
.
getId
(),
null
,
String
.
class
);
*
}
* @param buskey 业务key
return
null
;
* @return {@link String}
}
**/
public
static
String
pause
(
String
buskey
)
{
/**
XxlJobInfo
byBusKey
=
findByBusKey
(
buskey
);
* 暂停任务
if
(
byBusKey
!=
null
)
{
*
return
doPost
(
adminAddresses
+
PAUSE_URL
+
"?id="
+
byBusKey
.
getId
(),
null
,
String
.
class
);
* @param buskey 业务key
}
* @return {@link String}
return
null
;
**/
}
public
static
String
pause
(
String
buskey
)
{
XxlJobInfo
byBusKey
=
findByBusKey
(
buskey
);
/**
if
(
byBusKey
!=
null
)
{
* 开始任务
return
doPost
(
adminAddresses
+
PAUSE_URL
+
"?id="
+
byBusKey
.
getId
(),
null
,
String
.
class
);
*
}
* @param buskey 业务key
return
null
;
* @return {@link String}
}
**/
public
static
String
start
(
String
buskey
)
{
/**
XxlJobInfo
byBusKey
=
findByBusKey
(
buskey
);
* 开始任务
if
(
byBusKey
!=
null
)
{
*
return
doPost
(
adminAddresses
+
START_URL
+
"?id="
+
byBusKey
.
getId
(),
null
,
String
.
class
);
* @param buskey 业务key
}
* @return {@link String}
return
null
;
**/
}
public
static
String
start
(
String
buskey
)
{
XxlJobInfo
byBusKey
=
findByBusKey
(
buskey
);
/**
if
(
byBusKey
!=
null
)
{
* 添加并启动
return
doPost
(
adminAddresses
+
START_URL
+
"?id="
+
byBusKey
.
getId
(),
null
,
String
.
class
);
*
}
* @param buskey 业务key
return
null
;
* @return {@link String}
}
**/
public
static
String
trigger
(
String
buskey
)
{
/**
XxlJobInfo
byBusKey
=
findByBusKey
(
buskey
);
* 添加并启动
if
(
byBusKey
!=
null
)
{
*
return
doPost
(
adminAddresses
+
ADD_AND_START_URL
+
"?id="
+
byBusKey
.
getId
(),
null
,
String
.
class
);
* @param buskey 业务key
}
* @return {@link String}
return
null
;
**/
}
public
static
String
trigger
(
String
buskey
)
{
XxlJobInfo
byBusKey
=
findByBusKey
(
buskey
);
/**
if
(
byBusKey
!=
null
)
{
* 根据业务id查询tigger
return
doPost
(
adminAddresses
+
ADD_AND_START_URL
+
"?id="
+
byBusKey
.
getId
(),
null
,
String
.
class
);
*
}
* @param busKey 任务信息
return
null
;
* @return {@link String}
}
**/
public
static
XxlJobInfo
findByBusKey
(
String
busKey
)
{
/**
XxlJobInfo
xxlJobInfo
=
doPost
(
adminAddresses
+
FINDBYBUSKEY
+
"?busKey="
+
busKey
+
"&jobGroup="
+
groupId
,
null
,
XxlJobInfo
.
class
);
* 根据业务id查询tigger
return
xxlJobInfo
;
*
}
* @param busKey 任务信息
* @return {@link String}
/**
**/
* 根据业务id查询jobGroup
public
static
XxlJobInfo
findByBusKey
(
String
busKey
)
{
*
XxlJobInfo
xxlJobInfo
=
doPost
(
adminAddresses
+
FINDBYBUSKEY
+
"?busKey="
+
busKey
+
"&jobGroup="
+
groupId
,
null
,
XxlJobInfo
.
class
);
* @return {@link String}
return
xxlJobInfo
;
**/
}
@PostConstruct
public
void
findJobGroup
()
{
/**
/*
* 根据业务id查询jobGroup
* Map resmap = doPost(adminAddresses + GET_GROUP_ID + "?appname=" + appname, null, Map.class);
*
* System.out.println(resmap);
* @return {@link String}
* Object data = resmap.get("data");
**/
* if(data!=null){
@PostConstruct
* String jsonString = JSONObject.toJSONString(data);
public
void
findJobGroup
()
{
* List<Map> maps = JSONObject.parseArray(jsonString, Map.class);
/*
* if(CollectionUtils.isNotEmpty(maps)){
* Map resmap = doPost(adminAddresses + GET_GROUP_ID + "?appname=" + appname, null, Map.class);
* Map map = maps.get(0);
* System.out.println(resmap);
* groupId= (Integer) map.get("id");
* Object data = resmap.get("data");
* }
* if(data!=null){
* }
* String jsonString = JSONObject.toJSONString(data);
*/
* List<Map> maps = JSONObject.parseArray(jsonString, Map.class);
}
* if(CollectionUtils.isNotEmpty(maps)){
* Map map = maps.get(0);
public
static
<
T
>
T
doPost
(
String
url
,
Object
json
,
Class
<
T
>
clazz
)
{
* groupId= (Integer) map.get("id");
log
.
info
(
"请求url{},请求参数{} {}:{}"
,
url
,
JSONObject
.
toJSONString
(
json
),
XxlJobRemotingUtil
.
XXL_JOB_ACCESS_TOKEN
,
accessToken
);
* }
ReturnT
<
T
>
returnT
=
XxlJobRemotingUtil
.
postBody
(
url
,
accessToken
,
30
,
json
,
clazz
);
* }
if
(
returnT
.
getCode
()
!=
SUCCESS_CODE
)
{
*/
log
.
info
(
String
.
format
(
"【xxl-job】接口调用失败,错误码:%s,原因:%s"
,
returnT
.
getCode
(),
returnT
.
getMsg
()));
}
}
return
returnT
.
getContent
();
public
static
<
T
>
T
doPost
(
String
url
,
Object
json
,
Class
<
T
>
clazz
)
{
}
log
.
info
(
"请求url{},请求参数{} {}:{}"
,
url
,
JSONObject
.
toJSONString
(
json
),
XxlJobRemotingUtil
.
XXL_JOB_ACCESS_TOKEN
,
accessToken
);
ReturnT
<
T
>
returnT
=
XxlJobRemotingUtil
.
postBody
(
url
,
accessToken
,
30
,
json
,
clazz
);
/**
if
(
returnT
.
getCode
()
!=
SUCCESS_CODE
)
{
* 登录
log
.
info
(
String
.
format
(
"【xxl-job】接口调用失败,错误码:%s,原因:%s"
,
returnT
.
getCode
(),
returnT
.
getMsg
()));
*
}
* @param url
return
returnT
.
getContent
();
* @param userName
}
* @param password
* @return
/**
* @throws HttpException
* 登录
* @throws IOException
*
*/
* @param url
* @param userName
public
static
String
login
(
String
userName
,
String
password
)
{
* @param password
HttpResponse
rsp
=
HttpUtil
.
createGet
(
adminAddresses
+
"/api/jobinfo/login?userName="
+
userName
+
"&password="
+
password
).
execute
();
* @return
List
<
HttpCookie
>
cookies
=
rsp
.
getCookies
();
* @throws HttpException
StringBuffer
tmpcookies
=
new
StringBuffer
();
* @throws IOException
for
(
HttpCookie
c
:
cookies
)
{
*/
tmpcookies
.
append
(
c
.
toString
()
+
";"
);
}
public
static
String
login
(
String
userName
,
String
password
)
{
cookie
=
tmpcookies
.
toString
();
HttpResponse
rsp
=
HttpUtil
.
createGet
(
adminAddresses
+
"/api/jobinfo/login?userName="
+
userName
+
"&password="
+
password
).
execute
();
return
cookie
;
List
<
HttpCookie
>
cookies
=
rsp
.
getCookies
();
}
StringBuffer
tmpcookies
=
new
StringBuffer
();
for
(
HttpCookie
c
:
cookies
)
{
tmpcookies
.
append
(
c
.
toString
()
+
";"
);
}
cookie
=
tmpcookies
.
toString
();
return
cookie
;
}
}
}
platform-process/src/main/java/cn/com/glsx/process/modules/controller/TestXXLJobController.java
View file @
2d9b00f
...
@@ -42,11 +42,17 @@ public class TestXXLJobController {
...
@@ -42,11 +42,17 @@ public class TestXXLJobController {
@PostMapping
(
"/jobtestupdate"
)
@PostMapping
(
"/jobtestupdate"
)
@Operation
(
summary
=
"动态任务更新"
,
description
=
"动态任务更新"
)
@Operation
(
summary
=
"动态任务更新"
,
description
=
"动态任务更新"
)
public
void
updatetest
(
@RequestParam
(
"cron"
)
String
cron
,
@RequestParam
(
"id"
)
Integer
id
)
{
public
void
updatetest
(
@RequestParam
(
"cron"
)
String
cron
,
@RequestParam
(
"id"
)
String
id
,
@RequestParam
(
"executorParam"
)
String
executorParam
,
@RequestParam
(
"jobDesc"
)
String
jobDesc
,
@RequestParam
(
"triggerStatus"
)
Integer
triggerStatus
)
{
XxlJobInfo
jobInfo
=
new
XxlJobInfo
();
XxlJobInfo
jobInfo
=
new
XxlJobInfo
();
jobInfo
.
set
Id
(
id
);
jobInfo
.
set
BusKey
(
id
);
jobInfo
.
setScheduleConf
(
cron
);
jobInfo
.
setScheduleConf
(
cron
);
jobInfo
.
setJobDesc
(
jobDesc
);
jobInfo
.
setExecutorParam
(
executorParam
);
jobInfo
.
setTriggerStatus
(
triggerStatus
);
XxlJobUtil
.
update
(
jobInfo
);
XxlJobUtil
.
update
(
jobInfo
);
}
}
...
...
platform-process/src/main/java/cn/com/glsx/process/modules/service/UserDemoService.java
View file @
2d9b00f
package
cn
.
com
.
glsx
.
process
.
modules
.
service
;
package
cn
.
com
.
glsx
.
process
.
modules
.
service
;
import
cn.com.glsx.process.job.xxljob.core.ExecutorRouteStrategyEnum
;
import
cn.com.glsx.process.modules.converter.UserConverter
;
import
cn.com.glsx.process.modules.converter.UserConverter
;
import
cn.com.glsx.process.modules.entity.User
;
import
cn.com.glsx.process.modules.entity.User
;
import
cn.com.glsx.process.modules.mapper.UserMapper
;
import
cn.com.glsx.process.modules.mapper.UserMapper
;
import
cn.com.glsx.process.modules.model.UserDTO
;
import
cn.com.glsx.process.modules.model.UserDTO
;
import
cn.com.glsx.process.modules.model.UserSearch
;
import
cn.com.glsx.process.modules.model.UserSearch
;
import
cn.com.glsx.process.redis.DistributedLock
;
import
cn.com.glsx.process.redis.DistributedLockUtils
;
import
cn.com.glsx.process.redis.DistributedLockUtils
;
import
com.github.pagehelper.PageInfo
;
import
com.github.pagehelper.PageInfo
;
import
com.glsx.plat.common.utils.ObjectUtils
;
import
com.glsx.plat.common.utils.ObjectUtils
;
...
@@ -146,7 +146,7 @@ public class UserDemoService {
...
@@ -146,7 +146,7 @@ public class UserDemoService {
}
}
private
void
aa
(
User
user
)
throws
InterruptedException
{
private
void
aa
(
User
user
)
throws
InterruptedException
{
System
.
out
.
println
(
"user"
);
System
.
out
.
println
(
ExecutorRouteStrategyEnum
.
FIRST
.
name
()
);
Thread
.
sleep
(
10
*
1000
);
Thread
.
sleep
(
10
*
1000
);
}
}
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment