|
@@ -2,7 +2,10 @@ package com.css.simulation.resource.scheduler.scheduler;
|
|
|
|
|
|
import api.common.pojo.constants.DictConstants;
|
|
|
import api.common.util.CollectionUtil;
|
|
|
+import api.common.util.LinuxUtil;
|
|
|
+import api.common.util.StringUtil;
|
|
|
import api.common.util.TimeUtil;
|
|
|
+import com.css.simulation.resource.scheduler.mapper.ProjectMapper;
|
|
|
import com.css.simulation.resource.scheduler.mapper.TaskMapper;
|
|
|
import com.css.simulation.resource.scheduler.pojo.po.TaskPO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -12,6 +15,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Component
|
|
@@ -19,12 +23,14 @@ import java.util.List;
|
|
|
public class TickScheduler {
|
|
|
|
|
|
@Value("${scheduler.manual-project.topic}")
|
|
|
- private String manualProjectTopic;
|
|
|
+ String manualProjectTopic;
|
|
|
@Autowired
|
|
|
StringRedisTemplate redisTemplate;
|
|
|
|
|
|
@Autowired
|
|
|
- private TaskMapper taskMapper;
|
|
|
+ TaskMapper taskMapper;
|
|
|
+ @Autowired
|
|
|
+ ProjectMapper projectMapper;
|
|
|
|
|
|
@Scheduled(fixedDelay = 2000)
|
|
|
public void tick() {
|
|
@@ -41,6 +47,7 @@ public class TickScheduler {
|
|
|
try {
|
|
|
String s = redisTemplate.opsForValue().get(manualProjectTopic + ":" + projectId + ":" + taskId);
|
|
|
|
|
|
+ assert s != null;
|
|
|
long tickTime = Long.parseLong(s);
|
|
|
long maxSimulationTime = task.getMaxSimulationTime() * 1000;
|
|
|
long now = TimeUtil.getNow();
|
|
@@ -57,4 +64,31 @@ public class TickScheduler {
|
|
|
});
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 检查如果有 job 在运行但是 pod 全部关闭的情况,此时需要重启一下 job
|
|
|
+ */
|
|
|
+ @Scheduled(fixedDelay = 60 * 1000)
|
|
|
+ public void checkProject() {
|
|
|
+
|
|
|
+ List<String> projectIdList = projectMapper.selectIdByState("20");
|
|
|
+
|
|
|
+ projectIdList.forEach(projectId -> {
|
|
|
+ try {
|
|
|
+ String execute = LinuxUtil.execute("kubectl get pod | grep project-" + projectId);
|
|
|
+ int i = StringUtil.countSubString(execute, projectId);
|
|
|
+ if (i == 0) {
|
|
|
+ LinuxUtil.execute("kubectl delete job project-" + projectId);
|
|
|
+ String jobTemplateYamlPathTarget = "/opt/simulation-cloud/simulation-resource-scheduler/job-yaml/" + "project-" + projectId + ".yaml";
|
|
|
+ LinuxUtil.execute("kubectl apply -f " + jobTemplateYamlPathTarget);
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
}
|