Browse Source

docker 配置 vtd 镜像

martin 2 years ago
parent
commit
ff3bf8e93c

+ 6 - 7
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/configuration/algorithm/AlgorithmPlatform.java

@@ -7,24 +7,23 @@ import com.fasterxml.jackson.databind.JsonNode;
 import lombok.SneakyThrows;
 import org.apache.http.client.config.RequestConfig;
 import org.apache.http.impl.client.CloseableHttpClient;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.stereotype.Component;
 
+import javax.annotation.Resource;
+
 @Component
 public class AlgorithmPlatform {
 
     private static final String TOKEN_KEY = "ALGPLATFORM:TOKEN";
 
-    @Autowired
+    @Resource
     OauthParameter oauthParameter;
-
-    @Autowired
+    @Resource
     StringRedisTemplate redisTemplate;
-
-    @Autowired
+    @Resource
     CloseableHttpClient closeableHttpClient;
-    @Autowired
+    @Resource
     RequestConfig requestConfig;
 
     /**

+ 3 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/configuration/kubernetes/KubernetesConfiguration.java

@@ -19,6 +19,9 @@ import java.util.List;
 @Data
 public class KubernetesConfiguration {
 
+    private String namespace;
+    private String podTimeout;
+    private String vtdImage;
     private List<KubernetesNodeTO> nodeList;
 
     @Bean

+ 0 - 28
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/controller/TestController.java

@@ -1,28 +0,0 @@
-package com.css.simulation.resource.scheduler.controller;
-
-
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.cloud.context.config.annotation.RefreshScope;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-@RefreshScope
-@RestController
-@RequestMapping("/test")
-public class TestController {
-
-    @Value("${hello}")
-    String hello;
-//    @Autowired
-//    ManualProjectConsumerTest manualProjectConsumerTest;
-
-    @RequestMapping("/hello")
-    public String hello() {
-        return hello;
-    }
-
-//    @PostMapping("/message")
-//    public void test(@RequestBody ProjectMessageDTO projectMessageDTO) {
-//        manualProjectConsumerTest.parseManualProjectTest(projectMessageDTO);
-//    }
-}

+ 4 - 3
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/scheduler/ProjectScheduler.java

@@ -6,6 +6,7 @@ import api.common.util.CollectionUtil;
 import api.common.util.JsonUtil;
 import api.common.util.StringUtil;
 import api.common.util.TimeUtil;
+import com.css.simulation.resource.scheduler.configuration.kubernetes.KubernetesConfiguration;
 import com.css.simulation.resource.scheduler.consumer.ProjectConsumer;
 import com.css.simulation.resource.scheduler.mapper.*;
 import com.css.simulation.resource.scheduler.pojo.po.ClusterPO;
@@ -42,8 +43,6 @@ public class ProjectScheduler {
     String password;
     @Value("${scheduler.linux-path.job-yaml}")
     String jobYaml;
-    @Value("${scheduler.kubernetes.pod-timeout}")
-    Long podTimeOut;    // 超时时间,单位毫秒
     // -------------------------------- Comment --------------------------------
     @Resource
     StringRedisTemplate stringRedisTemplate;
@@ -63,6 +62,8 @@ public class ProjectScheduler {
     ProjectUtil projectUtil;
     @Resource
     UserMapper userMapper;
+    @Resource
+    KubernetesConfiguration kubernetesConfiguration;
 
 
     /**
@@ -207,7 +208,7 @@ public class ProjectScheduler {
             }
             long lastTickTime = Long.parseLong(tickTime);
             // 如果心跳超时则更改任务状态为 Aborted
-            if (TimeUtil.getNow() - lastTickTime > podTimeOut) {
+            if (TimeUtil.getNow() - lastTickTime > Long.parseLong(kubernetesConfiguration.getPodTimeout())) {
                 String podName = stringRedisTemplate.opsForValue().get(redisPrefix.getTaskPodKey());
                 taskService.taskState(taskId, DictConstants.TASK_ABORTED, podName);
             }

+ 1 - 4
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/service/AlgorithmService.java

@@ -2,11 +2,9 @@ package com.css.simulation.resource.scheduler.service;
 
 import api.common.pojo.common.ResponseBodyVO;
 import api.common.util.FileUtil;
-import com.css.simulation.resource.scheduler.mapper.AlgorithmMapper;
 import com.css.simulation.resource.scheduler.util.MinioUtil;
 import io.minio.MinioClient;
 import lombok.SneakyThrows;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
@@ -16,8 +14,7 @@ import java.io.InputStream;
 @Service
 public class AlgorithmService {
 
-    @Resource
-    AlgorithmMapper algorithmMapper;
+
     @Resource
     MinioClient minioClient;
     @Value("${minio.bucket-name}")

+ 11 - 11
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/service/ProjectService.java

@@ -4,6 +4,7 @@ import api.common.pojo.constants.DictConstants;
 import api.common.pojo.dto.ProjectMessageDTO;
 import api.common.util.*;
 import com.css.simulation.resource.scheduler.configuration.docker.DockerConfiguration;
+import com.css.simulation.resource.scheduler.configuration.kubernetes.KubernetesConfiguration;
 import com.css.simulation.resource.scheduler.mapper.*;
 import com.css.simulation.resource.scheduler.pojo.po.*;
 import com.css.simulation.resource.scheduler.pojo.to.*;
@@ -13,7 +14,6 @@ import com.css.simulation.resource.scheduler.util.ProjectUtil;
 import com.css.simulation.resource.scheduler.util.RedisUtil;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import io.kubernetes.client.openapi.ApiClient;
 import io.minio.MinioClient;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
@@ -36,7 +36,7 @@ import java.util.stream.Collectors;
 public class ProjectService {
 
     /*
-    algorithm-platform:
+      algorithm-platform:
       appid: 2af6f44d98104dc5adcbfb49809ff9d5
       secret: db129a741fde1e9f474199dea24f3901
       token-uri: https://open.zoogooy.com.cn/cgi-bin/token/token?grant_type=client_credential
@@ -68,8 +68,7 @@ public class ProjectService {
     String username;
     @Value("${scheduler.host.password}")
     String password;
-    @Value("${scheduler.kubernetes.namespace}")
-    String kubernetesNamespace;
+
     @Resource
     StringRedisTemplate stringRedisTemplate;
     @Resource
@@ -91,11 +90,11 @@ public class ProjectService {
     @Resource
     AlgorithmMapper algorithmMapper;
     @Resource
-    ApiClient apiClient;
-    @Resource
     ProjectUtil projectUtil;
     @Resource
     DockerConfiguration dockerConfiguration;
+    @Resource
+    KubernetesConfiguration kubernetesConfiguration;
 
 
     // -------------------------------- Comment --------------------------------
@@ -421,9 +420,10 @@ public class ProjectService {
     public void createPod(String projectId, Map<String, Integer> nodeMap, String algorithmDockerImage) {
         String podString = FileUtil.read(new File(podTemplateYaml));
         String replace0 = podString.replace("vtd-container", "vtd-" + projectId);
-        String replace1 = replace0.replace("algorithm-container", "algorithm-" + projectId);
-        String replace2 = replace1.replace("algorithm-image", algorithmDockerImage);
-        String podTemplateStringOfProject = replace2.replace("kafkaTopic", projectId);     // 消息主题名称为 projectId
+        String replace1 = replace0.replace("vtd-image", kubernetesConfiguration.getVtdImage());
+        String replace2 = replace1.replace("algorithm-container", "algorithm-" + projectId);
+        String replace3 = replace2.replace("algorithm-image", algorithmDockerImage);
+        String podTemplateStringOfProject = replace3.replace("kafkaTopic", projectId);     // 消息主题名称为 projectId
         String podTemplateFileNameOfProject = "project-" + projectId + ".yaml";     // 模板文件名称
         FileUtil.writeStringToLocalFile(podTemplateStringOfProject, podYamlDirectory + podTemplateFileNameOfProject);
 
@@ -431,7 +431,7 @@ public class ProjectService {
             for (int i = 0; i < parallelism; i++) {
                 String podName = projectUtil.getRandomPodName(projectId);   // 生成 podName
                 String tempReplace4 = podTemplateStringOfProject.replace("pod-name", podName); // pod 名称包括 projectId 和 随机字符串
-                String tempReplace5 = tempReplace4.replace("namespace-name", kubernetesNamespace); // pod 名称包括 projectId 和 随机字符串
+                String tempReplace5 = tempReplace4.replace("namespace-name", kubernetesConfiguration.getNamespace()); // pod 名称包括 projectId 和 随机字符串
                 String tempPodString = tempReplace5.replace("node-name", nodeName);     // 指定 pod 运行节点
                 log.info("ProjectService--createPod 在节点 " + nodeName + " 开始执行 pod:" + tempPodString);
                 projectUtil.createPod(nodeName, podName, tempPodString);
@@ -442,7 +442,7 @@ public class ProjectService {
 
     /**
      * @param projectId   手动项目 id 或自动项目子id
-     * @param projectType
+     * @param projectType 项目类型
      */
     @SneakyThrows
     public void stopProject(String projectId, String projectType) {

+ 2 - 2
simulation-resource-scheduler/src/main/resources/kubernetes/template/pod/pod-template.yaml

@@ -17,7 +17,7 @@ spec:
   containers:
     - name: vtd-container
       image: vtd.run.perception:latest
-      imagePullPolicy: Never
+      imagePullPolicy: IfNotPresent
       command: [ "/Controller/VTDController", "/Controller/config/docker_cloud.ini", "kafkaTopic" ]
       env:
         - name: PodName
@@ -46,7 +46,7 @@ spec:
           cpu: "0.5"
     - name: algorithm-container
       image: algorithm-image
-      imagePullPolicy: Never
+      imagePullPolicy: IfNotPresent
       command: [ "/bin/sh", "-c", "/run.sh; touch /tmp/hello.txt;while true;do /bin/echo $(date +%T) >> /tmp/hello.txt; sleep 5; done;" ]
       resources:
         limits:

+ 1 - 1
simulation-resource-server/src/main/java/com/css/simulation/resource/model/ctrl/VehicleCtrl.java

@@ -52,7 +52,7 @@ public class VehicleCtrl {
     @RequestMapping("/getVehicleInfo")
     @ResponseBody
     public ResponseBodyVO<VehicleVO> getVehicleInfo(@RequestBody VehicleParam vehicleParam){
-        ResponseBodyVO<VehicleVO> response = new ResponseBodyVO<VehicleVO>(ResponseBodyVO.Response.SUCCESS);
+        ResponseBodyVO<VehicleVO> response = new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
         response.setInfo(vehicleService.getVehicleInfo(vehicleParam));
         return response;
     }

+ 2 - 2
simulation-resource-server/src/main/resources/mapper/model/VehicleMapper.xml

@@ -79,8 +79,8 @@
             height_distance,
             wheelbase,
             share
-        from model_vehicle v
-        where v.id = #{id,jdbcType=VARCHAR} limit 1
+        from model_vehicle
+        where id = #{id}
     </select>
 
     <select id="checkVehicleName" parameterType="api.common.pojo.po.model.VehiclePO" resultMap="VehicleVOMap">