| @@ -7,12 +7,15 @@ import com.ruoyi.platform.mapper.DevEnvironmentDao; | |||||
| import com.ruoyi.platform.mapper.ServiceDao; | import com.ruoyi.platform.mapper.ServiceDao; | ||||
| import com.ruoyi.platform.service.JupyterService; | import com.ruoyi.platform.service.JupyterService; | ||||
| import com.ruoyi.platform.service.ResourceOccupyService; | import com.ruoyi.platform.service.ResourceOccupyService; | ||||
| import com.ruoyi.platform.service.ServiceService; | |||||
| import com.ruoyi.platform.vo.PodStatusVo; | import com.ruoyi.platform.vo.PodStatusVo; | ||||
| import org.springframework.scheduling.annotation.Scheduled; | import org.springframework.scheduling.annotation.Scheduled; | ||||
| import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||
| import javax.annotation.Resource; | import javax.annotation.Resource; | ||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Map; | |||||
| import java.util.stream.Collectors; | |||||
| @Component() | @Component() | ||||
| public class ResourceOccupyTask { | public class ResourceOccupyTask { | ||||
| @@ -26,6 +29,9 @@ public class ResourceOccupyTask { | |||||
| @Resource | @Resource | ||||
| private ServiceDao serviceDao; | private ServiceDao serviceDao; | ||||
| @Resource | |||||
| private ServiceService serviceService; | |||||
| @Resource | @Resource | ||||
| private JupyterService jupyterService; | private JupyterService jupyterService; | ||||
| @@ -50,8 +56,13 @@ public class ResourceOccupyTask { | |||||
| @Scheduled(cron = "0 0/1 * * * ?") // 每1分钟执行一次 | @Scheduled(cron = "0 0/1 * * * ?") // 每1分钟执行一次 | ||||
| public void serviceDeduceCredit() { | public void serviceDeduceCredit() { | ||||
| List<ServiceVersion> serviceVersions = serviceDao.getRunning(); | List<ServiceVersion> serviceVersions = serviceDao.getRunning(); | ||||
| List<String> deploymentNames = serviceVersions.stream().map(ServiceVersion::getDeploymentName).collect(Collectors.toList()); | |||||
| Map<String, String> runStates = serviceService.getRunState(deploymentNames); | |||||
| serviceService.updateRunState(runStates, serviceVersions); | |||||
| for (ServiceVersion serviceVersion : serviceVersions) { | for (ServiceVersion serviceVersion : serviceVersions) { | ||||
| resourceOccupyService.deducing(Constant.TaskType_Service, null, serviceVersion.getId(), null, null); | |||||
| if (Constant.Running.equals(serviceVersion.getRunState())) { | |||||
| resourceOccupyService.deducing(Constant.TaskType_Service, null, serviceVersion.getId(), null, null); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -45,4 +45,8 @@ public interface ServiceService { | |||||
| Map<String, Object> getServiceVersionDocs(Long id); | Map<String, Object> getServiceVersionDocs(Long id); | ||||
| List<ServiceVersion> serviceVersionList(Long id); | List<ServiceVersion> serviceVersionList(Long id); | ||||
| Map<String, String> getRunState(List<String> deploymentNames); | |||||
| void updateRunState(Map<String, String> runStates, List<ServiceVersion> serviceVersionList); | |||||
| } | } | ||||
| @@ -401,7 +401,8 @@ public class ServiceServiceImpl implements ServiceService { | |||||
| return serviceVersionVo; | return serviceVersionVo; | ||||
| } | } | ||||
| Map<String, String> getRunState(List<String> deploymentNames) { | |||||
| @Override | |||||
| public Map<String, String> getRunState(List<String> deploymentNames) { | |||||
| HashMap<String, Object> paramMap = new HashMap<>(); | HashMap<String, Object> paramMap = new HashMap<>(); | ||||
| paramMap.put("deployment_names", deploymentNames); | paramMap.put("deployment_names", deploymentNames); | ||||
| String req = HttpUtils.sendPost(argoUrl + modelService + "/getStatus", JSON.toJSONString(paramMap)); | String req = HttpUtils.sendPost(argoUrl + modelService + "/getStatus", JSON.toJSONString(paramMap)); | ||||
| @@ -417,7 +418,8 @@ public class ServiceServiceImpl implements ServiceService { | |||||
| } | } | ||||
| } | } | ||||
| void updateRunState(Map<String, String> runStates, List<ServiceVersion> serviceVersionList) { | |||||
| @Override | |||||
| public void updateRunState(Map<String, String> runStates, List<ServiceVersion> serviceVersionList) { | |||||
| for (ServiceVersion sv : serviceVersionList) { | for (ServiceVersion sv : serviceVersionList) { | ||||
| String runState = runStates.get(sv.getDeploymentName()); | String runState = runStates.get(sv.getDeploymentName()); | ||||
| sv.setRunState(runState); | sv.setRunState(runState); | ||||
| @@ -56,9 +56,9 @@ | |||||
| </sql> | </sql> | ||||
| <select id="getServiceById" resultType="com.ruoyi.platform.domain.Service"> | <select id="getServiceById" resultType="com.ruoyi.platform.domain.Service"> | ||||
| select a.*,count(b.id) as version_count | |||||
| select a.*, count(b.id) as version_count | |||||
| from service a | from service a | ||||
| left join (select * from service_version where state = 1) b on a.id = b.service_id | |||||
| left join (select * from service_version where state = 1) b on a.id = b.service_id | |||||
| where a.id = #{id} | where a.id = #{id} | ||||
| </select> | </select> | ||||
| @@ -75,31 +75,43 @@ | |||||
| </select> | </select> | ||||
| <select id="getServiceByName" resultType="com.ruoyi.platform.domain.Service"> | <select id="getServiceByName" resultType="com.ruoyi.platform.domain.Service"> | ||||
| select * from service where service_name = #{serviceName} and state = 1 | |||||
| select * | |||||
| from service | |||||
| where service_name = #{serviceName} | |||||
| and state = 1 | |||||
| </select> | </select> | ||||
| <select id="getSvByVersion" resultType="com.ruoyi.platform.domain.ServiceVersion"> | <select id="getSvByVersion" resultType="com.ruoyi.platform.domain.ServiceVersion"> | ||||
| select * | select * | ||||
| from service_version | from service_version | ||||
| where service_id = #{serviceId} and version = #{version} and state = 1 | |||||
| where service_id = #{serviceId} | |||||
| and version = #{version} | |||||
| and state = 1 | |||||
| </select> | </select> | ||||
| <select id="getRunning" resultType="com.ruoyi.platform.domain.ServiceVersion"> | <select id="getRunning" resultType="com.ruoyi.platform.domain.ServiceVersion"> | ||||
| select * | select * | ||||
| from service_version where state = 1 and run_state = 'Running' | |||||
| from service_version | |||||
| where state = 1 | |||||
| and (run_state = 'Running' or run_state = 'Pending' or run_state = 'Init') | |||||
| </select> | </select> | ||||
| <insert id="insertService" keyProperty="id" useGeneratedKeys="true"> | <insert id="insertService" keyProperty="id" useGeneratedKeys="true"> | ||||
| insert into service(service_name, service_type, description, create_by, update_by) | insert into service(service_name, service_type, description, create_by, update_by) | ||||
| values (#{service.serviceName}, #{service.serviceType}, #{service.description}, #{service.createBy}, #{service.updateBy}) | |||||
| values (#{service.serviceName}, #{service.serviceType}, #{service.description}, #{service.createBy}, | |||||
| #{service.updateBy}) | |||||
| </insert> | </insert> | ||||
| <insert id="insertServiceVersion" keyProperty="id" useGeneratedKeys="true"> | <insert id="insertServiceVersion" keyProperty="id" useGeneratedKeys="true"> | ||||
| insert into service_version(service_id, version, model, description, image, resource, computing_resource_id, replicas, mount_path, env_variables, | |||||
| insert into service_version(service_id, version, model, description, image, resource, computing_resource_id, | |||||
| replicas, mount_path, env_variables, | |||||
| code_config, command, create_by, update_by, deploy_type) | code_config, command, create_by, update_by, deploy_type) | ||||
| values (#{serviceVersion.serviceId}, #{serviceVersion.version}, #{serviceVersion.model}, #{serviceVersion.description}, #{serviceVersion.image}, | |||||
| #{serviceVersion.resource}, #{serviceVersion.computingResourceId}, #{serviceVersion.replicas}, #{serviceVersion.mountPath}, #{serviceVersion.envVariables}, | |||||
| #{serviceVersion.codeConfig}, #{serviceVersion.command}, #{serviceVersion.createBy}, #{serviceVersion.updateBy}, #{serviceVersion.deployType}) | |||||
| values (#{serviceVersion.serviceId}, #{serviceVersion.version}, #{serviceVersion.model}, | |||||
| #{serviceVersion.description}, #{serviceVersion.image}, | |||||
| #{serviceVersion.resource}, #{serviceVersion.computingResourceId}, #{serviceVersion.replicas}, | |||||
| #{serviceVersion.mountPath}, #{serviceVersion.envVariables}, | |||||
| #{serviceVersion.codeConfig}, #{serviceVersion.command}, #{serviceVersion.createBy}, | |||||
| #{serviceVersion.updateBy}, #{serviceVersion.deployType}) | |||||
| </insert> | </insert> | ||||
| <update id="updateService"> | <update id="updateService"> | ||||