Browse Source

[bug][task-plugins]fix switch class name and add param check to the switch task plugin (#10894)

* fix switch class name and add param check to the switch task plugin
3.1.0-release
Tq 2 years ago committed by GitHub
parent
commit
499e5b1307
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 40
      dolphinscheduler-task-plugin/dolphinscheduler-task-switch/src/main/java/org/apache/dolphinscheduler/plugin/task/switchtask/SwitchCondition.java
  2. 101
      dolphinscheduler-task-plugin/dolphinscheduler-task-switch/src/main/java/org/apache/dolphinscheduler/plugin/task/switchtask/SwitchParameters.java
  3. 42
      dolphinscheduler-task-plugin/dolphinscheduler-task-switch/src/main/java/org/apache/dolphinscheduler/plugin/task/switchtask/SwitchResult.java
  4. 7
      dolphinscheduler-task-plugin/dolphinscheduler-task-switch/src/main/java/org/apache/dolphinscheduler/plugin/task/switchtask/SwitchTaskChannel.java
  5. 12
      dolphinscheduler-task-plugin/dolphinscheduler-task-switch/src/main/java/org/apache/dolphinscheduler/plugin/task/switchtask/SwitchTaskChannelFactory.java

40
dolphinscheduler-task-plugin/dolphinscheduler-task-switch/src/main/java/org/apache/dolphinscheduler/plugin/task/switchtask/SwitchCondition.java

@ -0,0 +1,40 @@
/*
* 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.switchtask;
public class SwitchCondition {
private String condition;
private Long nextNode;
public String getCondition() {
return condition;
}
public void setCondition(String condition) {
this.condition = condition;
}
public Long getNextNode() {
return nextNode;
}
public void setNextNode(Long nextNode) {
this.nextNode = nextNode;
}
}

101
dolphinscheduler-task-plugin/dolphinscheduler-task-switch/src/main/java/org/apache/dolphinscheduler/plugin/task/switchtask/SwitchParameters.java

@ -0,0 +1,101 @@
/*
* 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.switchtask;
import org.apache.dolphinscheduler.plugin.task.api.model.Property;
import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo;
import org.apache.dolphinscheduler.plugin.task.api.parameters.AbstractParameters;
import org.apache.dolphinscheduler.spi.utils.StringUtils;
import java.util.List;
public class SwitchParameters extends AbstractParameters {
/**
* shell script
*/
private String rawScript;
/**
* local parameters
*/
public List<Property> localParams;
private SwitchResult switchResult;
/**
* 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 List<Property> getLocalParams() {
return localParams;
}
@Override
public void setLocalParams(List<Property> localParams) {
this.localParams = localParams;
}
public SwitchResult getSwitchResult() {
return switchResult;
}
public void setSwitchResult(SwitchResult switchResult) {
this.switchResult = switchResult;
}
@Override
public boolean checkParameters() {
//default next node should not be null
boolean defaultNode = switchResult != null && switchResult.getNextNode() != null;
if (!defaultNode) {
return false;
}
//validate conditions must have next node
List<SwitchCondition> conditions = this.switchResult.getDependTaskList();
if (conditions != null && conditions.size() != 0) {
if (conditions.stream().anyMatch(e -> (StringUtils.isNotEmpty(e.getCondition()) && e.getNextNode() == null))) {
return false;
}
}
return true;
}
@Override
public List<ResourceInfo> getResourceFilesList() {
return resourceList;
}
}

42
dolphinscheduler-task-plugin/dolphinscheduler-task-switch/src/main/java/org/apache/dolphinscheduler/plugin/task/switchtask/SwitchResult.java

@ -0,0 +1,42 @@
/*
* 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.switchtask;
import java.util.List;
public class SwitchResult {
private List<SwitchCondition> dependTaskList;
private Long nextNode;
public List<SwitchCondition> getDependTaskList() {
return dependTaskList;
}
public void setDependTaskList(List<SwitchCondition> dependTaskList) {
this.dependTaskList = dependTaskList;
}
public Long getNextNode() {
return nextNode;
}
public void setNextNode(Long nextNode) {
this.nextNode = nextNode;
}
}

7
dolphinscheduler-task-plugin/dolphinscheduler-task-switch/src/main/java/org/apache/dolphinscheduler/plugin/task/switchtask/SubProcessTaskChannel.java → dolphinscheduler-task-plugin/dolphinscheduler-task-switch/src/main/java/org/apache/dolphinscheduler/plugin/task/switchtask/SwitchTaskChannel.java

@ -22,12 +22,10 @@ import org.apache.dolphinscheduler.plugin.task.api.TaskChannel;
import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
import org.apache.dolphinscheduler.plugin.task.api.parameters.AbstractParameters;
import org.apache.dolphinscheduler.plugin.task.api.parameters.ParametersNode;
import org.apache.dolphinscheduler.plugin.task.api.parameters.SwitchParameters;
import org.apache.dolphinscheduler.plugin.task.api.parameters.resource.ResourceParametersHelper;
import org.apache.dolphinscheduler.spi.utils.JSONUtils;
import org.apache.dolphinscheduler.spi.utils.StringUtils;
public class SubProcessTaskChannel implements TaskChannel {
public class SwitchTaskChannel implements TaskChannel {
@Override
public void cancelApplication(boolean status) {
@ -41,8 +39,7 @@ public class SubProcessTaskChannel implements TaskChannel {
@Override
public AbstractParameters parseParameters(ParametersNode parametersNode) {
return JSONUtils.parseObject(StringUtils.isEmpty(parametersNode.getSwitchResult())
? parametersNode.getTaskParams() : parametersNode.getSwitchResult(), SwitchParameters.class);
return JSONUtils.parseObject(parametersNode.getTaskParams(), SwitchParameters.class);
}
@Override

12
dolphinscheduler-task-plugin/dolphinscheduler-task-switch/src/main/java/org/apache/dolphinscheduler/plugin/task/switchtask/SubProcessTaskChannelFactory.java → dolphinscheduler-task-plugin/dolphinscheduler-task-switch/src/main/java/org/apache/dolphinscheduler/plugin/task/switchtask/SwitchTaskChannelFactory.java

@ -17,26 +17,24 @@
package org.apache.dolphinscheduler.plugin.task.switchtask;
import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.TASK_TYPE_SWITCH;
import com.google.auto.service.AutoService;
import org.apache.dolphinscheduler.plugin.task.api.TaskChannel;
import org.apache.dolphinscheduler.plugin.task.api.TaskChannelFactory;
import org.apache.dolphinscheduler.plugin.task.api.TaskConstants;
import org.apache.dolphinscheduler.spi.params.base.PluginParams;
import java.util.List;
import com.google.auto.service.AutoService;
@AutoService(TaskChannelFactory.class)
public class SubProcessTaskChannelFactory implements TaskChannelFactory {
public class SwitchTaskChannelFactory implements TaskChannelFactory {
@Override
public TaskChannel create() {
return new SubProcessTaskChannel();
return new SwitchTaskChannel();
}
@Override
public String getName() {
return TASK_TYPE_SWITCH;
return TaskConstants.TASK_TYPE_SWITCH;
}
@Override
Loading…
Cancel
Save