|
|
|
@@ -1,14 +1,19 @@ |
|
|
|
package com.ruoyi.platform.service.impl; |
|
|
|
|
|
|
|
import com.ruoyi.common.security.utils.SecurityUtils; |
|
|
|
import com.ruoyi.platform.domain.*; |
|
|
|
import com.ruoyi.platform.mapper.*; |
|
|
|
import com.ruoyi.platform.service.ExperimentInsService; |
|
|
|
import com.ruoyi.platform.service.ModelsService; |
|
|
|
import com.ruoyi.platform.service.WorkflowService; |
|
|
|
import com.ruoyi.platform.service.GitService; |
|
|
|
import com.ruoyi.platform.service.WorkspaceService; |
|
|
|
import lombok.val; |
|
|
|
import org.checkerframework.checker.units.qual.C; |
|
|
|
import com.ruoyi.platform.utils.JacksonUtil; |
|
|
|
import com.ruoyi.platform.utils.JsonUtils; |
|
|
|
import com.ruoyi.platform.utils.NewHttpUtils; |
|
|
|
import com.ruoyi.system.api.constant.Constant; |
|
|
|
import com.ruoyi.system.api.model.LoginUser; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import redis.clients.jedis.Jedis; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.util.HashMap; |
|
|
|
@@ -18,36 +23,33 @@ import java.util.Map; |
|
|
|
@Service("WorkspaceService") |
|
|
|
public class WorkspaceServiceImpl implements WorkspaceService { |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
private WorkflowService workflowService; |
|
|
|
@Resource |
|
|
|
private WorkflowDao workflowDao; |
|
|
|
@Resource |
|
|
|
private ExperimentDao experimentDao; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private ExperimentInsDao experimentInsDao; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private ExperimentInsService experimentInsService; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private ModelsService modelsService; |
|
|
|
@Resource |
|
|
|
private ModelsDao modelsDao; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private DatasetDao datasetDao; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private ImageDao imageDao; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private ComponentDao componentDao; |
|
|
|
@Resource |
|
|
|
private GitService gitService; |
|
|
|
@Resource |
|
|
|
private NewHttpUtils httpUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${git.endpoint}") |
|
|
|
String gitendpoint; |
|
|
|
@Value("${spring.redis.host}") |
|
|
|
private String redisHost; |
|
|
|
@Value("${spring.redis.port}") |
|
|
|
private Integer redisPort; |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> getOverview() { |
|
|
|
@@ -59,16 +61,16 @@ public class WorkspaceServiceImpl implements WorkspaceService { |
|
|
|
|
|
|
|
// 获取运行中实验实例数量 |
|
|
|
List<ExperimentIns> experimentInsList = experimentInsService.queryByExperimentIsNotTerminated(); |
|
|
|
if (experimentInsList!=null && !experimentInsList.isEmpty()) { |
|
|
|
if (experimentInsList != null && !experimentInsList.isEmpty()) { |
|
|
|
Integer experimentInsCount = experimentInsList.size(); |
|
|
|
resMap.put("runningExperimentInsCount", experimentInsCount); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
resMap.put("runningExperimentInsCount", 0); |
|
|
|
} |
|
|
|
//得到最近的三条实例记录,放进返回map |
|
|
|
List<ExperimentIns> latestExperimentInsList = experimentInsDao.getLatestInsList(); |
|
|
|
if (latestExperimentInsList != null && !latestExperimentInsList.isEmpty()) { |
|
|
|
for (ExperimentIns experimentIns : latestExperimentInsList){ |
|
|
|
for (ExperimentIns experimentIns : latestExperimentInsList) { |
|
|
|
Integer experimentId = experimentIns.getExperimentId(); |
|
|
|
Experiment experiment = this.experimentDao.queryById(experimentId); |
|
|
|
//拿到对应的流水线id |
|
|
|
@@ -83,22 +85,47 @@ public class WorkspaceServiceImpl implements WorkspaceService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Integer> getAssetCount(Boolean isPublic) { |
|
|
|
Map<String,Integer> assetCountMap = new HashMap<String, Integer>(); |
|
|
|
int availableRange = isPublic ? 1 : 0; |
|
|
|
//统计数据集数量 |
|
|
|
Dataset dataset = new Dataset(); |
|
|
|
dataset.setAvailableRange(availableRange); |
|
|
|
Integer datasetCount = (int) this.datasetDao.count(dataset); |
|
|
|
assetCountMap.put("dataset", datasetCount); |
|
|
|
//统计模型数量 |
|
|
|
Models models = new Models(); |
|
|
|
models.setAvailableRange(availableRange); |
|
|
|
Integer modelCount = (int) this.modelsDao.count(models); |
|
|
|
assetCountMap.put("model", modelCount); |
|
|
|
//统计镜像数量 |
|
|
|
public Map<String, Integer> getAssetCount(Boolean isPublic) throws Exception { |
|
|
|
Map<String, Integer> assetCountMap = new HashMap<>(); |
|
|
|
String token = gitService.checkoutToken(); |
|
|
|
int availableRange = isPublic ? Constant.Image_Type_Pub : Constant.Image_Type_Pri; |
|
|
|
if (isPublic) { |
|
|
|
// 数据集 |
|
|
|
String url = gitendpoint + "/api/projects.json?sort_direction=updated_on&sort_by=desc&category_id=" + Constant.Git_Category_Id; |
|
|
|
String req = httpUtils.sendGetWithToken(url, null, token); |
|
|
|
Map<String, Object> stringObjectMap = JacksonUtil.parseJSONStr2Map(req); |
|
|
|
List<Map<String, Object>> projects = (List<Map<String, Object>>) stringObjectMap.get("projects"); |
|
|
|
assetCountMap.put("dataset", projects.size()); |
|
|
|
|
|
|
|
// 模型 |
|
|
|
url = gitendpoint + "/api/projects.json?sort_direction=updated_on&sort_by=desc&category_id=" + Constant.Git_Category_Id; |
|
|
|
req = httpUtils.sendGetWithToken(url, null, token); |
|
|
|
stringObjectMap = JacksonUtil.parseJSONStr2Map(req); |
|
|
|
projects = (List<Map<String, Object>>) stringObjectMap.get("projects"); |
|
|
|
assetCountMap.put("model", projects.size()); |
|
|
|
} else { |
|
|
|
Jedis jedis = new Jedis(redisHost, redisPort); |
|
|
|
LoginUser loginUser = SecurityUtils.getLoginUser(); |
|
|
|
String ci4sUsername = loginUser.getUsername(); |
|
|
|
String userReq = jedis.get(ci4sUsername + "_gitUserInfo"); |
|
|
|
Map<String, Object> userInfo = JsonUtils.jsonToMap(userReq); |
|
|
|
|
|
|
|
String url = gitendpoint + "/api/users/" + userInfo.get("login") + "/projects.json?category=manage"; |
|
|
|
String req = httpUtils.sendGetWithToken(url, null, token); |
|
|
|
Map<String, Object> stringObjectMap = JacksonUtil.parseJSONStr2Map(req); |
|
|
|
List<Map<String, Object>> projects = (List<Map<String, Object>>) stringObjectMap.get("projects"); |
|
|
|
assetCountMap.put("dataset", projects.size()); |
|
|
|
|
|
|
|
url = gitendpoint + "/api/users/" + userInfo.get("login") + "/projects.json?category=manage"; |
|
|
|
req = httpUtils.sendGetWithToken(url, null, token); |
|
|
|
stringObjectMap = JacksonUtil.parseJSONStr2Map(req); |
|
|
|
projects = (List<Map<String, Object>>) stringObjectMap.get("projects"); |
|
|
|
assetCountMap.put("model", projects.size()); |
|
|
|
} |
|
|
|
|
|
|
|
// 镜像 |
|
|
|
Image image = new Image(); |
|
|
|
image.setImageType(availableRange); |
|
|
|
image.setImageType(Constant.Image_Type_Pub); |
|
|
|
Integer imageCount = (int) this.imageDao.count(image); |
|
|
|
assetCountMap.put("image", imageCount); |
|
|
|
//统计组件数量 |
|
|
|
@@ -113,6 +140,4 @@ public class WorkspaceServiceImpl implements WorkspaceService { |
|
|
|
|
|
|
|
return assetCountMap; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |