|
@@ -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;
|
|
|
-
|
|
|
@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;
|
|
|
- }
|
|
|
-
|
|
|
- int restParallelism = projectUtil.getRestParallelism();
|
|
|
- if (restParallelism == 0) {
|
|
|
- log.info("run 集群中没有可用并行度,项目 " + projectId + " 继续等待。");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (restParallelism > 0L) {
|
|
|
- log.info("run 集群 " + clusterId + " 执行项目项目 " + projectId);
|
|
|
- projectMessageDTO.setCurrentParallelism(restParallelism);
|
|
|
- projectConsumer.parseProject(projectMessageDTO, projectRunningKey);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|