Commit bb33dcc2c10c7568e421d2f4fb09d6562fdadb27
1 parent
14574303
添加获取GPU的列表接口;
Showing
5 changed files
with
96 additions
and
2 deletions
Linux服务器监听运维功能.md
... | ... | @@ -362,6 +362,52 @@ |
362 | 362 | } |
363 | 363 | ``` |
364 | 364 | |
365 | +## 1.7 获取GPU的列表 | |
366 | + | |
367 | +| 调用方式 | 接口地址 | | |
368 | +| ------------ | :---------------------------------------------------- | | |
369 | +| POST | http://ip:port/occupationOfBasicResources/getGpuItems | | |
370 | +| Content-Type | application/json;charset=UTF-8 | | |
371 | + | |
372 | +| 返回结果 | | | | | |
373 | +| -------- | ----------- | ------ | --------------------------------- | | |
374 | +| 参数项 | 名称 | 类型 | 描述 | | |
375 | +| code | 响应码 | int | 200为操作成功,其他code表示失败 | | |
376 | +| message | 提示信息 | string | 200为操作成功, 其他为对应错误信息 | | |
377 | +| data | 返回信息 | | | | |
378 | +| +uuid | GPU对应uuid | String | GPU对应uuid | | |
379 | +| +index | gpu编号 | String | gpu编号 | | |
380 | +| +gpuName | GPU名称 | String | GPU名称 | | |
381 | + | |
382 | +``` | |
383 | +响应示例 | |
384 | +{ | |
385 | + "code": 200, | |
386 | + "message": "操作成功", | |
387 | + "data": [ | |
388 | + { | |
389 | + "gpuName": "GeForce GTX 1080 Ti", | |
390 | + "index": "GPU 0", | |
391 | + "uuid": " GPU-99b735ea-99c6-a569-fadb-01f39ae045f7" | |
392 | + }, | |
393 | + { | |
394 | + "gpuName": "GeForce RTX 2080", | |
395 | + "index": "GPU 1", | |
396 | + "uuid": " GPU-c8f60855-479c-6658-16d1-140dac044159" | |
397 | + }, | |
398 | + { | |
399 | + "gpuName": "Tesla P4", | |
400 | + "index": "GPU 2", | |
401 | + "uuid": " GPU-0d60b67b-8df9-e3bb-2aa0-c632b1726ef1" | |
402 | + }, | |
403 | + { | |
404 | + "gpuName": "Tesla P4", | |
405 | + "index": "GPU 3", | |
406 | + "uuid": " GPU-95e656d9-fbe3-b17c-3f37-a05814bbcc79" | |
407 | + } | |
408 | + ] | |
409 | +} | |
410 | +``` | |
365 | 411 | |
366 | 412 | |
367 | 413 | ... | ... |
src/main/java/com/objecteye/controller/OccupationOfBasicResourcesController.java
1 | 1 | package com.objecteye.controller; |
2 | 2 | |
3 | 3 | import com.alibaba.fastjson.JSONArray; |
4 | +import com.alibaba.fastjson.JSONObject; | |
4 | 5 | import com.objecteye.common.CommonResult; |
5 | 6 | import com.objecteye.service.IOccupationOfBasicResourcesService; |
6 | 7 | import io.swagger.annotations.Api; |
... | ... | @@ -8,6 +9,7 @@ import io.swagger.annotations.ApiOperation; |
8 | 9 | import org.springframework.beans.factory.annotation.Autowired; |
9 | 10 | import org.springframework.web.bind.annotation.*; |
10 | 11 | |
12 | +import java.util.List; | |
11 | 13 | import java.util.Map; |
12 | 14 | |
13 | 15 | @RestController |
... | ... | @@ -29,6 +31,17 @@ public class OccupationOfBasicResourcesController extends BasicController { |
29 | 31 | } |
30 | 32 | } |
31 | 33 | |
34 | + @ApiOperation("获取GPU的列表") | |
35 | + @RequestMapping(value = "/getGpuItems", method = RequestMethod.POST, produces = "application/json;charset=UTF-8") | |
36 | + public CommonResult<List<JSONObject>> getGpuItems() { | |
37 | + List<JSONObject> resultList = iOccupationOfBasicResourcesService.getGpuItems(); | |
38 | + if (resultList == null || resultList.size() == 0) { | |
39 | + return CommonResult.success(201, "没有找到合适数据", null); | |
40 | + } else { | |
41 | + return CommonResult.success(resultList); | |
42 | + } | |
43 | + } | |
44 | + | |
32 | 45 | @ApiOperation("jar包发布") |
33 | 46 | @RequestMapping(value = "/deployJarFile", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) |
34 | 47 | public CommonResult deployJarFile(@RequestBody Map<String, Object> requestMap) { | ... | ... |
src/main/java/com/objecteye/service/IOccupationOfBasicResourcesService.java
... | ... | @@ -3,6 +3,7 @@ package com.objecteye.service; |
3 | 3 | import com.alibaba.fastjson.JSONArray; |
4 | 4 | import com.alibaba.fastjson.JSONObject; |
5 | 5 | |
6 | +import java.util.List; | |
6 | 7 | import java.util.Map; |
7 | 8 | |
8 | 9 | /** |
... | ... | @@ -27,6 +28,13 @@ public interface IOccupationOfBasicResourcesService { |
27 | 28 | JSONArray getInfoByModule(String module); |
28 | 29 | |
29 | 30 | /** |
31 | + * 获取GPU的列表 | |
32 | + * | |
33 | + * @return 结果集 | |
34 | + */ | |
35 | + List<JSONObject> getGpuItems(); | |
36 | + | |
37 | + /** | |
30 | 38 | * jar包发布 |
31 | 39 | * |
32 | 40 | * @param requestMap 请求参数 | ... | ... |
src/main/java/com/objecteye/service/impl/LogFileListenerServiceImpl.java
... | ... | @@ -139,8 +139,8 @@ public class LogFileListenerServiceImpl implements ILogFileListenerService { |
139 | 139 | */ |
140 | 140 | @Override |
141 | 141 | public JSONObject downloadLogFile(HttpServletResponse httpServletResponse, String logKey) { |
142 | -// String logPath = (String) redisTemplate.opsForHash().get(GeneralContent.REDIS_LOG_KEY_PATH, logKey); | |
143 | - String logPath = "E:\\testResources\\111.jpg"; | |
142 | + String logPath = (String) redisTemplate.opsForHash().get(GeneralContent.REDIS_LOG_KEY_PATH, logKey); | |
143 | +// String logPath = "E:\\testResources\\111.jpg"; | |
144 | 144 | JSONObject resultObj = new JSONObject(); |
145 | 145 | if (logPath == null) { |
146 | 146 | resultObj.put("error", "找不到文件"); | ... | ... |
src/main/java/com/objecteye/service/impl/OccupationOfBasicResourcesServiceImpl.java
... | ... | @@ -68,6 +68,33 @@ public class OccupationOfBasicResourcesServiceImpl implements IOccupationOfBasic |
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
71 | + * 获取GPU的列表 | |
72 | + * | |
73 | + * @return 结果集 | |
74 | + */ | |
75 | + @Override | |
76 | + public List<JSONObject> getGpuItems() { | |
77 | + final String gpuCommand = "nvidia-smi -L"; | |
78 | + List<String> outList = new ArrayList<>(); | |
79 | + LinuxUtils.executeLinuxCmd(gpuCommand, outList); | |
80 | + List<JSONObject> resultList = new ArrayList<>(); | |
81 | + for (String outStr : outList) { | |
82 | + if (outStr == null || "".equals(outStr)) { | |
83 | + continue; | |
84 | + } | |
85 | + String uuid = outStr.substring(outStr.lastIndexOf(":") + 1, outStr.indexOf(")")); | |
86 | + String index = outStr.substring(0, outStr.indexOf(":")); | |
87 | + String gpuName = outStr.substring(outStr.indexOf(":") + 1, outStr.indexOf("(")).trim(); | |
88 | + JSONObject itemObj = new JSONObject(); | |
89 | + itemObj.put("uuid", uuid); | |
90 | + itemObj.put("index", index); | |
91 | + itemObj.put("gpuName", gpuName); | |
92 | + resultList.add(itemObj); | |
93 | + } | |
94 | + return resultList; | |
95 | + } | |
96 | + | |
97 | + /** | |
71 | 98 | * jar包发布 |
72 | 99 | * |
73 | 100 | * @param requestMap 请求参数 | ... | ... |