| @@ -2,6 +2,9 @@ package com.ruoyi.platform.controller.workspace; | |||||
| import com.ruoyi.common.core.web.controller.BaseController; | import com.ruoyi.common.core.web.controller.BaseController; | ||||
| import com.ruoyi.common.core.web.domain.AjaxResult; | import com.ruoyi.common.core.web.domain.AjaxResult; | ||||
| import com.ruoyi.common.core.web.domain.GenericsAjaxResult; | |||||
| import com.ruoyi.platform.service.JupyterService; | |||||
| import com.ruoyi.platform.service.WorkspaceService; | |||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import org.springframework.web.bind.annotation.GetMapping; | import org.springframework.web.bind.annotation.GetMapping; | ||||
| @@ -9,14 +12,20 @@ import org.springframework.web.bind.annotation.PathVariable; | |||||
| import org.springframework.web.bind.annotation.RequestMapping; | import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.RestController; | import org.springframework.web.bind.annotation.RestController; | ||||
| import javax.annotation.Resource; | |||||
| import java.util.Map; | |||||
| @RestController | @RestController | ||||
| @RequestMapping("workspace") | @RequestMapping("workspace") | ||||
| @Api("工作空间管理") | @Api("工作空间管理") | ||||
| public class WorkspaceController extends BaseController { | public class WorkspaceController extends BaseController { | ||||
| @Resource | |||||
| private WorkspaceService workspaceService; | |||||
| @GetMapping("/overview") | @GetMapping("/overview") | ||||
| @ApiOperation("运行概览") | |||||
| public AjaxResult queryById(@PathVariable("id") Integer id) { | |||||
| return AjaxResult.success(this.datasetService.queryById(id)); | |||||
| @ApiOperation("得到运行概览") | |||||
| public GenericsAjaxResult<Map<String, Object>> getOverview() { | |||||
| return genericsSuccess(this.workspaceService.getOverview()); | |||||
| } | } | ||||
| } | } | ||||
| @@ -39,6 +39,14 @@ public interface ExperimentInsDao { | |||||
| */ | */ | ||||
| long count(@Param("experimentIns") ExperimentIns experimentIns); | long count(@Param("experimentIns") ExperimentIns experimentIns); | ||||
| /* | |||||
| 统计实验实例总数 | |||||
| @return 总行数 | |||||
| */ | |||||
| // long experimentInsCount(String status); | |||||
| /** | /** | ||||
| * 新增数据 | * 新增数据 | ||||
| * | * | ||||
| @@ -89,6 +97,10 @@ public interface ExperimentInsDao { | |||||
| */ | */ | ||||
| List<ExperimentIns> getByExperimentId(Integer experimentId); | List<ExperimentIns> getByExperimentId(Integer experimentId); | ||||
| List<ExperimentIns> getLatestInsList(); | |||||
| List<ExperimentIns> queryByExperiment(@Param("experimentIns") ExperimentIns experimentIns); | List<ExperimentIns> queryByExperiment(@Param("experimentIns") ExperimentIns experimentIns); | ||||
| List<ExperimentIns> queryByExperimentId(Integer id); | List<ExperimentIns> queryByExperimentId(Integer id); | ||||
| @@ -33,13 +33,25 @@ public interface WorkflowDao { | |||||
| List<Workflow> queryAllByLimit(@Param("workflow") Workflow workflow, @Param("pageable") Pageable pageable); | List<Workflow> queryAllByLimit(@Param("workflow") Workflow workflow, @Param("pageable") Pageable pageable); | ||||
| /** | /** | ||||
| * 统计总行数 | |||||
| * 统计总行数 实体作为筛选条件 | |||||
| * | * | ||||
| * @param workflow 查询条件 | * @param workflow 查询条件 | ||||
| * @return 总行数 | * @return 总行数 | ||||
| */ | */ | ||||
| long count(@Param("workflow") Workflow workflow); | long count(@Param("workflow") Workflow workflow); | ||||
| /** | |||||
| * 统计流水线总数 | |||||
| * | |||||
| * | |||||
| * @return 总行数 | |||||
| */ | |||||
| long workflowCount(); | |||||
| /** | /** | ||||
| * 新增数据 | * 新增数据 | ||||
| * | * | ||||
| @@ -103,4 +103,6 @@ public interface ExperimentInsService { | |||||
| * @return | * @return | ||||
| */ | */ | ||||
| List<ExperimentIns> queryByExperimentIsNotTerminated(); | List<ExperimentIns> queryByExperimentIsNotTerminated(); | ||||
| Map<String, Long> countByStatus(); | |||||
| } | } | ||||
| @@ -1,11 +1,23 @@ | |||||
| package com.ruoyi.platform.service; | package com.ruoyi.platform.service; | ||||
| import java.util.Map; | |||||
| /** | /** | ||||
| * (workspace)服务接口 | * (workspace)服务接口 | ||||
| * | * | ||||
| * @author Xidaray | * @author Xidaray | ||||
| * @since 2024-5-06 14:38:07 | * @since 2024-5-06 14:38:07 | ||||
| */ | */ | ||||
| public class WorkspaceService { | |||||
| public interface WorkspaceService { | |||||
| /** | |||||
| * 得到工作空间数据概览 | |||||
| * | |||||
| * @return 概览数据 | |||||
| */ | |||||
| Map<String, Object> getOverview(); | |||||
| } | } | ||||
| @@ -1,7 +1,6 @@ | |||||
| package com.ruoyi.platform.service.impl; | package com.ruoyi.platform.service.impl; | ||||
| import com.ruoyi.common.security.utils.SecurityUtils; | import com.ruoyi.common.security.utils.SecurityUtils; | ||||
| import com.ruoyi.platform.domain.Experiment; | |||||
| import com.ruoyi.platform.domain.ExperimentIns; | import com.ruoyi.platform.domain.ExperimentIns; | ||||
| import com.ruoyi.platform.mapper.ExperimentDao; | import com.ruoyi.platform.mapper.ExperimentDao; | ||||
| import com.ruoyi.platform.mapper.ExperimentInsDao; | import com.ruoyi.platform.mapper.ExperimentInsDao; | ||||
| @@ -62,6 +61,15 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { | |||||
| this.minioUtil = minioUtil; | this.minioUtil = minioUtil; | ||||
| } | } | ||||
| public enum ExperimentInsStatus { | |||||
| Running, | |||||
| Succeeded, | |||||
| Pending, | |||||
| Failed, | |||||
| Terminated | |||||
| } | |||||
| /** | /** | ||||
| * 通过ID查询单条数据 | * 通过ID查询单条数据 | ||||
| * | * | ||||
| @@ -533,6 +541,26 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { | |||||
| return experimentInsDao.queryByExperimentIsNotTerminated(); | return experimentInsDao.queryByExperimentIsNotTerminated(); | ||||
| } | } | ||||
| @Override | |||||
| public Map<String, Long> countByStatus() { | |||||
| // 创建一个用于存储状态计数的映射 | |||||
| Map<String, Long> statusCountMap = new HashMap<>(); | |||||
| // 遍历枚举中的所有状态 | |||||
| for (ExperimentInsStatus status : ExperimentInsStatus.values()) { | |||||
| ExperimentIns experimentIns = new ExperimentIns(); | |||||
| experimentIns.setStatus(status.toString()); // 设置实例的状态为枚举中的状态 | |||||
| // 查询具有相同状态的实例数量 | |||||
| Long count = experimentInsDao.count(experimentIns); | |||||
| // 将状态及其对应的实例数量放入映射中 | |||||
| statusCountMap.put(status.toString(), count); | |||||
| } | |||||
| return statusCountMap; | |||||
| } | |||||
| private boolean isTerminatedState(ExperimentIns ins) throws IOException { | private boolean isTerminatedState(ExperimentIns ins) throws IOException { | ||||
| // 定义终止态的列表,例如 "Succeeded", "Failed" 等 | // 定义终止态的列表,例如 "Succeeded", "Failed" 等 | ||||
| String status = ins.getStatus(); | String status = ins.getStatus(); | ||||
| @@ -1,7 +1,78 @@ | |||||
| package com.ruoyi.platform.service.impl; | package com.ruoyi.platform.service.impl; | ||||
| import com.ruoyi.platform.domain.ExperimentIns; | |||||
| import com.ruoyi.platform.mapper.*; | |||||
| import com.ruoyi.platform.service.ExperimentInsService; | |||||
| import com.ruoyi.platform.service.ModelsService; | import com.ruoyi.platform.service.ModelsService; | ||||
| import com.ruoyi.platform.service.WorkflowService; | |||||
| import com.ruoyi.platform.service.WorkspaceService; | |||||
| import lombok.val; | |||||
| import org.springframework.stereotype.Service; | |||||
| public class WorkspaceServiceImpl implements ModelsService { | |||||
| import javax.annotation.Resource; | |||||
| import java.util.HashMap; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| @Service("WorkspaceService") | |||||
| public class WorkspaceServiceImpl implements WorkspaceService { | |||||
| @Resource | |||||
| private WorkflowService workflowService; | |||||
| @Resource | |||||
| private WorkflowDao workflowDao; | |||||
| @Resource | |||||
| private ExperimentDao experimentDao; | |||||
| @Resource | |||||
| private ExperimentInsDao experimentInsDao; | |||||
| @Resource | |||||
| private ExperimentInsService experimentInsService; | |||||
| @Resource | |||||
| private ModelsService modelsService; | |||||
| @Resource | |||||
| private ModelsDao modelsDao; | |||||
| @Resource | |||||
| private DatasetDao datasetDao; | |||||
| @Resource | |||||
| private ImageDao imageDao; | |||||
| @Resource | |||||
| private ComponentDao componentDao; | |||||
| @Override | |||||
| public Map<String, Object> getOverview() { | |||||
| Map<String, Object> resMap = new HashMap<String, Object>(); | |||||
| // 获取流水线数量 | |||||
| Long workflowCount = workflowDao.workflowCount(); | |||||
| resMap.put("workflowCount", workflowCount); | |||||
| // 获取运行中实验实例数量 | |||||
| List<ExperimentIns> experimentInsList = experimentInsService.queryByExperimentIsNotTerminated(); | |||||
| if (experimentInsList!=null&&!experimentInsList.isEmpty()) { | |||||
| Integer experimentInsCount = experimentInsList.size(); | |||||
| resMap.put("runningExperimentInsCount", experimentInsCount); | |||||
| }else{ | |||||
| resMap.put("runningExperimentInsCount", 0); | |||||
| } | |||||
| //得到最近的三条实例记录,放进返回map | |||||
| List<ExperimentIns> latestExperimentInsList = experimentInsDao.getLatestInsList(); | |||||
| if (latestExperimentInsList != null && !latestExperimentInsList.isEmpty()) { | |||||
| resMap.put("latestExperimentInsList", latestExperimentInsList); | |||||
| } | |||||
| Map<String, Long> statusMap = experimentInsService.countByStatus(); | |||||
| resMap.put("experimentInsStatus", statusMap); | |||||
| return resMap; | |||||
| } | |||||
| } | } | ||||
| @@ -45,6 +45,16 @@ | |||||
| limit 5 | limit 5 | ||||
| </select> | </select> | ||||
| <!--查询最近的3个实例列表--> | |||||
| <select id="getLatestInsList" resultMap="ExperimentInsMap"> | |||||
| select id, experiment_id, argo_ins_name, argo_ins_ns, status, nodes_status,nodes_result, nodes_logs, global_param, start_time, finish_time, create_by, create_time, update_by, update_time, state | |||||
| from experiment_ins | |||||
| where state = 1 | |||||
| order by create_time DESC | |||||
| limit 3 | |||||
| </select> | |||||
| <select id="queryByExperiment" resultMap="ExperimentInsMap"> | <select id="queryByExperiment" resultMap="ExperimentInsMap"> | ||||
| select | select | ||||
| @@ -98,6 +98,13 @@ | |||||
| </where> | </where> | ||||
| </select> | </select> | ||||
| <!--统计总行数--> | |||||
| <select id="workflowCount" resultType="java.lang.Long"> | |||||
| select count(1) | |||||
| from workflow | |||||
| where state = 1 | |||||
| </select> | |||||
| <!--新增所有列--> | <!--新增所有列--> | ||||
| <insert id="insert" keyProperty="id" useGeneratedKeys="true"> | <insert id="insert" keyProperty="id" useGeneratedKeys="true"> | ||||
| insert into workflow(name, description, dag, global_param, create_by, create_time, update_by, update_time,state) | insert into workflow(name, description, dag, global_param, create_by, create_time, update_by, update_time,state) | ||||