|
@@ -2,57 +2,42 @@ package com.css.simulation.resource.scheduler.service;
|
|
|
|
|
|
import api.common.util.SshUtil;
|
|
|
import com.css.simulation.resource.scheduler.manager.TaskManager;
|
|
|
-import com.css.simulation.resource.scheduler.mapper.IndexTemplateMapper;
|
|
|
-import com.css.simulation.resource.scheduler.mapper.ManualProjectMapper;
|
|
|
import com.css.simulation.resource.scheduler.mapper.TaskMapper;
|
|
|
import com.css.simulation.resource.scheduler.pojo.po.TaskPO;
|
|
|
import com.css.simulation.resource.scheduler.pojo.to.PrefixTO;
|
|
|
import com.css.simulation.resource.scheduler.util.ProjectUtil;
|
|
|
-import io.minio.MinioClient;
|
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.sshd.client.SshClient;
|
|
|
import org.apache.sshd.client.session.ClientSession;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
public class TaskService {
|
|
|
|
|
|
-
|
|
|
- @Value("${minio.bucket-name}")
|
|
|
- String bucketName;
|
|
|
@Value("${scheduler.host.hostname}")
|
|
|
String hostname;
|
|
|
@Value("${scheduler.host.username}")
|
|
|
String username;
|
|
|
@Value("${scheduler.host.password}")
|
|
|
String password;
|
|
|
- @Value("${spring.kafka.delete-command}")
|
|
|
- String kafkaDeleteCommand;
|
|
|
- // -------------------------------- Comment --------------------------------
|
|
|
-
|
|
|
- @Autowired
|
|
|
- StringRedisTemplate stringRedisTemplate;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
TaskManager taskManager;
|
|
|
- @Autowired
|
|
|
- IndexTemplateMapper indexTemplateMapper;
|
|
|
- @Autowired
|
|
|
- MinioClient minioClient;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
TaskMapper taskMapper;
|
|
|
- @Autowired
|
|
|
- ManualProjectMapper manualProjectMapper;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
ProjectUtil projectUtil;
|
|
|
|
|
|
+ // -------------------------------- Comment --------------------------------
|
|
|
|
|
|
@SneakyThrows
|
|
|
public void taskState(String taskId, String state, String podName) {
|
|
|
+ SshClient sshClient = SshUtil.getClient();
|
|
|
+ ClientSession clientSession = SshUtil.getSession(sshClient, hostname, username, password);
|
|
|
log.info("TaskService--state 接收到参数为:taskId=" + taskId + ",state=" + state + ",podName=" + podName);
|
|
|
TaskPO taskPO = taskMapper.selectById(taskId);
|
|
|
if (taskPO == null) {
|
|
@@ -62,8 +47,6 @@ public class TaskService {
|
|
|
String projectId = taskPO.getPId();
|
|
|
String userId = taskPO.getCreateUserId();
|
|
|
PrefixTO redisPrefix = projectUtil.getRedisPrefixByUserIdAndProjectIdAndTaksId(userId, projectId, taskId);
|
|
|
- SshClient sshClient = SshUtil.getClient();
|
|
|
- ClientSession clientSession = SshUtil.getSession(sshClient, hostname, username, password);
|
|
|
//1 判断项目是否已完成
|
|
|
boolean projectCompleted = taskManager.isProjectCompleted(redisPrefix, projectId, taskId, state, podName);
|
|
|
if (!projectCompleted) {
|
|
@@ -71,21 +54,14 @@ public class TaskService {
|
|
|
sshClient.stop();
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
//2 准备打分
|
|
|
log.info("TaskService--taskState 项目 " + projectId + "准备打分!");
|
|
|
taskManager.prepareScore(redisPrefix.getProjectRunningKey());
|
|
|
-
|
|
|
//3 打分
|
|
|
taskManager.score(redisPrefix, userId, projectId, clientSession);
|
|
|
-
|
|
|
- // -------------------------------- 收尾 --------------------------------
|
|
|
-
|
|
|
- taskManager.done(redisPrefix,sshClient, clientSession, projectId);
|
|
|
+ //4 结束
|
|
|
+ taskManager.done(redisPrefix, sshClient, clientSession, projectId);
|
|
|
log.info("TaskService--taskState 项目 " + projectId + " 执行完成!");
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|