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 @@
<groupId>
com.glsx
</groupId>
<artifactId>
rest-admin-redis
</artifactId>
</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>
<build>
...
...
platform-process/src/main/java/cn/com/glsx/Application.java
View file @
2d9b00f
...
...
@@ -34,6 +34,8 @@ public class Application implements CommandLineRunner {
SpringApplication
.
run
(
Application
.
class
,
args
);
}
@PostConstruct
void
started
()
{
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;
@Component
@Slf4j
public
class
XxlJobUtil
{
public
static
final
int
SUCCESS_CODE
=
200
;
private
static
String
adminAddresses
;
private
static
String
appname
;
private
static
Integer
groupId
;
private
static
String
accessToken
;
private
static
String
cookie
=
""
;
@Value
(
"${xxl.job.admin.addresses}"
)
public
void
setAdminAddresses
(
String
adminAddresses
)
{
XxlJobUtil
.
adminAddresses
=
adminAddresses
;
}
@Value
(
"${xxl.job.accessToken}"
)
public
void
setAccessToken
(
String
accessToken
)
{
XxlJobUtil
.
accessToken
=
accessToken
;
}
@Value
(
"${xxl.job.executor.appname}"
)
public
void
setAppname
(
String
appname
)
{
XxlJobUtil
.
appname
=
appname
;
}
@Value
(
"${xxl.job.executor.groupId}"
)
public
void
setGroupId
(
Integer
groupId
)
{
XxlJobUtil
.
groupId
=
groupId
;
}
private
static
final
String
ADD_URL
=
"/jobinfo/postadd"
;
private
static
final
String
UPDATE_URL
=
"/jobinfo/postupdate"
;
private
static
final
String
REMOVE_URL
=
"/jobinfo/remove"
;
private
static
final
String
PAUSE_URL
=
"/jobinfo/stop"
;
private
static
final
String
START_URL
=
"/jobinfo/start"
;
private
static
final
String
ADD_AND_START_URL
=
"/jobinfo/trigger"
;
private
static
final
String
FINDBYBUSKEY
=
"/jobinfo/findByBusKey"
;
private
static
final
String
GET_GROUP_ID
=
"/jobgroup/pageList"
;
private
static
final
String
LOGIN
=
"/login"
;
/**
* 添加任务
*
* @param jobInfo 任务信息
* @return {@link String} 任务id
**/
public
static
String
add
(
XxlJobInfo
jobInfo
)
{
jobInfo
.
setJobGroup
(
groupId
);
jobInfo
.
setGlueType
(
"BEAN"
);
jobInfo
.
setExecutorBlockStrategy
(
"SERIAL_EXECUTION"
);
jobInfo
.
setExecutorRouteStrategy
(
"FIRST"
);
jobInfo
.
setMisfireStrategy
(
"DO_NOTHING"
);
jobInfo
.
setScheduleType
(
ScheduleTypeEnum
.
CRON
.
name
());
return
doPost
(
adminAddresses
+
ADD_URL
,
jobInfo
,
String
.
class
);
}
/**
* 修改执行时间
*
* @return {@link String}
**/
public
static
String
update
(
XxlJobInfo
jobInfo
)
{
return
doPost
(
adminAddresses
+
UPDATE_URL
,
jobInfo
,
String
.
class
);
}
/**
* 删除任务
*
* @param buskey 业务key
* @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
);
}
return
null
;
}
/**
* 暂停任务
*
* @param buskey 业务key
* @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
);
}
return
null
;
}
/**
* 开始任务
*
* @param buskey 业务key
* @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
);
}
return
null
;
}
/**
* 添加并启动
*
* @param buskey 业务key
* @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
);
}
return
null
;
}
/**
* 根据业务id查询tigger
*
* @param busKey 任务信息
* @return {@link String}
**/
public
static
XxlJobInfo
findByBusKey
(
String
busKey
)
{
XxlJobInfo
xxlJobInfo
=
doPost
(
adminAddresses
+
FINDBYBUSKEY
+
"?busKey="
+
busKey
+
"&jobGroup="
+
groupId
,
null
,
XxlJobInfo
.
class
);
return
xxlJobInfo
;
}
/**
* 根据业务id查询jobGroup
*
* @return {@link String}
**/
@PostConstruct
public
void
findJobGroup
()
{
/*
* Map resmap = doPost(adminAddresses + GET_GROUP_ID + "?appname=" + appname, null, Map.class);
* System.out.println(resmap);
* 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);
* groupId= (Integer) map.get("id");
* }
* }
*/
}
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
()));
}
return
returnT
.
getContent
();
}
/**
* 登录
*
* @param url
* @param userName
* @param password
* @return
* @throws HttpException
* @throws IOException
*/
public
static
String
login
(
String
userName
,
String
password
)
{
HttpResponse
rsp
=
HttpUtil
.
createGet
(
adminAddresses
+
"/api/jobinfo/login?userName="
+
userName
+
"&password="
+
password
).
execute
();
List
<
HttpCookie
>
cookies
=
rsp
.
getCookies
();
StringBuffer
tmpcookies
=
new
StringBuffer
();
for
(
HttpCookie
c
:
cookies
)
{
tmpcookies
.
append
(
c
.
toString
()
+
";"
);
}
cookie
=
tmpcookies
.
toString
();
return
cookie
;
}
public
static
final
int
SUCCESS_CODE
=
200
;
private
static
String
adminAddresses
;
private
static
String
appname
;
private
static
Integer
groupId
;
private
static
String
accessToken
;
private
static
String
cookie
=
""
;
@Value
(
"${xxl.job.admin.addresses}"
)
public
void
setAdminAddresses
(
String
adminAddresses
)
{
XxlJobUtil
.
adminAddresses
=
adminAddresses
;
}
@Value
(
"${xxl.job.accessToken}"
)
public
void
setAccessToken
(
String
accessToken
)
{
XxlJobUtil
.
accessToken
=
accessToken
;
}
@Value
(
"${xxl.job.executor.appname}"
)
public
void
setAppname
(
String
appname
)
{
XxlJobUtil
.
appname
=
appname
;
}
@Value
(
"${xxl.job.executor.groupId}"
)
public
void
setGroupId
(
Integer
groupId
)
{
XxlJobUtil
.
groupId
=
groupId
;
}
private
static
final
String
ADD_URL
=
"/jobinfo/postadd"
;
private
static
final
String
UPDATE_URL
=
"/jobinfo/postupdate"
;
private
static
final
String
REMOVE_URL
=
"/jobinfo/remove"
;
private
static
final
String
PAUSE_URL
=
"/jobinfo/stop"
;
private
static
final
String
START_URL
=
"/jobinfo/start"
;
private
static
final
String
ADD_AND_START_URL
=
"/jobinfo/trigger"
;
private
static
final
String
FINDBYBUSKEY
=
"/jobinfo/findByBusKey"
;
private
static
final
String
GET_GROUP_ID
=
"/jobgroup/pageList"
;
private
static
final
String
LOGIN
=
"/login"
;
/**
* 添加任务
*
* @param jobInfo 任务信息
* @return {@link String} 任务id
**/
public
static
String
add
(
XxlJobInfo
jobInfo
)
{
jobInfo
.
setJobGroup
(
groupId
);
jobInfo
.
setGlueType
(
"BEAN"
);
jobInfo
.
setExecutorBlockStrategy
(
"SERIAL_EXECUTION"
);
jobInfo
.
setExecutorRouteStrategy
(
"FIRST"
);
jobInfo
.
setMisfireStrategy
(
"DO_NOTHING"
);
jobInfo
.
setScheduleType
(
ScheduleTypeEnum
.
CRON
.
name
());
return
doPost
(
adminAddresses
+
ADD_URL
,
jobInfo
,
String
.
class
);
}
/**
* 修改执行时间
*
* @return {@link String}
**/
public
static
String
update
(
XxlJobInfo
jobInfo
)
{
String
busKey
=
jobInfo
.
getBusKey
();
XxlJobInfo
byBusKey
=
findByBusKey
(
busKey
);
if
(
byBusKey
!=
null
)
{
jobInfo
.
setId
(
byBusKey
.
getId
());
return
doPost
(
adminAddresses
+
UPDATE_URL
,
jobInfo
,
String
.
class
);
}
return
null
;
}
/**
* 删除任务
*
* @param buskey 业务key
* @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
);
}
return
null
;
}
/**
* 暂停任务
*
* @param buskey 业务key
* @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
);
}
return
null
;
}
/**
* 开始任务
*
* @param buskey 业务key
* @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
);
}
return
null
;
}
/**
* 添加并启动
*
* @param buskey 业务key
* @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
);
}
return
null
;
}
/**
* 根据业务id查询tigger
*
* @param busKey 任务信息
* @return {@link String}
**/
public
static
XxlJobInfo
findByBusKey
(
String
busKey
)
{
XxlJobInfo
xxlJobInfo
=
doPost
(
adminAddresses
+
FINDBYBUSKEY
+
"?busKey="
+
busKey
+
"&jobGroup="
+
groupId
,
null
,
XxlJobInfo
.
class
);
return
xxlJobInfo
;
}
/**
* 根据业务id查询jobGroup
*
* @return {@link String}
**/
@PostConstruct
public
void
findJobGroup
()
{
/*
* Map resmap = doPost(adminAddresses + GET_GROUP_ID + "?appname=" + appname, null, Map.class);
* System.out.println(resmap);
* 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);
* groupId= (Integer) map.get("id");
* }
* }
*/
}
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
()));
}
return
returnT
.
getContent
();
}
/**
* 登录
*
* @param url
* @param userName
* @param password
* @return
* @throws HttpException
* @throws IOException
*/
public
static
String
login
(
String
userName
,
String
password
)
{
HttpResponse
rsp
=
HttpUtil
.
createGet
(
adminAddresses
+
"/api/jobinfo/login?userName="
+
userName
+
"&password="
+
password
).
execute
();
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 {
@PostMapping
(
"/jobtestupdate"
)
@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
();
jobInfo
.
set
Id
(
id
);
jobInfo
.
set
BusKey
(
id
);
jobInfo
.
setScheduleConf
(
cron
);
jobInfo
.
setJobDesc
(
jobDesc
);
jobInfo
.
setExecutorParam
(
executorParam
);
jobInfo
.
setTriggerStatus
(
triggerStatus
);
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
;
import
cn.com.glsx.process.job.xxljob.core.ExecutorRouteStrategyEnum
;
import
cn.com.glsx.process.modules.converter.UserConverter
;
import
cn.com.glsx.process.modules.entity.User
;
import
cn.com.glsx.process.modules.mapper.UserMapper
;
import
cn.com.glsx.process.modules.model.UserDTO
;
import
cn.com.glsx.process.modules.model.UserSearch
;
import
cn.com.glsx.process.redis.DistributedLock
;
import
cn.com.glsx.process.redis.DistributedLockUtils
;
import
com.github.pagehelper.PageInfo
;
import
com.glsx.plat.common.utils.ObjectUtils
;
...
...
@@ -146,7 +146,7 @@ public class UserDemoService {
}
private
void
aa
(
User
user
)
throws
InterruptedException
{
System
.
out
.
println
(
"user"
);
System
.
out
.
println
(
ExecutorRouteStrategyEnum
.
FIRST
.
name
()
);
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