Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -338,23 +339,48 @@ public void cancelApplication() throws TaskException {

private Map<String, String> generateVariables() {
Map<String, String> variables = new ConcurrentHashMap<>();
List<Property> propertyList = JSONUtils.toList(taskExecutionContext.getGlobalParams(), Property.class);
if (propertyList != null && !propertyList.isEmpty()) {
for (Property property : propertyList) {
variables.put(property.getProp(), property.getValue());
Map<String, Property> prepareParamsMap = taskExecutionContext.getPrepareParamsMap();

// 全量参数,先统一插入到variables,有些key可能是没值的
// 后面从取taskParams和prepareParamsMap交集,交集key先从localParams获取value,有值的放到variables;没值的从globalParams获取
prepareParamsMap.forEach((key, property) -> {
if (Objects.nonNull(property) && Objects.nonNull(property.getValue())) {
variables.put(key, property.getValue());
}
}
});

List<Property> localParams = this.dinkyParameters.getLocalParams();
Map<String, Property> prepareParamsMap = taskExecutionContext.getPrepareParamsMap();
if (localParams == null || localParams.isEmpty()) {
return variables;
}
Map<String, String> convertMap = ParameterUtils.convert(prepareParamsMap);
for (Property property : localParams) {
String propertyValue = property.getValue();
String value = PlaceholderUtils.replacePlaceholders(propertyValue, convertMap, true);
variables.put(property.getProp(), value);
List<Property> globalParams = JSONUtils.toList(taskExecutionContext.getGlobalParams(), Property.class);

if (!localParams.isEmpty()) {
for (Property localParam : localParams) {
// 如果variables没有这个key || value空的,从局部、全局 解析值,插入variables
if (Objects.isNull(variables.get(localParam.getProp())) || variables.get(localParam.getProp()).isEmpty()) {
if (localParam.getValue() != null && !localParam.getValue().isEmpty()) {
// 解析value
String value = ParameterUtils.convertParameterPlaceholders(localParam.getValue(), variables);
if (StringUtils.isNotBlank(value)) {
variables.put(localParam.getProp(), value);
}
} else {
if (!globalParams.isEmpty()) {
for (Property globalParam : globalParams) {
if (globalParam.getProp().equals(localParam.getProp())) {
if (globalParam.getValue() != null && !globalParam.getValue().isEmpty()) {
// 解析value
String value = ParameterUtils.convertParameterPlaceholders(globalParam.getValue(), variables);
if (StringUtils.isNotBlank(value)) {
variables.put(localParam.getProp(), value);
}
}
}
}
}
}
}
}
}
log.info("will send variables to dinky: {}", variables);
return variables;
}

Expand Down