You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

RunPodMapper.xml 11 kB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3. <mapper namespace="com.imitate.common.k8s.mapper.RunPodMapper">
  4. <resultMap id="BaseResultMap"
  5. type="com.imitate.common.k8s.pojo.RunPod">
  6. <id column="id" property="id" jdbcType="BIGINT" />
  7. <result column="cluster" property="cluster" jdbcType="VARCHAR" />
  8. <result column="name" property="name" jdbcType="VARCHAR" />
  9. <result column="image_name" property="imageName"
  10. jdbcType="VARCHAR" />
  11. <result column="cpu_limit" property="cpuLimit"
  12. jdbcType="DOUBLE" />
  13. <result column="memory_limit" property="memoryLimit"
  14. jdbcType="INTEGER" />
  15. <result column="cpu_request" property="cpuRequest"
  16. jdbcType="DOUBLE" />
  17. <result column="memory_request" property="memoryRequest"
  18. jdbcType="INTEGER" />
  19. <result column="create_by" property="createBy"
  20. jdbcType="VARCHAR" />
  21. <result column="node_ip" property="nodeIp"
  22. jdbcType="VARCHAR" />
  23. <result column="run_pod_type" property="runPodType"
  24. jdbcType="INTEGER" />
  25. <result column="priority" property="priority" jdbcType="BIGINT" />
  26. <result column="svc_port" property="svcPort" jdbcType="VARCHAR" />
  27. <result column="ssh_port" property="sshPort" jdbcType="VARCHAR" />
  28. <result column="expire_time" property="expireTime"
  29. jdbcType="TIMESTAMP" />
  30. <result column="create_time" property="createTime"
  31. jdbcType="TIMESTAMP" />
  32. <result column="update_time" property="updateTime"
  33. jdbcType="TIMESTAMP" />
  34. </resultMap>
  35. <sql id="Base_Column_List">
  36. id, cluster, name, image_name,
  37. cpu_limit, memory_limit, cpu_request, memory_request,
  38. create_by, node_ip,
  39. run_pod_type, svc_port, ssh_port,
  40. priority,
  41. expire_time, create_time, update_time
  42. </sql>
  43. <delete id="deleteByName" parameterType="java.lang.String">
  44. delete from
  45. run_pod
  46. where name = #{name,jdbcType=VARCHAR}
  47. </delete>
  48. <delete id="deleteByNameExpired">
  49. delete from
  50. run_pod
  51. where name = #{name,jdbcType=VARCHAR} and expire_time &lt;= #{expireTime,jdbcType=TIMESTAMP}
  52. </delete>
  53. <insert id="insert"
  54. parameterType="com.imitate.common.k8s.pojo.RunPod">
  55. insert into run_pod (id,cluster, name,
  56. image_name,
  57. cpu_limit,
  58. memory_limit,
  59. cpu_request,
  60. memory_request,
  61. create_by,
  62. node_ip,
  63. run_pod_type,
  64. priority,
  65. svc_port,
  66. ssh_port,
  67. expire_time,
  68. create_time,
  69. update_time)
  70. values
  71. (#{id,jdbcType=BIGINT},
  72. #{cluster,jdbcType=VARCHAR},#{name,jdbcType=VARCHAR},
  73. #{imageName,jdbcType=VARCHAR},
  74. #{cpuLimit,jdbcType=DOUBLE},
  75. #{memoryLimit,jdbcType=INTEGER},
  76. #{cpuRequest,jdbcType=DOUBLE},
  77. #{memoryRequest,jdbcType=INTEGER},
  78. #{createBy,jdbcType=VARCHAR},
  79. #{nodeIp,jdbcType=VARCHAR},
  80. #{runPodType,jdbcType=INTEGER},
  81. #{priority,jdbcType=BIGINT},
  82. #{svcPort,jdbcType=VARCHAR},
  83. #{sshPort,jdbcType=VARCHAR},
  84. #{expireTime,jdbcType=TIMESTAMP},
  85. #{createTime,jdbcType=TIMESTAMP},
  86. #{updateTime,jdbcType=TIMESTAMP})
  87. </insert>
  88. <insert id="insertSelective"
  89. parameterType="com.imitate.common.k8s.pojo.RunPod">
  90. insert into run_pod
  91. <trim prefix="(" suffix=")" suffixOverrides=",">
  92. <if test="id != null">
  93. id,
  94. </if>
  95. <if test="cluster != null">
  96. cluster,
  97. </if>
  98. <if test="name != null">
  99. name,
  100. </if>
  101. <if test="imageName != null">
  102. image_name,
  103. </if>
  104. <if test="cpuLimit != null">
  105. cpu_limit,
  106. </if>
  107. <if test="memoryLimit != null">
  108. memory_limit,
  109. </if>
  110. <if test="cpuRequest != null">
  111. cpu_request,
  112. </if>
  113. <if test="memoryRequest != null">
  114. memory_request,
  115. </if>
  116. <if test="createBy != null">
  117. create_by,
  118. </if>
  119. <if test="nodeIp != null">
  120. node_ip,
  121. </if>
  122. <if test="runPodType != null">
  123. run_pod_type,
  124. </if>
  125. <if test="priority != null">
  126. priority,
  127. </if>
  128. <if test="svcPort != null">
  129. svc_port,
  130. </if>
  131. <if test="sshPort != null">
  132. ssh_port,
  133. </if>
  134. <if test="expireTime != null">
  135. expire_time,
  136. </if>
  137. <if test="createTime != null">
  138. create_time,
  139. </if>
  140. <if test="updateTime != null">
  141. update_time,
  142. </if>
  143. </trim>
  144. <trim prefix="values (" suffix=")" suffixOverrides=",">
  145. <if test="id != null">
  146. #{id,jdbcType=BIGINT},
  147. </if>
  148. <if test="cluster != null">
  149. #{cluster,jdbcType=VARCHAR},
  150. </if>
  151. <if test="name != null">
  152. #{name,jdbcType=VARCHAR},
  153. </if>
  154. <if test="imageName != null">
  155. #{imageName,jdbcType=VARCHAR},
  156. </if>
  157. <if test="cpuLimit != null">
  158. #{cpuLimit,jdbcType=DOUBLE},
  159. </if>
  160. <if test="memoryLimit != null">
  161. #{memoryLimit,jdbcType=INTEGER},
  162. </if>
  163. <if test="cpuRequest != null">
  164. #{cpuRequest,jdbcType=DOUBLE},
  165. </if>
  166. <if test="memoryRequest != null">
  167. #{memoryRequest,jdbcType=INTEGER},
  168. </if>
  169. <if test="createBy != null">
  170. #{createBy,jdbcType=VARCHAR},
  171. </if>
  172. <if test="nodeIp != null">
  173. #{nodeIp,jdbcType=VARCHAR},
  174. </if>
  175. <if test="runPodType != null">
  176. #{runPodType,jdbcType=INTEGER},
  177. </if>
  178. <if test="priority != null">
  179. #{priority,jdbcType=BIGINT},
  180. </if>
  181. <if test="svcPort != null">
  182. #{svcPort,jdbcType=VARCHAR},
  183. </if>
  184. <if test="sshPort != null">
  185. #{sshPort,jdbcType=VARCHAR},
  186. </if>
  187. <if test="expireTime != null">
  188. #{expireTime,jdbcType=TIMESTAMP},
  189. </if>
  190. <if test="createTime != null">
  191. #{createTime,jdbcType=TIMESTAMP},
  192. </if>
  193. <if test="updateTime != null">
  194. #{updateTime,jdbcType=TIMESTAMP},
  195. </if>
  196. </trim>
  197. </insert>
  198. <update id="updateByPrimaryKeySelective"
  199. parameterType="com.imitate.common.k8s.pojo.RunPod">
  200. update run_pod
  201. <set>
  202. <if test="name != null">
  203. name = #{name,jdbcType=VARCHAR},
  204. </if>
  205. <if test="cluster != null">
  206. cluster = #{cluster,jdbcType=VARCHAR},
  207. </if>
  208. <if test="imageName != null">
  209. image_name = #{imageName,jdbcType=VARCHAR},
  210. </if>
  211. <if test="cpuLimit != null">
  212. cpu_limit = #{cpuLimit,jdbcType=DOUBLE},
  213. </if>
  214. <if test="memoryLimit != null">
  215. memory_limit = #{memoryLimit,jdbcType=INTEGER},
  216. </if>
  217. <if test="cpuRequest != null">
  218. cpu_request = #{cpuRequest,jdbcType=DOUBLE},
  219. </if>
  220. <if test="memoryRequest != null">
  221. memory_request = #{memoryRequest,jdbcType=INTEGER},
  222. </if>
  223. <if test="createBy != null">
  224. create_by = #{createBy,jdbcType=VARCHAR},
  225. </if>
  226. <if test="nodeIp != null">
  227. node_ip = #{nodeIp,jdbcType=VARCHAR},
  228. </if>
  229. <if test="runPodType != null">
  230. run_pod_type = #{runPodType,jdbcType=INTEGER},
  231. </if>
  232. <if test="priority != null">
  233. priority = #{priority,jdbcType=BIGINT},
  234. </if>
  235. <if test="svcPort != null">
  236. svc_port = #{svcPort,jdbcType=VARCHAR},
  237. </if>
  238. <if test="sshPort != null">
  239. ssh_port = #{sshPort,jdbcType=VARCHAR},
  240. </if>
  241. <if test="expireTime != null">
  242. expire_time = #{expireTime,jdbcType=TIMESTAMP},
  243. </if>
  244. <if test="createTime != null">
  245. create_time = #{createTime,jdbcType=TIMESTAMP},
  246. </if>
  247. <if test="updateTime != null">
  248. update_time = #{updateTime,jdbcType=TIMESTAMP},
  249. </if>
  250. </set>
  251. where id = #{id,jdbcType=BIGINT}
  252. </update>
  253. <update id="updateByNameSelective"
  254. parameterType="com.imitate.common.k8s.pojo.RunPod">
  255. update run_pod
  256. <set>
  257. <if test="expireTime != null">
  258. expire_time = #{expireTime,jdbcType=TIMESTAMP},
  259. </if>
  260. <if test="updateTime != null">
  261. update_time = #{updateTime,jdbcType=TIMESTAMP},
  262. </if>
  263. </set>
  264. where name = #{name,jdbcType=VARCHAR}
  265. </update>
  266. <update id="delayRunPodExpireTime"
  267. parameterType="com.imitate.common.k8s.pojo.RunPod">
  268. update run_pod set expire_time = #{expireTime,jdbcType=TIMESTAMP},
  269. update_time = #{updateTime,jdbcType=TIMESTAMP}
  270. where name = #{name,jdbcType=VARCHAR} and expire_time &lt; #{expireTime,jdbcType=TIMESTAMP}
  271. </update>
  272. <update id="updateByPrimaryKey"
  273. parameterType="com.imitate.common.k8s.pojo.RunPod">
  274. update run_pod
  275. set name = #{name,jdbcType=VARCHAR},
  276. cluster = #{cluster,jdbcType=VARCHAR},
  277. image_name =
  278. #{imageName,jdbcType=VARCHAR},
  279. cpu_limit =
  280. #{cpuLimit,jdbcType=DOUBLE},
  281. memory_limit =
  282. #{memoryLimit,jdbcType=INTEGER},
  283. cpu_request =
  284. #{cpuRequest,jdbcType=DOUBLE},
  285. memory_request =
  286. #{memoryRequest,jdbcType=INTEGER},
  287. create_by =
  288. #{createBy,jdbcType=VARCHAR},
  289. node_ip =
  290. #{nodeIp,jdbcType=VARCHAR},
  291. run_pod_type =
  292. #{runPodType,jdbcType=INTEGER},
  293. priority = #{priority,jdbcType=BIGINT},
  294. svc_port = #{svcPort,jdbcType=VARCHAR},
  295. ssh_port =
  296. #{sshPort,jdbcType=VARCHAR},
  297. expire_time =
  298. #{expireTime,jdbcType=TIMESTAMP},
  299. create_time
  300. =#{createTime,jdbcType=TIMESTAMP},
  301. update_time
  302. =#{updateTime,jdbcType=TIMESTAMP}
  303. where id = #{id,jdbcType=BIGINT}
  304. </update>
  305. <select id="selectRunPodForUpdate" resultMap="BaseResultMap"
  306. parameterType="java.lang.String">
  307. select
  308. <include refid="Base_Column_List" />
  309. from run_pod
  310. where name = #{name,jdbcType=VARCHAR} for update
  311. </select>
  312. <select id="selectByName" resultMap="BaseResultMap"
  313. parameterType="java.lang.String">
  314. select
  315. <include refid="Base_Column_List" />
  316. from run_pod
  317. where name = #{name,jdbcType=VARCHAR}
  318. </select>
  319. <select id="selectSshRunPodByTpiID" resultMap="BaseResultMap"
  320. parameterType="java.lang.String">
  321. select
  322. <include refid="Base_Column_List" />
  323. from run_pod
  324. where name = concat('evassh-',#{name,jdbcType=VARCHAR})
  325. or name = concat('webssh-',#{name,jdbcType=VARCHAR}) limit 1
  326. </select>
  327. <select id="selectRunPods" resultMap="BaseResultMap"
  328. parameterType="com.imitate.common.k8s.bean.RunPodQueryParam">
  329. select
  330. <include refid="Base_Column_List" />
  331. from run_pod
  332. where 1 = 1
  333. <if test="expireTime != null">
  334. and expire_time &lt; #{expireTime,jdbcType=TIMESTAMP}
  335. </if>
  336. <if test="cluster != null">
  337. and cluster = #{cluster,jdbcType=VARCHAR}
  338. </if>
  339. <if test="nodeIp != null">
  340. and node_ip = #{nodeIp,jdbcType=VARCHAR}
  341. </if>
  342. </select>
  343. <update id="updatePortByName"
  344. parameterType="com.imitate.common.k8s.bean.RunPodQueryParam">
  345. UPDATE
  346. run_pod
  347. <set>
  348. <if test="svcPort != null">
  349. svc_port = #{svcPort,jdbcType=VARCHAR},
  350. </if>
  351. <if test="sshPort != null">
  352. ssh_port = #{sshPort,jdbcType=VARCHAR},
  353. </if>
  354. <if test="nodeIp != null">
  355. node_ip = #{nodeIp,jdbcType=VARCHAR},
  356. </if>
  357. </set>
  358. WHERE
  359. name = #{name,jdbcType=VARCHAR}
  360. </update>
  361. <update id="updateExpireTimeByNodeIp"
  362. parameterType="com.imitate.common.k8s.bean.RunPodQueryParam">
  363. UPDATE
  364. run_pod
  365. <set>
  366. <if test="expireTime != null">
  367. expire_time = #{expireTime,jdbcType=VARCHAR},
  368. </if>
  369. </set>
  370. WHERE
  371. cluster = #{cluster,jdbcType=VARCHAR}
  372. and node_ip = #{nodeIp,jdbcType=VARCHAR}
  373. </update>
  374. <select id="statNodeRes" resultType="com.imitate.common.k8s.bean.NodeResStat"
  375. parameterType="com.imitate.common.k8s.bean.RunPodQueryParam">
  376. select count(id) as podNum, sum(cpu_request) as cpuRequest, sum(memory_request) as memoryRequest,
  377. cluster, node_ip from run_pod group by cluster, node_ip
  378. </select>
  379. <select id="podNumStatGroupByNodeIp" parameterType="java.lang.String" resultType="java.lang.String">
  380. select node_ip from (
  381. select node_ip,SUM(IF(memory_request>=500 and name not like 'evaluate%',1,0)) as num from run_pod
  382. where cluster = #{cluster,jdbcType=VARCHAR} group by node_ip order by num
  383. ) as temp where node_ip is not NULL
  384. </select>
  385. </mapper>

No Description