|
@@ -18,6 +18,8 @@ import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.http.client.config.RequestConfig;
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+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;
|
|
@@ -26,10 +28,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@@ -366,13 +365,22 @@ public class ProjectService {
|
|
|
String replace7 = replace6.replace("apiVers1on", "apiVersion");
|
|
|
String replace8 = replace7.replace("1atch/v1", "batch/v1");
|
|
|
// 根据 kubernetes 的 node 分配 job
|
|
|
- //1 获取 node 列表
|
|
|
- //2 获取 node 的 pod 列表
|
|
|
- //3 获取 pod 数量最少的 node
|
|
|
- //4 将 job 指定 node 执行
|
|
|
-
|
|
|
-
|
|
|
- String finalYaml = replace8;
|
|
|
+ SshClient client = SshUtil.getClient();
|
|
|
+ ClientSession session = SshUtil.getSession(client, hostname, username, password);
|
|
|
+ String nodeListString = SshUtil.execute(session, "kubectl get node");
|
|
|
+ String podListString = SshUtil.execute(session, "kubectl get pod -o wide");
|
|
|
+ String[] lineArray = nodeListString.split("\n");
|
|
|
+ String minNodeName = "master";
|
|
|
+ long minPodNumber = 9999L;
|
|
|
+ for (int i = 1; i < lineArray.length; i++) {
|
|
|
+ String[] attributeArray = StringUtil.splitByBlank(lineArray[i]);
|
|
|
+ String nodeName = attributeArray[0];
|
|
|
+ long podNumberOfNode = Arrays.stream(podListString.split("\n")).filter(string -> string.contains(nodeName)).count();
|
|
|
+ if (podNumberOfNode < minPodNumber) {
|
|
|
+ minNodeName = nodeName;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String finalYaml = replace8.replace("node-name", minNodeName);
|
|
|
log.info("ProjectConsumer--parseManualProject 开始执行 yaml 文件" + finalYaml);
|
|
|
FileUtil.writeStringToLocalFile(finalYaml, jobTemplateYamlPathTarget);
|
|
|
// 启动
|