From c9a2eabb5e88276bb7dd40353256cf321e24b13a Mon Sep 17 00:00:00 2001 From: lvzk <897706680@qq.com> Date: Fri, 20 Jun 2025 18:53:47 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=E8=87=AA=E5=8A=A8=E5=8C=96?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E7=94=A8=E7=8E=AF=E5=A2=83=E5=85=A5=E5=8F=A3?= =?UTF-8?q?=E6=8E=A7=E5=88=B6runner=E7=BB=84=E8=8C=83=E5=9B=B4=20#[1437065?= =?UTF-8?q?558851584]=E8=87=AA=E5=8A=A8=E5=8C=96=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E7=94=A8=E7=8E=AF=E5=A2=83=E5=85=A5=E5=8F=A3=E6=8E=A7=E5=88=B6?= =?UTF-8?q?runner=E7=BB=84=E8=8C=83=E5=9B=B4=20http://192.168.0.96:8090/de?= =?UTF-8?q?mo/rdm.html#/story-detail/939050947543040/939050947543042/14370?= =?UTF-8?q?65558851584?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../action/AutoexecJobSourceTypeHandler.java | 81 ++++++++++++++----- .../changelog/2025-06-17/neatlogic_tenant.sql | 2 + 2 files changed, 64 insertions(+), 19 deletions(-) create mode 100644 src/main/resources/neatlogic/resources/autoexec/changelog/2025-06-17/neatlogic_tenant.sql diff --git a/src/main/java/neatlogic/module/autoexec/job/source/action/AutoexecJobSourceTypeHandler.java b/src/main/java/neatlogic/module/autoexec/job/source/action/AutoexecJobSourceTypeHandler.java index c3ac3066..afa3c8ba 100644 --- a/src/main/java/neatlogic/module/autoexec/job/source/action/AutoexecJobSourceTypeHandler.java +++ b/src/main/java/neatlogic/module/autoexec/job/source/action/AutoexecJobSourceTypeHandler.java @@ -19,6 +19,7 @@ import neatlogic.framework.autoexec.job.source.type.AutoexecJobSourceTypeHandler import neatlogic.framework.autoexec.util.AutoexecUtil; import neatlogic.framework.common.util.IpUtil; import neatlogic.framework.dao.mapper.TagMapper; +import neatlogic.framework.dao.mapper.UserSessionContentMapper; import neatlogic.framework.dao.mapper.runner.RunnerMapper; import neatlogic.framework.dto.TagVo; import neatlogic.framework.dto.runner.GroupNetworkVo; @@ -29,6 +30,7 @@ import neatlogic.framework.exception.runner.RunnerGroupRunnerNotFoundException; import neatlogic.framework.exception.runner.RunnerHttpRequestException; import neatlogic.framework.exception.runner.RunnerNotFoundException; import neatlogic.framework.integration.authentication.enums.AuthenticateType; +import neatlogic.framework.util.AviatorEvaluatorUtil; import neatlogic.framework.util.HttpRequestUtil; import neatlogic.framework.util.I18nUtils; import neatlogic.framework.util.TableResultUtil; @@ -67,6 +69,9 @@ public class AutoexecJobSourceTypeHandler extends AutoexecJobSourceTypeHandlerBa @Resource TagMapper tagMapper; + @Resource + UserSessionContentMapper userSessionContentMapper; + @Override public String getName() { return JobSourceType.AUTOEXEC.getValue(); @@ -258,9 +263,10 @@ public class AutoexecJobSourceTypeHandler extends AutoexecJobSourceTypeHandlerBa String runnerGroupTagNameStr = StringUtils.EMPTY; //满足标签的执行器组id列表 List runnerGroupIdListWithTag = new ArrayList<>(); - List runnerGroupIdNameListWithTag = new ArrayList<>(); + List runnerGroupIdListWithTagAndRule; List runnerGroupTagList = null; Boolean isJobRunnerGroupTag = null; + List runnerGroupIdListWithRule = getMatchRuleRunnerGroupList(); //优先获取runner phase声明的执行器组标签 if (ExecMode.RUNNER.getValue().equals(jobPhaseVo.getExecMode()) && combopPhaseExecuteConfigVo != null && combopPhaseExecuteConfigVo.getExecuteConfig() != null && combopPhaseExecuteConfigVo.getExecuteConfig().getRunnerGroupTag() != null) { @@ -297,10 +303,17 @@ public class AutoexecJobSourceTypeHandler extends AutoexecJobSourceTypeHandlerBa runnerGroupTagNameStr = tagVoList.stream().map(TagVo::getName).collect(Collectors.joining("、")); List runnerGroupVos = runnerMapper.getRunnerGroupByTagIdOrNameList(runnerGroupTagList); if (CollectionUtils.isNotEmpty(runnerGroupVos)) { + runnerGroupVos = runnerGroupVos.stream().filter(rg -> runnerGroupIdListWithRule.contains(rg.getId())).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(runnerGroupVos)) { + runnerGroupIdListWithTagAndRule = runnerGroupVos.stream().map(RunnerGroupVo::getId).collect(Collectors.toList()); + } else { + if (Boolean.TRUE.equals(isJobRunnerGroupTag)) { + throw new AutoexecRunnerGroupNotFoundByTagAndRuleException(runnerGroupTagNameStr); + } else { + throw new AutoexecRunnerGroupNotFoundByTagAndRuleException(runnerGroupTagNameStr, jobPhaseVo); + } + } runnerGroupIdListWithTag = runnerGroupVos.stream().map(RunnerGroupVo::getId).collect(Collectors.toList()); - List runnerGroupIdStrListWithTag = runnerGroupIdListWithTag.stream().map(Object::toString).collect(Collectors.toList()); - runnerGroupIdNameListWithTag = runnerGroupVos.stream().map(RunnerGroupVo::getName).collect(Collectors.toList()); - runnerGroupIdNameListWithTag.addAll(runnerGroupIdStrListWithTag); } else { if (Boolean.TRUE.equals(isJobRunnerGroupTag)) { throw new AutoexecRunnerGroupNotFoundByTagException(runnerGroupTagNameStr); @@ -308,11 +321,13 @@ public class AutoexecJobSourceTypeHandler extends AutoexecJobSourceTypeHandlerBa throw new AutoexecRunnerGroupNotFoundByTagException(runnerGroupTagNameStr, jobPhaseVo); } } + } else { + runnerGroupIdListWithTagAndRule = runnerGroupIdListWithRule; } if (Arrays.asList(ExecMode.TARGET.getValue(), ExecMode.RUNNER_TARGET.getValue()).contains(jobPhaseVo.getExecMode())) { - List networkVoList = runnerMapper.getAllNetworkMask(runnerGroupIdListWithTag); + List networkVoList = runnerMapper.getAllNetworkMask(runnerGroupIdListWithTagAndRule); for (GroupNetworkVo networkVo : networkVoList) { if (IpUtil.isBelongSegment(jobPhaseVo.getCurrentNode().getHost(), networkVo.getNetworkIp(), networkVo.getMask())) { RunnerGroupVo groupVo = runnerMapper.getRunnerMapGroupById(networkVo.getGroupId()); @@ -326,13 +341,6 @@ public class AutoexecJobSourceTypeHandler extends AutoexecJobSourceTypeHandlerBa break; } } -// if (CollectionUtils.isEmpty(runnerMapVos)) { -// if (CollectionUtils.isNotEmpty(runnerGroupIdListWithTag)) { -// throw new RunnerNotMatchException(jobPhaseVo.getCurrentNode().getHost(), jobPhaseVo.getCurrentNode().getResourceId(), runnerGroupTagNameStr); -// } else { -// throw new RunnerNotMatchException(jobPhaseVo.getCurrentNode().getHost(), jobPhaseVo.getCurrentNode().getResourceId()); -// } -// } } else { //默认随机分配 String runnerGroup = null; @@ -369,11 +377,8 @@ public class AutoexecJobSourceTypeHandler extends AutoexecJobSourceTypeHandlerBa runnerGroup = "-1"; } if (Objects.equals(runnerGroup, "-1")) {//-1 代表 “随机匹配” - runnerMapVos = runnerMapper.getAllRunnerMap(runnerGroupIdListWithTag); + runnerMapVos = runnerMapper.getAllRunnerMap(runnerGroupIdListWithTagAndRule); if (CollectionUtils.isEmpty(runnerMapVos)) { - if (CollectionUtils.isNotEmpty(runnerGroupIdListWithTag)) { - throw new AutoexecRunnerGroupTagNotMatchException(runnerGroupTagNameStr); - } throw new RunnerNotFoundException(); } } else { @@ -381,7 +386,7 @@ public class AutoexecJobSourceTypeHandler extends AutoexecJobSourceTypeHandlerBa if (runnerGroupVo == null) { throw new RunnerGroupNotFoundException(runnerGroup); } - if (CollectionUtils.isNotEmpty(runnerGroupIdListWithTag) && !runnerGroupIdNameListWithTag.contains(runnerGroup)) { + if (CollectionUtils.isNotEmpty(runnerGroupIdListWithTag) && !runnerGroupIdListWithTag.contains(runnerGroupVo.getId())) { String runnerGroupFrom = I18nUtils.getMessage("nmajsa.autoexecjobsourcetypehandler.getrunnermaplist"); if (Boolean.FALSE.equals(isJobRunnerGroup)) { runnerGroupFrom = I18nUtils.getMessage("nfac.paramtype.phase") + "“" + jobPhaseVo.getName() + "“"; @@ -392,9 +397,16 @@ public class AutoexecJobSourceTypeHandler extends AutoexecJobSourceTypeHandlerBa } throw new AutoexecRunnerGroupTagNotMatchException(runnerGroupFrom, runnerGroupTagFrom, runnerGroupVo.getName(), runnerGroupTagNameStr); } + if (!runnerGroupIdListWithRule.contains(runnerGroupVo.getId())) { + if (Boolean.FALSE.equals(isJobRunnerGroup)) { + throw new AutoexecRunnerGroupRuleNotMatchException(runnerGroupVo, I18nUtils.getMessage("nfac.paramtype.phase"), jobPhaseVo.getName()); + } else { + throw new AutoexecRunnerGroupRuleNotMatchException(runnerGroupVo, I18nUtils.getMessage("nmajsa.autoexecjobsourcetypehandler.getrunnermaplist")); + } + } runnerMapVos = runnerMapper.getRunnerMapListByRunnerGroupId(runnerGroupVo.getId()); if (CollectionUtils.isEmpty(runnerMapVos)) { - throw new RunnerGroupRunnerNotFoundException(runnerGroup); + throw new RunnerGroupRunnerNotFoundException(runnerGroupVo.getName() + "(" + runnerGroupVo.getId() + ")"); } } @@ -402,6 +414,36 @@ public class AutoexecJobSourceTypeHandler extends AutoexecJobSourceTypeHandlerBa return runnerMapVos; } + /** + * 返回所有rule为空 或 满足rule的执行器组 + */ + private List getMatchRuleRunnerGroupList() { + List matchRuleRunnerGroupIdList = new ArrayList<>(); + List runnerGroups = runnerMapper.getAllRunnerGroupList(); + JSONObject headers = null; + //如果存在规则的执行器组,则先校验 + for (RunnerGroupVo runnerGroupVo : runnerGroups) { + if (StringUtils.isNotBlank(runnerGroupVo.getRule())) { + if (MapUtils.isEmpty(headers) && UserContext.get() != null) { + String tokenHash = UserContext.get().getTokenHash(); + if (StringUtils.isNotBlank(tokenHash)) { + String sessionContentStr = userSessionContentMapper.getUserSessionContentByHash(tokenHash); + JSONObject sessionContentJson = JSON.parseObject(sessionContentStr); + if (MapUtils.isNotEmpty(sessionContentJson)) { + headers = sessionContentJson.getJSONObject("headers"); + } + } + } + if (MapUtils.isNotEmpty(headers) && AviatorEvaluatorUtil.evaluateBoolean(runnerGroupVo.getRule(), headers)) { + matchRuleRunnerGroupIdList.add(runnerGroupVo.getId()); + } + } else { + matchRuleRunnerGroupIdList.add(runnerGroupVo.getId()); + } + } + return matchRuleRunnerGroupIdList; + } + @Override public AutoexecCombopVo getAutoexecCombop(AutoexecJobVo autoexecJobParam) { AutoexecCombopVo combopVo = autoexecCombopMapper.getAutoexecCombopById(autoexecJobParam.getOperationId()); @@ -456,7 +498,8 @@ public class AutoexecJobSourceTypeHandler extends AutoexecJobSourceTypeHandlerBa } @Override - public List getPhaseSqlStatusList(AutoexecJobPhaseVo jobPhaseVo, Long runnerMapId, List needCountStatusList) { + public List getPhaseSqlStatusList(AutoexecJobPhaseVo jobPhaseVo, Long + runnerMapId, List needCountStatusList) { return autoexecJobMapper.getJobSqlDetailStatusList(jobPhaseVo.getJobId(), jobPhaseVo.getName(), runnerMapId, needCountStatusList); } diff --git a/src/main/resources/neatlogic/resources/autoexec/changelog/2025-06-17/neatlogic_tenant.sql b/src/main/resources/neatlogic/resources/autoexec/changelog/2025-06-17/neatlogic_tenant.sql new file mode 100644 index 00000000..ecaef31b --- /dev/null +++ b/src/main/resources/neatlogic/resources/autoexec/changelog/2025-06-17/neatlogic_tenant.sql @@ -0,0 +1,2 @@ +ALTER TABLE `runnergroup` +ADD COLUMN `rule` text NULL COMMENT '规则' AFTER `description`; \ No newline at end of file -- Gitee