| @@ -49,6 +49,9 @@ public class ResourceOccupy { | |||||
| @ApiModelProperty("流水线id") | @ApiModelProperty("流水线id") | ||||
| private Long workflowId; | private Long workflowId; | ||||
| @ApiModelProperty("任务名称") | |||||
| private String taskName; | |||||
| @ApiModelProperty("流水线节点id") | @ApiModelProperty("流水线节点id") | ||||
| private String nodeId; | private String nodeId; | ||||
| } | } | ||||
| @@ -14,7 +14,7 @@ public interface ResourceOccupyDao { | |||||
| int edit(@Param("resourceOccupy") ResourceOccupy resourceOccupy); | int edit(@Param("resourceOccupy") ResourceOccupy resourceOccupy); | ||||
| List<ResourceOccupy> getResourceOccupyByTask(@Param("taskType") String taskType, @Param("taskId") Long taskId, @Param("nodeId") String nodeId); | |||||
| List<ResourceOccupy> getResourceOccupyByTask(@Param("taskType") String taskType, @Param("taskInsId") Long taskInsId, @Param("nodeId") String nodeId); | |||||
| int deduceCredit(@Param("credit") Double credit, @Param("userId") Long userId); | int deduceCredit(@Param("credit") Double credit, @Param("userId") Long userId); | ||||
| @@ -11,11 +11,11 @@ public interface ResourceOccupyService { | |||||
| Boolean haveResource(Integer computingResourceId) throws Exception; | Boolean haveResource(Integer computingResourceId) throws Exception; | ||||
| void startDeduce(Integer computingResourceId, String taskType, Long taskId, Long taskInsId, Long workflowId, String nodeId); | |||||
| void startDeduce(Integer computingResourceId, String taskType, Long taskId, Long taskInsId, Long workflowId, String taskName, String nodeId); | |||||
| void endDeduce(String taskType, Long taskId, String nodeId, Date nodeStartTime); | |||||
| void endDeduce(String taskType, Long taskInsId, String nodeId, Date nodeStartTime); | |||||
| void deducing(String taskType, Long taskId, String nodeId, Date nodeStartTime); | |||||
| void deducing(String taskType, Long taskInsId, String nodeId, Date nodeStartTime); | |||||
| Page<ResourceOccupy> queryByPage(PageRequest pageRequest); | Page<ResourceOccupy> queryByPage(PageRequest pageRequest); | ||||
| @@ -38,7 +38,7 @@ public interface ServiceService { | |||||
| String stopServiceVersion(Long id); | String stopServiceVersion(Long id); | ||||
| String updateServiceVersion(ServiceVersion serviceVersion); | |||||
| String updateServiceVersion(ServiceVersion serviceVersion) throws Exception; | |||||
| HashMap<String, String> getServiceVersionLog(Long id, String startTime, String endTime); | HashMap<String, String> getServiceVersionLog(Long id, String startTime, String endTime); | ||||
| @@ -313,7 +313,7 @@ public class ExperimentServiceImpl implements ExperimentService { | |||||
| // 记录开始扣积分 | // 记录开始扣积分 | ||||
| for (Map.Entry<String, Map<String, Object>> entry : resourceInfo.entrySet()) { | for (Map.Entry<String, Map<String, Object>> entry : resourceInfo.entrySet()) { | ||||
| Map<String, Object> node = entry.getValue(); | Map<String, Object> node = entry.getValue(); | ||||
| resourceOccupyService.startDeduce((Integer) node.get("computing_resource_id"), Constant.TaskType_Workflow, Long.valueOf(id), Long.valueOf(insert.getId()), experiment.getWorkflowId(), entry.getKey()); | |||||
| resourceOccupyService.startDeduce((Integer) node.get("computing_resource_id"), Constant.TaskType_Workflow, Long.valueOf(id), Long.valueOf(insert.getId()), experiment.getWorkflowId(), experiment.getName(), entry.getKey()); | |||||
| } | } | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| @@ -206,7 +206,7 @@ public class RayServiceImpl implements RayService { | |||||
| rayInsDao.insert(rayIns); | rayInsDao.insert(rayIns); | ||||
| rayInsService.updateRayStatus(id); | rayInsService.updateRayStatus(id); | ||||
| // 记录开始扣除积分 | // 记录开始扣除积分 | ||||
| resourceOccupyService.startDeduce(ray.getComputingResourceId(), Constant.TaskType_Ray, id, rayIns.getId(), null, null); | |||||
| resourceOccupyService.startDeduce(ray.getComputingResourceId(), Constant.TaskType_Ray, id, rayIns.getId(), null, ray.getName(), null); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
| } | } | ||||
| @@ -53,7 +53,7 @@ public class ResourceOccupyServiceImpl implements ResourceOccupyService { | |||||
| @Override | @Override | ||||
| @Transactional | @Transactional | ||||
| public void startDeduce(Integer computingResourceId, String taskType, Long taskId, Long taskInsId, Long workflowId, String nodeId) { | |||||
| public void startDeduce(Integer computingResourceId, String taskType, Long taskId, Long taskInsId, Long workflowId, String taskName, String nodeId) { | |||||
| ResourceOccupy resourceOccupy = new ResourceOccupy(); | ResourceOccupy resourceOccupy = new ResourceOccupy(); | ||||
| ComputingResource computingResource = computingResourceDao.queryById(computingResourceId); | ComputingResource computingResource = computingResourceDao.queryById(computingResourceId); | ||||
| resourceOccupy.setComputingResourceId(computingResourceId); | resourceOccupy.setComputingResourceId(computingResourceId); | ||||
| @@ -65,6 +65,7 @@ public class ResourceOccupyServiceImpl implements ResourceOccupyService { | |||||
| resourceOccupy.setTaskId(taskId); | resourceOccupy.setTaskId(taskId); | ||||
| resourceOccupy.setTaskInsId(taskInsId); | resourceOccupy.setTaskInsId(taskInsId); | ||||
| resourceOccupy.setWorkflowId(workflowId); | resourceOccupy.setWorkflowId(workflowId); | ||||
| resourceOccupy.setTaskName(taskName); | |||||
| resourceOccupy.setNodeId(nodeId); | resourceOccupy.setNodeId(nodeId); | ||||
| resourceOccupyDao.save(resourceOccupy); | resourceOccupyDao.save(resourceOccupy); | ||||
| @@ -77,10 +78,10 @@ public class ResourceOccupyServiceImpl implements ResourceOccupyService { | |||||
| @Override | @Override | ||||
| @Transactional | @Transactional | ||||
| public void endDeduce(String taskType, Long taskId, String nodeId, Date nodeStartTime) { | |||||
| List<ResourceOccupy> resourceOccupys = resourceOccupyDao.getResourceOccupyByTask(taskType, taskId, nodeId); | |||||
| public void endDeduce(String taskType, Long taskInsId, String nodeId, Date nodeStartTime) { | |||||
| List<ResourceOccupy> resourceOccupys = resourceOccupyDao.getResourceOccupyByTask(taskType, taskInsId, nodeId); | |||||
| for (ResourceOccupy resourceOccupy : resourceOccupys) { | for (ResourceOccupy resourceOccupy : resourceOccupys) { | ||||
| deducing(taskType, taskId, nodeId, nodeStartTime); | |||||
| deducing(taskType, taskInsId, nodeId, nodeStartTime); | |||||
| resourceOccupy.setState(Constant.State_invalid); | resourceOccupy.setState(Constant.State_invalid); | ||||
| resourceOccupyDao.edit(resourceOccupy); | resourceOccupyDao.edit(resourceOccupy); | ||||
| @@ -95,8 +96,8 @@ public class ResourceOccupyServiceImpl implements ResourceOccupyService { | |||||
| @Override | @Override | ||||
| @Transactional | @Transactional | ||||
| public void deducing(String taskType, Long taskId, String nodeId, Date nodeStartTime) { | |||||
| List<ResourceOccupy> resourceOccupys = resourceOccupyDao.getResourceOccupyByTask(taskType, taskId, nodeId); | |||||
| public void deducing(String taskType, Long taskInsId, String nodeId, Date nodeStartTime) { | |||||
| List<ResourceOccupy> resourceOccupys = resourceOccupyDao.getResourceOccupyByTask(taskType, taskInsId, nodeId); | |||||
| for (ResourceOccupy resourceOccupy : resourceOccupys) { | for (ResourceOccupy resourceOccupy : resourceOccupys) { | ||||
| Date now = new Date(); | Date now = new Date(); | ||||
| long timeDifferenceMillis; | long timeDifferenceMillis; | ||||
| @@ -149,13 +149,14 @@ public class ServiceServiceImpl implements ServiceService { | |||||
| public String editServiceVersion(ServiceVersionVo serviceVersionVo) throws Exception { | public String editServiceVersion(ServiceVersionVo serviceVersionVo) throws Exception { | ||||
| ServiceVersion serviceVersion = getServiceVersion(serviceVersionVo); | ServiceVersion serviceVersion = getServiceVersion(serviceVersionVo); | ||||
| ServiceVersion oldServiceVersion = serviceDao.getServiceVersionById(serviceVersionVo.getId()); | ServiceVersion oldServiceVersion = serviceDao.getServiceVersionById(serviceVersionVo.getId()); | ||||
| if (!oldServiceVersion.getReplicas().equals(serviceVersionVo.getReplicas()) || !oldServiceVersion.getResource().equals(serviceVersionVo.getResource()) | |||||
| if (!oldServiceVersion.getReplicas().equals(serviceVersionVo.getReplicas()) || !oldServiceVersion.getComputingResourceId().equals(serviceVersionVo.getComputingResourceId()) | |||||
| || serviceVersionVo.getRerun()) { | || serviceVersionVo.getRerun()) { | ||||
| updateServiceVersion(serviceVersion); | updateServiceVersion(serviceVersion); | ||||
| } | } | ||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| serviceVersion.setUpdateBy(loginUser.getUsername()); | serviceVersion.setUpdateBy(loginUser.getUsername()); | ||||
| serviceDao.updateServiceVersion(serviceVersion); | serviceDao.updateServiceVersion(serviceVersion); | ||||
| return "修改成功"; | return "修改成功"; | ||||
| } | } | ||||
| @@ -274,7 +275,7 @@ public class ServiceServiceImpl implements ServiceService { | |||||
| serviceDao.updateServiceVersion(serviceVersion); | serviceDao.updateServiceVersion(serviceVersion); | ||||
| // 记录开始扣积分 | // 记录开始扣积分 | ||||
| resourceOccupyService.startDeduce(serviceVersion.getComputingResourceId(), Constant.TaskType_Service, serviceVersion.getServiceId(), serviceVersion.getId(), null, null); | |||||
| resourceOccupyService.startDeduce(serviceVersion.getComputingResourceId(), Constant.TaskType_Service, serviceVersion.getServiceId(), serviceVersion.getId(), null, service.getServiceName(), null); | |||||
| return "启动成功"; | return "启动成功"; | ||||
| } else { | } else { | ||||
| throw new RuntimeException("启动失败"); | throw new RuntimeException("启动失败"); | ||||
| @@ -304,19 +305,26 @@ public class ServiceServiceImpl implements ServiceService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public String updateServiceVersion(ServiceVersion serviceVersion) { | |||||
| HashMap<String, Object> paramMap = new HashMap<>(); | |||||
| paramMap.put("deployment_name", serviceVersion.getDeploymentName()); | |||||
| HashMap<String, Object> updateMap = new HashMap<>(); | |||||
| updateMap.put("replicas", serviceVersion.getReplicas()); | |||||
| updateMap.put("resource", serviceVersion.getResource()); | |||||
| paramMap.put("update_model", new JSONObject(updateMap)); | |||||
| String req = HttpUtils.sendPost(argoUrl + modelService + "/update", JSON.toJSONString(paramMap)); | |||||
| if (StringUtils.isNotEmpty(req)) { | |||||
| return "修改成功"; | |||||
| } else { | |||||
| throw new RuntimeException("更新失败"); | |||||
| public String updateServiceVersion(ServiceVersion serviceVersion) throws Exception { | |||||
| // 判断是否有资源 | |||||
| if (resourceOccupyService.haveResource(serviceVersion.getComputingResourceId())) { | |||||
| HashMap<String, Object> paramMap = new HashMap<>(); | |||||
| paramMap.put("deployment_name", serviceVersion.getDeploymentName()); | |||||
| HashMap<String, Object> updateMap = new HashMap<>(); | |||||
| updateMap.put("replicas", serviceVersion.getReplicas()); | |||||
| updateMap.put("resource", serviceVersion.getResource()); | |||||
| paramMap.put("update_model", new JSONObject(updateMap)); | |||||
| String req = HttpUtils.sendPost(argoUrl + modelService + "/update", JSON.toJSONString(paramMap)); | |||||
| if (StringUtils.isNotEmpty(req)) { | |||||
| com.ruoyi.platform.domain.Service service = serviceDao.getServiceById(serviceVersion.getServiceId()); | |||||
| // 记录开始扣积分 | |||||
| resourceOccupyService.startDeduce(serviceVersion.getComputingResourceId(), Constant.TaskType_Service, serviceVersion.getServiceId(), serviceVersion.getId(), null, service.getServiceName(), null); | |||||
| return "修改成功"; | |||||
| } else { | |||||
| throw new RuntimeException("更新失败"); | |||||
| } | |||||
| } | } | ||||
| throw new RuntimeException("更新失败"); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -517,7 +517,7 @@ public class K8sClientUtil { | |||||
| String nodeName = getNodeName(podName, namespace); | String nodeName = getNodeName(podName, namespace); | ||||
| // 记录开始扣除积分 | // 记录开始扣除积分 | ||||
| resourceOccupyService.startDeduce(devEnvironment.getComputingResourceId(), Constant.TaskType_Dev, Long.valueOf(devEnvironment.getId()), null, null, null); | |||||
| resourceOccupyService.startDeduce(devEnvironment.getComputingResourceId(), Constant.TaskType_Dev, Long.valueOf(devEnvironment.getId()), null, null, devEnvironment.getName(), null); | |||||
| } | } | ||||
| } catch (ApiException e) { | } catch (ApiException e) { | ||||
| throw new RuntimeException("创建pod异常:" + e.getResponseBody()); | throw new RuntimeException("创建pod异常:" + e.getResponseBody()); | ||||
| @@ -3,11 +3,11 @@ | |||||
| <mapper namespace="com.ruoyi.platform.mapper.ResourceOccupyDao"> | <mapper namespace="com.ruoyi.platform.mapper.ResourceOccupyDao"> | ||||
| <insert id="save"> | <insert id="save"> | ||||
| insert into resource_occupy (user_id, computing_resource_id, credit_per_hour, description, task_type, task_id, | insert into resource_occupy (user_id, computing_resource_id, credit_per_hour, description, task_type, task_id, | ||||
| task_ins_id, workflow_id, | |||||
| task_ins_id, workflow_id, task_name, | |||||
| node_id) | node_id) | ||||
| values (#{resourceOccupy.userId}, #{resourceOccupy.computingResourceId}, #{resourceOccupy.creditPerHour}, | values (#{resourceOccupy.userId}, #{resourceOccupy.computingResourceId}, #{resourceOccupy.creditPerHour}, | ||||
| #{resourceOccupy.description}, #{resourceOccupy.taskType}, #{resourceOccupy.taskId}, | #{resourceOccupy.description}, #{resourceOccupy.taskType}, #{resourceOccupy.taskId}, | ||||
| #{resourceOccupy.taskInsId}, #{resourceOccupy.workflowId}, | |||||
| #{resourceOccupy.taskInsId}, #{resourceOccupy.workflowId}, #{resourceOccupy.taskName}, | |||||
| #{resourceOccupy.nodeId}) | #{resourceOccupy.nodeId}) | ||||
| </insert> | </insert> | ||||
| @@ -55,7 +55,7 @@ | |||||
| select * | select * | ||||
| from resource_occupy | from resource_occupy | ||||
| where task_type = #{taskType} | where task_type = #{taskType} | ||||
| and task_id = #{taskId} | |||||
| and task_ins_id = #{taskInsId} | |||||
| <if test="nodeId != null and nodeId !=''"> | <if test="nodeId != null and nodeId !=''"> | ||||
| and node_id = #{nodeId} | and node_id = #{nodeId} | ||||
| </if> | </if> | ||||
| @@ -75,6 +75,11 @@ | |||||
| credit_per_hour, | credit_per_hour, | ||||
| TRUNCATE(deduce_credit, 1) as deduce_credit, | TRUNCATE(deduce_credit, 1) as deduce_credit, | ||||
| start_time, | start_time, | ||||
| task_type, | |||||
| task_id, | |||||
| task_ins_id, | |||||
| workflow_id, | |||||
| task_name, | |||||
| state | state | ||||
| from resource_occupy | from resource_occupy | ||||
| where user_id = #{userId} | where user_id = #{userId} | ||||