| @@ -3,7 +3,9 @@ package com.ruoyi.platform.controller.resources; | |||
| import com.ruoyi.common.core.web.controller.BaseController; | |||
| import com.ruoyi.common.core.web.domain.GenericsAjaxResult; | |||
| import com.ruoyi.platform.domain.ComputingResource; | |||
| import com.ruoyi.platform.domain.ResourceOccupy; | |||
| import com.ruoyi.platform.service.ComputingResourceService; | |||
| import com.ruoyi.platform.service.ResourceOccupyService; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.springframework.data.domain.Page; | |||
| @@ -28,6 +30,9 @@ public class ComputingResourceController extends BaseController { | |||
| @Resource | |||
| private ComputingResourceService computingResourceService; | |||
| @Resource | |||
| private ResourceOccupyService resourceOccupyService; | |||
| /** | |||
| * 分页查询 | |||
| * | |||
| @@ -36,12 +41,12 @@ public class ComputingResourceController extends BaseController { | |||
| */ | |||
| @GetMapping | |||
| @ApiOperation("分页查询") | |||
| public GenericsAjaxResult<Page<ComputingResource>> queryByPage(ComputingResource computingResource, @RequestParam("page") int page, | |||
| public GenericsAjaxResult<Page<ComputingResource>> queryByPage(ComputingResource computingResource, @RequestParam("page") int page, | |||
| @RequestParam("size") int size, | |||
| @RequestParam(value = "resource_type") String resourceType ) { | |||
| @RequestParam(value = "resource_type") String resourceType) { | |||
| computingResource.setComputingResource(resourceType); | |||
| PageRequest pageRequest = PageRequest.of(page,size); | |||
| return genericsSuccess(this.computingResourceService.queryByPage(computingResource, pageRequest)); | |||
| PageRequest pageRequest = PageRequest.of(page, size); | |||
| return genericsSuccess(this.computingResourceService.queryByPage(computingResource, pageRequest)); | |||
| } | |||
| /** | |||
| @@ -53,7 +58,7 @@ public class ComputingResourceController extends BaseController { | |||
| @GetMapping("{id}") | |||
| @ApiOperation("根据id查询") | |||
| public GenericsAjaxResult<ComputingResource> queryById(@PathVariable("id") Integer id) { | |||
| return genericsSuccess(this.computingResourceService.queryById(id)); | |||
| return genericsSuccess(this.computingResourceService.queryById(id)); | |||
| } | |||
| /** | |||
| @@ -65,7 +70,7 @@ public class ComputingResourceController extends BaseController { | |||
| @PostMapping | |||
| @ApiOperation("新增计算资源") | |||
| public GenericsAjaxResult<ComputingResource> add(@RequestBody ComputingResource computingResource) { | |||
| return genericsSuccess(this.computingResourceService.insert(computingResource)); | |||
| return genericsSuccess(this.computingResourceService.insert(computingResource)); | |||
| } | |||
| /** | |||
| @@ -77,7 +82,7 @@ public class ComputingResourceController extends BaseController { | |||
| @PutMapping | |||
| @ApiOperation("编辑计算资源") | |||
| public GenericsAjaxResult<ComputingResource> edit(@RequestBody ComputingResource computingResource) { | |||
| return genericsSuccess(this.computingResourceService.update(computingResource)); | |||
| return genericsSuccess(this.computingResourceService.update(computingResource)); | |||
| } | |||
| /** | |||
| @@ -89,8 +94,15 @@ public class ComputingResourceController extends BaseController { | |||
| @DeleteMapping("{id}") | |||
| @ApiOperation("删除计算资源") | |||
| public GenericsAjaxResult<String> deleteById(@PathVariable("id") Integer id) { | |||
| return genericsSuccess(this.computingResourceService.removeById(id)); | |||
| return genericsSuccess(this.computingResourceService.removeById(id)); | |||
| } | |||
| @GetMapping("/resouceOccupy") | |||
| @ApiOperation("分页查询用户资源使用情况") | |||
| public GenericsAjaxResult<Page<ResourceOccupy>> queryResourceOccupyByPage(@RequestParam("page") int page, | |||
| @RequestParam("size") int size) { | |||
| PageRequest pageRequest = PageRequest.of(page, size); | |||
| return genericsSuccess(resourceOccupyService.queryByPage(pageRequest)); | |||
| } | |||
| } | |||
| @@ -68,9 +68,5 @@ public class ComputingResource implements Serializable { | |||
| @ApiModelProperty(value = "状态标识", notes = "0表示失效,1表示生效") | |||
| private Integer state; | |||
| @ApiModelProperty(value = "节点") | |||
| private String node; | |||
| } | |||
| @@ -73,8 +73,6 @@ public interface ComputingResourceDao { | |||
| */ | |||
| int update(@Param("computingResource") ComputingResource computingResource); | |||
| int updateUsedStateByNode(@Param("node")String node, @Param("usedState") Integer usedState); | |||
| /** | |||
| * 通过主键删除数据 | |||
| * | |||
| @@ -2,6 +2,9 @@ package com.ruoyi.platform.mapper; | |||
| import com.ruoyi.platform.domain.ResourceOccupy; | |||
| import org.apache.ibatis.annotations.Param; | |||
| import org.springframework.data.domain.Pageable; | |||
| import java.util.List; | |||
| public interface ResourceOccupyDao { | |||
| @@ -18,4 +21,8 @@ public interface ResourceOccupyDao { | |||
| int updateUsed(@Param("id") Integer id, @Param("used") Integer used); | |||
| int updateUnUsed(@Param("id") Integer id, @Param("used") Integer used); | |||
| long count(); | |||
| List<ResourceOccupy> queryByPage(@Param("pageable") Pageable pageable); | |||
| } | |||
| @@ -1,5 +1,9 @@ | |||
| package com.ruoyi.platform.service; | |||
| import com.ruoyi.platform.domain.ResourceOccupy; | |||
| import org.springframework.data.domain.Page; | |||
| import org.springframework.data.domain.PageRequest; | |||
| public interface ResourceOccupyService { | |||
| Boolean haveResource(Integer computingResourceId) throws Exception; | |||
| @@ -10,4 +14,5 @@ public interface ResourceOccupyService { | |||
| void deducing(String taskType, Long taskId); | |||
| Page<ResourceOccupy> queryByPage(PageRequest pageRequest); | |||
| } | |||
| @@ -46,9 +46,6 @@ import java.util.*; | |||
| public class ExperimentServiceImpl implements ExperimentService { | |||
| @Resource | |||
| private ExperimentDao experimentDao; | |||
| @Resource | |||
| private ExperimentInsDao experimentInsDao; | |||
| @Resource | |||
| private ModelsService modelsService; | |||
| @Resource | |||
| @@ -74,8 +71,6 @@ public class ExperimentServiceImpl implements ExperimentService { | |||
| private String argoConvert; | |||
| @Value("${argo.workflowRun}") | |||
| private String argoWorkflowRun; | |||
| @Value("${argo.workflowStatus}") | |||
| private String argoWorkflowStatus; | |||
| @Value("${git.localPath}") | |||
| String localPath; | |||
| @@ -164,6 +164,7 @@ public class RayServiceImpl implements RayService { | |||
| if (resourceOccupyService.haveResource(ray.getComputingResourceId())) { | |||
| RayParamVo rayParamVo = new RayParamVo(); | |||
| BeanUtils.copyProperties(ray, rayParamVo); | |||
| rayParamVo.setResource(ray.getComputingResourceId()); | |||
| rayParamVo.setCodeConfig(JsonUtils.jsonToMap(ray.getCodeConfig())); | |||
| rayParamVo.setDataset(JsonUtils.jsonToMap(ray.getDataset())); | |||
| rayParamVo.setModel(JsonUtils.jsonToMap(ray.getModel())); | |||
| @@ -8,6 +8,9 @@ import com.ruoyi.platform.mapper.ComputingResourceDao; | |||
| import com.ruoyi.platform.mapper.ResourceOccupyDao; | |||
| import com.ruoyi.platform.service.ResourceOccupyService; | |||
| import com.ruoyi.system.api.model.LoginUser; | |||
| import org.springframework.data.domain.Page; | |||
| import org.springframework.data.domain.PageImpl; | |||
| import org.springframework.data.domain.PageRequest; | |||
| import org.springframework.stereotype.Service; | |||
| import javax.annotation.Resource; | |||
| @@ -90,4 +93,10 @@ public class ResourceOccupyServiceImpl implements ResourceOccupyService { | |||
| resourceOccupy.setDeduceLastTime(new Date()); | |||
| resourceOccupyDao.edit(resourceOccupy); | |||
| } | |||
| @Override | |||
| public Page<ResourceOccupy> queryByPage(PageRequest pageRequest) { | |||
| long total = resourceOccupyDao.count(); | |||
| return new PageImpl<>(resourceOccupyDao.queryByPage(pageRequest), pageRequest, total); | |||
| } | |||
| } | |||
| @@ -250,7 +250,7 @@ public class ServiceServiceImpl implements ServiceService { | |||
| HashMap<String, Object> paramMap = new HashMap<>(); | |||
| paramMap.put("service_name", service.getServiceName()); | |||
| paramMap.put("description", serviceVersion.getDescription()); | |||
| paramMap.put("resource", serviceVersion.getResource()); | |||
| paramMap.put("resource", serviceVersion.getComputingResourceId()); | |||
| paramMap.put("mount_path", serviceVersion.getMountPath()); | |||
| paramMap.put("replicas", serviceVersion.getReplicas()); | |||
| paramMap.put("env", JSONObject.parseObject(serviceVersion.getEnvVariables())); | |||
| @@ -2,7 +2,9 @@ package com.ruoyi.platform.utils; | |||
| import com.alibaba.fastjson2.JSON; | |||
| import com.ruoyi.platform.constant.Constant; | |||
| import com.ruoyi.platform.domain.ComputingResource; | |||
| import com.ruoyi.platform.domain.DevEnvironment; | |||
| import com.ruoyi.platform.mapper.ComputingResourceDao; | |||
| import com.ruoyi.platform.service.ResourceOccupyService; | |||
| import io.kubernetes.client.Exec; | |||
| import io.kubernetes.client.custom.IntOrString; | |||
| @@ -12,7 +14,9 @@ import io.kubernetes.client.openapi.ApiException; | |||
| import io.kubernetes.client.openapi.apis.AppsV1Api; | |||
| import io.kubernetes.client.openapi.apis.CoreV1Api; | |||
| import io.kubernetes.client.openapi.models.*; | |||
| import io.kubernetes.client.util.ClientBuilder; | |||
| import io.kubernetes.client.util.Config; | |||
| import io.kubernetes.client.util.credentials.AccessTokenAuthentication; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.apache.commons.lang.StringUtils; | |||
| import org.json.JSONObject; | |||
| @@ -50,6 +54,9 @@ public class K8sClientUtil { | |||
| @Resource | |||
| private ResourceOccupyService resourceOccupyService; | |||
| @Resource | |||
| private ComputingResourceDao computingResourceDao; | |||
| /** | |||
| * 构建集群POD内通过SA访问的客户端 | |||
| * loading the in-cluster config, including: | |||
| @@ -485,7 +492,7 @@ public class K8sClientUtil { | |||
| //配置资源 | |||
| V1ResourceRequirements v1ResourceRequirements = setPodResource(devEnvironment.getStandard()); | |||
| V1ResourceRequirements v1ResourceRequirements = setPodResource(devEnvironment.getComputingResourceId()); | |||
| V1Pod pod = new V1PodBuilder() | |||
| .withNewMetadata() | |||
| @@ -688,87 +695,17 @@ public class K8sClientUtil { | |||
| } | |||
| public Integer createDeployment(String dpName, String namespace, Integer replicas, String model, String image, Integer port, String resource, String mountPath | |||
| , String envVariables, String codeConfig) { | |||
| AppsV1Api api = new AppsV1Api(apiClient); | |||
| //配置标签选择 | |||
| HashMap<String, String> selector = new HashMap<>(); | |||
| selector.put("app", dpName); | |||
| //配置资源 | |||
| V1ResourceRequirements v1ResourceRequirements = setPodResource(resource); | |||
| //配置环境变量 | |||
| List<V1EnvVar> env = new ArrayList<>(); | |||
| if (StringUtils.isNotEmpty(envVariables)) { | |||
| HashMap<String, String> envMap = JSON.parseObject(envVariables, HashMap.class); | |||
| for (String key : envMap.keySet()) { | |||
| V1EnvVar envVar = new V1EnvVar().name(key).value(envMap.get(key)); | |||
| env.add(envVar); | |||
| } | |||
| } | |||
| // 配置卷和卷挂载 | |||
| // List<V1VolumeMount> volumeMounts = new ArrayList<>(); | |||
| // volumeMounts.add(new V1VolumeMount().name("workspace").mountPath(mountPath)); | |||
| // volumeMounts.add(new V1VolumeMount().name("minio-pvc").mountPath("/opt/code").subPath(codeConfig).readOnly(true)); | |||
| // volumeMounts.add(new V1VolumeMount().name("minio-pvc").mountPath("/opt/model").subPath(model).readOnly(true)); | |||
| // | |||
| // List<V1Volume> volumes = new ArrayList<>(); | |||
| // volumes.add(new V1Volume().name("workspace").persistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource().claimName(pvc.getMetadata().getName()))); | |||
| // volumes.add(new V1Volume().name("minio-pvc").persistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource().claimName(dataPvcName))); | |||
| V1ResourceRequirements setPodResource(Integer computingResourceId) { | |||
| ComputingResource computingResource = computingResourceDao.queryById(computingResourceId); | |||
| //创建deployment | |||
| V1Deployment deployment = new V1DeploymentBuilder().withNewMetadata() | |||
| .withName(dpName) | |||
| .endMetadata() | |||
| .withNewSpec() | |||
| .withReplicas(replicas) | |||
| .withSelector(new V1LabelSelector().matchLabels(selector)) | |||
| .withNewTemplate() | |||
| .withNewMetadata() | |||
| .addToLabels("app", dpName) | |||
| .endMetadata() | |||
| .withNewSpec() | |||
| .addNewContainer() | |||
| .withName(dpName) | |||
| .withImage(image) | |||
| .withEnv(env) | |||
| .withPorts(new V1ContainerPort().containerPort(port).protocol("TCP")) | |||
| .withResources(v1ResourceRequirements) | |||
| .endContainer() | |||
| .endSpec() | |||
| .endTemplate() | |||
| .endSpec() | |||
| .build(); | |||
| try { | |||
| api.createNamespacedDeployment(namespace, deployment, null, null, null); | |||
| } catch (ApiException e) { | |||
| throw new RuntimeException("创建deployment异常:" + e.getResponseBody()); | |||
| } | |||
| V1Service service = createService(namespace, dpName + "-svc", port, selector); | |||
| return service.getSpec().getPorts().get(0).getNodePort(); | |||
| } | |||
| V1ResourceRequirements setPodResource(String resource) { | |||
| //配置pod资源 | |||
| JSONObject standardJson = new JSONObject(resource); | |||
| JSONObject valueJson = (JSONObject) standardJson.get("value"); | |||
| int cpu = (int) valueJson.get("cpu"); | |||
| String memory = (String) valueJson.get("memory"); | |||
| String memory = computingResource.getMemoryGb().toString(); | |||
| memory = memory.substring(0, memory.length() - 1).concat("i"); | |||
| Integer gpu = (Integer) valueJson.get("gpu"); | |||
| HashMap<String, Quantity> limitMap = new HashMap<>(); | |||
| if (gpu != null && gpu != 0) { | |||
| limitMap.put("nvidia.com/gpu", new Quantity(String.valueOf(gpu))); | |||
| if (computingResource.getGpuNums() != null && computingResource.getGpuNums() != 0) { | |||
| limitMap.put("nvidia.com/gpu", new Quantity(String.valueOf(computingResource.getGpuNums()))); | |||
| } | |||
| limitMap.put("cpu", new Quantity(String.valueOf(cpu))); | |||
| limitMap.put("cpu", new Quantity(String.valueOf(computingResource.getCpuCores()))); | |||
| limitMap.put("memory", new Quantity(memory)); | |||
| limitMap.put("ephemeral-storage", new Quantity("100Gi")); | |||
| @@ -44,5 +44,5 @@ public class RayParamVo { | |||
| private Integer minSamplesRequired; | |||
| private String resource; | |||
| private Integer resource; | |||
| } | |||
| @@ -148,10 +148,6 @@ computing_resource = values(computing_resource)standard = values(standard)descri | |||
| where id = #{computingResource.id} | |||
| </update> | |||
| <update id="updateUsedStateByNode"> | |||
| update computing_resource set used_state = #{usedState} where node = #{node} | |||
| </update> | |||
| <!--通过主键删除--> | |||
| <delete id="deleteById"> | |||
| delete from computing_resource where id = #{id} | |||
| @@ -49,4 +49,14 @@ | |||
| where task_type = #{task_type} | |||
| and task_id = #{task_id} | |||
| </select> | |||
| <select id="count" resultType="java.lang.Long"> | |||
| select count(1) resource_occupy | |||
| </select> | |||
| <select id="queryByPage" resultType="com.ruoyi.platform.domain.ResourceOccupy"> | |||
| select * | |||
| from resource_occupy | |||
| order by start_time desc limit #{pageable.offset}, #{pageable.pageSize} | |||
| </select> | |||
| </mapper> | |||
| @@ -86,7 +86,7 @@ | |||
| <select id="getRunning" resultType="com.ruoyi.platform.domain.ServiceVersion"> | |||
| select * | |||
| from service_version where state = 1 and status = 'Running' | |||
| from service_version where state = 1 and run_state = 'Running' | |||
| </select> | |||
| <insert id="insertService" keyProperty="id" useGeneratedKeys="true"> | |||
| @@ -25,6 +25,7 @@ | |||
| <result property="remark" column="remark"/> | |||
| <result property="gitLinkUsername" column="git_link_username"/> | |||
| <result property="gitLinkPassword" column="git_link_password"/> | |||
| <result property="credit" column="credit"/> | |||
| <association property="dept" javaType="SysDept" resultMap="deptResult"/> | |||
| <collection property="roles" javaType="java.util.List" resultMap="RoleResult"/> | |||
| </resultMap> | |||
| @@ -59,6 +60,7 @@ | |||
| u.password, | |||
| u.git_link_username, | |||
| u.git_link_password, | |||
| u.credit, | |||
| u.sex, | |||
| u.status, | |||
| u.del_flag, | |||
| @@ -88,7 +90,7 @@ | |||
| <select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult"> | |||
| select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, | |||
| u.git_link_username, | |||
| u.git_link_username, u.credit, | |||
| u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader | |||
| from sys_user u | |||
| left join sys_dept d on u.dept_id = d.dept_id | |||
| @@ -123,7 +125,7 @@ | |||
| </select> | |||
| <select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult"> | |||
| select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time, u.git_link_username | |||
| select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time, u.credit, u.git_link_username | |||
| from sys_user u | |||
| left join sys_dept d on u.dept_id = d.dept_id | |||
| left join sys_user_role ur on u.user_id = ur.user_id | |||
| @@ -140,7 +142,7 @@ | |||
| </select> | |||
| <select id="selectUnallocatedList" parameterType="SysUser" resultMap="SysUserResult"> | |||
| select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time ,u.git_link_username | |||
| select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time , u.credit, u.git_link_username | |||
| from sys_user u | |||
| left join sys_dept d on u.dept_id = d.dept_id | |||
| left join sys_user_role ur on u.user_id = ur.user_id | |||
| @@ -212,6 +214,7 @@ | |||
| <if test="remark != null and remark != ''">remark,</if> | |||
| <if test="gitLinkUsername != null and gitLinkUsername != ''">git_link_username,</if> | |||
| <if test="gitLinkPassword != null and gitLinkPassword != ''">git_link_password,</if> | |||
| <if test="credit != null">credit,</if> | |||
| create_time | |||
| )values( | |||
| <if test="userId != null and userId != ''">#{userId},</if> | |||
| @@ -228,6 +231,7 @@ | |||
| <if test="remark != null and remark != ''">#{remark},</if> | |||
| <if test="gitLinkUsername != null and gitLinkUsername != ''">#{gitLinkUsername},</if> | |||
| <if test="gitLinkPassword != null and gitLinkPassword != ''">#{gitLinkPassword},</if> | |||
| <if test="credit != null">#{credit},</if> | |||
| sysdate() | |||
| ) | |||
| </insert> | |||
| @@ -250,6 +254,7 @@ | |||
| <if test="remark != null">remark = #{remark},</if> | |||
| <if test="gitLinkUsername != null and gitLinkUsername != ''">git_link_username = #{gitLinkUsername},</if> | |||
| <if test="gitLinkPassword != null and gitLinkPassword != ''">git_link_password = #{gitLinkPassword},</if> | |||
| <if test="credit != null">credit = #{credit},</if> | |||
| update_time = sysdate() | |||
| </set> | |||
| where user_id = #{userId} | |||