martin 3 tahun lalu
induk
melakukan
1cb935bc2c

+ 12 - 0
api-common/src/main/java/api/common/util/EncodeUtil.java

@@ -0,0 +1,12 @@
+package api.common.util;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+
+public class EncodeUtil {
+
+    public static String utf8(String string) throws UnsupportedEncodingException {
+        return URLEncoder.encode(string, "utf-8");
+    }
+
+}

+ 3 - 0
simulation-oauth-client/src/main/java/com/css/simulation/oauth/client/configuration/oauth/OauthParameter.java

@@ -2,8 +2,11 @@ package com.css.simulation.oauth.client.configuration.oauth;
 
 import lombok.Data;
 import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
 import org.springframework.stereotype.Component;
 
+
+@RefreshScope
 @Data
 @Component
 @ConfigurationProperties(prefix = "oauth")

+ 10 - 6
simulation-oauth-client/src/main/java/com/css/simulation/oauth/client/controller/SignController.java

@@ -1,10 +1,11 @@
 package com.css.simulation.oauth.client.controller;
 
 import api.common.pojo.common.ResponseBodyVO;
-import api.common.pojo.param.SignUsernameParameter;
 import api.common.pojo.param.SignSingleParameter;
+import api.common.pojo.param.SignUsernameParameter;
 import api.common.pojo.po.UserPO;
 import api.common.pojo.vo.SimulationTokenVO;
+import api.common.util.EncodeUtil;
 import api.common.util.EncryptUtil;
 import api.common.util.HttpUtil;
 import api.common.util.JsonUtil;
@@ -24,7 +25,6 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 
 import javax.annotation.Resource;
-import java.net.URLEncoder;
 
 @Controller
 @RequestMapping("/sign")
@@ -59,10 +59,10 @@ public class SignController {
     @SneakyThrows
     public String entry(@RequestParam("ticket") String ticket) {
         log.info("------- /entry 接收到的 ticket 为:" + ticket);
-        String encodeTicket = URLEncoder.encode(ticket, "utf-8");
+        String encodeTicket = EncodeUtil.utf8(ticket);
         log.info("------- /entry ticket 编码之后为:" + encodeTicket);
         log.info("------- /entry 重定向地址为:" + oauthParameter.getZoogooyRedirectUri());
-        String encodeRedirect = URLEncoder.encode(oauthParameter.getZoogooyRedirectUri(), "utf-8");
+        String encodeRedirect = EncodeUtil.utf8(oauthParameter.getZoogooyRedirectUri());
         log.info("------- /entry 重定向地址编码之后为:" + encodeRedirect);
 
         String zoogooyAuthorizeUrl = oauthParameter.getZoogooyAuthorizeUri() +
@@ -86,14 +86,18 @@ public class SignController {
     public ResponseBodyVO<SimulationTokenVO> single(@RequestBody SignSingleParameter signSingleParameter) {
 
         String code = signSingleParameter.getCode();
+        String encodeCode = EncodeUtil.utf8(code);
         String ticket = signSingleParameter.getTicket();
+        String encodeTicket = EncodeUtil.utf8(ticket);
         log.info("------- /single 接收到的 code 为:" + code);
+        log.info("------- /single code 编码之后为:" + code);
         log.info("------- /single 接收到的 ticket 为:" + ticket);
+        log.info("------- /single ticket 编码之后为:" + ticket);
         //1 根据统一凭条 code 获取统一平台 access_token
 
         String zoogooyTokenUrl = oauthParameter.getZoogooyTokenUri() + "?appid=" + oauthParameter.getZoogooyAppid() +
                 "&secret=" + oauthParameter.getZoogooyAppSecret() +
-                "&code=" + code +
+                "&code=" + encodeCode +
                 "&grant_type=authorization_code";
 
 
@@ -109,7 +113,7 @@ public class SignController {
         String zoogooyUserUrl = oauthParameter.getZoogooyUserUri() +
                 "?access_token=" + accessToken +
                 "&openid=" + openid +
-                "&ticket=" + ticket;
+                "&ticket=" + encodeTicket;
         String zoogooyUserJson = HttpUtil.post(closeableHttpClient, requestConfig, zoogooyUserUrl, null, null);
         ObjectMapper objectMapper2 = new ObjectMapper();
         JsonNode userRoot = objectMapper2.readTree(zoogooyUserJson);

+ 13 - 1
simulation-oauth-server/src/main/java/com/css/simulation/oauth/server/cofiguration/oauth/OauthAuthorizationServerConfiguration.java

@@ -57,7 +57,19 @@ public class OauthAuthorizationServerConfiguration extends AuthorizationServerCo
                 )  // 客户端拥有的资源列表
                 .authorizedGrantTypes("password", "refresh_token") // 允许的授权方式
                 .scopes("all")    // 授权范围划分
-                .autoApprove(true); // 是否自动通过,即是否跳过 scope 选择界面,跳过的话代表将所有 scope 授权范围赋予该 client
+                .autoApprove(true)
+                .and()
+                .withClient("algorithm-client")       // 客户端 id
+                .secret("hPT7zVteEXvRzS41NhJXoQYqtGmai3W0")   // 客户端密钥
+                .resourceIds(
+                        "simulation-resource-common",
+                        "simulation-resource-scheduler",
+                        "simulation-resource-sever"
+                )  // 客户端拥有的资源列表
+                .authorizedGrantTypes("password", "refresh_token") // 允许的授权方式
+                .scopes("other")    // 授权范围划分
+                .autoApprove(true)
+        ; // 是否自动通过,即是否跳过 scope 选择界面,跳过的话代表将所有 scope 授权范围赋予该 client
     }
 
     /**

+ 25 - 24
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/consumer/ManualProjectConsumer.java

@@ -202,32 +202,33 @@ public class ManualProjectConsumer {
             commonService.send(new KafkaParameter(projectId, taskJson));
         }
 
-        // -------------------------------- 4 算法(一期按单机版做) --------------------------------
-        // 私有仓库导入算法镜像(搭建私有仓库)
-        String algorithmId = projectMessageDTO.getAlgorithmId();    // 算法 id
-        //4-1 根据算法 id 获取算法文件地址、是否已导入成镜像。
-        AlgorithmPO algorithmPO = algorithmMapper.selectById(algorithmId);
-        String minioPath = algorithmPO.getMinioPath();
-        String dockerImage;
-        if ("0".equals(algorithmPO.getDockerImport())) {
-            dockerImage = "algorithm_" + algorithmId + ":latest";
-            String algorithmTarLinuxTempPath = linuxTempPath + minioPath;
-            // 下载算法文件到本地( 2 到仓库服务器)
-            Response response = commonService.download(new MinioParameter(minioPath));
-            InputStream inputStream = response.body().asInputStream();
-            FileUtil.writeInputStreamToLocalFile(inputStream, algorithmTarLinuxTempPath);
-            //4-2 本地执行 docker load 算法文件成镜像(集群版可改成用 docker-java 操作仓库)
-            LinuxUtil.execute("docker import " + algorithmTarLinuxTempPath + " " + dockerImage);
-        } else if ("1".equals(algorithmPO.getDockerImport()) && StringUtil.isNotEmpty(algorithmPO.getDockerImage())) {
-            dockerImage = algorithmPO.getDockerImage();
-        } else {
-            throw new RuntimeException("算法 " + algorithmId + "的 mysql 数据有误!");
-        }
+        // -------------------------------- 4 算法导入(一期按单机版做) --------------------------------
+//        // 私有仓库导入算法镜像(搭建私有仓库)
+//        String algorithmId = projectMessageDTO.getAlgorithmId();    // 算法 id
+//        //4-1 根据算法 id 获取算法文件地址、是否已导入成镜像。
+//        AlgorithmPO algorithmPO = algorithmMapper.selectById(algorithmId);
+//        String minioPath = algorithmPO.getMinioPath();
+//        String dockerImage;
+//        if ("0".equals(algorithmPO.getDockerImport())) {
+//            dockerImage = "algorithm_" + algorithmId + ":latest";
+//            String algorithmTarLinuxTempPath = linuxTempPath + minioPath;
+//            // 下载算法文件到本地( 2 到仓库服务器)
+//            Response response = commonService.download(new MinioParameter(minioPath));
+//            InputStream inputStream = response.body().asInputStream();
+//            FileUtil.writeInputStreamToLocalFile(inputStream, algorithmTarLinuxTempPath);
+//            //4-2 本地执行 docker load 算法文件成镜像(集群版可改成用 docker-java 操作仓库)
+//            LinuxUtil.execute("docker import " + algorithmTarLinuxTempPath + " " + dockerImage);
+//        } else if ("1".equals(algorithmPO.getDockerImport()) && StringUtil.isNotEmpty(algorithmPO.getDockerImage())) {
+//            dockerImage = algorithmPO.getDockerImage();
+//        } else {
+//            throw new RuntimeException("算法 " + algorithmId + "的 mysql 数据有误!");
+//        }
         // -------------------------------- 5 创建 pod 开始执行 --------------------------------
         int completions = sceneList.size();     // 结束标
         int parallelism = projectMessageDTO.getParallelism();    // 并行度
         BatchV1Api batchV1Api = new BatchV1Api(apiClient);
-        V1Job yaml = (V1Job) Yaml.load(ResourceUtils.getFile("classpath:kubernetes/template/job-template.yaml"));
+//        V1Job yaml = (V1Job) Yaml.load(ResourceUtils.getFile("classpath:kubernetes/template/job-template.yaml"));
+        V1Job yaml = (V1Job) Yaml.load(ResourceUtils.getFile("classpath:kubernetes/template/job-test.yaml"));
         //1 apiVersion
         //2 kind
         //3 metadata
@@ -249,12 +250,12 @@ public class ManualProjectConsumer {
             }
             if ("algorithm".equals(name)) {
                 container.setName("algorithm_" + projectId);
-                container.setImage(dockerImage);
+//                container.setImage(dockerImage);
             }
         }
         //4-4 创建
         yaml.setSpec(job);
-        batchV1Api.createNamespacedJob("simulation-task", yaml, null, null, null);
+        batchV1Api.createNamespacedJob("simulation-cloud", yaml, null, null, null);
     }
 
 

+ 5 - 4
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/service/TaskService.java

@@ -17,14 +17,13 @@ import com.css.simulation.resource.scheduler.pojo.po.TaskIndexPO;
 import com.css.simulation.resource.scheduler.pojo.po.TaskPO;
 import com.css.simulation.resource.scheduler.pojo.to.ScoreTO;
 import feign.Response;
+import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.io.IOUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.io.BufferedInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.*;
@@ -75,6 +74,7 @@ public class TaskService {
     }
 
     @Transactional
+    @SneakyThrows
     public void taskState(String taskId, String state) {
         log.info("------- 接收到任务 " + taskId + "的状态:" + state);
         //1 根据 taskId 修改任务状态 taskState。
@@ -92,10 +92,11 @@ public class TaskService {
         // -------------------------------- 查询叶子指标 --------------------------------
         List<IndexTemplatePO> leafIndexTemplateList = indexTemplateMapper.selectLeafIndexWithRuleDetailsByPackageId(scenePackageId);
         List<TaskIndexPO> leafTaskIndexList = new ArrayList<>();
-        for (int i = 0; i < leafTaskIndexList.size(); i++) {
+        for (int i = 0; i < leafIndexTemplateList.size(); i++) {
+            IndexTemplatePO indexTemplatePO = leafIndexTemplateList.get(i);
             // -------------------------------- 将叶子节点对应的打分规则保存到临时目录 --------------------------------
             String ruleDetails = indexTemplatePO.getRuleDetails();    // 打分脚本内容
-            String ruleDetailsPath = linuxTempPath + "rule-script/" + projectId + "_1";
+            String ruleDetailsPath = linuxTempPath + "rule-script/" + projectId + "_" + i;
             FileUtil.writeInputStreamToLocalFile(IoUtil.stringToInputStream(ruleDetails), ruleDetailsPath);
             // -------------------------------- 查询每个叶子指标包括的场景 --------------------------------
             Set<String> sceneIdSet = new HashSet<>();

File diff ditekan karena terlalu besar
+ 2 - 3
simulation-resource-scheduler/src/main/resources/kubernetes/config


+ 39 - 0
simulation-resource-scheduler/src/main/resources/kubernetes/template/job/job-test.yaml

@@ -0,0 +1,39 @@
+apiVersion: v1
+kind: Pod
+metadata:
+  name: ros-algorithm-test
+spec:
+  restartPolicy: Never
+  containers:
+    - name: vtd
+      image: vtd.run.perception:latest
+      imagePullPolicy: Never
+#      command: ["/Controller/VTDController", "/Controller/config/local_docker.ini"]
+      command: [ "/bin/sh","-c","touch /tmp/hello.txt;while true;do /bin/echo $(date +%T) >> /tmp/hello.txt; sleep 3000; done;" ]
+      env:
+        - name: NodeID
+          valueFrom:
+            fieldRef:
+              fieldPath: metadata.name
+        - name: LM_LICENSE_FILE
+          value: 27500@192.168.10.179
+      volumeMounts:
+        - name: nvidia0
+          mountPath: /dev/nvidia0
+        - name: nvidiactl
+          mountPath: /dev/nvidiactl
+      securityContext:
+        privileged: true
+    - name: algorithm
+      image: aeb.ros:latest
+      imagePullPolicy: Never
+#        command: [ "/AEB/start.sh" ]
+      command: [ "/bin/sh","-c","touch /tmp/hello.txt;while true;do /bin/echo $(date +%T) >> /tmp/hello.txt; sleep 3000; done;" ]
+  volumes:
+    - name: nvidia0
+      hostPath:
+        path: /dev/nvidia0
+    - name: nvidiactl
+      hostPath:
+        path: /dev/nvidiactl
+

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini