Browse Source

修改终止后status与node_status状态不一致的问题 + 修改因pending而status为空的BUG

tags/v20240126^2
fans 2 years ago
parent
commit
771d468591
6 changed files with 58 additions and 29 deletions
  1. +4
    -3
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/experiment/ExperimentController.java
  2. +5
    -4
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/experiment/ExperimentInsController.java
  3. +5
    -4
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ExperimentInsService.java
  4. +4
    -3
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ExperimentService.java
  5. +36
    -12
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java
  6. +4
    -3
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentServiceImpl.java

+ 4
- 3
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/experiment/ExperimentController.java View File

@@ -10,6 +10,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException;


/** /**
* (Experiment)表控制层 * (Experiment)表控制层
@@ -42,7 +43,7 @@ public class ExperimentController {


@GetMapping(("/status")) @GetMapping(("/status"))
@ApiOperation("查询实验状态") @ApiOperation("查询实验状态")
public AjaxResult selectStatus(@RequestBody Experiment experiment, PageRequest pageRequest){
public AjaxResult selectStatus(@RequestBody Experiment experiment, PageRequest pageRequest) throws IOException {
return AjaxResult.success(this.experimentService.selectStatus(experiment, pageRequest)); return AjaxResult.success(this.experimentService.selectStatus(experiment, pageRequest));
} }


@@ -61,7 +62,7 @@ public class ExperimentController {
*/ */
@GetMapping("{id}") @GetMapping("{id}")
@ApiOperation("通过id查询实验") @ApiOperation("通过id查询实验")
public AjaxResult queryById(@PathVariable("id") Integer id) {
public AjaxResult queryById(@PathVariable("id") Integer id) throws IOException {
return AjaxResult.success(this.experimentService.queryById(id)); return AjaxResult.success(this.experimentService.queryById(id));
} }


@@ -85,7 +86,7 @@ public class ExperimentController {
*/ */
@PutMapping @PutMapping
@ApiOperation("编辑实验") @ApiOperation("编辑实验")
public AjaxResult edit(@RequestBody Experiment experiment) {
public AjaxResult edit(@RequestBody Experiment experiment) throws IOException {
return AjaxResult.success(this.experimentService.update(experiment)); return AjaxResult.success(this.experimentService.update(experiment));
} }




+ 5
- 4
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/experiment/ExperimentInsController.java View File

@@ -9,6 +9,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException;
import java.util.Map; import java.util.Map;


/** /**
@@ -35,7 +36,7 @@ public class ExperimentInsController {
*/ */
@GetMapping @GetMapping
@ApiOperation("分页查询") @ApiOperation("分页查询")
public AjaxResult queryByPage(ExperimentIns experimentIns, int page, int size) {
public AjaxResult queryByPage(ExperimentIns experimentIns, int page, int size) throws IOException {
PageRequest pageRequest = PageRequest.of(page,size); PageRequest pageRequest = PageRequest.of(page,size);
return AjaxResult.success(this.experimentInsService.queryByPage(experimentIns, pageRequest)); return AjaxResult.success(this.experimentInsService.queryByPage(experimentIns, pageRequest));
} }
@@ -48,7 +49,7 @@ public class ExperimentInsController {
*/ */
@GetMapping("{id}") @GetMapping("{id}")
@ApiOperation("通过id查询实验实例") @ApiOperation("通过id查询实验实例")
public AjaxResult queryById(@PathVariable("id") Integer id) {
public AjaxResult queryById(@PathVariable("id") Integer id) throws IOException {
return AjaxResult.success(this.experimentInsService.queryById(id)); return AjaxResult.success(this.experimentInsService.queryById(id));
} }


@@ -60,7 +61,7 @@ public class ExperimentInsController {
*/ */
@GetMapping("/queryByExperimentId/{Experiment_id}") @GetMapping("/queryByExperimentId/{Experiment_id}")
@ApiOperation("通过实验id查询查询实验实例列表") @ApiOperation("通过实验id查询查询实验实例列表")
public AjaxResult queryByExperimentId(@PathVariable("Experiment_id") Integer experimentId) {
public AjaxResult queryByExperimentId(@PathVariable("Experiment_id") Integer experimentId) throws IOException {
return AjaxResult.success(this.experimentInsService.getByExperimentId(experimentId)); return AjaxResult.success(this.experimentInsService.getByExperimentId(experimentId));
} }


@@ -84,7 +85,7 @@ public class ExperimentInsController {
*/ */
@PutMapping @PutMapping
@ApiOperation("编辑实验实例") @ApiOperation("编辑实验实例")
public AjaxResult edit(@RequestBody ExperimentIns experimentIns) {
public AjaxResult edit(@RequestBody ExperimentIns experimentIns) throws IOException {
return AjaxResult.success(this.experimentInsService.update(experimentIns)); return AjaxResult.success(this.experimentInsService.update(experimentIns));
} }




+ 5
- 4
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ExperimentInsService.java View File

@@ -4,6 +4,7 @@ import com.ruoyi.platform.domain.ExperimentIns;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;


import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;


@@ -21,7 +22,7 @@ public interface ExperimentInsService {
* @param id 主键 * @param id 主键
* @return 实例对象 * @return 实例对象
*/ */
ExperimentIns queryById(Integer id);
ExperimentIns queryById(Integer id) throws IOException;






@@ -31,7 +32,7 @@ public interface ExperimentInsService {
* @param experimentId 实验id,不是实例id * @param experimentId 实验id,不是实例id
* @return 实例列表 * @return 实例列表
*/ */
List<ExperimentIns> getByExperimentId(Integer experimentId);
List<ExperimentIns> getByExperimentId(Integer experimentId) throws IOException;


/** /**
* 分页查询 * 分页查询
@@ -40,7 +41,7 @@ public interface ExperimentInsService {
* @param pageRequest 分页对象 * @param pageRequest 分页对象
* @return 查询结果 * @return 查询结果
*/ */
Page<ExperimentIns> queryByPage(ExperimentIns experimentIns, PageRequest pageRequest);
Page<ExperimentIns> queryByPage(ExperimentIns experimentIns, PageRequest pageRequest) throws IOException;


/** /**
* 新增数据 * 新增数据
@@ -56,7 +57,7 @@ public interface ExperimentInsService {
* @param experimentIns 实例对象 * @param experimentIns 实例对象
* @return 实例对象 * @return 实例对象
*/ */
ExperimentIns update(ExperimentIns experimentIns);
ExperimentIns update(ExperimentIns experimentIns) throws IOException;








+ 4
- 3
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ExperimentService.java View File

@@ -5,6 +5,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;


import java.io.IOException;
import java.util.List; import java.util.List;


/** /**
@@ -21,7 +22,7 @@ public interface ExperimentService {
* @param id 主键 * @param id 主键
* @return 实例对象 * @return 实例对象
*/ */
Experiment queryById(Integer id);
Experiment queryById(Integer id) throws IOException;


/** /**
* 分页查询 * 分页查询
@@ -46,7 +47,7 @@ public interface ExperimentService {
* @param experiment 实例对象 * @param experiment 实例对象
* @return 实例对象 * @return 实例对象
*/ */
Experiment update(Experiment experiment);
Experiment update(Experiment experiment) throws IOException;


/** /**
* 通过主键删除数据 * 通过主键删除数据
@@ -67,7 +68,7 @@ public interface ExperimentService {
* @param pageRequest 分页对象 * @param pageRequest 分页对象
* @return 查询结果 * @return 查询结果
*/ */
Page<Experiment> selectStatus(Experiment experiment, PageRequest pageRequest);
Page<Experiment> selectStatus(Experiment experiment, PageRequest pageRequest) throws IOException;








+ 36
- 12
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java View File

@@ -18,6 +18,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;


import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;


@@ -55,12 +56,12 @@ public class ExperimentInsServiceImpl implements ExperimentInsService {
* @return 实例对象 * @return 实例对象
*/ */
@Override @Override
public ExperimentIns queryById(Integer id) {
public ExperimentIns queryById(Integer id) throws IOException {
ExperimentIns experimentIns = this.experimentInsDao.queryById(id); ExperimentIns experimentIns = this.experimentInsDao.queryById(id);
if (experimentIns != null && (StringUtils.isEmpty(experimentIns.getStatus())) || !isTerminatedState(experimentIns.getStatus())) {
if (experimentIns != null && (StringUtils.isEmpty(experimentIns.getStatus())) || !isTerminatedState(experimentIns)) {
experimentIns = this.queryStatusFromArgo(experimentIns); experimentIns = this.queryStatusFromArgo(experimentIns);
//只有当新状态是终止态时才更新数据库 //只有当新状态是终止态时才更新数据库
if (isTerminatedState(experimentIns.getStatus())) {
if (isTerminatedState(experimentIns)) {
//同时更新各个节点 //同时更新各个节点
this.update(experimentIns); this.update(experimentIns);
} }
@@ -77,17 +78,17 @@ public class ExperimentInsServiceImpl implements ExperimentInsService {
* @return 实验列表 * @return 实验列表
*/ */
@Override @Override
public List<ExperimentIns> getByExperimentId(Integer experimentId) {
public List<ExperimentIns> getByExperimentId(Integer experimentId) throws IOException {
List<ExperimentIns> experimentInsList = experimentInsDao.getByExperimentId(experimentId); List<ExperimentIns> experimentInsList = experimentInsDao.getByExperimentId(experimentId);


List<ExperimentIns> result = new ArrayList<ExperimentIns>(); List<ExperimentIns> result = new ArrayList<ExperimentIns>();
if (experimentInsList!=null&&experimentInsList.size()>0) { if (experimentInsList!=null&&experimentInsList.size()>0) {
for (ExperimentIns experimentIns : experimentInsList) { for (ExperimentIns experimentIns : experimentInsList) {
//当原本状态为null或非终止态时才调用argo接口 //当原本状态为null或非终止态时才调用argo接口
if (experimentIns != null && (StringUtils.isEmpty(experimentIns.getStatus())) || !isTerminatedState(experimentIns.getStatus())) {
if (experimentIns != null && (StringUtils.isEmpty(experimentIns.getStatus())) || !isTerminatedState(experimentIns)) {
experimentIns = this.queryStatusFromArgo(experimentIns); experimentIns = this.queryStatusFromArgo(experimentIns);
//只有当新状态是终止态时才更新数据库 //只有当新状态是终止态时才更新数据库
if (isTerminatedState(experimentIns.getStatus())) {
if (isTerminatedState(experimentIns)) {
//同时更新各个节点 //同时更新各个节点
this.update(experimentIns); this.update(experimentIns);
} }
@@ -108,7 +109,7 @@ public class ExperimentInsServiceImpl implements ExperimentInsService {
* @return 查询结果 * @return 查询结果
*/ */
@Override @Override
public Page<ExperimentIns> queryByPage(ExperimentIns experimentIns, PageRequest pageRequest) {
public Page<ExperimentIns> queryByPage(ExperimentIns experimentIns, PageRequest pageRequest) throws IOException {
long total = this.experimentInsDao.count(experimentIns); long total = this.experimentInsDao.count(experimentIns);
List<ExperimentIns> experimentInsList = this.experimentInsDao.queryAllByLimit(experimentIns, pageRequest); List<ExperimentIns> experimentInsList = this.experimentInsDao.queryAllByLimit(experimentIns, pageRequest);
if (experimentInsList!=null && experimentInsList.size()>0) { if (experimentInsList!=null && experimentInsList.size()>0) {
@@ -151,7 +152,7 @@ public class ExperimentInsServiceImpl implements ExperimentInsService {
* @return 实例对象 * @return 实例对象
*/ */
@Override @Override
public ExperimentIns update(ExperimentIns experimentIns) {
public ExperimentIns update(ExperimentIns experimentIns) throws IOException {
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
experimentIns.setUpdateBy(loginUser.getUsername()); experimentIns.setUpdateBy(loginUser.getUsername());
experimentIns.setUpdateTime(new Date()); experimentIns.setUpdateTime(new Date());
@@ -261,7 +262,12 @@ public class ExperimentInsServiceImpl implements ExperimentInsService {


String nodeStatusJson = JsonUtils.mapToJson(modifiedNodes); String nodeStatusJson = JsonUtils.mapToJson(modifiedNodes);
experimentIns.setNodesStatus(nodeStatusJson); experimentIns.setNodesStatus(nodeStatusJson);
experimentIns.setStatus((String) status.get("phase"));

//终止态为终止不改
if (!StringUtils.equals(experimentIns.getStatus(),"Terminated")) {
experimentIns.setStatus(StringUtils.isNotEmpty((String) status.get("phase"))?(String) status.get("phase"):"Pending");
}



return experimentIns; return experimentIns;


@@ -323,6 +329,7 @@ public class ExperimentInsServiceImpl implements ExperimentInsService {
//更新experimentIns,确保状态更新被保存到数据库 //更新experimentIns,确保状态更新被保存到数据库
ExperimentIns ins = queryStatusFromArgo(experimentIns); ExperimentIns ins = queryStatusFromArgo(experimentIns);
ins.setStatus("Terminated"); ins.setStatus("Terminated");
ins.setFinishTime(new Date());
this.experimentInsDao.update(ins); this.experimentInsDao.update(ins);
return true; return true;
} else { } else {
@@ -387,10 +394,27 @@ public class ExperimentInsServiceImpl implements ExperimentInsService {
} }
} }


private boolean isTerminatedState(String state) {
private boolean isTerminatedState(ExperimentIns ins) throws IOException {
// 定义终止态的列表,例如 "Succeeded", "Failed" 等 // 定义终止态的列表,例如 "Succeeded", "Failed" 等
List<String> terminatedStates = Arrays.asList("Succeeded", "Failed", "Terminated");
return terminatedStates.contains(state);
String status = ins.getStatus();
boolean flag = true;
List<String> terminatedStates = Arrays.asList("Succeeded", "Failed");
flag = terminatedStates.contains(status);
if (StringUtils.equals(status, "Terminated")){
//如果跟node_status里面不一样,就要去更新node_status的信息
String nodesStatus = ins.getNodesStatus();
Map<String, Object> nodeMap = JsonUtils.jsonToMap(nodesStatus);
String keyStartsWithWorkflow = nodeMap.keySet().stream()
.filter(key -> key.startsWith("workflow-"))
.findFirst()
.orElse(null);
Map workflowMap = (Map) nodeMap.get(keyStartsWithWorkflow);
if (workflowMap != null){
flag = StringUtils.equals("Terminated", (String) workflowMap.get("phase"));
}
}

return flag;
} }


} }

+ 4
- 3
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentServiceImpl.java View File

@@ -23,6 +23,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;


import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException;
import java.util.*; import java.util.*;


/** /**
@@ -66,7 +67,7 @@ public class ExperimentServiceImpl implements ExperimentService {
* @return 实例对象 * @return 实例对象
*/ */
@Override @Override
public Experiment queryById(Integer id) {
public Experiment queryById(Integer id) throws IOException {
List<ExperimentIns> experimentInsList = this.experimentInsService.getByExperimentId(id); List<ExperimentIns> experimentInsList = this.experimentInsService.getByExperimentId(id);
Experiment experiment = this.experimentDao.queryById(id); Experiment experiment = this.experimentDao.queryById(id);
if (experiment == null) { if (experiment == null) {
@@ -106,7 +107,7 @@ public class ExperimentServiceImpl implements ExperimentService {
* @param pageRequest 分页对象 * @param pageRequest 分页对象
* @return 查询结果 * @return 查询结果
*/ */
public Page<Experiment> selectStatus(Experiment experiment, PageRequest pageRequest) {
public Page<Experiment> selectStatus(Experiment experiment, PageRequest pageRequest) throws IOException {
List<Experiment> experimentList = this.experimentDao.queryAllByLimit(experiment, pageRequest); List<Experiment> experimentList = this.experimentDao.queryAllByLimit(experiment, pageRequest);
// 存储所有实验的ID列表 // 存储所有实验的ID列表
List<Integer> experimentIds = new ArrayList<>(); List<Integer> experimentIds = new ArrayList<>();
@@ -144,7 +145,7 @@ public class ExperimentServiceImpl implements ExperimentService {
* @return 实例对象 * @return 实例对象
*/ */
@Override @Override
public Experiment update(Experiment experiment) {
public Experiment update(Experiment experiment) throws IOException {
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
experiment.setUpdateBy(loginUser.getUsername()); experiment.setUpdateBy(loginUser.getUsername());
experiment.setUpdateTime(new Date()); experiment.setUpdateTime(new Date());


Loading…
Cancel
Save