Commit 95405dae by xmh

ops:

1. 视频资源查询时可以根据是否带任务进行过滤
2. 视频文件大小优化

task:
1. 重构运行计划代码
2. 添加接口调用记录 LogInterceptor
3. 任务相关接口进行大量优化
1 parent 2737dc87
Showing 26 changed files with 681 additions and 251 deletions
...@@ -19,7 +19,7 @@ public class GlobalExceptionHandler { ...@@ -19,7 +19,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
public Object exceptionHandler(Exception e) { public Object exceptionHandler(Exception e) {
log.info("", e); log.error("", e);
return JsonMessageUtil.getErrorJsonMsg(e.getMessage()); return JsonMessageUtil.getErrorJsonMsg(e.getMessage());
} }
...@@ -27,8 +27,7 @@ public class GlobalExceptionHandler { ...@@ -27,8 +27,7 @@ public class GlobalExceptionHandler {
public Object fanXingExceptionHandler(FanXingException fanXingException) { public Object fanXingExceptionHandler(FanXingException fanXingException) {
JsonMessageUtil.JsonMessage errorJsonMsg = JsonMessageUtil.getErrorJsonMsg(fanXingException.getMessage()); JsonMessageUtil.JsonMessage errorJsonMsg = JsonMessageUtil.getErrorJsonMsg(fanXingException.getMessage());
errorJsonMsg.setData(fanXingException.getData()); errorJsonMsg.setData(fanXingException.getData());
StackTraceElement[] stackTrace = fanXingException.getStackTrace(); log.error("", fanXingException);
log.info("\n接口调用出错\n错误信息:[{}]\n错误原因:[{}]", fanXingException.getMessage(), stackTrace.length > 0 ? stackTrace[0].toString() : "未知");
return errorJsonMsg; return errorJsonMsg;
} }
} }
...@@ -2,13 +2,11 @@ package com.viontech.fanxing.commons.vo; ...@@ -2,13 +2,11 @@ package com.viontech.fanxing.commons.vo;
import com.viontech.fanxing.commons.model.Channel; import com.viontech.fanxing.commons.model.Channel;
import com.viontech.fanxing.commons.vobase.ChannelVoBase; import com.viontech.fanxing.commons.vobase.ChannelVoBase;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
public class ChannelVo extends ChannelVoBase { public class ChannelVo extends ChannelVoBase {
private Boolean tree; private Boolean tree;
private boolean withTask;
public ChannelVo() { public ChannelVo() {
super(); super();
...@@ -26,4 +24,13 @@ public class ChannelVo extends ChannelVoBase { ...@@ -26,4 +24,13 @@ public class ChannelVo extends ChannelVoBase {
this.tree = tree; this.tree = tree;
return this; return this;
} }
public boolean isWithTask() {
return withTask;
}
public ChannelVo setWithTask(boolean withTask) {
this.withTask = withTask;
return this;
}
} }
\ No newline at end of file \ No newline at end of file
...@@ -4,13 +4,11 @@ import com.alibaba.fastjson.JSONObject; ...@@ -4,13 +4,11 @@ import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.viontech.fanxing.commons.base.BaseExample; import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.constant.ChannelType; import com.viontech.fanxing.commons.constant.ChannelType;
import com.viontech.fanxing.commons.model.Channel; import com.viontech.fanxing.commons.model.*;
import com.viontech.fanxing.commons.model.ChannelExample;
import com.viontech.fanxing.commons.model.ChannelTag;
import com.viontech.fanxing.commons.model.ChannelTagExample;
import com.viontech.fanxing.commons.vo.ChannelVo; import com.viontech.fanxing.commons.vo.ChannelVo;
import com.viontech.fanxing.commons.vo.DictCodeVo; import com.viontech.fanxing.commons.vo.DictCodeVo;
import com.viontech.fanxing.ops.controller.base.ChannelBaseController; import com.viontech.fanxing.ops.controller.base.ChannelBaseController;
import com.viontech.fanxing.ops.feign.TaskFeignClient;
import com.viontech.fanxing.ops.service.adapter.ChannelTagService; import com.viontech.fanxing.ops.service.adapter.ChannelTagService;
import com.viontech.keliu.util.JsonMessageUtil; import com.viontech.keliu.util.JsonMessageUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -19,8 +17,10 @@ import org.springframework.util.Assert; ...@@ -19,8 +17,10 @@ import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.viontech.keliu.util.JsonMessageUtil.getSuccessJsonMsg; import static com.viontech.keliu.util.JsonMessageUtil.getSuccessJsonMsg;
...@@ -31,6 +31,8 @@ import static com.viontech.keliu.util.JsonMessageUtil.getSuccessJsonMsg; ...@@ -31,6 +31,8 @@ import static com.viontech.keliu.util.JsonMessageUtil.getSuccessJsonMsg;
public class ChannelController extends ChannelBaseController { public class ChannelController extends ChannelBaseController {
@Resource @Resource
private ChannelTagService channelTagService; private ChannelTagService channelTagService;
@Resource
private TaskFeignClient taskFeignClient;
@Override @Override
protected BaseExample getExample(ChannelVo channelVo, int type) { protected BaseExample getExample(ChannelVo channelVo, int type) {
...@@ -44,9 +46,21 @@ public class ChannelController extends ChannelBaseController { ...@@ -44,9 +46,21 @@ public class ChannelController extends ChannelBaseController {
@RequestParam(value = "page", defaultValue = "-1") int page, @RequestParam(value = "page", defaultValue = "-1") int page,
@RequestParam(value = "pageSize", defaultValue = "100") int pageSize, @RequestParam(value = "pageSize", defaultValue = "100") int pageSize,
String sortName, String sortOrder) { String sortName, String sortOrder) {
final Set<String> channelUnidSet = new HashSet<>();
if (channelVo.isWithTask()) {
JsonMessageUtil.JsonMessage<List<Task>> allTask = taskFeignClient.getAllTask();
List<Task> data = allTask.getData();
channelUnidSet.addAll(data.stream().map(Task::getChannelUnid).collect(Collectors.toSet()));
}
if (channelVo.getTree() != null && channelVo.getTree()) { if (channelVo.getTree() != null && channelVo.getTree()) {
BaseExample example = getExample(channelVo, EXAMPLE_TYPE_PAGE); BaseExample example = getExample(channelVo, EXAMPLE_TYPE_PAGE);
List<Channel> channels = channelService.selectByExample(example); List<Channel> channels = channelService.selectByExample(example);
if (channelVo.isWithTask()) {
channels = channels.stream().filter(x -> channelUnidSet.contains(x.getChannelUnid())).collect(Collectors.toList());
}
List<DictCodeVo> dictCodeVos = channelService.channelOrg(channels); List<DictCodeVo> dictCodeVos = channelService.channelOrg(channels);
return JsonMessageUtil.getSuccessJsonMsg(dictCodeVos); return JsonMessageUtil.getSuccessJsonMsg(dictCodeVos);
} else { } else {
...@@ -61,6 +75,9 @@ public class ChannelController extends ChannelBaseController { ...@@ -61,6 +75,9 @@ public class ChannelController extends ChannelBaseController {
List<Channel> channels; List<Channel> channels;
if (page <= 0) { if (page <= 0) {
channels = getService().selectByExample(baseExample); channels = getService().selectByExample(baseExample);
if (channelVo.isWithTask()) {
channels = channels.stream().filter(x -> channelUnidSet.contains(x.getChannelUnid())).collect(Collectors.toList());
}
response = channels; response = channels;
} else { } else {
PageInfo<Channel> pageInfo = (PageInfo<Channel>) getService().pagedQuery(baseExample, page, pageSize); PageInfo<Channel> pageInfo = (PageInfo<Channel>) getService().pagedQuery(baseExample, page, pageSize);
......
...@@ -84,11 +84,8 @@ ...@@ -84,11 +84,8 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List_Root" > <sql id="Base_Column_List_Root" >
` channel `.id as channel_id, `channel`.id as channel_id, `channel`.unid as channel_unid, `channel`.channel_unid as channel_channel_unid,
` channel `.unid as channel_unid, `channel`.device_unid as channel_device_unid, `channel`.`type` as `channel_type`,
` channel `.channel_unid as channel_channel_unid,
` channel `.device_unid as channel_device_unid,
` channel `.`type` as `channel_type`,
`channel`.stream_type as channel_stream_type, `channel`.stream_path as channel_stream_path, `channel`.stream_type as channel_stream_type, `channel`.stream_path as channel_stream_path,
`channel`.username as channel_username, `channel`.`password` as `channel_password`, `channel`.username as channel_username, `channel`.`password` as `channel_password`,
`channel`.brand as channel_brand, `channel`.direction as channel_direction, `channel`.address_unid as channel_address_unid, `channel`.brand as channel_brand, `channel`.direction as channel_direction, `channel`.address_unid as channel_address_unid,
......
...@@ -96,9 +96,9 @@ ...@@ -96,9 +96,9 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List_Root" > <sql id="Base_Column_List_Root" >
` channel_tag `.id as channel_tag_id, `channel_tag`.id as channel_tag_id,
` channel_tag `.channel_id as channel_tag_channel_id, `channel_tag`.channel_id as channel_tag_channel_id,
` channel_tag `.tag as channel_tag_tag `channel_tag`.tag as channel_tag_tag
</sql> </sql>
<sql id="Base_Column_List" > <sql id="Base_Column_List" >
<if test="!(_parameter.getClass().getSimpleName() == 'ChannelTagExample')" > <if test="!(_parameter.getClass().getSimpleName() == 'ChannelTagExample')" >
......
...@@ -21,6 +21,7 @@ import org.springframework.web.multipart.MultipartFile; ...@@ -21,6 +21,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.text.DecimalFormat;
import java.util.DoubleSummaryStatistics; import java.util.DoubleSummaryStatistics;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
...@@ -49,6 +50,7 @@ public class VideoService { ...@@ -49,6 +50,7 @@ public class VideoService {
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void uploadVideo(List<MultipartFile> files, List<String> tags) { public void uploadVideo(List<MultipartFile> files, List<String> tags) {
DecimalFormat decimalFormat = new DecimalFormat(".00");
for (MultipartFile file : files) { for (MultipartFile file : files) {
String originalFilename = file.getOriginalFilename(); String originalFilename = file.getOriginalFilename();
String basePath = vionConfig.getImage().getPath() + File.separator + "uploadVideo" + File.separator; String basePath = vionConfig.getImage().getPath() + File.separator + "uploadVideo" + File.separator;
...@@ -82,7 +84,7 @@ public class VideoService { ...@@ -82,7 +84,7 @@ public class VideoService {
double mbSize = videoLength / 1024 / 1024; double mbSize = videoLength / 1024 / 1024;
// 再更新 // 再更新
channel.setExpand(String.valueOf(mbSize)); channel.setExpand(decimalFormat.format(mbSize));
channelService.updateByPrimaryKeySelective(channel); channelService.updateByPrimaryKeySelective(channel);
if (tags != null && tags.size() > 0) { if (tags != null && tags.size() > 0) {
...@@ -101,6 +103,7 @@ public class VideoService { ...@@ -101,6 +103,7 @@ public class VideoService {
*/ */
@LocalCache(value = "video_overView", duration = 20, timeunit = TimeUnit.SECONDS) @LocalCache(value = "video_overView", duration = 20, timeunit = TimeUnit.SECONDS)
public JSONObject overview() { public JSONObject overview() {
DecimalFormat decimalFormat = new DecimalFormat(".00");
ChannelExample channelExample = new ChannelExample(); ChannelExample channelExample = new ChannelExample();
channelExample.createCriteria().andTypeEqualTo(ChannelType.FILE.value); channelExample.createCriteria().andTypeEqualTo(ChannelType.FILE.value);
channelExample.createColumns().hasExpandColumn(); channelExample.createColumns().hasExpandColumn();
...@@ -110,8 +113,7 @@ public class VideoService { ...@@ -110,8 +113,7 @@ public class VideoService {
.collect(Collectors.summarizingDouble(x -> x)); .collect(Collectors.summarizingDouble(x -> x));
JSONObject res = new JSONObject(); JSONObject res = new JSONObject();
res.put("fileCount", summary.getCount()); res.put("fileCount", summary.getCount());
res.put("size", summary.getSum()); res.put("size", decimalFormat.format(summary.getSum()) + " MB");
res.put("unit", "MB");
return res; return res;
} }
} }
package com.viontech.fanxing.task.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* .
*
* @author 谢明辉
* @date 2021/5/26
*/
@Component
@Slf4j
public class LogInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
request.setAttribute("request_start", System.currentTimeMillis());
return true;
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
Object o = request.getAttribute("request_start");
if (o != null) {
Long requestStart = (Long) o;
String queryString = request.getQueryString();
String uri = request.getRequestURL().toString();
String path = queryString == null ? uri : uri + "?" + queryString;
log.debug("请求信息:[{}]-请求方式:[{}]-处理时长:[{}]", path, request.getMethod(), System.currentTimeMillis() - requestStart);
}
super.afterCompletion(request, response, handler, ex);
}
}
package com.viontech.fanxing.task.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.annotation.Resource;
/**
* .
*
* @author 谢明辉
* @date 2021/10/26
*/
@Configuration
public class TaskWebConfig implements WebMvcConfigurer {
@Resource
private LogInterceptor logInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(logInterceptor).addPathPatterns("/**");
}
}
package com.viontech.fanxing.task.controller.web; package com.viontech.fanxing.task.controller.web;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.MultimapBuilder;
import com.viontech.fanxing.commons.base.BaseExample; import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.base.BaseModel; import com.viontech.fanxing.commons.base.BaseMapper;
import com.viontech.fanxing.commons.exception.FanXingException;
import com.viontech.fanxing.commons.model.Channel;
import com.viontech.fanxing.commons.model.DictCode;
import com.viontech.fanxing.commons.model.Task; import com.viontech.fanxing.commons.model.Task;
import com.viontech.fanxing.commons.model.TaskExample; import com.viontech.fanxing.commons.model.TaskExample;
import com.viontech.fanxing.commons.vo.TaskVo; import com.viontech.fanxing.commons.vo.TaskVo;
import com.viontech.fanxing.task.controller.base.TaskBaseController; import com.viontech.fanxing.task.controller.base.TaskBaseController;
import com.viontech.fanxing.task.model.ConfigBuilder;
import com.viontech.fanxing.task.service.OpsClientService;
import com.viontech.fanxing.task.utils.SceneUtils;
import com.viontech.keliu.util.JsonMessageUtil; import com.viontech.keliu.util.JsonMessageUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -24,6 +42,9 @@ import static com.viontech.keliu.util.JsonMessageUtil.getSuccessJsonMsg; ...@@ -24,6 +42,9 @@ import static com.viontech.keliu.util.JsonMessageUtil.getSuccessJsonMsg;
public class TaskController extends TaskBaseController { public class TaskController extends TaskBaseController {
@Resource
private OpsClientService opsClientService;
@Override @Override
protected BaseExample getExample(TaskVo taskVo, int type) { protected BaseExample getExample(TaskVo taskVo, int type) {
TaskExample taskExample = (TaskExample) super.getExample(taskVo, type); TaskExample taskExample = (TaskExample) super.getExample(taskVo, type);
...@@ -71,26 +92,15 @@ public class TaskController extends TaskBaseController { ...@@ -71,26 +92,15 @@ public class TaskController extends TaskBaseController {
return JsonMessageUtil.getSuccessJsonMsg(); return JsonMessageUtil.getSuccessJsonMsg();
} }
@GetMapping("/{id}/start") @GetMapping("/{id}/start")
public JsonMessageUtil.JsonMessage<TaskVo> startTask(@PathVariable("id") Long id) { public JsonMessageUtil.JsonMessage<TaskVo> startTask(@PathVariable("id") Long id) {
try {
taskService.startTask(id); taskService.startTask(id);
} catch (Exception e) {
log.error("启动任务异常", e);
return JsonMessageUtil.getErrorJsonMsg(e.getMessage());
}
return JsonMessageUtil.getSuccessJsonMsg(); return JsonMessageUtil.getSuccessJsonMsg();
} }
@GetMapping("/{id}/stop") @GetMapping("/{id}/stop")
public JsonMessageUtil.JsonMessage stopTask(@PathVariable("id") Long id) { public JsonMessageUtil.JsonMessage stopTask(@PathVariable("id") Long id) {
try {
taskService.stopTask(id); taskService.stopTask(id);
} catch (Exception e) {
log.error("停止任务异常", e);
return JsonMessageUtil.getErrorJsonMsg(e.getMessage());
}
return JsonMessageUtil.getSuccessJsonMsg(); return JsonMessageUtil.getSuccessJsonMsg();
} }
...@@ -108,12 +118,129 @@ public class TaskController extends TaskBaseController { ...@@ -108,12 +118,129 @@ public class TaskController extends TaskBaseController {
@GetMapping("channelUnidWithTask") @GetMapping("channelUnidWithTask")
public JsonMessageUtil.JsonMessage channelUnidWithTask() { public JsonMessageUtil.JsonMessage channelUnidWithTask() {
TaskExample taskExample = new TaskExample(); TaskExample taskExample = new TaskExample();
taskExample.createColumns().hasChannelUnidColumn().addColumnStr("count(*) as count"); BaseMapper<Task> mapper = taskService.getMapper();
taskExample.setGroupByClause("channel_unid"); List<Task> tasks = mapper.selectByExample(taskExample);
taskExample.setOrderByClause("channel_unid"); Map<String, List<Task>> collect = tasks.stream().collect(Collectors.groupingBy(Task::getChannelUnid, Collectors.toList()));
List<Task> tasks = taskService.selectByExample(taskExample); return JsonMessageUtil.getSuccessJsonMsg(collect);
Map<String, Long> result = tasks.stream().collect(Collectors.toMap(Task::getChannelUnid, BaseModel::getCount)); }
return JsonMessageUtil.getSuccessJsonMsg(result);
/**
* 上传场景配置
*
* @return
*/
@PostMapping("uploadRoiAndConfig")
public Object uploadRoiAndConfig(@RequestParam Long taskId, @RequestParam String sceneUnid, @RequestParam MultipartFile file) throws IOException {
Task task = taskService.selectByPrimaryKey(taskId);
Assert.notNull(task, "找不到对应任务");
String scene = task.getScene();
JSONArray sceneArr = JSON.parseArray(scene);
JSONObject targetScene = null;
for (int i = 0; i < sceneArr.size(); i++) {
JSONObject jsonObject = sceneArr.getJSONObject(i);
String scene_unid = jsonObject.getString("scene_unid");
if (sceneUnid.equals(scene_unid)) {
targetScene = jsonObject;
}
}
if (targetScene == null) {
throw new FanXingException("找不到对应场景");
}
byte[] bytes = file.getBytes();
String s = new String(bytes, StandardCharsets.UTF_8);
JSONObject source = JSON.parseObject(s);
// 合并配置
SceneUtils.INSTANCE.mergeScene(source, targetScene);
// 合并之后,因为需要设备信息的配置,所以需要重新构建
JSONObject config = targetScene.getJSONObject("config");
if (config != null) {
String xml = config.getString("xml");
ConfigBuilder configBuilder = new ConfigBuilder();
Channel channel = opsClientService.getChannelByChannelUnid(task.getChannelUnid());
String addressUnid = channel.getAddressUnid();
String addressName = null;
if (addressUnid != null) {
DictCode dictCode = opsClientService.getDictCodeByUnid(addressUnid);
addressName = dictCode.getName();
}
String c = configBuilder.buildDefaultConfig(xml)
.buildVchanInfo(channel.getName(), channel.getChannelUnid(), addressUnid, addressName)
.build();
config.put("xml", c);
}
TaskVo temp = new TaskVo();
temp.setId(taskId);
temp.setScene(sceneArr.toJSONString());
return update(taskId, temp);
}
/**
* 下载场景配置和roi
*
* @param taskId 任务ID
* @param sceneUnid 任务中场景的unid
*/
@GetMapping("downloadRoiAndConfig")
public void downloadRoiAndConfig(@RequestParam String taskId, @RequestParam String sceneUnid, HttpServletResponse response) throws Exception {
Task task = taskService.selectByPrimaryKey(taskId);
Assert.notNull(task, "找不到对应任务");
String scene = task.getScene();
JSONArray sceneArr = JSON.parseArray(scene);
JSONObject sceneNeed = null;
for (int i = 0; i < sceneArr.size(); i++) {
JSONObject jsonObject = sceneArr.getJSONObject(i);
String scene_unid = jsonObject.getString("scene_unid");
if (sceneUnid.equals(scene_unid)) {
sceneNeed = jsonObject;
}
}
if (sceneNeed == null) {
throw new FanXingException("找不到对应场景");
}
JSONObject result = new JSONObject();
result.put("config", sceneNeed.getJSONObject("config"));
result.put("rois", sceneNeed.getJSONArray("rois"));
String s = result.toString();
byte[] bytes = s.getBytes(StandardCharsets.UTF_8);
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.setHeader("Content-Disposition",
"attachment;filename=" + sceneUnid + ".json");
IOUtils.write(bytes, response.getOutputStream());
}
/**
* 批量启动暂停删除
*/
@GetMapping("batchOperation")
public JsonMessageUtil.JsonMessage batchOperation(@RequestParam Long[] taskIdArr, @RequestParam Integer type) {
if (type < 1 || type > 3) {
throw new FanXingException("无效操作类型:" + type);
}
// 1 启动, 2暂停, 3删除
ListMultimap<String, Long> build = MultimapBuilder.treeKeys().linkedListValues().build();
for (Long taskId : taskIdArr) {
try {
switch (type) {
case 1:
taskService.startTask(taskId);
break;
case 2:
taskService.stopTask(taskId);
break;
case 3:
taskService.removeTask(taskId);
break;
default:
break;
}
} catch (Exception e) {
log.info("", e);
build.put("error", taskId);
}
build.put("success", taskId);
}
return JsonMessageUtil.getSuccessJsonMsg(build);
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -35,7 +35,7 @@ public class ConfigBuilder { ...@@ -35,7 +35,7 @@ public class ConfigBuilder {
document.setRootElement(DocumentHelper.createElement("root")); document.setRootElement(DocumentHelper.createElement("root"));
} }
public void setText(Element element, String name, String text) { private void setText(Element element, String name, String text) {
Element e = element.element(name); Element e = element.element(name);
if (e == null) { if (e == null) {
e = element.addElement(name); e = element.addElement(name);
......
package com.viontech.fanxing.task.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;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
/**
* type
* <li>0 每天运行,指定开始和结束的时间</li>
* <li>1 运行一次,指定具体的开始和结束的日期时间</li>
* <li>2 按照星期配置,指定每周某天的开始和结束的时间</li>
* <li>3 随机运行,指定运行时长</li>
* <li>4 全天执行,只能手动停止</li>
*
* @author 谢明辉
* @date 2021/7/13
*/
@Getter
@Setter
@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");
private int type;
private HashMap<Integer, Config> weekConfigMap;
private Config singleConfig;
public RuntimeConfig(Task task) {
String runtimeConf = task.getRuntimeConf();
JSONObject jsonObject = JSON.parseObject(runtimeConf);
Integer typeT = jsonObject.getInteger("type");
if (typeT == null) {
throw new InvalidParameterException("运行配置中type为空");
}
this.type = typeT;
JSONObject config = jsonObject.getJSONObject("config");
switch (this.type) {
case 0:
String start = config.getString("start");
String end = config.getString("end");
this.singleConfig = new Config().setStart(LocalTime.parse(start, TIME_FORMATTER)).setEnd(LocalTime.parse(end, TIME_FORMATTER));
break;
case 1:
String start1 = config.getString("start");
String end1 = config.getString("end");
this.singleConfig = new Config().setStartTime(LocalDateTime.parse(start1, DATE_TIME_FORMATTER)).setEndTime(LocalDateTime.parse(end1, DATE_TIME_FORMATTER));
break;
case 2:
this.weekConfigMap = new HashMap<>();
for (int i = 0; i < WEEK_ARR.length; i++) {
String week = WEEK_ARR[i];
JSONObject configMap = config.getJSONObject(week);
if (configMap == null) {
continue;
}
String weekStart = configMap.getString("start");
String weekEnd = configMap.getString("end");
Config weekConfig = new Config().setStart(LocalTime.parse(weekStart, TIME_FORMATTER)).setEnd(LocalTime.parse(weekEnd, TIME_FORMATTER));
this.weekConfigMap.put(i, weekConfig);
}
break;
// 随机执行
case 3:
Long runningTime = config.getLong("runningTime");
this.singleConfig = new Config().setRunningTime(runningTime);
break;
// 开始后一直执行
case 4:
this.singleConfig = new Config().setStartTime(LocalDateTime.now());
break;
default:
throw new InvalidParameterException("错误的type");
}
}
/**
* @return org.apache.commons.lang3.tuple.ImmutablePair<Long, Long>
* <li>left 下一次任务下发时间</li>
* <li>right 下一次任务终止时间</li>
*/
public ImmutablePair<Long, Long> getNextTimeOfExecutionAndTerminal() {
Long executeTimestamp = null;
Long terminateTimestamp = null;
LocalDateTime now = LocalDateTime.now();
LocalDateTime executeTime;
LocalDateTime terminateTime;
switch (this.type) {
case 0:
LocalTime start = singleConfig.getStart();
executeTime = LocalDateTime.of(LocalDate.now(), start);
LocalTime end = singleConfig.getEnd();
terminateTime = LocalDateTime.of(executeTime.toLocalDate(), end);
// 如果终止时间在现在的时间之前需要明天执行
if (terminateTime.isBefore(now)) {
executeTime = executeTime.plusDays(1);
terminateTime = terminateTime.plusDays(1);
}
executeTimestamp = executeTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
terminateTimestamp = terminateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
break;
case 1:
executeTime = singleConfig.getStartTime();
terminateTime = singleConfig.getEndTime();
if (terminateTime.isBefore(now)) {
return ImmutablePair.nullPair();
}
executeTimestamp = executeTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
terminateTimestamp = terminateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
break;
case 2:
Calendar instance = Calendar.getInstance();
instance.setTime(new Date());
int dayOfWeek = instance.get(Calendar.DAY_OF_WEEK);
dayOfWeek -= 1;
LocalDate localDate = LocalDate.now();
Config config;
boolean success = false;
for (int i = 0; i <= 7; i++) {
config = this.weekConfigMap.get(dayOfWeek);
if (config != null) {
executeTime = LocalDateTime.of(localDate, config.getStart());
terminateTime = LocalDateTime.of(executeTime.toLocalDate(), config.getEnd());
if (terminateTime.isAfter(now)) {
executeTimestamp = executeTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
terminateTimestamp = terminateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
success = true;
break;
}
}
localDate = localDate.plusDays(1);
dayOfWeek = (dayOfWeek + 1) % 7;
}
if (!success) {
return ImmutablePair.nullPair();
}
break;
case 3:
// 随机执行,待完善
break;
case 4:
executeTimestamp = singleConfig.getStartTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
break;
default:
return ImmutablePair.nullPair();
}
return ImmutablePair.of(executeTimestamp, terminateTimestamp);
}
public
@Getter
@Setter
@Accessors(chain = true)
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;
}
}
package com.viontech.fanxing.task.model; package com.viontech.fanxing.task.model;
import com.viontech.fanxing.commons.model.Task; import com.viontech.fanxing.commons.model.Task;
import com.viontech.fanxing.task.model.runtime.RuntimeConfig;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
...@@ -27,7 +28,7 @@ public class TaskData implements Serializable { ...@@ -27,7 +28,7 @@ public class TaskData implements Serializable {
public TaskData(Task task) { public TaskData(Task task) {
this.task = task; this.task = task;
runtimeConfig = new RuntimeConfig(task); runtimeConfig = RuntimeConfig.createConfig(task.getRuntimeConf(), task.getRuntimeType());
} }
......
package com.viontech.fanxing.task.model.runtime;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.commons.exception.FanXingException;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.commons.lang3.tuple.ImmutablePair;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
/**
* .
*
* @author 谢明辉
* @date 2021/10/27
*/
@NoArgsConstructor
@Getter
@Setter
public class DailyRuntimeConfig implements RuntimeConfig {
private List<Config> multiConfig;
/**
* 解析配置并排序
*/
public DailyRuntimeConfig(String runtimeConf) {
JSONObject jsonObject = JSON.parseObject(runtimeConf);
JSONArray config0 = jsonObject.getJSONArray("config");
multiConfig = new ArrayList<>(config0.size());
for (int i = 0; i < config0.size(); i++) {
JSONObject item = config0.getJSONObject(i);
String start = item.getString("start");
String end = item.getString("end");
Config config = new Config().setStart(LocalTime.parse(start, TIME_FORMATTER)).setEnd(LocalTime.parse(end, TIME_FORMATTER));
multiConfig.add(config);
}
// 判断是否有重复的时间段
for (int i = 0; i < multiConfig.size(); i++) {
for (int j = 1; j < multiConfig.size(); j++) {
if (i == j) {
continue;
}
Config configI = multiConfig.get(i);
Config configJ = multiConfig.get(j);
// 判断时间段是否有交叉
if ((configJ.getStart().isAfter(configI.getStart()) && configJ.getStart().isBefore(configI.getEnd())
|| (configJ.getEnd().isAfter(configI.getStart()) && configJ.getEnd().isBefore(configI.getEnd())))) {
throw new FanXingException("配置有误请检查配置");
}
}
}
multiConfig.sort((o1, o2) -> {
LocalTime start1 = o1.getStart();
LocalTime start2 = o2.getStart();
return start1.isBefore(start2) ? -1 : start1.isAfter(start2) ? 1 : 0;
});
}
@Override
public ImmutablePair<Long, Long> getNextTimeOfExecutionAndTerminal() {
LocalDateTime executeTime = null;
LocalDateTime terminateTime = null;
boolean tomorrow = true;
for (Config config : multiConfig) {
LocalTime start = config.getStart();
executeTime = LocalDateTime.of(LocalDate.now(), start);
LocalTime end = config.getEnd();
terminateTime = LocalDateTime.of(executeTime.toLocalDate(), end);
// 如果终止时间在现在的时间之前需要明天执行
if (!terminateTime.isBefore(LocalDateTime.now())) {
tomorrow = false;
break;
}
}
// 如果今天找不到运行配置,那么就明天运行
if (tomorrow) {
Config config = multiConfig.get(0);
executeTime = LocalDateTime.of(LocalDate.now(), config.getStart()).plusDays(1);
terminateTime = LocalDateTime.of(executeTime.toLocalDate(), config.getEnd());
}
long executeTimestamp = executeTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
long terminateTimestamp = terminateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
return ImmutablePair.of(executeTimestamp, terminateTimestamp);
}
}
package com.viontech.fanxing.task.model.runtime;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.tuple.ImmutablePair;
import java.time.LocalDateTime;
import java.time.ZoneId;
/**
* .
*
* @author 谢明辉
* @date 2021/10/27
*/
@NoArgsConstructor
public class ManualRuntimeConfig implements RuntimeConfig {
public ManualRuntimeConfig(String runtimeConf) {
}
@Override
public ImmutablePair<Long, Long> getNextTimeOfExecutionAndTerminal() {
long l = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
return ImmutablePair.of(l, null);
}
}
package com.viontech.fanxing.task.model.runtime;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.tuple.ImmutablePair;
import java.time.LocalDateTime;
import java.time.ZoneId;
/**
* .
*
* @author 谢明辉
* @date 2021/10/27
*/
@NoArgsConstructor
public class OnceRuntimeConfig implements RuntimeConfig {
private LocalDateTime start;
private LocalDateTime end;
public OnceRuntimeConfig(String runtimeConf) {
JSONObject jsonObject = JSON.parseObject(runtimeConf);
JSONObject config1 = jsonObject.getJSONObject("config");
String start1 = config1.getString("start");
String end1 = config1.getString("end");
start = LocalDateTime.parse(start1, DATE_TIME_FORMATTER);
end = LocalDateTime.parse(end1, DATE_TIME_FORMATTER);
}
@Override
public ImmutablePair<Long, Long> getNextTimeOfExecutionAndTerminal() {
long l = start.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
long r = end.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
return ImmutablePair.of(l, r);
}
}
package com.viontech.fanxing.task.model.runtime;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.commons.model.Task;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.commons.lang3.tuple.ImmutablePair;
/**
* .
*
* @author 谢明辉
* @date 2021/10/27
*/
@NoArgsConstructor
@Getter
@Setter
public class RandomRuntimeConfig implements RuntimeConfig {
private Long runningTime;
public RandomRuntimeConfig(String runtimeConf) {
JSONObject jsonObject = JSON.parseObject(runtimeConf);
JSONObject config3 = jsonObject.getJSONObject("config");
runningTime = config3.getLong("runningTime");
}
@Override
public ImmutablePair<Long, Long> getNextTimeOfExecutionAndTerminal() {
// todo
return ImmutablePair.nullPair();
}
}
package com.viontech.fanxing.task.model.runtime;
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.exception.FanXingException;
import lombok.Getter;
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.LocalTime;
import java.time.format.DateTimeFormatter;
/**
* type
* <li>0 每天运行,指定开始和结束的时间</li>
* <li>1 运行一次,指定具体的开始和结束的日期时间</li>
* <li>2 按照星期配置,指定每周某天的开始和结束的时间</li>
* <li>3 随机运行,指定运行时长</li>
* <li>4 全天执行,只能手动停止</li>
*
* @author 谢明辉
* @date 2021/7/13
*/
public interface RuntimeConfig extends Serializable {
String[] WEEK_ARR = new String[]{"sun", "mon", "tue", "wed", "thu", "fri", "sat"};
DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss");
DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
/**
* 根据配置创建运行计划
*
* @param runtimeConf 运行计划的配置(json字符串)
* @param type 运行计划的类型
*
* @return 返回运行计划配置
*/
static RuntimeConfig createConfig(String runtimeConf, Integer type) {
if (type == null) {
throw new InvalidParameterException("运行配置中type为空");
}
RuntimeConfig res;
switch (type) {
case 0:
res = new DailyRuntimeConfig(runtimeConf);
break;
case 1:
res = new OnceRuntimeConfig(runtimeConf);
break;
case 2:
res = new WeeklyRuntimeConfig(runtimeConf);
break;
case 3:
res = new RandomRuntimeConfig(runtimeConf);
break;
case 4:
res = new ManualRuntimeConfig(runtimeConf);
break;
default:
throw new FanXingException("配置类型有误:" + type);
}
return res;
}
/**
* @return org.apache.commons.lang3.tuple.ImmutablePair<Long, Long>
* <li>left 下一次任务下发时间</li>
* <li>right 下一次任务终止时间</li>
*/
ImmutablePair<Long, Long> getNextTimeOfExecutionAndTerminal();
@Getter
@Setter
@Accessors(chain = true)
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;
}
}
package com.viontech.fanxing.task.model.runtime;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.tuple.ImmutablePair;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
/**
* .
*
* @author 谢明辉
* @date 2021/10/27
*/
@NoArgsConstructor
public class WeeklyRuntimeConfig implements RuntimeConfig {
private HashMap<Integer, Config> weekConfigMap;
public WeeklyRuntimeConfig(String runtimeConf) {
JSONObject jsonObject = JSON.parseObject(runtimeConf);
JSONObject config2 = jsonObject.getJSONObject("config");
this.weekConfigMap = new HashMap<>();
for (int i = 0; i < WEEK_ARR.length; i++) {
String week = WEEK_ARR[i];
JSONObject configMap = config2.getJSONObject(week);
if (configMap == null) {
continue;
}
String weekStart = configMap.getString("start");
String weekEnd = configMap.getString("end");
Config weekConfig = new Config().setStart(LocalTime.parse(weekStart, TIME_FORMATTER)).setEnd(LocalTime.parse(weekEnd, TIME_FORMATTER));
this.weekConfigMap.put(i, weekConfig);
}
}
@Override
public ImmutablePair<Long, Long> getNextTimeOfExecutionAndTerminal() {
Long executeTimestamp = null;
Long terminateTimestamp = null;
LocalDateTime executeTime;
LocalDateTime terminateTime;
Calendar instance = Calendar.getInstance();
instance.setTime(new Date());
int dayOfWeek = instance.get(Calendar.DAY_OF_WEEK);
dayOfWeek -= 1;
LocalDate localDate = LocalDate.now();
Config config;
boolean success = false;
for (int i = 0; i <= 7; i++) {
config = this.weekConfigMap.get(dayOfWeek);
if (config != null) {
executeTime = LocalDateTime.of(localDate, config.getStart());
terminateTime = LocalDateTime.of(executeTime.toLocalDate(), config.getEnd());
if (terminateTime.isAfter(LocalDateTime.now())) {
executeTimestamp = executeTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
terminateTimestamp = terminateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
success = true;
break;
}
}
localDate = localDate.plusDays(1);
dayOfWeek = (dayOfWeek + 1) % 7;
}
if (!success) {
return ImmutablePair.nullPair();
}
return ImmutablePair.of(executeTimestamp, terminateTimestamp);
}
}
...@@ -23,6 +23,8 @@ public class VaServerInfo implements Serializable { ...@@ -23,6 +23,8 @@ public class VaServerInfo implements Serializable {
private String proxy; private String proxy;
/** 可用资源数量 */ /** 可用资源数量 */
private Float availableResources; private Float availableResources;
/** 设备类型 */
private String platType;
/** 状态 1在线,0离线 */ /** 状态 1在线,0离线 */
private int status = 1; private int status = 1;
......
...@@ -39,11 +39,14 @@ public class TaskInitRunner implements CommandLineRunner { ...@@ -39,11 +39,14 @@ public class TaskInitRunner implements CommandLineRunner {
List<Task> tasks = taskMapper.selectByExampleWithBLOBs(new TaskExample()); List<Task> tasks = taskMapper.selectByExampleWithBLOBs(new TaskExample());
for (Task task : tasks) { for (Task task : tasks) {
if (StringUtils.isNotBlank(task.getScene()) && task.getStoreConfigId() != null && !TaskStatus.PAUSE.valEqual(task.getStatus())) { // scene和storage不为空,不处于未部署状态
if (StringUtils.isNotBlank(task.getScene()) && task.getStoreConfigId() != null && !TaskStatus.AWAIT.valEqual(task.getStatus())) {
try { try {
TaskData taskData = taskDataService.getRepository().getTaskDataByUnid(task.getUnid()); TaskData taskData = taskDataService.getRepository().getTaskDataByUnid(task.getUnid());
if (taskData == null) { if (taskData == null) {
taskDataService.addTask(task); taskDataService.addTask(task);
} else if (taskData.getTask().getStatus() == TaskStatus.RUNNING.val) {
taskDataService.distributeTask(taskData);
} }
} catch (Exception e) { } catch (Exception e) {
log.info("初始化任务失败,任务unid:{},失败信息:{}", task.getUnid(), e.getMessage()); log.info("初始化任务失败,任务unid:{},失败信息:{}", task.getUnid(), e.getMessage());
......
...@@ -74,7 +74,7 @@ public class TaskRunner { ...@@ -74,7 +74,7 @@ public class TaskRunner {
} }
// 指定了VAServer // 指定了VAServer
if (StringUtils.isNotBlank(taskVaType)) { if (StringUtils.isNotBlank(taskVaType)) {
if (!taskVaType.equals(temp.getServiceName())) { if (!taskVaType.equals(temp.getPlatType())) {
continue; continue;
} }
} }
...@@ -93,7 +93,7 @@ public class TaskRunner { ...@@ -93,7 +93,7 @@ public class TaskRunner {
// 找不到可以用来执行的设备,需要修改状态 // 找不到可以用来执行的设备,需要修改状态
if (server == null) { if (server == null) {
log.info("找不到可用的 VAServer,跳过:{}", taskUnid); log.debug("找不到可用的 VAServer,跳过:{}", taskUnid);
taskService.updateStatus(task.getId(), TaskStatus.CAN_NOT_RUN.val); taskService.updateStatus(task.getId(), TaskStatus.CAN_NOT_RUN.val);
continue; continue;
} }
......
...@@ -4,8 +4,8 @@ import com.viontech.fanxing.commons.exception.FanXingException; ...@@ -4,8 +4,8 @@ import com.viontech.fanxing.commons.exception.FanXingException;
import com.viontech.fanxing.commons.model.StoreConfig; import com.viontech.fanxing.commons.model.StoreConfig;
import com.viontech.fanxing.commons.model.Task; import com.viontech.fanxing.commons.model.Task;
import com.viontech.fanxing.commons.service.RedisService; import com.viontech.fanxing.commons.service.RedisService;
import com.viontech.fanxing.task.model.RuntimeConfig;
import com.viontech.fanxing.task.model.TaskData; import com.viontech.fanxing.task.model.TaskData;
import com.viontech.fanxing.task.model.runtime.RuntimeConfig;
import com.viontech.fanxing.task.model.vaserver.VaServerInfo; import com.viontech.fanxing.task.model.vaserver.VaServerInfo;
import com.viontech.fanxing.task.repository.TaskDataRedisRepository; import com.viontech.fanxing.task.repository.TaskDataRedisRepository;
import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.ImmutablePair;
...@@ -57,7 +57,7 @@ public class TaskDataService { ...@@ -57,7 +57,7 @@ public class TaskDataService {
// 如果任务正在执行则不进行分配 // 如果任务正在执行则不进行分配
VaServerInfo vaServerInfo = taskRunOn(taskUnid); VaServerInfo vaServerInfo = taskRunOn(taskUnid);
if (vaServerInfo != null) { if (vaServerInfo != null) {
return false; return true;
} }
ImmutablePair<Long, Long> nextTime = runtimeConfig.getNextTimeOfExecutionAndTerminal(); ImmutablePair<Long, Long> nextTime = runtimeConfig.getNextTimeOfExecutionAndTerminal();
......
...@@ -232,7 +232,7 @@ public class VAServerHttpService { ...@@ -232,7 +232,7 @@ public class VAServerHttpService {
* 获取默认算法配置 * 获取默认算法配置
*/ */
public JSONObject getDefaultAlgorithmConfig(VaServerInfo vaServerInfo, String taskAlgType) { public JSONObject getDefaultAlgorithmConfig(VaServerInfo vaServerInfo, String taskAlgType) {
String path = "/api/vaserver/v1/get_algo_param_template"; String path = "/api/vaserver/v1/runtime_config";
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("task_algo_type", taskAlgType); jsonObject.put("task_algo_type", taskAlgType);
Mono<String> mono = WebClient.create(vaServerInfo.getServiceBaseUrl()) Mono<String> mono = WebClient.create(vaServerInfo.getServiceBaseUrl())
......
package com.viontech.fanxing.task.utils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
/**
* .
*
* @author 谢明辉
* @date 2021/10/25
*/
public enum SceneUtils {
/** 实例 */
INSTANCE;
/**
* 合并 source 的 config 和 roi 到 target
*/
public void mergeScene(JSONObject source, JSONObject target) {
if (source.containsKey("rois")) {
JSONArray rois = source.getJSONArray("rois");
target.put("rois", rois);
}
if (source.containsKey("config")) {
JSONObject config = source.getJSONObject("config");
target.put("config", config);
}
}
}
...@@ -5,14 +5,17 @@ ...@@ -5,14 +5,17 @@
<property name="pattern" value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] [%thread] %logger{50} - %msg%n"/> <property name="pattern" value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] [%thread] %logger{50} - %msg%n"/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>info</level> <level>debug</level>
</filter> </filter>
<encoder> <encoder>
<Pattern>${pattern}</Pattern> <Pattern>${pattern}</Pattern>
</encoder> </encoder>
</appender> </appender>
<root level="debug"> <logger name="com.viontech" level="debug">
<appender-ref ref="CONSOLE"/> <appender-ref ref="CONSOLE"/>
</root> </logger>
<logger name="com.viontech.fanxing.task.mapper" level="off">
</logger>
</configuration> </configuration>
\ No newline at end of file \ No newline at end of file
package com.viontech.fanxing.task; package com.viontech.fanxing.task;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.viontech.fanxing.commons.model.Channel; import com.viontech.fanxing.commons.model.Channel;
import com.viontech.fanxing.commons.model.DictCode; import com.viontech.fanxing.commons.model.DictCode;
import com.viontech.fanxing.commons.model.Task; import com.viontech.fanxing.task.model.runtime.DailyRuntimeConfig;
import com.viontech.fanxing.task.service.OpsClientService; import com.viontech.fanxing.task.service.OpsClientService;
import com.viontech.fanxing.task.service.impl.TaskServiceImpl; import com.viontech.fanxing.task.service.impl.TaskServiceImpl;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
...@@ -16,6 +14,7 @@ import org.springframework.test.context.ActiveProfiles; ...@@ -16,6 +14,7 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date;
/** /**
* . * .
...@@ -46,4 +45,12 @@ public class MainTest { ...@@ -46,4 +45,12 @@ public class MainTest {
System.out.println(JSON.toJSONString(defaultConfig)); System.out.println(JSON.toJSONString(defaultConfig));
} }
@Test
public void dailyRuntimeConfigTest() {
DailyRuntimeConfig dailyRuntimeConfig = new DailyRuntimeConfig("{\"config\":[{\"start\":\"08:00:00\",\"end\":\"10:00:00\"}]}");
ImmutablePair<Long, Long> n = dailyRuntimeConfig.getNextTimeOfExecutionAndTerminal();
System.out.println(new Date(n.left));
System.out.println(new Date(n.right));
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!