|
@@ -11,6 +11,7 @@ import com.css.simulation.resource.scheduler.mapper.*;
|
|
|
import com.css.simulation.resource.scheduler.pojo.po.ClusterPO;
|
|
|
import com.css.simulation.resource.scheduler.pojo.po.ProjectPO;
|
|
|
import com.css.simulation.resource.scheduler.pojo.po.TaskPO;
|
|
|
+import com.css.simulation.resource.scheduler.pojo.po.UserPO;
|
|
|
import com.css.simulation.resource.scheduler.pojo.to.KubernetesNodeTO;
|
|
|
import com.css.simulation.resource.scheduler.pojo.to.PrefixTO;
|
|
|
import com.css.simulation.resource.scheduler.service.TaskService;
|
|
@@ -60,6 +61,8 @@ public class ProjectScheduler {
|
|
|
ProjectConsumer projectConsumer;
|
|
|
@Resource
|
|
|
ProjectUtil projectUtil;
|
|
|
+ @Resource
|
|
|
+ UserMapper userMapper;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -82,18 +85,48 @@ public class ProjectScheduler {
|
|
|
String projectType = project.getProjectType();
|
|
|
long parallelism = Long.parseLong(project.getParallelism());
|
|
|
String userId = project.getCreateUserId();
|
|
|
- ClusterPO clusterPO = clusterMapper.selectByUserId(userId);
|
|
|
- if (clusterPO == null) {
|
|
|
- log.error("ProjectScheduler--dispatchProject 项目 " + projectId + " 的创建用户 " + userId + " 没有分配集群!");
|
|
|
+ UserPO userPO = userMapper.selectById(userId);
|
|
|
+ String roleCode = userPO.getRoleCode();
|
|
|
+ String useType = userPO.getUseType();
|
|
|
+ ClusterPO clusterPO = null;
|
|
|
+ String clusterId;
|
|
|
+ boolean isSystem = false;
|
|
|
+ if (DictConstants.ROLE_CODE_SYSADMIN.equals(roleCode) || DictConstants.ROLE_CODE_ADMIN.equals(roleCode)) { //3-1 管理员账户和管理员子账户直接执行
|
|
|
+ clusterId = DictConstants.SYSTEM_CLUSTER_ID;
|
|
|
+ isSystem = true;
|
|
|
+ } else if (DictConstants.ROLE_CODE_UESR.equals(roleCode)) { //3-2 普通账户,不管是独占还是共享,都在自己的集群里排队,根据自己的独占节点排队
|
|
|
+ clusterPO = clusterMapper.selectByUserId(userId);
|
|
|
+ if (clusterPO == null) {
|
|
|
+ log.error("ProjectScheduler--dispatchProject 项目 " + projectId + " 的创建用户 " + userId + " 没有分配集群!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ clusterId = clusterPO.getId();
|
|
|
+ } else if (DictConstants.ROLE_CODE_SUBUESR.equals(roleCode)) {
|
|
|
+ if (DictConstants.USE_TYPE_EXCLUSIVE.equals(useType)) { //3-3 普通子账户,根据自己的独占节点排队
|
|
|
+ clusterPO = clusterMapper.selectByUserId(userId);
|
|
|
+ } else { //3-4 共享子账户,根据父账户的共享节点排队
|
|
|
+ String parentUserId = userPO.getCreateUserId();
|
|
|
+ clusterPO = clusterMapper.selectByUserId(parentUserId);
|
|
|
+ }
|
|
|
+ if (clusterPO == null) {
|
|
|
+ log.error("ProjectScheduler--dispatchProject 项目 " + projectId + " 的创建用户 " + userId + " 没有分配集群!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ clusterId = clusterPO.getId();
|
|
|
+ } else {
|
|
|
+ log.error("ProjectConsumer--dispatchProject 项目 " + projectId + " 的创建人 " + userId + " 为未知账户类型,不予执行!");
|
|
|
return;
|
|
|
}
|
|
|
- String clusterId = clusterPO.getId();
|
|
|
PrefixTO redisPrefix = projectUtil.getRedisPrefixByClusterIdAndProjectId(clusterId, projectId);
|
|
|
// -------------------------------- 判断项目是否已经在执行,如果执行则 continue --------------------------------
|
|
|
if (StringUtil.isNotEmpty(stringRedisTemplate.opsForValue().get(redisPrefix.getProjectRunningKey()))) {
|
|
|
continue;
|
|
|
}
|
|
|
// -------------------------------- 项目没有执行说明等待中 --------------------------------
|
|
|
+ if (isSystem) { // 系统管理员直接执行
|
|
|
+ run(clusterId, projectId, projectType, redisPrefix.getProjectWaitingKey(), redisPrefix.getProjectRunningKey(), parallelism);
|
|
|
+ return;
|
|
|
+ }
|
|
|
int simulationLicenseNumber = clusterPO.getNumSimulationLicense();
|
|
|
// 获取该用户正在运行的项目数量
|
|
|
Set<String> clusterRunningKeySet = stringRedisTemplate.keys(redisPrefix.getClusterRunningPrefix() + "*");
|
|
@@ -129,7 +162,7 @@ public class ProjectScheduler {
|
|
|
return;
|
|
|
}
|
|
|
//1 获取一个剩余可用并行度最大的节点
|
|
|
- KubernetesNodeTO maxParallelismPNodeTO = projectUtil.getMaxParallelismPNode();
|
|
|
+ KubernetesNodeTO maxParallelismPNodeTO = projectUtil.getMaxParallelismNode();
|
|
|
String maxRestParallelismNode = maxParallelismPNodeTO.getName();
|
|
|
Long maxRestParallelism = maxParallelismPNodeTO.getMaxParallelism();
|
|
|
|