Commit ada3a183 by xmh

1. <feat> 完善数据库初始化脚本 繁星3.0.sql

2. <feat> 请求出错时,打印请求地址 GlobalExceptionHandler
3. <feat> 随机任务运行规则初步制定 RandomRuntimeConfig
4. <fix> 批量操作返回信息修复
5. <refactor> 缩短任务概览的缓存时间到 10秒
6. <fix> 下发任务时添加任务使用资源数
1 parent 97591d73
...@@ -113,5 +113,9 @@ ...@@ -113,5 +113,9 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId> <artifactId>spring-boot-configuration-processor</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file \ No newline at end of file
...@@ -7,6 +7,9 @@ import org.slf4j.LoggerFactory; ...@@ -7,6 +7,9 @@ import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;
import java.util.Optional;
/** /**
* . * .
* *
...@@ -18,16 +21,16 @@ public class GlobalExceptionHandler { ...@@ -18,16 +21,16 @@ public class GlobalExceptionHandler {
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class); private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
public Object exceptionHandler(Exception e) { public Object exceptionHandler(Exception e, HttpServletRequest request) {
log.error("", e); log.error(request.getRequestURI() + "?" + Optional.ofNullable(request.getQueryString()).orElse(""), e);
return JsonMessageUtil.getErrorJsonMsg(e.getMessage()); return JsonMessageUtil.getErrorJsonMsg(e.getMessage());
} }
@ExceptionHandler(FanXingException.class) @ExceptionHandler(FanXingException.class)
public Object fanXingExceptionHandler(FanXingException fanXingException) { public Object fanXingExceptionHandler(FanXingException fanXingException, HttpServletRequest request) {
JsonMessageUtil.JsonMessage errorJsonMsg = JsonMessageUtil.getErrorJsonMsg(fanXingException.getMessage()); JsonMessageUtil.JsonMessage errorJsonMsg = JsonMessageUtil.getErrorJsonMsg(fanXingException.getMessage());
errorJsonMsg.setData(fanXingException.getData()); errorJsonMsg.setData(fanXingException.getData());
log.error("", fanXingException); log.error(request.getRequestURI() + "?" + Optional.ofNullable(request.getQueryString()).orElse(""), fanXingException);
return errorJsonMsg; return errorJsonMsg;
} }
} }
...@@ -21,6 +21,7 @@ import com.viontech.fanxing.task.utils.SceneUtils; ...@@ -21,6 +21,7 @@ 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.apache.commons.io.IOUtils;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -73,7 +74,11 @@ public class TaskController extends TaskBaseController { ...@@ -73,7 +74,11 @@ public class TaskController extends TaskBaseController {
@PostMapping @PostMapping
@Override @Override
public Object add(@RequestBody TaskVo taskVo) { public Object add(@RequestBody TaskVo taskVo) {
taskVo = taskService.addTask(taskVo.getModel()); try {
taskVo = taskService.addTask(taskVo.getModel());
} catch (DuplicateKeyException e) {
return JsonMessageUtil.getErrorJsonMsg("任务名称重复:" + taskVo.getName());
}
return JsonMessageUtil.getSuccessJsonMsg(taskVo); return JsonMessageUtil.getSuccessJsonMsg(taskVo);
} }
...@@ -236,12 +241,12 @@ public class TaskController extends TaskBaseController { ...@@ -236,12 +241,12 @@ public class TaskController extends TaskBaseController {
default: default:
break; break;
} }
build.put("success", taskId);
} catch (Exception e) { } catch (Exception e) {
log.info("", e); log.info("", e);
build.put("error", taskId); build.put("error", taskId);
} }
build.put("success", taskId);
} }
return JsonMessageUtil.getSuccessJsonMsg("success", build); return JsonMessageUtil.getSuccessJsonMsg("success", build.asMap());
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -2,11 +2,14 @@ package com.viontech.fanxing.task.model.runtime; ...@@ -2,11 +2,14 @@ package com.viontech.fanxing.task.model.runtime;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.viontech.keliu.util.DateUtil;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.ImmutablePair;
import java.util.Date;
import java.util.SplittableRandom;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
...@@ -32,9 +35,17 @@ public class RandomRuntimeConfig implements RuntimeConfig { ...@@ -32,9 +35,17 @@ public class RandomRuntimeConfig implements RuntimeConfig {
@Override @Override
public ImmutablePair<Long, Long> getNextTimeOfExecutionAndTerminal() { public ImmutablePair<Long, Long> getNextTimeOfExecutionAndTerminal() {
// todo
long running = TimeUnit.MINUTES.toMillis(runningTime);
return ImmutablePair.nullPair(); // todo 目前逻辑还未定
long running = TimeUnit.MINUTES.toMillis(runningTime);
Date date = DateUtil.setDayMinTime(new Date());
long time = date.getTime() - running;
if (time < System.currentTimeMillis()) {
long l = System.currentTimeMillis();
return ImmutablePair.of(l, l + running);
}
SplittableRandom splittableRandom = new SplittableRandom();
long l = splittableRandom.nextLong(System.currentTimeMillis(), time);
return ImmutablePair.of(l, l + running);
} }
} }
...@@ -29,6 +29,7 @@ public class VATask { ...@@ -29,6 +29,7 @@ public class VATask {
private String channel_unid; private String channel_unid;
private String stream_path; private String stream_path;
private Integer stream_type; private Integer stream_type;
private Float resource_use;
private JSONArray scene; private JSONArray scene;
public VATask(TaskData taskData) { public VATask(TaskData taskData) {
...@@ -40,6 +41,7 @@ public class VATask { ...@@ -40,6 +41,7 @@ public class VATask {
this.channel_unid = task.getChannelUnid(); this.channel_unid = task.getChannelUnid();
this.stream_path = task.getStreamPath(); this.stream_path = task.getStreamPath();
this.stream_type = task.getStreamType(); this.stream_type = task.getStreamType();
this.resource_use = task.getResourceNeed();
this.scene = JSON.parseArray(task.getScene()); this.scene = JSON.parseArray(task.getScene());
} }
} }
...@@ -210,7 +210,7 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic ...@@ -210,7 +210,7 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic
} }
@Override @Override
@LocalCache(value = "task_overview", duration = 30, timeunit = TimeUnit.SECONDS) @LocalCache(value = "task_overview", duration = 10, timeunit = TimeUnit.SECONDS)
public JSONObject overview() { public JSONObject overview() {
List<Task> tasks = selectByExample(new TaskExample()); List<Task> tasks = selectByExample(new TaskExample());
int resourceCount = 0; int resourceCount = 0;
......
...@@ -4,9 +4,10 @@ CREATE TABLE IF NOT EXISTS s_task ...@@ -4,9 +4,10 @@ CREATE TABLE IF NOT EXISTS s_task
( (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()), unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
name VARCHAR(128) NOT NULL COMMENT '任务名称', -- 任务名称不能重复
name VARCHAR(128) NOT NULL UNIQUE COMMENT '任务名称',
alg_type VARCHAR(36) NOT NULL COMMENT '算法类型', alg_type VARCHAR(36) NOT NULL COMMENT '算法类型',
alg_enabled VARCHAR(128) COMMENT '已启用的算法类型', alg_enabled VARCHAR(1024) COMMENT '已启用的算法类型',
resource_need FLOAT NOT NULL COMMENT '任务所需资源数量', resource_need FLOAT NOT NULL COMMENT '任务所需资源数量',
priority INT NOT NULL DEFAULT 0 COMMENT '任务优先级', priority INT NOT NULL DEFAULT 0 COMMENT '任务优先级',
store_config_id BIGINT NOT NULL COMMENT '存储配置id', store_config_id BIGINT NOT NULL COMMENT '存储配置id',
...@@ -236,6 +237,7 @@ CREATE TABLE IF NOT EXISTS s_channel ...@@ -236,6 +237,7 @@ CREATE TABLE IF NOT EXISTS s_channel
( (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()), unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
-- 设备unid不能重复
channel_unid VARCHAR(64) NOT NULL UNIQUE COMMENT '设备中每一路视频通道本身的编码', channel_unid VARCHAR(64) NOT NULL UNIQUE COMMENT '设备中每一路视频通道本身的编码',
device_unid VARCHAR(64) COMMENT '设备自身的编码', device_unid VARCHAR(64) COMMENT '设备自身的编码',
type INT NOT NULL default 0 COMMENT '设备信息来源类型,0手动添加,1平台拉取,2视频资源上传', type INT NOT NULL default 0 COMMENT '设备信息来源类型,0手动添加,1平台拉取,2视频资源上传',
...@@ -247,6 +249,7 @@ CREATE TABLE IF NOT EXISTS s_channel ...@@ -247,6 +249,7 @@ CREATE TABLE IF NOT EXISTS s_channel
brand varchar(64) COMMENT '品牌/厂家', brand varchar(64) COMMENT '品牌/厂家',
direction varchar(64) COMMENT '方向', direction varchar(64) COMMENT '方向',
address_unid VARCHAR(36) COMMENT '绑定的组织结构,组织结构在字典表中', address_unid VARCHAR(36) COMMENT '绑定的组织结构,组织结构在字典表中',
-- 设备名称不能重复
name VARCHAR(128) UNIQUE COMMENT '名称', name VARCHAR(128) UNIQUE COMMENT '名称',
ip VARCHAR(36) COMMENT 'ip地址', ip VARCHAR(36) COMMENT 'ip地址',
port INT COMMENT '端口号', port INT COMMENT '端口号',
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!