|
@@ -1,8 +1,6 @@
|
|
|
package com.css.simulation.resource.scheduler.service;
|
|
|
|
|
|
-import api.common.pojo.constants.DictConstants;
|
|
|
import api.common.util.SshUtil;
|
|
|
-import api.common.util.TimeUtil;
|
|
|
import com.css.simulation.resource.scheduler.manager.TaskManager;
|
|
|
import com.css.simulation.resource.scheduler.mapper.IndexTemplateMapper;
|
|
|
import com.css.simulation.resource.scheduler.mapper.ManualProjectMapper;
|
|
@@ -64,13 +62,13 @@ public class TaskService {
|
|
|
String projectId = taskPO.getPId();
|
|
|
String userId = taskPO.getCreateUserId();
|
|
|
PrefixTO redisPrefix = projectUtil.getRedisPrefixByUserIdAndProjectIdAndTaksId(userId, projectId, taskId);
|
|
|
- SshClient client = SshUtil.getClient();
|
|
|
- ClientSession session = SshUtil.getSession(client, hostname, username, password);
|
|
|
+ SshClient sshClient = SshUtil.getClient();
|
|
|
+ ClientSession clientSession = SshUtil.getSession(sshClient, hostname, username, password);
|
|
|
//1 判断项目是否已完成
|
|
|
- boolean projectCompleted = taskManager.isProjectCompleted(redisPrefix, projectId, taskId, state, podName, session);
|
|
|
+ boolean projectCompleted = taskManager.isProjectCompleted(redisPrefix, projectId, taskId, state, podName, clientSession);
|
|
|
if (!projectCompleted) {
|
|
|
- session.close();
|
|
|
- client.stop();
|
|
|
+ clientSession.close();
|
|
|
+ sshClient.stop();
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -79,35 +77,18 @@ public class TaskService {
|
|
|
taskManager.prepareScore(redisPrefix.getProjectRunningKey());
|
|
|
|
|
|
//3 打分
|
|
|
- taskManager.score(redisPrefix, userId, projectId, session);
|
|
|
+ taskManager.score(redisPrefix, userId, projectId, clientSession);
|
|
|
|
|
|
// -------------------------------- 收尾 --------------------------------
|
|
|
- manualProjectMapper.updateProjectState(projectId, DictConstants.PROJECT_COMPLETED, TimeUtil.getNowForMysql()); // 修改该 project 的状态为已完成
|
|
|
- log.info("TaskManager--score 项目 " + projectId + " 执行完成!");
|
|
|
|
|
|
- stringRedisTemplate.delete(redisPrefix.getProjectRunningKey());
|
|
|
- // 删除所有 key
|
|
|
-// Set<String> keys = redisTemplate.keys("manualProject:" + projectId + "*");
|
|
|
-// assert keys != null;
|
|
|
-// redisTemplate.delete(keys);
|
|
|
-// log.info("------- /state 任务 " + taskId + " 的父项目为:" + projectId);
|
|
|
+ taskManager.done(redisPrefix,sshClient, clientSession, projectId);
|
|
|
+ log.info("TaskService--taskState 项目 " + projectId + " 执行完成!");
|
|
|
|
|
|
|
|
|
- // 删除 kafka topic
|
|
|
-// SshClient clientKafka = SshUtil.getClient();
|
|
|
-// ClientSession sessionKafka = SshUtil.getSession(clientKafka, hostnameKafka, usernameKafka, passwordKafka);
|
|
|
-// String topicDeleteCommand = StringUtil.replace(kafkaDeleteCommand, "topicName", projectId);
|
|
|
-// SshUtil.execute(sessionKafka, topicDeleteCommand);
|
|
|
-// SshUtil.stop(clientKafka, sessionKafka);
|
|
|
-
|
|
|
-
|
|
|
- // 删除 job
|
|
|
- SshUtil.execute(session, "kubectl delete job project-" + projectId);
|
|
|
- session.close();
|
|
|
- client.stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public Boolean taskConfirm(String taskId) {
|
|
|
return taskManager.taskConfirm(taskId);
|
|
|
}
|