diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java index 43e49a952ba9..87717171bc85 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java @@ -264,6 +264,9 @@ public Map createWorkflowDefinition(User loginUser, definition.getName(), definition.getCode()); throw new ServiceException(Status.WORKFLOW_DEFINITION_NAME_EXIST, name); } + + validateGlobalParams(globalParams); + List taskDefinitionLogs = generateTaskDefinitionList(taskDefinitionJson); List taskRelationList = generateTaskRelationList(taskRelationJson, taskDefinitionLogs); @@ -784,6 +787,9 @@ public Map updateWorkflowDefinition(User loginUser, putMsg(result, Status.DESCRIPTION_TOO_LONG_ERROR); return result; } + + validateGlobalParams(globalParams); + List taskDefinitionLogs = generateTaskDefinitionList(taskDefinitionJson); List taskRelationList = generateTaskRelationList(taskRelationJson, taskDefinitionLogs); @@ -820,6 +826,38 @@ public Map updateWorkflowDefinition(User loginUser, return result; } + /** + * Validates global parameters: non-empty keys, no duplicates + */ + private void validateGlobalParams(String globalParams) { + if (StringUtils.isBlank(globalParams)) { + return; + } + + List params; + try { + params = JSONUtils.toList(globalParams, Property.class); + } catch (Exception e) { + throw new ServiceException("Invalid globalParams"); + } + + if (params == null || params.isEmpty()) { + return; + } + + Set keys = new HashSet<>(); + for (Property p : params) { + if (StringUtils.isEmpty(p.getProp())) { + throw new ServiceException("Global param key cannot be empty"); + } + + String key = p.getProp().trim(); + if (!keys.add(key)) { + throw new ServiceException("Duplicate global param key: " + key); + } + } + } + /** * Task want to delete whether used in other task, should throw exception when have be used. *