Browse Source

[Fix-13187] refactor OpenmldbParameters (#13190)

3.2.0-release
HuangWei 2 years ago committed by GitHub
parent
commit
43e6ac32dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      dolphinscheduler-task-plugin/dolphinscheduler-task-openmldb/src/main/java/org/apache/dolphinscheduler/plugin/task/openmldb/OpenmldbParameters.java
  2. 18
      dolphinscheduler-task-plugin/dolphinscheduler-task-openmldb/src/main/java/org/apache/dolphinscheduler/plugin/task/openmldb/OpenmldbTask.java

25
dolphinscheduler-task-plugin/dolphinscheduler-task-openmldb/src/main/java/org/apache/dolphinscheduler/plugin/task/openmldb/OpenmldbParameters.java

@ -17,14 +17,11 @@
package org.apache.dolphinscheduler.plugin.task.openmldb;
import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo;
import org.apache.dolphinscheduler.plugin.task.api.parameters.AbstractParameters;
import org.apache.dolphinscheduler.plugin.task.python.PythonParameters;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
public class OpenmldbParameters extends AbstractParameters {
public class OpenmldbParameters extends PythonParameters {
private String zk;
private String zkPath;
@ -34,11 +31,6 @@ public class OpenmldbParameters extends AbstractParameters {
*/
private String sql;
/**
* resource list
*/
private List<ResourceInfo> resourceList;
public String getZk() {
return zk;
}
@ -71,21 +63,8 @@ public class OpenmldbParameters extends AbstractParameters {
this.sql = sql;
}
public List<ResourceInfo> getResourceList() {
return resourceList;
}
public void setResourceList(List<ResourceInfo> resourceList) {
this.resourceList = resourceList;
}
@Override
public boolean checkParameters() {
return StringUtils.isNotEmpty(zk) && StringUtils.isNotEmpty(zkPath) && StringUtils.isNotEmpty(sql);
}
@Override
public List<ResourceInfo> getResourceFilesList() {
return this.resourceList;
}
}

18
dolphinscheduler-task-plugin/dolphinscheduler-task-openmldb/src/main/java/org/apache/dolphinscheduler/plugin/task/openmldb/OpenmldbTask.java

@ -21,7 +21,6 @@ import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.plugin.task.api.TaskException;
import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
import org.apache.dolphinscheduler.plugin.task.api.model.Property;
import org.apache.dolphinscheduler.plugin.task.api.parameters.AbstractParameters;
import org.apache.dolphinscheduler.plugin.task.api.parser.ParamUtils;
import org.apache.dolphinscheduler.plugin.task.api.parser.ParameterUtils;
import org.apache.dolphinscheduler.plugin.task.python.PythonTask;
@ -42,9 +41,8 @@ import com.google.common.base.Preconditions;
public class OpenmldbTask extends PythonTask {
/**
* openmldb parameters
* openmldb parameters: cast pythonParameters to OpenmldbParameters
*/
private OpenmldbParameters openmldbParameters;
/**
* python process(openmldb only supports version 3 by default)
@ -63,11 +61,10 @@ public class OpenmldbTask extends PythonTask {
@Override
public void init() {
pythonParameters = JSONUtils.parseObject(taskRequest.getTaskParams(), OpenmldbParameters.class);
openmldbParameters = JSONUtils.parseObject(taskRequest.getTaskParams(), OpenmldbParameters.class);
logger.info("Initialize openmldb task params {}", JSONUtils.toPrettyJsonString(openmldbParameters));
if (openmldbParameters == null || !openmldbParameters.checkParameters()) {
logger.info("Initialize openmldb task params {}", JSONUtils.toPrettyJsonString(pythonParameters));
if (pythonParameters == null || !pythonParameters.checkParameters()) {
throw new TaskException("openmldb task params is not valid");
}
}
@ -78,11 +75,6 @@ public class OpenmldbTask extends PythonTask {
return "";
}
@Override
public AbstractParameters getParameters() {
return openmldbParameters;
}
/**
* build python command file path
*
@ -100,6 +92,7 @@ public class OpenmldbTask extends PythonTask {
*/
@Override
protected String buildPythonScriptContent() {
OpenmldbParameters openmldbParameters = (OpenmldbParameters) pythonParameters;
logger.info("raw sql script : {}", openmldbParameters.getSql());
String rawSQLScript = openmldbParameters.getSql().replaceAll("[\\r]?\\n", "\n");
@ -117,6 +110,7 @@ public class OpenmldbTask extends PythonTask {
StringBuilder builder = new StringBuilder("import openmldb\nimport sqlalchemy as db\n");
// connect to openmldb
OpenmldbParameters openmldbParameters = (OpenmldbParameters) pythonParameters;
builder.append(String.format("engine = db.create_engine('openmldb:///?zk=%s&zkPath=%s')\n",
openmldbParameters.getZk(), openmldbParameters.getZkPath()));
builder.append("con = engine.connect()\n");

Loading…
Cancel
Save