Browse Source

Fix out parameter may loss (#15617)

dev_wenjun_refactorMaster
Wenjun Ruan 9 months ago committed by GitHub
parent
commit
24ff70dc88
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 47
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parameters/AbstractParameters.java
  2. 27
      dolphinscheduler-task-plugin/dolphinscheduler-task-shell/src/main/java/org/apache/dolphinscheduler/plugin/task/shell/ShellParameters.java
  3. 77
      dolphinscheduler-task-plugin/dolphinscheduler-task-shell/src/test/java/org/apache/dolphinscheduler/plugin/task/shell/ShellParametersTest.java

47
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parameters/AbstractParameters.java

@ -36,14 +36,22 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
@Getter
@Slf4j
public abstract class AbstractParameters implements IParameters {
@Setter
public List<Property> localParams;
public List<Property> varPool = new ArrayList<>();
@Override
public abstract boolean checkParameters();
@ -52,33 +60,6 @@ public abstract class AbstractParameters implements IParameters {
return new ArrayList<>();
}
/**
* local parameters
*/
public List<Property> localParams;
/**
* var pool
*/
public List<Property> varPool;
/**
* get local parameters list
*
* @return Property list
*/
public List<Property> getLocalParams() {
return localParams;
}
public void setLocalParams(List<Property> localParams) {
this.localParams = localParams;
}
/**
* get local parameters map
* @return parameters map
*/
public Map<String, Property> getLocalParametersMap() {
Map<String, Property> localParametersMaps = new LinkedHashMap<>();
if (localParams != null) {
@ -131,10 +112,6 @@ public abstract class AbstractParameters implements IParameters {
return varPoolMap;
}
public List<Property> getVarPool() {
return varPool;
}
public void setVarPool(String varPool) {
if (StringUtils.isEmpty(varPool)) {
this.varPool = new ArrayList<>();
@ -161,8 +138,12 @@ public abstract class AbstractParameters implements IParameters {
if (StringUtils.isNotEmpty(propValue)) {
info.setValue(propValue);
addPropertyToValPool(info);
} else {
log.warn("Cannot find the output parameter {} in the task output parameters", info.getProp());
continue;
}
addPropertyToValPool(info);
if (StringUtils.isEmpty(info.getValue())) {
log.warn("The output parameter {} value is empty and cannot find the out parameter from task output",
info);
}
}
}

27
dolphinscheduler-task-plugin/dolphinscheduler-task-shell/src/main/java/org/apache/dolphinscheduler/plugin/task/shell/ShellParameters.java

@ -22,34 +22,17 @@ import org.apache.dolphinscheduler.plugin.task.api.parameters.AbstractParameters
import java.util.List;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ShellParameters extends AbstractParameters {
/**
* shell script
*/
private String rawScript;
/**
* resource list
*/
private List<ResourceInfo> resourceList;
public String getRawScript() {
return rawScript;
}
public void setRawScript(String rawScript) {
this.rawScript = rawScript;
}
public List<ResourceInfo> getResourceList() {
return resourceList;
}
public void setResourceList(List<ResourceInfo> resourceList) {
this.resourceList = resourceList;
}
@Override
public boolean checkParameters() {
return rawScript != null && !rawScript.isEmpty();

77
dolphinscheduler-task-plugin/dolphinscheduler-task-shell/src/test/java/org/apache/dolphinscheduler/plugin/task/shell/ShellParametersTest.java

@ -0,0 +1,77 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.plugin.task.shell;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.dolphinscheduler.plugin.task.api.enums.DataType;
import org.apache.dolphinscheduler.plugin.task.api.enums.Direct;
import org.apache.dolphinscheduler.plugin.task.api.model.Property;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import com.google.common.collect.Lists;
class ShellParametersTest {
@Test
void dealOutParamTest() {
ShellParameters shellParameters = new ShellParameters();
List<Property> localParams = Lists.newArrayList(new Property("a", Direct.OUT, DataType.VARCHAR, "a"));
shellParameters.setLocalParams(localParams);
Map<String, String> taskOutputParams = new HashMap<>();
taskOutputParams.put("b", "b");
shellParameters.dealOutParam(taskOutputParams);
List<Property> varPool = shellParameters.getVarPool();
assertEquals(1, varPool.size());
assertEquals("a", varPool.get(0).getValue());
}
@Test
void dealOutParamTest_notTaskOutput() {
ShellParameters shellParameters = new ShellParameters();
List<Property> localParams = Lists.newArrayList(new Property("a", Direct.OUT, DataType.VARCHAR, "a"));
shellParameters.setLocalParams(localParams);
Map<String, String> taskOutputParams = new HashMap<>();
shellParameters.dealOutParam(taskOutputParams);
List<Property> varPool = shellParameters.getVarPool();
assertEquals(1, varPool.size());
assertEquals("a", varPool.get(0).getValue());
}
@Test
void dealOutParamTest_taskOutputOverrideOut() {
ShellParameters shellParameters = new ShellParameters();
List<Property> localParams = Lists.newArrayList(new Property("a", Direct.OUT, DataType.VARCHAR, "a"));
shellParameters.setLocalParams(localParams);
Map<String, String> taskOutputParams = new HashMap<>();
taskOutputParams.put("a", "b");
shellParameters.dealOutParam(taskOutputParams);
List<Property> varPool = shellParameters.getVarPool();
assertEquals(1, varPool.size());
assertEquals("b", varPool.get(0).getValue());
}
}
Loading…
Cancel
Save