|
@@ -2,7 +2,9 @@ package com.css.simulation.resource.scheduler.util;
|
|
|
|
|
|
import api.common.pojo.constants.DictConstants;
|
|
|
import api.common.util.StringUtil;
|
|
|
+import com.css.simulation.resource.scheduler.mapper.AutoSubProjectMapper;
|
|
|
import com.css.simulation.resource.scheduler.mapper.ClusterMapper;
|
|
|
+import com.css.simulation.resource.scheduler.mapper.ManualProjectMapper;
|
|
|
import com.css.simulation.resource.scheduler.mapper.UserMapper;
|
|
|
import com.css.simulation.resource.scheduler.pojo.po.UserPO;
|
|
|
import com.css.simulation.resource.scheduler.pojo.to.PrefixTO;
|
|
@@ -22,6 +24,10 @@ import java.util.stream.Collectors;
|
|
|
@Slf4j
|
|
|
public class ProjectUtil {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ ManualProjectMapper manualProjectMapper;
|
|
|
+ @Autowired
|
|
|
+ AutoSubProjectMapper autoSubProjectMapper;
|
|
|
@Autowired
|
|
|
UserMapper userMapper;
|
|
|
@Autowired
|
|
@@ -106,7 +112,6 @@ public class ProjectUtil {
|
|
|
.projectWaitingKey(projectWaitingKey)
|
|
|
.projectCheckKey(projectCheckKey)
|
|
|
.build();
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
@@ -139,4 +144,49 @@ public class ProjectUtil {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public PrefixTO getRedisPrefixByProjectIdAndProjectType(String projectId, String projectType) {
|
|
|
+ String userId;
|
|
|
+ if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) {
|
|
|
+ userId = manualProjectMapper.selectCreateUserById(projectId);
|
|
|
+ } else if (DictConstants.PROJECT_TYPE_AUTO_SUB.equals(projectType)) {
|
|
|
+ userId = autoSubProjectMapper.selectCreateUserById(projectId);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("PrjectUtil--getRedisPrefixByProjectIdAndProjectType 未知的项目类型!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //3 获取用户类型(管理员账户、管理员子账户、普通账户、普通子账户)(独占、共享)
|
|
|
+ UserPO userPO = userMapper.selectById(userId);
|
|
|
+ String roleCode = userPO.getRoleCode();
|
|
|
+ String useType = userPO.getUseType();
|
|
|
+ String clusterId;
|
|
|
+ if (DictConstants.ROLE_CODE_SYSADMIN.equals(roleCode) || DictConstants.ROLE_CODE_ADMIN.equals(roleCode)) { //3-1 管理员账户和管理员子账户直接执行
|
|
|
+ clusterId = DictConstants.SYSTEM_CLUSTER_ID;
|
|
|
+ } else if (DictConstants.ROLE_CODE_UESR.equals(roleCode)) { //3-2 普通账户,不管是独占还是共享,都在自己的集群里排队,根据自己的独占节点排队
|
|
|
+ clusterId = clusterMapper.selectByUserId(userId).getId();
|
|
|
+ } else if (DictConstants.ROLE_CODE_SUBUESR.equals(roleCode)) {
|
|
|
+ if (DictConstants.USE_TYPE_EXCLUSIVE.equals(useType)) { //3-3 普通子账户,根据自己的独占节点排队
|
|
|
+ clusterId = clusterMapper.selectByUserId(userId).getId();
|
|
|
+ } else { //3-4 共享子账户,根据父账户的共享节点排队
|
|
|
+ String parentUserId = userPO.getCreateUserId();
|
|
|
+ clusterId = clusterMapper.selectByUserId(parentUserId).getId();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("ProjectUtil--getRedisPrefixByUserIdAndProjectIdAndTaksId 未知账户类型,无法获取集群信息!");
|
|
|
+ }
|
|
|
+ String clusterPrefix = "cluster:" + clusterId;
|
|
|
+ String clusterRunningPrefix = clusterPrefix + ":running";
|
|
|
+ String clusterWaitingPrefix = clusterPrefix + ":waiting";
|
|
|
+ String projectRunningKey = clusterRunningPrefix + ":" + projectId;
|
|
|
+ String projectWaitingKey = clusterWaitingPrefix + ":" + projectId;
|
|
|
+ String projectCheckKey = projectRunningKey + ":check";
|
|
|
+
|
|
|
+ return PrefixTO.builder()
|
|
|
+ .clusterPrefix(clusterPrefix)
|
|
|
+ .clusterRunningPrefix(clusterRunningPrefix)
|
|
|
+ .clusterWaitingPrefix(clusterWaitingPrefix)
|
|
|
+ .projectRunningKey(projectRunningKey)
|
|
|
+ .projectWaitingKey(projectWaitingKey)
|
|
|
+ .projectCheckKey(projectCheckKey)
|
|
|
+ .build();
|
|
|
+ }
|
|
|
}
|