|
@@ -1,15 +1,11 @@
|
|
|
package com.css.simulation.resource.scheduler.web.scheduler;
|
|
|
|
|
|
-import api.common.pojo.dto.ProjectMessageDTO;
|
|
|
import api.common.util.CollectionUtil;
|
|
|
-import api.common.util.JsonUtil;
|
|
|
import com.css.simulation.resource.scheduler.common.util.ProjectUtil;
|
|
|
import com.css.simulation.resource.scheduler.common.util.RedisUtil;
|
|
|
import com.css.simulation.resource.scheduler.web.consumer.ProjectConsumer;
|
|
|
-import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
@@ -20,14 +16,6 @@ import java.util.List;
|
|
|
@Component
|
|
|
@Slf4j
|
|
|
public class ProjectScheduler {
|
|
|
-
|
|
|
- @Value("${scheduler.host.hostname}")
|
|
|
- private String hostname;
|
|
|
- @Value("${scheduler.host.username}")
|
|
|
- private String username;
|
|
|
- @Value("${scheduler.host.password}")
|
|
|
- private String password;
|
|
|
- // -------------------------------- Comment --------------------------------
|
|
|
@Resource
|
|
|
private StringRedisTemplate stringRedisTemplate;
|
|
|
@Resource
|
|
@@ -35,15 +23,14 @@ public class ProjectScheduler {
|
|
|
@Resource
|
|
|
private ProjectUtil projectUtil;
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 调度项目启动
|
|
|
*/
|
|
|
@Scheduled(fixedDelay = 60 * 1000)
|
|
|
public void dispatchProject() {
|
|
|
- log.info("//1 查询等待中的项目任务。");
|
|
|
List<String> projectMessageKeys = projectUtil.getWaitingProjectMessageKeys();
|
|
|
if (!CollectionUtil.isEmpty(projectMessageKeys)) {
|
|
|
+ log.info("尝试启动等待中的项目:" + projectMessageKeys);
|
|
|
for (String projectMessageKey : projectMessageKeys) {
|
|
|
final String projectMessage = RedisUtil.getStringByKey(stringRedisTemplate, projectMessageKey);
|
|
|
ConsumerRecord<String, String> projectRecord = new ConsumerRecord<>("", 0, 0L, null, projectMessage);
|
|
@@ -52,62 +39,4 @@ public class ProjectScheduler {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- @SneakyThrows
|
|
|
- public void run(String clusterId, String projectId, String projectWaitingKey, String projectRunningKey) {
|
|
|
- ProjectMessageDTO projectMessageDTO;
|
|
|
- try {
|
|
|
- projectMessageDTO = JsonUtil.jsonToBean(RedisUtil.getStringByKey(stringRedisTemplate, projectWaitingKey), ProjectMessageDTO.class);
|
|
|
- } catch (Exception e) {
|
|
|
- log.info("run 等待执行的项目信息已经从 redis 删除。");
|
|
|
- return;
|
|
|
- }
|
|
|
- //1 获取所有节点的剩余可用并行度
|
|
|
- int restParallelism = projectUtil.getRestParallelism();
|
|
|
- if (restParallelism == 0) {
|
|
|
- log.info("run 集群中没有可用并行度,项目 " + projectId + " 继续等待。");
|
|
|
- return;
|
|
|
- }
|
|
|
- //2 判断剩余可用并行度是否大于项目并行度,否则继续等待
|
|
|
- if (restParallelism > 0L) {
|
|
|
- log.info("run 集群 " + clusterId + " 执行项目项目 " + projectId);
|
|
|
- projectMessageDTO.setCurrentParallelism(restParallelism); // 设置实际的并行度
|
|
|
- projectConsumer.parseProject(projectMessageDTO, projectRunningKey);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-// /**
|
|
|
-// * 处理 pod 超时
|
|
|
-// * 同时也可处理 pod 莫名关闭,因为关闭之后也会超时
|
|
|
-// */
|
|
|
-// @Scheduled(fixedDelay = 60 * 1000)
|
|
|
-// @Transactional
|
|
|
-// public void taskTimeout() {
|
|
|
-// //1 查询任务信息(需要过滤已经删除的项目,因为页面上删除项目不会删除任务)
|
|
|
-// List<TaskPO> executingTaskList = taskMapper.selectByRunStateAndProjectIsNotDeleted(DictConstants.TASK_RUNNING);
|
|
|
-// if (CollectionUtil.isEmpty(executingTaskList)) {
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// log.info("taskTimeout 正在运行的任务有:" + executingTaskList);
|
|
|
-// for (TaskPO task : executingTaskList) {
|
|
|
-// String userId = task.getCreateUserId();
|
|
|
-// String projectId = task.getPId();
|
|
|
-// String taskId = task.getId();
|
|
|
-// PrefixTO redisPrefix = projectUtil.getRedisPrefixByUserIdAndProjectIdAndTaskId(userId, projectId, taskId);
|
|
|
-// // 获取心跳时间
|
|
|
-// String tickTime = stringRedisTemplate.opsForValue().get(redisPrefix.getTaskTickKey());
|
|
|
-// if (StringUtil.isEmpty(tickTime)) {
|
|
|
-// log.error(redisPrefix.getTaskTickKey() + ",该 key 的心跳时间为空!");
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-// long lastTickTime = Long.parseLong(tickTime);
|
|
|
-// // 如果心跳超时则更改任务状态为 Aborted
|
|
|
-// if (TimeUtil.getNow() - lastTickTime > Long.parseLong(kubernetesConfiguration.getPodTimeout())) {
|
|
|
-// String podName = stringRedisTemplate.opsForValue().get(redisPrefix.getTaskPodKey());
|
|
|
-// taskService.taskState(taskId, DictConstants.TASK_ABORTED, podName);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
}
|