| @@ -10,22 +10,21 @@ public class Constant { | |||||
| public final static int State_valid = 1; // 有效 | public final static int State_valid = 1; // 有效 | ||||
| public final static int State_invalid = 0; // 无效 | public final static int State_invalid = 0; // 无效 | ||||
| public final static int State_building = 2; //创建中 | public final static int State_building = 2; //创建中 | ||||
| public final static int State_failed = 3; //运行失败 | |||||
| public final static int Used_State_used = 1; // 已占用 | public final static int Used_State_used = 1; // 已占用 | ||||
| public final static int Used_State_unused = 0; // 未占用 | public final static int Used_State_unused = 0; // 未占用 | ||||
| public final static String Computing_Resource_CPU = "CPU"; // 计算资源_CPU | public final static String Computing_Resource_CPU = "CPU"; // 计算资源_CPU | ||||
| public final static String Computing_Resource_GPU = "GPU"; // 计算资源_GPU | public final static String Computing_Resource_GPU = "GPU"; // 计算资源_GPU | ||||
| public final static int Git_Category_Id = 39; | public final static int Git_Category_Id = 39; | ||||
| public final static String Source_Auto_Export = "auto_export"; | public final static String Source_Auto_Export = "auto_export"; | ||||
| public final static String Source_Hand_Export = "hand_export"; | public final static String Source_Hand_Export = "hand_export"; | ||||
| public final static String Source_Add = "add"; | public final static String Source_Add = "add"; | ||||
| } | } | ||||
| @@ -68,20 +68,25 @@ public class ServiceController extends BaseController { | |||||
| @DeleteMapping("{id}") | @DeleteMapping("{id}") | ||||
| @ApiOperation("删除服务") | @ApiOperation("删除服务") | ||||
| public GenericsAjaxResult<String> deleteService(@PathVariable("id") Long id){ | |||||
| public GenericsAjaxResult<String> deleteService(@PathVariable("id") Long id) { | |||||
| return genericsSuccess(serviceService.deleteService(id)); | return genericsSuccess(serviceService.deleteService(id)); | ||||
| } | } | ||||
| @DeleteMapping("/serviceVersion/{id}") | @DeleteMapping("/serviceVersion/{id}") | ||||
| @ApiOperation("删除服务版本") | @ApiOperation("删除服务版本") | ||||
| public GenericsAjaxResult<String> deleteServiceVersion(@PathVariable("id") Long id){ | |||||
| public GenericsAjaxResult<String> deleteServiceVersion(@PathVariable("id") Long id) { | |||||
| return genericsSuccess(serviceService.deleteServiceVersion(id)); | return genericsSuccess(serviceService.deleteServiceVersion(id)); | ||||
| } | } | ||||
| @GetMapping("/runServiceVersion/{id}") | @GetMapping("/runServiceVersion/{id}") | ||||
| @ApiOperation("启动服务版本") | @ApiOperation("启动服务版本") | ||||
| public GenericsAjaxResult<String> runServiceVersion(@PathVariable("id") Long id){ | |||||
| serviceService.runServiceVersion(id); | |||||
| return genericsSuccess(""); | |||||
| public GenericsAjaxResult<String> runServiceVersion(@PathVariable("id") Long id) { | |||||
| return genericsSuccess(serviceService.runServiceVersion(id)); | |||||
| } | |||||
| @GetMapping("/stopServiceVersion/{id}") | |||||
| @ApiOperation("停止服务版本") | |||||
| public GenericsAjaxResult<String> stopServiceVersion(@PathVariable("id") Long id) { | |||||
| return genericsSuccess(serviceService.stopServiceVersion(id)); | |||||
| } | } | ||||
| } | } | ||||
| @@ -9,7 +9,7 @@ import java.io.Serializable; | |||||
| import java.util.Date; | import java.util.Date; | ||||
| @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||||
| @ApiModel("服务") | |||||
| @ApiModel("服务版本") | |||||
| @Data | @Data | ||||
| public class ServiceVersion implements Serializable { | public class ServiceVersion implements Serializable { | ||||
| private Long id; | private Long id; | ||||
| @@ -18,6 +18,8 @@ public class ServiceVersion implements Serializable { | |||||
| private String version; | private String version; | ||||
| private String description; | |||||
| private String model; | private String model; | ||||
| private String image; | private String image; | ||||
| @@ -45,4 +47,10 @@ public class ServiceVersion implements Serializable { | |||||
| private Date updateTime; | private Date updateTime; | ||||
| private Integer state; | private Integer state; | ||||
| private Integer runState; | |||||
| private String deploymentName; | |||||
| private String svcName; | |||||
| } | } | ||||
| @@ -25,8 +25,8 @@ public interface ServiceDao { | |||||
| int updateServiceVersion(@Param("serviceVersion") ServiceVersion serviceVersion); | int updateServiceVersion(@Param("serviceVersion") ServiceVersion serviceVersion); | ||||
| Service getServiceById(Long id); | |||||
| Service getServiceById(@Param("id") Long id); | |||||
| ServiceVersion getServiceVersionById(Long id); | |||||
| ServiceVersion getServiceVersionById(@Param("id") Long id); | |||||
| } | } | ||||
| @@ -26,5 +26,7 @@ public interface ServiceService { | |||||
| String deleteServiceVersion(Long id); | String deleteServiceVersion(Long id); | ||||
| void runServiceVersion(Long id); | |||||
| String runServiceVersion(Long id); | |||||
| String stopServiceVersion(Long id); | |||||
| } | } | ||||
| @@ -1,12 +1,17 @@ | |||||
| package com.ruoyi.platform.service.impl; | package com.ruoyi.platform.service.impl; | ||||
| import com.alibaba.fastjson2.JSON; | |||||
| import com.alibaba.fastjson2.JSONObject; | |||||
| import com.ruoyi.common.security.utils.SecurityUtils; | import com.ruoyi.common.security.utils.SecurityUtils; | ||||
| import com.ruoyi.platform.constant.Constant; | import com.ruoyi.platform.constant.Constant; | ||||
| import com.ruoyi.platform.domain.ServiceVersion; | import com.ruoyi.platform.domain.ServiceVersion; | ||||
| import com.ruoyi.platform.mapper.ServiceDao; | import com.ruoyi.platform.mapper.ServiceDao; | ||||
| import com.ruoyi.platform.service.ServiceService; | import com.ruoyi.platform.service.ServiceService; | ||||
| import com.ruoyi.platform.utils.HttpUtils; | |||||
| import com.ruoyi.platform.utils.JacksonUtil; | |||||
| import com.ruoyi.system.api.model.LoginUser; | import com.ruoyi.system.api.model.LoginUser; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.springframework.beans.factory.annotation.Value; | |||||
| import org.springframework.data.domain.Page; | import org.springframework.data.domain.Page; | ||||
| import org.springframework.data.domain.PageImpl; | import org.springframework.data.domain.PageImpl; | ||||
| import org.springframework.data.domain.PageRequest; | import org.springframework.data.domain.PageRequest; | ||||
| @@ -14,11 +19,16 @@ import org.springframework.stereotype.Service; | |||||
| import javax.annotation.Resource; | import javax.annotation.Resource; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import java.util.HashMap; | |||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Map; | |||||
| @Service("serviceService") | @Service("serviceService") | ||||
| public class ServiceServiceImpl implements ServiceService { | public class ServiceServiceImpl implements ServiceService { | ||||
| @Value("${argo.url}") | |||||
| private String argoUrl; | |||||
| @Resource | @Resource | ||||
| private ServiceDao serviceDao; | private ServiceDao serviceDao; | ||||
| @@ -108,10 +118,46 @@ public class ServiceServiceImpl implements ServiceService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public void runServiceVersion(Long id) { | |||||
| public String runServiceVersion(Long id) { | |||||
| ServiceVersion serviceVersion = serviceDao.getServiceVersionById(id); | ServiceVersion serviceVersion = serviceDao.getServiceVersionById(id); | ||||
| com.ruoyi.platform.domain.Service service = serviceDao.getServiceById(serviceVersion.getServiceId()); | |||||
| HashMap<String, Object> paramMap = new HashMap<>(); | |||||
| paramMap.put("code_config", serviceVersion.getCodeConfig()); | |||||
| paramMap.put("description", serviceVersion.getDescription()); | |||||
| paramMap.put("env", JSONObject.parseObject(serviceVersion.getEnvVariables())); | |||||
| paramMap.put("image", serviceVersion.getImage()); | |||||
| paramMap.put("model", JSONObject.parseObject(serviceVersion.getModel())); | |||||
| paramMap.put("mount_path", serviceVersion.getMountPath()); | |||||
| paramMap.put("replicas", serviceVersion.getReplicas()); | |||||
| paramMap.put("resource", serviceVersion.getResource()); | |||||
| paramMap.put("service_name", service.getServiceName()); | |||||
| paramMap.put("service_type", service.getServiceType()); | |||||
| String req = HttpUtils.sendPost(argoUrl + "/model/service/create", JSON.toJSONString(paramMap)); | |||||
| if (StringUtils.isNotEmpty(req)) { | |||||
| Map<String, Object> reqMap = JacksonUtil.parseJSONStr2Map(req); | |||||
| serviceVersion.setUrl((String) reqMap.get("url")); | |||||
| serviceVersion.setDeploymentName((String) reqMap.get("deployment_name")); | |||||
| serviceVersion.setSvcName((String) reqMap.get("svc_name")); | |||||
| serviceVersion.setRunState(Constant.State_building); | |||||
| serviceDao.updateServiceVersion(serviceVersion); | |||||
| return "启动成功"; | |||||
| } else { | |||||
| throw new RuntimeException("创建失败"); | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public String stopServiceVersion(Long id) { | |||||
| ServiceVersion serviceVersion = serviceDao.getServiceVersionById(id); | |||||
| HashMap<String, Object> paramMap = new HashMap<>(); | |||||
| paramMap.put("deployment_name", serviceVersion.getDeploymentName()); | |||||
| String req = HttpUtils.sendPost(argoUrl + "/model/service/create", JSON.toJSONString(paramMap)); | |||||
| if (StringUtils.isNotEmpty(req)) { | |||||
| serviceVersion.setRunState(Constant.State_invalid); | |||||
| serviceDao.updateServiceVersion(serviceVersion); | |||||
| return "停止成功"; | |||||
| }else { | |||||
| throw new RuntimeException("停止失败"); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -23,7 +23,7 @@ | |||||
| and a.service_name like concat('%', #{service.serviceName}, '%') | and a.service_name like concat('%', #{service.serviceName}, '%') | ||||
| </if> | </if> | ||||
| <if test="service.serviceType != null"> | <if test="service.serviceType != null"> | ||||
| and a. = #{service.serviceType} | |||||
| and a.service_type = #{service.serviceType} | |||||
| </if> | </if> | ||||
| </where> | </where> | ||||
| group by a.id | group by a.id | ||||
| @@ -69,30 +69,31 @@ | |||||
| <insert id="insertService"> | <insert id="insertService"> | ||||
| 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 (#{serviceName}, #{serviceType}, #{description}, #{createBy}, #{updateBy}) | |||||
| values (#{service.serviceName}, #{service.serviceType}, #{service.description}, #{service.createBy}, #{service.updateBy}) | |||||
| </insert> | </insert> | ||||
| <insert id="insertServiceVersion"> | <insert id="insertServiceVersion"> | ||||
| insert into service_version(service_id, version, model, image, resouce, replicas, mount_path, env_variables, | |||||
| insert into service_version(service_id, version, model, description, image, resouce, replicas, mount_path, env_variables, | |||||
| code_config, command, create_by, update_by) | code_config, command, create_by, update_by) | ||||
| values (#{serviceId}, #{version}, #{model}, #{image}, #{replicas}, #{mountPath}, #{envVariables}, | |||||
| #{codeConfig}, #{command}, #{createBy}, #{updateBy}) | |||||
| values (#{serviceVersion.serviceId}, #{serviceVersion.version}, #{serviceVersion.model}, #{serviceVersion.description}, #{serviceVersion.image}, | |||||
| #{serviceVersion.replicas}, #{serviceVersion.mountPath}, #{serviceVersion.envVariables}, | |||||
| #{serviceVersion.codeConfig}, #{serviceVersion.command}, #{serviceVersion.createBy}, #{serviceVersion.updateBy}) | |||||
| </insert> | </insert> | ||||
| <update id="updateService"> | <update id="updateService"> | ||||
| update service | update service | ||||
| <set> | <set> | ||||
| <if test="service.serviceName != null and service.serviceName !=''"> | <if test="service.serviceName != null and service.serviceName !=''"> | ||||
| service_name = #{service.serviceName} | |||||
| service_name = #{service.serviceName}, | |||||
| </if> | </if> | ||||
| <if test="service.serviceType != null"> | <if test="service.serviceType != null"> | ||||
| service_type = #{service.serviceType} | |||||
| service_type = #{service.serviceType}, | |||||
| </if> | </if> | ||||
| <if test="service.description != null and service.description !=''"> | <if test="service.description != null and service.description !=''"> | ||||
| description = #{service.description} | |||||
| description = #{service.description}, | |||||
| </if> | </if> | ||||
| <if test="service.state != null"> | <if test="service.state != null"> | ||||
| state = #{service.state} | |||||
| state = #{service.state}, | |||||
| </if> | </if> | ||||
| </set> | </set> | ||||
| where id = #{service.id} | where id = #{service.id} | ||||
| @@ -101,6 +102,9 @@ | |||||
| <update id="updateServiceVersion"> | <update id="updateServiceVersion"> | ||||
| update service_version | update service_version | ||||
| <set> | <set> | ||||
| <if test="serviceVersion.description != null and serviceVersion.description !=''"> | |||||
| description = #{serviceVersion.description}, | |||||
| </if> | |||||
| <if test="serviceVersion.model != null and serviceVersion.model !=''"> | <if test="serviceVersion.model != null and serviceVersion.model !=''"> | ||||
| model = #{serviceVersion.model}, | model = #{serviceVersion.model}, | ||||
| </if> | </if> | ||||
| @@ -128,6 +132,18 @@ | |||||
| <if test="serviceVersion.url != null and serviceVersion.url !=''"> | <if test="serviceVersion.url != null and serviceVersion.url !=''"> | ||||
| url = #{serviceVersion.url}, | url = #{serviceVersion.url}, | ||||
| </if> | </if> | ||||
| <if test="serviceVersion.state != null"> | |||||
| state = #{serviceVersion.state}, | |||||
| </if> | |||||
| <if test="serviceVersion.runState != null"> | |||||
| run_state = #{serviceVersion.runState}, | |||||
| </if> | |||||
| <if test="serviceVersion.deploymentName != null and serviceVersion.deploymentName !=''"> | |||||
| deployment_name = #{serviceVersion.deploymentName}, | |||||
| </if> | |||||
| <if test="serviceVersion.svcName != null and serviceVersion.svcName !=''"> | |||||
| svc_name = #{serviceVersion.svcName}, | |||||
| </if> | |||||
| </set> | </set> | ||||
| where id = #{serviceVersion.id} | where id = #{serviceVersion.id} | ||||
| </update> | </update> | ||||