Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
谢明辉
/
fanxing3
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 4c0f5b97
authored
Aug 25, 2021
by
xmh
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化代码
1 parent
5fc02e5f
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
175 additions
and
97 deletions
fanxing-commons/src/main/java/com/viontech/fanxing/commons/service/RedisService.java
fanxing-commons/src/main/java/com/viontech/fanxing/commons/vo/StoreConfigVo.java
fanxing-forward/src/main/java/com/viontech/fanxing/forward/batch/processor/CompositeItemStreamProcessor.java
fanxing-forward/src/main/java/com/viontech/fanxing/forward/runner/JobStartRunner.java
fanxing-task-manager/src/main/java/com/viontech/fanxing/task/manager/controller/web/StoreConfigController.java
fanxing-task-manager/src/main/java/com/viontech/fanxing/task/manager/controller/web/TaskController.java
fanxing-task-manager/src/main/java/com/viontech/fanxing/task/manager/service/impl/TaskServiceImpl.java
fanxing-task-scheduling/src/main/java/com/viontech/fanxing/task/scheduling/controller/TaskController.java
fanxing-task-scheduling/src/main/java/com/viontech/fanxing/task/scheduling/feign/TaskClient.java
fanxing-task-scheduling/src/main/java/com/viontech/fanxing/task/scheduling/model/RuntimeConfig.java
fanxing-task-scheduling/src/main/java/com/viontech/fanxing/task/scheduling/repository/VAServerRedisRepository.java
fanxing-task-scheduling/src/main/java/com/viontech/fanxing/task/scheduling/runner/TaskRunner.java
fanxing-task-scheduling/src/main/java/com/viontech/fanxing/task/scheduling/service/VAServerHttpService.java
fanxing-task-scheduling/src/main/java/com/viontech/fanxing/task/scheduling/service/VAServerService.java
fanxing-task-scheduling/src/test/java/com/viontech/fanxing/task/scheduling/service/VAServerHttpServiceTest.java
fanxing-commons/src/main/java/com/viontech/fanxing/commons/service/RedisService.java
View file @
4c0f5b9
...
...
@@ -44,7 +44,7 @@ public class RedisService {
while
(!
isLock
)
{
try
{
isLock
=
lock
.
tryLock
(
30
,
25
,
TimeUnit
.
SECONDS
);
}
catch
(
Interrupted
Exception
ignore
)
{
}
catch
(
Exception
ignore
)
{
}
}
return
lock
;
...
...
fanxing-commons/src/main/java/com/viontech/fanxing/commons/vo/StoreConfigVo.java
View file @
4c0f5b9
...
...
@@ -2,8 +2,10 @@ package com.viontech.fanxing.commons.vo;
import
com.viontech.fanxing.commons.model.StoreConfig
;
import
com.viontech.fanxing.commons.vobase.StoreConfigVoBase
;
import
org.springframework.web.multipart.MultipartFile
;
public
class
StoreConfigVo
extends
StoreConfigVoBase
{
private
MultipartFile
file
;
public
StoreConfigVo
()
{
super
();
...
...
@@ -12,4 +14,13 @@ public class StoreConfigVo extends StoreConfigVoBase {
public
StoreConfigVo
(
StoreConfig
storeConfig
)
{
super
(
storeConfig
);
}
public
MultipartFile
getFile
()
{
return
file
;
}
public
StoreConfigVo
setFile
(
MultipartFile
file
)
{
this
.
file
=
file
;
return
this
;
}
}
\ No newline at end of file
fanxing-forward/src/main/java/com/viontech/fanxing/forward/batch/processor/CompositeItemStreamProcessor.java
View file @
4c0f5b9
...
...
@@ -16,15 +16,15 @@ import java.util.List;
* 支持Stream
* Created by suman on 2018/7/19.
*/
public
class
CompositeItemStreamProcessor
<
I
,
O
>
extends
CompositeItemProcessor
<
I
,
O
>
implements
ItemStream
,
ItemProcessor
<
I
,
O
>,
InitializingBean
{
public
class
CompositeItemStreamProcessor
<
I
,
O
>
extends
CompositeItemProcessor
<
I
,
O
>
implements
ItemStream
,
ItemProcessor
<
I
,
O
>,
InitializingBean
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
CompositeItemStreamProcessor
.
class
);
private
boolean
ignoreItemStream
=
false
;
private
Logger
logger
=
LoggerFactory
.
getLogger
(
CompositeItemStreamProcessor
.
class
);
private
List
<?
extends
ItemProcessor
<?,
?>>
delegates
;
public
void
setIgnoreItemStream
(
boolean
ignoreItemStream
)
{
this
.
ignoreItemStream
=
ignoreItemStream
;
}
private
List
<?
extends
ItemProcessor
<?,
?>>
delegates
;
@Override
@SuppressWarnings
(
"unchecked"
)
public
O
process
(
I
item
)
throws
Exception
{
...
...
@@ -37,10 +37,8 @@ public class CompositeItemStreamProcessor<I,O> extends CompositeItemProcessor<I,
long
start
=
System
.
currentTimeMillis
();
result
=
processItem
(
delegate
,
result
);
long
end
=
System
.
currentTimeMillis
();
long
c
=
end
-
start
;
if
(
c
>
1
)
{
logger
.
info
(
delegate
.
getClass
().
getSimpleName
()
+
"Processor执行时间:"
+
(
end
-
start
));
}
long
c
=
end
-
start
;
logger
.
info
(
delegate
.
getClass
().
getSimpleName
()
+
"Processor执行时间:"
+
(
end
-
start
));
}
logger
.
info
(
item
.
getClass
().
getSimpleName
()
+
"整体处理时间:"
+
(
System
.
currentTimeMillis
()
-
startAll
));
return
(
O
)
result
;
...
...
@@ -64,8 +62,9 @@ public class CompositeItemStreamProcessor<I,O> extends CompositeItemProcessor<I,
/**
* Establishes the {@link ItemProcessor} delegates that will work on the item to be
* processed.
*
* @param delegates list of {@link ItemProcessor} delegates that will work on the
* item.
*
item.
*/
@Override
public
void
setDelegates
(
List
<?
extends
ItemProcessor
<?,
?>>
delegates
)
{
...
...
fanxing-forward/src/main/java/com/viontech/fanxing/forward/runner/JobStartRunner.java
View file @
4c0f5b9
...
...
@@ -6,10 +6,10 @@ import org.springframework.batch.core.JobParametersBuilder;
import
org.springframework.batch.core.launch.support.SimpleJobLauncher
;
import
org.springframework.batch.core.repository.JobRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.core.task.SimpleAsyncTaskExecutor
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
...
...
@@ -36,6 +36,8 @@ public class JobStartRunner implements CommandLineRunner {
private
Job
trafficFlowJob
;
@Resource
private
Job
behaviorJob
;
@Value
(
"${vion.forward.enable:false}"
)
private
Boolean
enableForward
;
@Override
public
void
run
(
String
...
args
)
throws
Exception
{
...
...
@@ -43,11 +45,27 @@ public class JobStartRunner implements CommandLineRunner {
sjl
.
setJobRepository
(
jobRepository
);
sjl
.
setTaskExecutor
(
new
SimpleAsyncTaskExecutor
());
sjl
.
afterPropertiesSet
();
JobParameters
jobParameters
=
new
JobParametersBuilder
().
addString
(
"uuid"
,
UUID
.
randomUUID
().
toString
()).
toJobParameters
();
sjl
.
run
(
trafficJob
,
jobParameters
);
jobParameters
=
new
JobParametersBuilder
().
addString
(
"uuid"
,
UUID
.
randomUUID
().
toString
()).
toJobParameters
();
sjl
.
run
(
trafficFlowJob
,
jobParameters
);
jobParameters
=
new
JobParametersBuilder
().
addString
(
"uuid"
,
UUID
.
randomUUID
().
toString
()).
toJobParameters
();
sjl
.
run
(
behaviorJob
,
jobParameters
);
JobParameters
jobParameters
;
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
jobParameters
=
new
JobParametersBuilder
().
addString
(
"uuid"
,
UUID
.
randomUUID
().
toString
()).
toJobParameters
();
sjl
.
run
(
trafficJob
,
jobParameters
);
}
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
jobParameters
=
new
JobParametersBuilder
().
addString
(
"uuid"
,
UUID
.
randomUUID
().
toString
()).
toJobParameters
();
sjl
.
run
(
trafficFlowJob
,
jobParameters
);
}
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
jobParameters
=
new
JobParametersBuilder
().
addString
(
"uuid"
,
UUID
.
randomUUID
().
toString
()).
toJobParameters
();
sjl
.
run
(
behaviorJob
,
jobParameters
);
}
if
(
enableForward
)
{
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
jobParameters
=
new
JobParametersBuilder
().
addString
(
"uuid"
,
UUID
.
randomUUID
().
toString
()).
toJobParameters
();
sjl
.
run
(
forwardJob
,
jobParameters
);
}
}
}
}
fanxing-task-manager/src/main/java/com/viontech/fanxing/task/manager/controller/web/StoreConfigController.java
View file @
4c0f5b9
package
com
.
viontech
.
fanxing
.
task
.
manager
.
controller
.
web
;
import
com.github.pagehelper.PageInfo
;
import
com.viontech.fanxing.commons.base.BaseExample
;
import
com.viontech.fanxing.commons.base.BaseMapper
;
import
com.viontech.fanxing.commons.vo.StoreConfigVo
;
import
com.viontech.fanxing.task.manager.controller.base.StoreConfigBaseController
;
import
com.viontech.fanxing.commons.model.StoreConfig
;
import
com.viontech.fanxing.commons.model.StoreConfigExample
;
import
com.viontech.fanxing.task.manager.mapper.StoreConfigMapper
;
import
com.viontech.fanxing.task.manager.service.adapter.StoreConfigService
;
import
com.viontech.fanxing.commons.vo.StoreConfigVo
;
import
com.viontech.fanxing.task.manager.controller.base.StoreConfigBaseController
;
import
com.viontech.keliu.util.JsonMessageUtil
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.util.StreamUtils
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.
util.List
;
import
static
com
.
viontech
.
keliu
.
util
.
JsonMessageUtil
.
getSuccessJsonMsg
;
import
java.
io.IOException
;
import
java.nio.charset.Charset
;
import
java.nio.charset.StandardCharsets
;
@Controller
@RequestMapping
(
"/storeConfigs"
)
...
...
@@ -22,7 +24,25 @@ public class StoreConfigController extends StoreConfigBaseController {
@Override
protected
BaseExample
getExample
(
StoreConfigVo
storeConfigVo
,
int
type
)
{
StoreConfigExample
storeConfigExample
=
(
StoreConfigExample
)
super
.
getExample
(
storeConfigVo
,
type
);
StoreConfigExample
storeConfigExample
=
(
StoreConfigExample
)
super
.
getExample
(
storeConfigVo
,
type
);
return
storeConfigExample
;
}
@Override
@PostMapping
@ResponseBody
public
Object
add
(
StoreConfigVo
storeConfigVo
)
{
MultipartFile
file
=
storeConfigVo
.
getFile
();
try
{
String
content
=
StreamUtils
.
copyToString
(
file
.
getInputStream
(),
Charset
.
forName
(
"GBK"
));
storeConfigVo
.
setContent
(
content
);
getService
().
insertSelective
(
storeConfigVo
);
storeConfigVo
.
setContent
(
null
);
storeConfigVo
.
setFile
(
null
);
return
JsonMessageUtil
.
getSuccessJsonMsg
(
storeConfigVo
);
}
catch
(
IOException
e
)
{
logger
.
error
(
""
,
e
);
return
JsonMessageUtil
.
getErrorJsonMsg
(
e
.
getMessage
());
}
}
}
\ No newline at end of file
fanxing-task-manager/src/main/java/com/viontech/fanxing/task/manager/controller/web/TaskController.java
View file @
4c0f5b9
...
...
@@ -42,4 +42,13 @@ public class TaskController extends TaskBaseController {
taskService
.
removeTask
(
id
);
return
JsonMessageUtil
.
getSuccessJsonMsg
(
"success"
);
}
@PutMapping
(
"/{id}"
)
public
JsonMessageUtil
.
JsonMessage
<
TaskVo
>
updateStatus
(
@PathVariable
(
"id"
)
Long
id
,
@RequestParam
Integer
status
)
{
TaskVo
taskVo
=
new
TaskVo
();
taskVo
.
setStatus
(
status
);
taskVo
.
setId
(
id
);
int
i
=
taskService
.
updateByPrimaryKeySelective
(
taskVo
);
return
JsonMessageUtil
.
getSuccessJsonMsg
(
"success"
);
}
}
\ No newline at end of file
fanxing-task-manager/src/main/java/com/viontech/fanxing/task/manager/service/impl/TaskServiceImpl.java
View file @
4c0f5b9
...
...
@@ -42,8 +42,6 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
public
TaskVo
updateTask
(
Task
task
)
{
task
=
insertSelective
(
task
);
task
=
selectByPrimaryKey
(
task
.
getId
());
JsonMessageUtil
.
JsonMessage
update
=
taskSchedulingClient
.
update
(
task
);
if
(
update
.
isSuccess
())
{
...
...
fanxing-task-scheduling/src/main/java/com/viontech/fanxing/task/scheduling/controller/TaskController.java
View file @
4c0f5b9
...
...
@@ -47,6 +47,9 @@ public class TaskController implements TaskSchedulingTasksAdapter {
// 计算运行时间并生成任务
boolean
success
=
taskService
.
distributeTask
(
taskData
);
if
(
success
)
{
taskService
.
getRepository
().
addOrUpdateTaskData
(
taskData
);
}
return
success
?
JsonMessageUtil
.
getSuccessJsonMsg
(
"success"
)
:
JsonMessageUtil
.
getErrorJsonMsg
(
"任务找不到可执行时间"
);
}
...
...
fanxing-task-scheduling/src/main/java/com/viontech/fanxing/task/scheduling/feign/TaskClient.java
View file @
4c0f5b9
...
...
@@ -5,10 +5,7 @@ import com.viontech.fanxing.commons.vo.TaskVo;
import
com.viontech.keliu.util.JsonMessageUtil
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.*
;
/**
* .
...
...
@@ -21,8 +18,8 @@ import org.springframework.web.bind.annotation.RequestBody;
@FeignClient
(
value
=
"fanxing-task-manager"
)
public
interface
TaskClient
{
@P
os
tMapping
(
"/tasks/{id}"
)
JsonMessageUtil
.
JsonMessage
<
TaskVo
>
updateTask
(
@PathVariable
(
"id"
)
Long
taskId
,
@RequestBody
TaskVo
taskVo
);
@P
u
tMapping
(
"/tasks/{id}"
)
JsonMessageUtil
.
JsonMessage
<
TaskVo
>
updateTask
Status
(
@PathVariable
(
"id"
)
Long
taskId
,
@RequestParam
Integer
status
);
@GetMapping
(
"/storeConfigs/{id}"
)
JsonMessageUtil
.
JsonMessage
<
StoreConfig
>
getStoreConfigById
(
@PathVariable
(
"id"
)
Long
storeConfigId
);
...
...
fanxing-task-scheduling/src/main/java/com/viontech/fanxing/task/scheduling/model/RuntimeConfig.java
View file @
4c0f5b9
...
...
@@ -2,12 +2,18 @@ package com.viontech.fanxing.task.scheduling.model;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.fasterxml.jackson.databind.annotation.JsonDeserialize
;
import
com.fasterxml.jackson.databind.annotation.JsonSerialize
;
import
com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer
;
import
com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer
;
import
com.viontech.fanxing.commons.model.Task
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
lombok.experimental.Accessors
;
import
org.apache.commons.lang3.tuple.ImmutablePair
;
import
java.io.Serializable
;
import
java.security.InvalidParameterException
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
...
...
@@ -31,7 +37,8 @@ import java.util.HashMap;
@Getter
@Setter
public
class
RuntimeConfig
{
@NoArgsConstructor
public
class
RuntimeConfig
implements
Serializable
{
private
static
final
String
[]
WEEK_ARR
=
new
String
[]{
"sun"
,
"mon"
,
"tue"
,
"wed"
,
"thu"
,
"fri"
,
"sat"
};
private
static
final
DateTimeFormatter
TIME_FORMATTER
=
DateTimeFormatter
.
ofPattern
(
"HH:mm:ss"
);
private
static
final
DateTimeFormatter
DATE_TIME_FORMATTER
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
);
...
...
@@ -162,11 +169,19 @@ public class RuntimeConfig {
@Getter
@Setter
@Accessors
(
chain
=
true
)
static
class
Config
{
static
class
Config
implements
Serializable
{
@JsonDeserialize
(
using
=
LocalDateTimeDeserializer
.
class
)
@JsonSerialize
(
using
=
LocalDateTimeSerializer
.
class
)
private
LocalTime
start
;
@JsonDeserialize
(
using
=
LocalDateTimeDeserializer
.
class
)
@JsonSerialize
(
using
=
LocalDateTimeSerializer
.
class
)
private
LocalTime
end
;
private
Long
runningTime
;
@JsonDeserialize
(
using
=
LocalDateTimeDeserializer
.
class
)
@JsonSerialize
(
using
=
LocalDateTimeSerializer
.
class
)
private
LocalDateTime
startTime
;
@JsonDeserialize
(
using
=
LocalDateTimeDeserializer
.
class
)
@JsonSerialize
(
using
=
LocalDateTimeSerializer
.
class
)
private
LocalDateTime
endTime
;
}
...
...
fanxing-task-scheduling/src/main/java/com/viontech/fanxing/task/scheduling/repository/VAServerRedisRepository.java
View file @
4c0f5b9
...
...
@@ -30,6 +30,9 @@ public class VAServerRedisRepository {
public
VaServerInfo
getVAServerInfoById
(
String
devId
)
{
VaServerInfo
vaServerInfo
=
vaServerMap
.
get
(
devId
);
if
(
vaServerInfo
==
null
)
{
return
null
;
}
if
(!
online
(
devId
))
{
vaServerInfo
.
setStatus
(
0
);
addOrUpdate
(
devId
,
vaServerInfo
);
...
...
fanxing-task-scheduling/src/main/java/com/viontech/fanxing/task/scheduling/runner/TaskRunner.java
View file @
4c0f5b9
...
...
@@ -84,18 +84,15 @@ public class TaskRunner {
// 找不到可以用来执行的设备,需要修改状态
if
(
server
==
null
)
{
TaskVo
taskVo
=
new
TaskVo
();
taskVo
.
setStatus
(
TaskStatus
.
CAN_NOT_RUN
.
val
);
taskClient
.
updateTask
(
task
.
getId
(),
taskVo
);
log
.
info
(
"找不到可用的 VAServer,跳过:{}"
,
taskUnid
);
taskClient
.
updateTaskStatus
(
task
.
getId
(),
TaskStatus
.
CAN_NOT_RUN
.
val
);
continue
;
}
boolean
success
=
vaServerService
.
executeTask
(
taskData
,
server
);
// 修改任务状态
TaskVo
taskVo
=
new
TaskVo
();
taskVo
.
setStatus
(
TaskStatus
.
RUNNING
.
val
);
taskClient
.
updateTask
(
task
.
getId
(),
taskVo
);
taskClient
.
updateTaskStatus
(
task
.
getId
(),
TaskStatus
.
RUNNING
.
val
);
// 移除任务
set
.
remove
(
taskUnid
);
...
...
@@ -130,6 +127,7 @@ public class TaskRunner {
// 获取可用的 vaserver ,执行任务终止动作,如果成功,解除 taskData和 vaServer 的关联,并且从 zset 中移除任务,恢复vaserver资源数,计算下次任务执行时间,放入zset中
boolean
success
=
vaServerService
.
terminateTask
(
taskUnid
);
if
(
success
)
{
taskClient
.
updateTaskStatus
(
taskData
.
getTask
().
getId
(),
TaskStatus
.
PAUSE
.
val
);
boolean
b
=
taskService
.
distributeTask
(
taskData
);
}
set
.
remove
(
taskUnid
);
...
...
fanxing-task-scheduling/src/main/java/com/viontech/fanxing/task/scheduling/service/VAServerHttpService.java
View file @
4c0f5b9
package
com
.
viontech
.
fanxing
.
task
.
scheduling
.
service
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.viontech.fanxing.task.scheduling.model.TaskData
;
import
com.viontech.fanxing.task.scheduling.model.vaserver.VATask
;
...
...
@@ -36,8 +37,7 @@ public class VAServerHttpService {
.
bodyToMono
(
String
.
class
);
String
response
=
stringMono
.
block
(
Duration
.
ofSeconds
(
20
));
log
.
info
(
"下发任务结果:{}"
,
response
);
return
response
;
return
JSON
.
parseObject
(
response
);
}
/**
...
...
@@ -55,28 +55,27 @@ public class VAServerHttpService {
.
bodyToMono
(
String
.
class
);
String
response
=
stringMono
.
block
(
Duration
.
ofSeconds
(
20
));
log
.
info
(
"下发任务结果:{}"
,
response
);
return
response
;
return
JSON
.
parseObject
(
response
)
;
}
/**
* 删除任务
*/
public
Object
rmTask
(
String
taskUnid
,
VaServerInfo
vaServerInfo
)
{
String
path
=
"/api/vaserver/v1/task}"
;
String
path
=
"/api/vaserver/v1/deleteTask"
;
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"task_unid"
,
taskUnid
);
Mono
<
String
>
stringMono
=
WebClient
.
create
(
vaServerInfo
.
getServiceBaseUrl
())
.
delete
()
.
uri
(
uriBuilder
->
uriBuilder
.
path
(
path
)
.
queryParam
(
"task_unid"
,
taskUnid
)
.
build
())
.
post
()
.
uri
(
uriBuilder
->
uriBuilder
.
path
(
path
).
build
())
.
bodyValue
(
jsonObject
.
toString
())
.
retrieve
()
.
bodyToMono
(
String
.
class
);
String
response
=
stringMono
.
block
(
Duration
.
ofSeconds
(
20
));
log
.
info
(
"删除任务结果:{}"
,
response
);
return
response
;
return
JSON
.
parseObject
(
response
);
}
/**
...
...
@@ -84,18 +83,19 @@ public class VAServerHttpService {
*/
public
Object
snapshot
(
String
taskUnid
,
VaServerInfo
vaServerInfo
)
{
String
path
=
"/api/vaserver/v1/snapshot"
;
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"task_unid"
,
taskUnid
);
Mono
<
String
>
stringMono
=
WebClient
.
create
(
vaServerInfo
.
getServiceBaseUrl
())
.
get
()
.
uri
(
uriBuilder
->
uriBuilder
.
path
(
path
)
.
queryParam
(
"task_unid"
,
taskUnid
)
.
build
())
.
post
()
.
uri
(
uriBuilder
->
uriBuilder
.
path
(
path
).
build
())
.
bodyValue
(
jsonObject
.
toString
())
.
retrieve
()
.
bodyToMono
(
String
.
class
);
String
response
=
stringMono
.
block
(
Duration
.
ofSeconds
(
20
));
log
.
info
(
"截图结果:{}"
,
response
);
return
response
;
String
block
=
stringMono
.
block
(
Duration
.
ofSeconds
(
20
));
return
JSON
.
parseObject
(
block
);
}
/**
...
...
@@ -116,7 +116,7 @@ public class VAServerHttpService {
String
response
=
stringMono
.
block
(
Duration
.
ofSeconds
(
10
));
log
.
info
(
"获取分析流地址结果 : {}"
,
response
);
return
response
;
return
JSON
.
parseObject
(
response
)
;
}
/**
...
...
@@ -139,8 +139,7 @@ public class VAServerHttpService {
String
response
=
stringMono
.
block
(
Duration
.
ofSeconds
(
20
));
log
.
info
(
"输出分析流结果:{}"
,
response
);
return
response
;
return
JSON
.
parseObject
(
response
);
}
/**
...
...
@@ -162,14 +161,13 @@ public class VAServerHttpService {
String
response
=
stringMono
.
block
(
Duration
.
ofSeconds
(
20
));
log
.
info
(
"场景切换结果:{}"
,
response
);
return
response
;
return
JSON
.
parseObject
(
response
);
}
/**
* 任务轮训状态切换
*/
public
Object
updateRotationStatus
(
String
taskUnid
,
Integer
rotationStatus
,
VaServerInfo
vaServerInfo
)
{
public
Object
updateRotationStatus
(
String
taskUnid
,
Integer
rotationStatus
,
VaServerInfo
vaServerInfo
)
{
String
path
=
"/api/vaserver/v1/alternate"
;
JSONObject
jsonObject
=
new
JSONObject
();
...
...
@@ -185,29 +183,28 @@ public class VAServerHttpService {
String
response
=
stringMono
.
block
(
Duration
.
ofSeconds
(
20
));
log
.
info
(
"轮训状态控制结果:{}"
,
response
);
return
response
;
return
JSON
.
parseObject
(
response
);
}
/**
* 任务轮训状态查询
*/
public
Object
getRotationStatus
(
String
taskUnid
,
VaServerInfo
vaServerInfo
)
{
String
path
=
"/api/vaserver/v1/alternate"
;
String
path
=
"/api/vaserver/v1/getAlternate"
;
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"task_unid"
,
taskUnid
);
Mono
<
String
>
stringMono
=
WebClient
.
create
(
vaServerInfo
.
getServiceBaseUrl
())
.
get
()
.
uri
(
uriBuilder
->
uriBuilder
.
path
(
path
)
.
queryParam
(
"task_unid"
,
taskUnid
)
.
build
())
.
post
()
.
uri
(
uriBuilder
->
uriBuilder
.
path
(
path
).
build
())
.
bodyValue
(
jsonObject
.
toString
())
.
retrieve
()
.
bodyToMono
(
String
.
class
);
String
response
=
stringMono
.
block
(
Duration
.
ofSeconds
(
20
));
log
.
info
(
"获取轮训状态:{}"
,
response
);
return
response
;
return
JSON
.
parseObject
(
response
);
}
/**
...
...
@@ -226,8 +223,7 @@ public class VAServerHttpService {
String
response
=
stringMono
.
block
(
Duration
.
ofSeconds
(
20
));
log
.
info
(
"运行状态查询:{}"
,
response
);
return
response
;
return
JSON
.
parseObject
(
response
);
}
...
...
fanxing-task-scheduling/src/main/java/com/viontech/fanxing/task/scheduling/service/VAServerService.java
View file @
4c0f5b9
...
...
@@ -51,6 +51,12 @@ public class VAServerService {
RBucket
<
Date
>
bucket
=
redisService
.
getValue
(
RedisKeys
.
getVAServerKeepAliveKey
(
devId
));
bucket
.
set
(
new
Date
());
bucket
.
expire
(
2
,
TimeUnit
.
MINUTES
);
VaServerInfo
vaserverInfo
=
vaServerRedisRepository
.
getVAServerInfoById
(
devId
);
if
(
vaserverInfo
!=
null
)
{
vaserverInfo
.
setStatus
(
1
);
vaServerRedisRepository
.
addOrUpdate
(
devId
,
vaserverInfo
);
}
}
...
...
fanxing-task-scheduling/src/test/java/com/viontech/fanxing/task/scheduling/service/VAServerHttpServiceTest.java
View file @
4c0f5b9
package
com
.
viontech
.
fanxing
.
task
.
scheduling
.
service
;
import
com.alibaba.fastjson.JSON
;
import
com.viontech.fanxing.commons.constant.
RedisKey
s
;
import
com.viontech.fanxing.commons.constant.
TaskStatu
s
;
import
com.viontech.fanxing.commons.model.StoreConfig
;
import
com.viontech.fanxing.commons.model.Task
;
import
com.viontech.fanxing.commons.service.RedisService
;
import
com.viontech.fanxing.commons.vo.TaskVo
;
import
com.viontech.fanxing.task.scheduling.feign.TaskClient
;
import
com.viontech.fanxing.task.scheduling.model.TaskData
;
import
com.viontech.fanxing.task.scheduling.model.vaserver.VaServerInfo
;
import
com.viontech.fanxing.task.scheduling.repository.TaskDataRedisRepository
;
import
com.viontech.fanxing.task.scheduling.repository.VAServerRedisRepository
;
import
com.viontech.keliu.util.DateUtil
;
import
com.viontech.keliu.util.JsonMessageUtil
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.runner.RunWith
;
import
org.redisson.api.RScoredSortedSet
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
...
...
@@ -30,7 +30,9 @@ import javax.annotation.Resource;
@RunWith
(
SpringRunner
.
class
)
class
VAServerHttpServiceTest
{
private
static
final
String
TASK_UNID
=
"0a263320bd274b529e5185e3b05aa157"
;
private
static
final
String
TASK_UNID
=
"abcd-xxxx-xxxxxx-xxxxxx"
;
private
static
final
String
DEV_ID
=
"sn3device1"
;
@Resource
VAServerHttpService
vaServerHttpService
;
@Resource
...
...
@@ -45,7 +47,7 @@ class VAServerHttpServiceTest {
@BeforeEach
public
void
before
()
{
this
.
vaServerInfo
=
vaServerRedisRepository
.
getVAServerInfoById
(
"xxx-xx"
);
this
.
vaServerInfo
=
vaServerRedisRepository
.
getVAServerInfoById
(
DEV_ID
);
this
.
taskData
=
new
TaskData
();
Task
task
=
new
Task
();
task
.
setUnid
(
TASK_UNID
);
...
...
@@ -65,7 +67,7 @@ class VAServerHttpServiceTest {
@Test
void
startAnalyzeStream
()
{
vaServerHttpService
.
startAnalyzeStream
(
TASK_UNID
,
vaServerInfo
,
"rtsp://192.168.9.
159:10087/0a263320bd274b529e5185e3b05aa157
"
);
vaServerHttpService
.
startAnalyzeStream
(
TASK_UNID
,
vaServerInfo
,
"rtsp://192.168.9.
245:10087/abcd-xxxx-xxxxxx-xxxxxx
"
);
}
@Test
...
...
@@ -90,7 +92,7 @@ class VAServerHttpServiceTest {
@Test
void
storeConfig
()
{
JsonMessageUtil
.
JsonMessage
<
StoreConfig
>
storeConfigById
=
taskClient
.
getStoreConfigById
(
3
L
);
JsonMessageUtil
.
JsonMessage
<
StoreConfig
>
storeConfigById
=
taskClient
.
getStoreConfigById
(
6
L
);
System
.
out
.
println
(
JSON
.
toJSONString
(
storeConfigById
.
getData
()));
}
...
...
@@ -100,15 +102,18 @@ class VAServerHttpServiceTest {
}
@Resource
private
TaskDataRedisRepository
taskDataRedisRepository
;
@Test
void
test
()
throws
Exception
{
// RMap<String, String> map = redisCacheService.getTaskVaServerMap();
// map.put("0a263320bd274b529e5185e3b05aa157", "xxx-xx");
RScoredSortedSet
<
String
>
set
=
redisService
.
getClient
().
getScoredSortedSet
(
RedisKeys
.
SCHEDULING_TO_BE_EXECUTED_TASK_UNID_SET
);
RScoredSortedSet
<
String
>
set2
=
redisService
.
getClient
().
getScoredSortedSet
(
RedisKeys
.
SCHEDULING_TO_BE_TERMINATED_TASK_UNID_SET
);
//
set
.
add
(
DateUtil
.
parse
(
"yyyy-MM-dd HH:mm:ss"
,
"2021-08-11 13:18:00"
).
getTime
(),
"tttttttttttttttttt"
);
set2
.
add
(
DateUtil
.
parse
(
"yyyy-MM-dd HH:mm:ss"
,
"2021-08-11 13:20:00"
).
getTime
(),
"tttttttttttttttttt"
);
// RMap<String, String> taskVaServerMap = redisService.getTaskVaServerMap();
// taskVaServerMap.put("b0c20c4a-fffd-11eb-a74d-0242ac11001d", DEV_ID);
JsonMessageUtil
.
JsonMessage
<
TaskVo
>
taskVoJsonMessage
=
taskClient
.
updateTaskStatus
(
19L
,
TaskStatus
.
RUNNING
.
val
);
System
.
out
.
println
(
JSON
.
toJSONString
(
taskVoJsonMessage
.
getData
()));
// RScoredSortedSet<String> set = redisService.getClient().getScoredSortedSet(RedisKeys.SCHEDULING_TO_BE_EXECUTED_TASK_UNID_SET);
// RScoredSortedSet<String> set2 = redisService.getClient().getScoredSortedSet(RedisKeys.SCHEDULING_TO_BE_TERMINATED_TASK_UNID_SET);
// set.add(DateUtil.parse("yyyy-MM-dd HH:mm:ss", "2021-08-11 13:18:00").getTime(), "tttttttttttttttttt");
// set2.add(DateUtil.parse("yyyy-MM-dd HH:mm:ss", "2021-08-11 13:20:00").getTime(), "tttttttttttttttttt");
}
}
\ No newline at end of file
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