|
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
- <mapper namespace="com.imitate.common.k8s.mapper.RunPodMapper">
- <resultMap id="BaseResultMap"
- type="com.imitate.common.k8s.pojo.RunPod">
- <id column="id" property="id" jdbcType="BIGINT" />
- <result column="cluster" property="cluster" jdbcType="VARCHAR" />
- <result column="name" property="name" jdbcType="VARCHAR" />
- <result column="image_name" property="imageName"
- jdbcType="VARCHAR" />
- <result column="cpu_limit" property="cpuLimit"
- jdbcType="DOUBLE" />
- <result column="memory_limit" property="memoryLimit"
- jdbcType="INTEGER" />
- <result column="cpu_request" property="cpuRequest"
- jdbcType="DOUBLE" />
- <result column="memory_request" property="memoryRequest"
- jdbcType="INTEGER" />
- <result column="create_by" property="createBy"
- jdbcType="VARCHAR" />
- <result column="node_ip" property="nodeIp"
- jdbcType="VARCHAR" />
- <result column="run_pod_type" property="runPodType"
- jdbcType="INTEGER" />
- <result column="priority" property="priority" jdbcType="BIGINT" />
- <result column="svc_port" property="svcPort" jdbcType="VARCHAR" />
- <result column="ssh_port" property="sshPort" jdbcType="VARCHAR" />
- <result column="expire_time" property="expireTime"
- jdbcType="TIMESTAMP" />
- <result column="create_time" property="createTime"
- jdbcType="TIMESTAMP" />
- <result column="update_time" property="updateTime"
- jdbcType="TIMESTAMP" />
- </resultMap>
-
- <sql id="Base_Column_List">
- id, cluster, name, image_name,
- cpu_limit, memory_limit, cpu_request, memory_request,
- create_by, node_ip,
- run_pod_type, svc_port, ssh_port,
- priority,
- expire_time, create_time, update_time
- </sql>
-
-
- <delete id="deleteByName" parameterType="java.lang.String">
- delete from
- run_pod
- where name = #{name,jdbcType=VARCHAR}
- </delete>
- <delete id="deleteByNameExpired">
- delete from
- run_pod
- where name = #{name,jdbcType=VARCHAR} and expire_time <= #{expireTime,jdbcType=TIMESTAMP}
- </delete>
-
- <insert id="insert"
- parameterType="com.imitate.common.k8s.pojo.RunPod">
- insert into run_pod (id,cluster, name,
- image_name,
- cpu_limit,
- memory_limit,
- cpu_request,
- memory_request,
- create_by,
- node_ip,
- run_pod_type,
- priority,
- svc_port,
- ssh_port,
- expire_time,
- create_time,
- update_time)
- values
- (#{id,jdbcType=BIGINT},
- #{cluster,jdbcType=VARCHAR},#{name,jdbcType=VARCHAR},
- #{imageName,jdbcType=VARCHAR},
- #{cpuLimit,jdbcType=DOUBLE},
- #{memoryLimit,jdbcType=INTEGER},
- #{cpuRequest,jdbcType=DOUBLE},
- #{memoryRequest,jdbcType=INTEGER},
- #{createBy,jdbcType=VARCHAR},
- #{nodeIp,jdbcType=VARCHAR},
- #{runPodType,jdbcType=INTEGER},
- #{priority,jdbcType=BIGINT},
- #{svcPort,jdbcType=VARCHAR},
- #{sshPort,jdbcType=VARCHAR},
- #{expireTime,jdbcType=TIMESTAMP},
- #{createTime,jdbcType=TIMESTAMP},
- #{updateTime,jdbcType=TIMESTAMP})
- </insert>
- <insert id="insertSelective"
- parameterType="com.imitate.common.k8s.pojo.RunPod">
- insert into run_pod
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="id != null">
- id,
- </if>
- <if test="cluster != null">
- cluster,
- </if>
- <if test="name != null">
- name,
- </if>
- <if test="imageName != null">
- image_name,
- </if>
- <if test="cpuLimit != null">
- cpu_limit,
- </if>
- <if test="memoryLimit != null">
- memory_limit,
- </if>
- <if test="cpuRequest != null">
- cpu_request,
- </if>
- <if test="memoryRequest != null">
- memory_request,
- </if>
- <if test="createBy != null">
- create_by,
- </if>
- <if test="nodeIp != null">
- node_ip,
- </if>
- <if test="runPodType != null">
- run_pod_type,
- </if>
- <if test="priority != null">
- priority,
- </if>
- <if test="svcPort != null">
- svc_port,
- </if>
- <if test="sshPort != null">
- ssh_port,
- </if>
- <if test="expireTime != null">
- expire_time,
- </if>
- <if test="createTime != null">
- create_time,
- </if>
- <if test="updateTime != null">
- update_time,
- </if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="id != null">
- #{id,jdbcType=BIGINT},
- </if>
- <if test="cluster != null">
- #{cluster,jdbcType=VARCHAR},
- </if>
- <if test="name != null">
- #{name,jdbcType=VARCHAR},
- </if>
- <if test="imageName != null">
- #{imageName,jdbcType=VARCHAR},
- </if>
- <if test="cpuLimit != null">
- #{cpuLimit,jdbcType=DOUBLE},
- </if>
- <if test="memoryLimit != null">
- #{memoryLimit,jdbcType=INTEGER},
- </if>
- <if test="cpuRequest != null">
- #{cpuRequest,jdbcType=DOUBLE},
- </if>
- <if test="memoryRequest != null">
- #{memoryRequest,jdbcType=INTEGER},
- </if>
- <if test="createBy != null">
- #{createBy,jdbcType=VARCHAR},
- </if>
- <if test="nodeIp != null">
- #{nodeIp,jdbcType=VARCHAR},
- </if>
- <if test="runPodType != null">
- #{runPodType,jdbcType=INTEGER},
- </if>
- <if test="priority != null">
- #{priority,jdbcType=BIGINT},
- </if>
- <if test="svcPort != null">
- #{svcPort,jdbcType=VARCHAR},
- </if>
- <if test="sshPort != null">
- #{sshPort,jdbcType=VARCHAR},
- </if>
- <if test="expireTime != null">
- #{expireTime,jdbcType=TIMESTAMP},
- </if>
- <if test="createTime != null">
- #{createTime,jdbcType=TIMESTAMP},
- </if>
- <if test="updateTime != null">
- #{updateTime,jdbcType=TIMESTAMP},
- </if>
- </trim>
- </insert>
- <update id="updateByPrimaryKeySelective"
- parameterType="com.imitate.common.k8s.pojo.RunPod">
- update run_pod
- <set>
- <if test="name != null">
- name = #{name,jdbcType=VARCHAR},
- </if>
- <if test="cluster != null">
- cluster = #{cluster,jdbcType=VARCHAR},
- </if>
- <if test="imageName != null">
- image_name = #{imageName,jdbcType=VARCHAR},
- </if>
- <if test="cpuLimit != null">
- cpu_limit = #{cpuLimit,jdbcType=DOUBLE},
- </if>
- <if test="memoryLimit != null">
- memory_limit = #{memoryLimit,jdbcType=INTEGER},
- </if>
- <if test="cpuRequest != null">
- cpu_request = #{cpuRequest,jdbcType=DOUBLE},
- </if>
- <if test="memoryRequest != null">
- memory_request = #{memoryRequest,jdbcType=INTEGER},
- </if>
- <if test="createBy != null">
- create_by = #{createBy,jdbcType=VARCHAR},
- </if>
- <if test="nodeIp != null">
- node_ip = #{nodeIp,jdbcType=VARCHAR},
- </if>
- <if test="runPodType != null">
- run_pod_type = #{runPodType,jdbcType=INTEGER},
- </if>
- <if test="priority != null">
- priority = #{priority,jdbcType=BIGINT},
- </if>
- <if test="svcPort != null">
- svc_port = #{svcPort,jdbcType=VARCHAR},
- </if>
- <if test="sshPort != null">
- ssh_port = #{sshPort,jdbcType=VARCHAR},
- </if>
- <if test="expireTime != null">
- expire_time = #{expireTime,jdbcType=TIMESTAMP},
- </if>
- <if test="createTime != null">
- create_time = #{createTime,jdbcType=TIMESTAMP},
- </if>
- <if test="updateTime != null">
- update_time = #{updateTime,jdbcType=TIMESTAMP},
- </if>
- </set>
- where id = #{id,jdbcType=BIGINT}
- </update>
-
- <update id="updateByNameSelective"
- parameterType="com.imitate.common.k8s.pojo.RunPod">
- update run_pod
- <set>
- <if test="expireTime != null">
- expire_time = #{expireTime,jdbcType=TIMESTAMP},
- </if>
- <if test="updateTime != null">
- update_time = #{updateTime,jdbcType=TIMESTAMP},
- </if>
- </set>
- where name = #{name,jdbcType=VARCHAR}
- </update>
-
- <update id="delayRunPodExpireTime"
- parameterType="com.imitate.common.k8s.pojo.RunPod">
- update run_pod set expire_time = #{expireTime,jdbcType=TIMESTAMP},
- update_time = #{updateTime,jdbcType=TIMESTAMP}
- where name = #{name,jdbcType=VARCHAR} and expire_time < #{expireTime,jdbcType=TIMESTAMP}
- </update>
-
-
- <update id="updateByPrimaryKey"
- parameterType="com.imitate.common.k8s.pojo.RunPod">
- update run_pod
- set name = #{name,jdbcType=VARCHAR},
- cluster = #{cluster,jdbcType=VARCHAR},
- image_name =
- #{imageName,jdbcType=VARCHAR},
- cpu_limit =
- #{cpuLimit,jdbcType=DOUBLE},
- memory_limit =
- #{memoryLimit,jdbcType=INTEGER},
- cpu_request =
- #{cpuRequest,jdbcType=DOUBLE},
- memory_request =
- #{memoryRequest,jdbcType=INTEGER},
- create_by =
- #{createBy,jdbcType=VARCHAR},
- node_ip =
- #{nodeIp,jdbcType=VARCHAR},
- run_pod_type =
- #{runPodType,jdbcType=INTEGER},
- priority = #{priority,jdbcType=BIGINT},
- svc_port = #{svcPort,jdbcType=VARCHAR},
- ssh_port =
- #{sshPort,jdbcType=VARCHAR},
- expire_time =
- #{expireTime,jdbcType=TIMESTAMP},
- create_time
- =#{createTime,jdbcType=TIMESTAMP},
- update_time
- =#{updateTime,jdbcType=TIMESTAMP}
- where id = #{id,jdbcType=BIGINT}
- </update>
-
- <select id="selectRunPodForUpdate" resultMap="BaseResultMap"
- parameterType="java.lang.String">
- select
- <include refid="Base_Column_List" />
- from run_pod
- where name = #{name,jdbcType=VARCHAR} for update
- </select>
-
- <select id="selectByName" resultMap="BaseResultMap"
- parameterType="java.lang.String">
- select
- <include refid="Base_Column_List" />
- from run_pod
- where name = #{name,jdbcType=VARCHAR}
- </select>
-
- <select id="selectSshRunPodByTpiID" resultMap="BaseResultMap"
- parameterType="java.lang.String">
- select
- <include refid="Base_Column_List" />
- from run_pod
- where name = concat('evassh-',#{name,jdbcType=VARCHAR})
- or name = concat('webssh-',#{name,jdbcType=VARCHAR}) limit 1
- </select>
-
- <select id="selectRunPods" resultMap="BaseResultMap"
- parameterType="com.imitate.common.k8s.bean.RunPodQueryParam">
- select
- <include refid="Base_Column_List" />
- from run_pod
- where 1 = 1
- <if test="expireTime != null">
- and expire_time < #{expireTime,jdbcType=TIMESTAMP}
- </if>
- <if test="cluster != null">
- and cluster = #{cluster,jdbcType=VARCHAR}
- </if>
- <if test="nodeIp != null">
- and node_ip = #{nodeIp,jdbcType=VARCHAR}
- </if>
- </select>
-
- <update id="updatePortByName"
- parameterType="com.imitate.common.k8s.bean.RunPodQueryParam">
- UPDATE
- run_pod
- <set>
- <if test="svcPort != null">
- svc_port = #{svcPort,jdbcType=VARCHAR},
- </if>
- <if test="sshPort != null">
- ssh_port = #{sshPort,jdbcType=VARCHAR},
- </if>
- <if test="nodeIp != null">
- node_ip = #{nodeIp,jdbcType=VARCHAR},
- </if>
- </set>
- WHERE
- name = #{name,jdbcType=VARCHAR}
- </update>
- <update id="updateExpireTimeByNodeIp"
- parameterType="com.imitate.common.k8s.bean.RunPodQueryParam">
- UPDATE
- run_pod
- <set>
- <if test="expireTime != null">
- expire_time = #{expireTime,jdbcType=VARCHAR},
- </if>
- </set>
- WHERE
- cluster = #{cluster,jdbcType=VARCHAR}
- and node_ip = #{nodeIp,jdbcType=VARCHAR}
- </update>
-
- <select id="statNodeRes" resultType="com.imitate.common.k8s.bean.NodeResStat"
- parameterType="com.imitate.common.k8s.bean.RunPodQueryParam">
- select count(id) as podNum, sum(cpu_request) as cpuRequest, sum(memory_request) as memoryRequest,
- cluster, node_ip from run_pod group by cluster, node_ip
- </select>
-
- <select id="podNumStatGroupByNodeIp" parameterType="java.lang.String" resultType="java.lang.String">
- select node_ip from (
- select node_ip,SUM(IF(memory_request>=500 and name not like 'evaluate%',1,0)) as num from run_pod
- where cluster = #{cluster,jdbcType=VARCHAR} group by node_ip order by num
- ) as temp where node_ip is not NULL
- </select>
-
- </mapper>
|