root 2 سال پیش
والد
کامیت
3a1439470d

+ 1 - 1
api-common/src/main/java/api/common/pojo/po/project/SimulationManualProjectPo.java

@@ -30,7 +30,7 @@ public class SimulationManualProjectPo extends BasePo {
     //算法
     private String algorithm;
 
-    //车辆
+    //车辆 id
     private String vehicle;
 
     //场景(包)

+ 8 - 8
simulation-resource-common/src/main/java/com/css/simulation/resource/common/configuration/minio/MinioConfiguration.java

@@ -26,13 +26,13 @@ public class MinioConfiguration {
         return new SubMinioClient(minioClient);
     }
 
-//    @Bean
-//    public SubMinioClient minioClientPublic() {
-//        MinioClient minioClient = MinioClient.builder()
-//                .endpoint(endpointPublic)
-//                .credentials(accessKey, secretKey)
-//                .build();
-//        return new SubMinioClient(minioClient);
-//    }
+    @Bean
+    public SubMinioClient minioClientPublic() {
+        MinioClient minioClient = MinioClient.builder()
+                .endpoint(endpointPublic)
+                .credentials(accessKey, secretKey)
+                .build();
+        return new SubMinioClient(minioClient);
+    }
 
 }

+ 3 - 2
simulation-resource-common/src/main/java/com/css/simulation/resource/common/controller/MinioController.java

@@ -39,8 +39,8 @@ public class MinioController {
     @Resource
     private MinioConfiguration minioConfiguration;
 
-//    @Resource(name = "minioClientPublic")
-//    private SubMinioClient minioClientPublic;
+    @Resource(name = "minioClientPublic")
+    private SubMinioClient minioClientPublic;
 
 
     @PostMapping("/hello")
@@ -162,6 +162,7 @@ public class MinioController {
         }
         Map<String, Object> result = new HashMap<>();//结果数据
         CreateMultipartUploadResponse multipartUpload = minioClientPrivate.createMultipartUpload(minioConfiguration.getBucketName(), null, objectName, null, null);
+//        CreateMultipartUploadResponse multipartUpload = minioClientPublic.createMultipartUpload(minioConfiguration.getBucketName(), null, objectName, null, null);
         String uploadId = multipartUpload.result().uploadId();
         List<String> UrlList = new LinkedList<>();
         Map<String, String> queryParam = new HashMap<>();

+ 3 - 3
simulation-resource-monitor/src/main/java/com/css/simulation/resource/monitor/manager/SystemServerManager.java

@@ -5,19 +5,19 @@ import com.css.simulation.resource.monitor.mappper.SystemServerMapper;
 import org.apache.ibatis.session.ExecutorType;
 import org.apache.ibatis.session.SqlSession;
 import org.apache.ibatis.session.SqlSessionFactory;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import javax.annotation.Resource;
 import java.util.List;
 
 @Component
 public class SystemServerManager {
 
 
-    @Autowired
+    @Resource
     private SqlSessionFactory sqlSessionFactory;
 
-    public void replace(List<SystemServerPO> systemServerPOList) {
+    public void deleteAndInsert(List<SystemServerPO> systemServerPOList) {
 
         try (SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false)) {
             SystemServerMapper systemServerMapper = sqlSession.getMapper(SystemServerMapper.class);

+ 53 - 49
simulation-resource-monitor/src/main/java/com/css/simulation/resource/monitor/scheduler/MyScheduler.java

@@ -12,6 +12,7 @@ import org.apache.sshd.client.SshClient;
 import org.apache.sshd.client.session.ClientSession;
 import org.dom4j.DocumentException;
 import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
@@ -33,57 +34,60 @@ public class MyScheduler {
     SystemServerManager systemServerManager;
 
 
-    //    @Scheduled(fixedDelay = 60 * 60 * 1000)
-    //@Scheduled(fixedDelay = 2 * 1000)
-    public void server() throws IOException, InterruptedException, DocumentException {
-        List<SystemServerPO> systemServerPOList = new ArrayList<>();
-        for (Host host : hostList) {
-            int taskNumber = 0;
-            SshClient sshClient = SshClient.setUpDefaultClient();
-            String ip = host.getHostname();
-            Integer port = host.getPort();
-            String username = host.getUsername();
-            String password = host.getPassword();
-            String type = host.getType();
-            ClientSession session = SshUtil.getSession(sshClient, ip, username, password);
-            double gpuUsage = 0.0;
-            long gpuTotal = 0L;
-            if ("gpu".equals(type)) {
-                gpuUsage = SshUtil.gpuUsage(session);
-                gpuTotal = SshUtil.gpuTotal(session);
-                String podList = SshUtil.execute(session, "kubectl get pod | grep project");
-                taskNumber = StringUtil.countSubString(podList, "project");
-            }
+    @Scheduled(fixedDelay = 60 * 1000)
+    public void server() {
+        try {
+            List<SystemServerPO> systemServerPOList = new ArrayList<>();
+            log.info("server() 服务器列表为:"+hostList);
+            for (Host host : hostList) {
+                int taskNumber = 0;
+                SshClient sshClient = SshClient.setUpDefaultClient();
+                String ip = host.getHostname();
+                String username = host.getUsername();
+                String password = host.getPassword();
+                String type = host.getType();
+                ClientSession session = SshUtil.getSession(sshClient, ip, username, password);
+                double gpuUsage = 0.0;
+                long gpuTotal = 0L;
+                if ("gpu".equals(type)) {
+                    gpuUsage = SshUtil.gpuUsage(session);
+                    gpuTotal = SshUtil.gpuTotal(session);
+                    String podList = SshUtil.execute(session, "kubectl get pod | grep project");
+                    taskNumber = StringUtil.countSubString(podList, "project");
+                }
 
-            SystemServerPO systemServerPO = SystemServerPO.builder()
-                    .id(StringUtil.getRandomUUID())
-                    .serverId(SshUtil.hostname(session))
-                    .serverAddress(ip)
-                    .serverType(type)
-                    .memoryUsage(SshUtil.memoryUsage(session))
-                    .memoryAvailable(SshUtil.memoryAvailable(session))
-                    .memoryTotal(SshUtil.memoryTotal(session))
-                    .diskUsage(SshUtil.diskUsage(session))
-                    .diskAvailable(SshUtil.diskAvailable(session))
-                    .diskTotal(SshUtil.diskTotal(session))
-                    .cpuUsage(SshUtil.cpuUsage(session))
-                    .cpuTotal(SshUtil.cpuTotal(session))
-                    .gpuUsage(gpuUsage)
-                    .gpuTotal(gpuTotal)
-                    .taskNumber(taskNumber)
-                    .build();
-            systemServerPO.setCreateTime(TimeUtil.getNowForMysql());
-            systemServerPO.setCreateUserId("simulation-resource-monitor");
-            systemServerPO.setModifyTime(TimeUtil.getNowForMysql());
-            systemServerPO.setModifyUserId("simulation-resource-monitor");
-            systemServerPO.setModifyTime(TimeUtil.getNowForMysql());
-            systemServerPO.setIsDeleted("0");
-            systemServerPOList.add(systemServerPO);
-            session.close();
-            sshClient.stop();
+                SystemServerPO systemServerPO = SystemServerPO.builder()
+                        .id(StringUtil.getRandomUUID())
+                        .serverId(SshUtil.hostname(session))
+                        .serverAddress(ip)
+                        .serverType(type)
+                        .memoryUsage(SshUtil.memoryUsage(session))
+                        .memoryAvailable(SshUtil.memoryAvailable(session))
+                        .memoryTotal(SshUtil.memoryTotal(session))
+                        .diskUsage(SshUtil.diskUsage(session))
+                        .diskAvailable(SshUtil.diskAvailable(session))
+                        .diskTotal(SshUtil.diskTotal(session))
+                        .cpuUsage(SshUtil.cpuUsage(session))
+                        .cpuTotal(SshUtil.cpuTotal(session))
+                        .gpuUsage(gpuUsage)
+                        .gpuTotal(gpuTotal)
+                        .taskNumber(taskNumber)
+                        .build();
+                systemServerPO.setCreateTime(TimeUtil.getNowForMysql());
+                systemServerPO.setCreateUserId("simulation-resource-monitor");
+                systemServerPO.setModifyTime(TimeUtil.getNowForMysql());
+                systemServerPO.setModifyUserId("simulation-resource-monitor");
+                systemServerPO.setModifyTime(TimeUtil.getNowForMysql());
+                systemServerPO.setIsDeleted("0");
+                systemServerPOList.add(systemServerPO);
+                session.close();
+                sshClient.stop();
+            }
+            log.info("MyScheduler-------server 获取服务器信息!" + systemServerPOList);
+            systemServerManager.deleteAndInsert(systemServerPOList);
+        } catch (IOException | DocumentException | InterruptedException e) {
+            throw new RuntimeException(e);
         }
-        log.info("MyScheduler-------server 获取服务器信息!" + systemServerPOList);
-        systemServerManager.replace(systemServerPOList);
 
     }
 

+ 2 - 4
simulation-resource-server/src/main/java/com/css/simulation/resource/algorithm/ctrl/AlgorithmCtrl.java

@@ -5,12 +5,12 @@ import api.common.pojo.common.ResponseBodyVO;
 import api.common.pojo.constants.LogConstants;
 import api.common.pojo.param.algorithm.AlgorithmParameter;
 import com.css.simulation.resource.algorithm.service.AlgorithmService;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 
+import javax.annotation.Resource;
 import java.io.IOException;
 import java.util.Map;
 
@@ -21,14 +21,12 @@ import java.util.Map;
 @RequestMapping(value = "/algorithm",name = LogConstants.MODULE_ALGORITH)
 public class AlgorithmCtrl {
 
-    @Autowired
+    @Resource
     private AlgorithmService service;
 
 
     /**
      * 新增/修改算法
-     * @param param
-     * @return
      */
     @RequestMapping("addOrUpdate")
     @ResponseBody

+ 1 - 3
simulation-resource-server/src/main/java/com/css/simulation/resource/common/utils/AuthUtil.java

@@ -35,9 +35,7 @@ public class AuthUtil {
     public static String getCurrentUseType() {
         Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
         MyUserDetails userDetails = (MyUserDetails) authentication.getPrincipal();
-        String useType = userDetails.getUseType();
-        log.info("AuthUtil--getCurrentUserId 当前用户的 useType 为:" + useType);
-        return useType;
+        return userDetails.getUseType();
     }
 
     /**

+ 33 - 14
simulation-resource-server/src/main/java/com/css/simulation/resource/home/service/HomePageService.java

@@ -3,17 +3,21 @@ package com.css.simulation.resource.home.service;
 import api.common.pojo.common.PageVO;
 import api.common.pojo.common.ResponseBodyVO;
 import api.common.pojo.po.home.SystemServerPO;
-import api.common.pojo.vo.home.*;
+import api.common.pojo.vo.home.HardwareVO;
+import api.common.pojo.vo.home.LineChartVO;
+import api.common.pojo.vo.home.ServiceVO;
+import api.common.pojo.vo.home.SystemServerVO;
+import api.common.util.NumberUtil;
 import api.common.util.ObjectUtil;
 import api.common.util.TimeUtil;
 import com.css.simulation.resource.common.utils.AuthUtil;
 import com.css.simulation.resource.common.utils.PageUtil;
 import com.css.simulation.resource.feign.OauthClientService;
-import com.css.simulation.resource.log.mapper.LogMapper;
 import com.css.simulation.resource.home.mapper.HomePageMapper;
+import com.css.simulation.resource.log.mapper.LogMapper;
 import com.css.simulation.resource.system.mapper.UserMapper;
 import com.github.pagehelper.PageInfo;
-import org.springframework.beans.factory.annotation.Autowired;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -23,16 +27,17 @@ import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
 
+@Slf4j
 @Service
 public class HomePageService {
 
     @Resource
     HomePageMapper homePageMapper;
 
-    @Autowired
+    @Resource
     UserMapper userMapper;
 
-    @Autowired
+    @Resource
     LogMapper logMapper;
 
     @Resource
@@ -41,16 +46,26 @@ public class HomePageService {
 
     public ResponseBodyVO<HardwareVO> selectHardware() {
         List<SystemServerPO> systemServerPOList = homePageMapper.selectAll();
-        long memorySum = systemServerPOList.stream().mapToLong(SystemServerPO::getMemoryTotal).sum();  // 内存之和
-        long diskSum = systemServerPOList.stream().mapToLong(SystemServerPO::getDiskTotal).sum();  // 磁盘之和
-        long cpuSum = systemServerPOList.stream().mapToLong(SystemServerPO::getCpuTotal).sum();  // cpu线程数 之和
-        long gpuSum = systemServerPOList.stream().mapToLong(SystemServerPO::getGpuTotal).sum();  // 显存之和
+        log.info("selectHardware() 服务器列表为:" + systemServerPOList);
+        long memoryTotalSum = systemServerPOList.stream().mapToLong(SystemServerPO::getMemoryTotal).sum();  // 内存之和
+        long diskTotalSum = systemServerPOList.stream().mapToLong(SystemServerPO::getDiskTotal).sum();  // 磁盘之和
+        long cpuTotalSum = systemServerPOList.stream().mapToLong(SystemServerPO::getCpuTotal).sum();  // cpu线程数 之和
+        long gpuTotalSum = systemServerPOList.stream().mapToLong(SystemServerPO::getGpuTotal).sum();  // 显存之和
+        log.info("selectHardware() 内存之和:" + memoryTotalSum);
+        log.info("selectHardware() 磁盘之和:" + diskTotalSum);
+        log.info("selectHardware() cpu线程数 之和:" + cpuTotalSum);
+        log.info("selectHardware() 显存之和 之和:" + gpuTotalSum);
+        long memoryUsedSum = systemServerPOList.stream().mapToLong(SystemServerPO::getMemoryAvailable).sum();  // 内存之和
+        long diskUsedSum = systemServerPOList.stream().mapToLong(SystemServerPO::getDiskAvailable).sum();  // 磁盘之和
+        long cpuUsedSum = systemServerPOList.stream().mapToLong(systemServer -> (long) (systemServer.getCpuTotal() * systemServer.getCpuUsage())).sum();  // cpu线程数 之和
+        long gpuUsedSum = systemServerPOList.stream().mapToLong(systemServer -> (long) (systemServer.getGpuTotal() * systemServer.getGpuUsage())).sum();  // cpu线程数 之和
+
         HardwareVO build = HardwareVO.builder()
                 .serverNumber(systemServerPOList.size())
-                .memoryUsage((int) systemServerPOList.stream().mapToDouble(po -> po.getMemoryUsage() * po.getMemoryTotal() * 1.0 / memorySum).sum() + "%")
-                .diskUsage((int) systemServerPOList.stream().mapToDouble(po -> po.getDiskUsage() * po.getDiskTotal() * 1.0 / diskSum).sum() + "%")
-                .cpuUsage((int) systemServerPOList.stream().mapToDouble(po -> po.getCpuUsage() * po.getCpuTotal() * 1.0 / cpuSum).sum() + "%")
-                .gpuUsage((int) systemServerPOList.stream().mapToDouble(po -> po.getGpuUsage() * po.getGpuTotal() * 1.0 / gpuSum).sum() + "%")
+                .memoryUsage(NumberUtil.cut(memoryUsedSum * 1.0 / memoryTotalSum, 2) + "%")
+                .diskUsage(NumberUtil.cut(diskUsedSum * 1.0 / diskTotalSum, 2) + "%")
+                .cpuUsage(NumberUtil.cut(cpuUsedSum * 1.0 / cpuTotalSum, 2) + "%")
+                .gpuUsage(NumberUtil.cut(gpuUsedSum * 1.0 / gpuTotalSum, 2) + "%")
                 .build();
         return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, build);
     }
@@ -59,9 +74,13 @@ public class HomePageService {
     public ResponseBodyVO<ServiceVO> selectService() {
         List<SystemServerPO> systemServerPOList = homePageMapper.selectAll();
         long count = systemServerPOList.stream().filter(system -> "gpu".equals(system.getServerType())).count();
+        int onlineNumber = oauthClientService.online().getInfo();
+        if (onlineNumber == 0){
+            onlineNumber = 1;
+        }
         ServiceVO build = ServiceVO.builder()
                 .userNumber(userMapper.selectCount())
-                .onlineNumber(oauthClientService.online().getInfo())
+                .onlineNumber(onlineNumber)
                 .simulationNodeNumber((int) count)
                 .simulationLicenseNumber(homePageMapper.selectSumOfTaskNumber())
                 .dynamicsLicenseNumber(0)   // 待定

+ 1 - 1
simulation-resource-server/src/main/java/com/css/simulation/resource/model/mapper/VehicleMapper.java

@@ -35,6 +35,6 @@ public interface VehicleMapper {
             "where model_label = #{oldModelLabel}")
     void updateModelLabel(@Param("oldModelLabel") String oldModelLabel, @Param("newModelLabel") String newModelLabel);
 
-    @Select("select parameter_type from model_vehicle where id = #{id}}")
+    @Select("select parameter_type from model_vehicle where id = #{id}")
     String selectParameterTypeById(@Param("id") String id);
 }

+ 9 - 6
simulation-resource-server/src/main/java/com/css/simulation/resource/project/impl/SimulationProjectServiceImpl.java

@@ -80,7 +80,7 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
     @Resource
     private ManualProjectMapper manualProjectMapper;
     @Resource
-    private  AutoSubProjectMapper autoSubProjectMapper;
+    private AutoSubProjectMapper autoSubProjectMapper;
     @Resource
     private SimulationAutomaticProjectMapper simulationAutomaticProjectMapper;
     @Resource
@@ -94,9 +94,9 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
     @Resource
     private AlgorithmMapper algorithmMapper;
     @Resource
-    private  KafkaTemplate<String, String> kafkaTemplate;
+    private KafkaTemplate<String, String> kafkaTemplate;
     @Resource
-    private  DictService dictService;
+    private DictService dictService;
     @Resource
     private AlgoPlatformService algoPlatformService;
     @Resource
@@ -300,9 +300,12 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         } else {    // 创建新的项目
             // 查询项目详情信息并保存
             String projectId = param.getId();
-            ProjectDetailsVo info = selectProjectDetailsByIdBackUp(SimulationManualProjectParam.builder()
-                    .id(projectId)
-                    .projectType(DictConstants.PROJECT_TYPE_MANUAL).build()).getInfo();
+            ProjectDetailsVo info = selectProjectDetailsByIdBackUp(
+                    SimulationManualProjectParam.builder()
+                            .id(projectId)
+                            .projectType(DictConstants.PROJECT_TYPE_MANUAL)
+                            .build()
+            ).getInfo();
             String infoJson = JsonUtil.beanToJson(info);
             log.info("updateProjectNowRunState() 项目 " + projectId + " 的详情信息为:" + infoJson);
             simulationProjectMapper.updateDetailsById(projectId, infoJson);

+ 0 - 5
simulation-resource-server/src/main/java/com/css/simulation/resource/scene/service/SceneGeneralExampleService.java

@@ -86,9 +86,6 @@ public class SceneGeneralExampleService {
 
     @SneakyThrows
     public ResponseBodyVO saveSceneGeneralExample(SceneGeneralTemplateVO vo) {
-   /*        //测试用
-        SceneGeneralTemplatePO po1=templateMapper.querySceneGeneralTemplateById(vo.getTemplateId());
-        BeanUtils.copyProperties(po1, vo);*/
 
         //查询泛化标志位并赋值
         SceneGeneralTemplatePO poV = templateMapper.querySceneGeneralTemplateById(vo.getTemplateId());
@@ -108,7 +105,6 @@ public class SceneGeneralExampleService {
 
         String obsStartX = "";
         String obsStartY = "";
-        ;
         String obsStartVelocity = "";
         String obsLateralAcceleration = "";
         String obsLongitudinalAcceleration = "";
@@ -207,7 +203,6 @@ public class SceneGeneralExampleService {
             }
         }
         dataMapper.saveSceneGeneralDataAll(list);
-        // po.setTemplateId(po.getId());  //前端需要帮忙赋值
         po.setId(exampleId);
         po.setSublistId(sublistId);
         po.setCreateTime(TimeUtil.getNowForMysql());