|
|
|
@ -17,35 +17,34 @@
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinler.plugin.task.mlflow; |
|
|
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; |
|
|
|
|
import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContextCacheManager; |
|
|
|
|
import org.apache.dolphinscheduler.plugin.task.api.utils.OSUtils; |
|
|
|
|
import org.apache.dolphinscheduler.plugin.task.mlflow.MlflowConstants; |
|
|
|
|
import org.apache.dolphinscheduler.plugin.task.mlflow.MlflowParameters; |
|
|
|
|
import org.apache.dolphinscheduler.plugin.task.mlflow.MlflowTask; |
|
|
|
|
import org.apache.dolphinscheduler.spi.utils.JSONUtils; |
|
|
|
|
import org.apache.dolphinscheduler.spi.utils.PropertyUtils; |
|
|
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
|
import org.junit.Assert; |
|
|
|
|
import org.junit.Before; |
|
|
|
|
import org.junit.Test; |
|
|
|
|
import org.junit.runner.RunWith; |
|
|
|
|
import org.mockito.Mockito; |
|
|
|
|
import org.powermock.api.mockito.PowerMockito; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
import org.apache.dolphinscheduler.spi.utils.PropertyUtils; |
|
|
|
|
|
|
|
|
|
import org.powermock.core.classloader.annotations.PrepareForTest; |
|
|
|
|
import org.powermock.core.classloader.annotations.PowerMockIgnore; |
|
|
|
|
import org.junit.runner.RunWith; |
|
|
|
|
import org.powermock.modules.junit4.PowerMockRunner; |
|
|
|
|
import org.powermock.core.classloader.annotations.PrepareForTest; |
|
|
|
|
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; |
|
|
|
|
import org.apache.dolphinscheduler.spi.utils.JSONUtils; |
|
|
|
|
import org.powermock.modules.junit4.PowerMockRunner; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
@RunWith(PowerMockRunner.class) |
|
|
|
|
@PrepareForTest({ |
|
|
|
|
JSONUtils.class, |
|
|
|
|
PropertyUtils.class, |
|
|
|
|
JSONUtils.class, |
|
|
|
|
PropertyUtils.class, |
|
|
|
|
}) |
|
|
|
|
@PowerMockIgnore({"javax.*"}) |
|
|
|
|
@SuppressStaticInitializationFor("org.apache.dolphinscheduler.spi.utils.PropertyUtils") |
|
|
|
@ -81,84 +80,85 @@ public class MlflowTaskTest {
|
|
|
|
|
public void testInitBasicAlgorithmTask() { |
|
|
|
|
MlflowTask mlflowTask = initTask(createBasicAlgorithmParameters()); |
|
|
|
|
Assert.assertEquals(mlflowTask.buildCommand(), |
|
|
|
|
"export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" + |
|
|
|
|
"data_path=/data/iris.csv\n" + |
|
|
|
|
"repo=https://github.com/apache/dolphinscheduler-mlflow#Project-BasicAlgorithm\n" + |
|
|
|
|
"mlflow run $repo " + |
|
|
|
|
"-P algorithm=xgboost " + |
|
|
|
|
"-P data_path=$data_path " + |
|
|
|
|
"-P params=\"n_estimators=100\" " + |
|
|
|
|
"-P search_params=\"\" " + |
|
|
|
|
"-P model_name=\"BasicAlgorithm\" " + |
|
|
|
|
"--experiment-name=\"BasicAlgorithm\" " + |
|
|
|
|
"--version=main "); |
|
|
|
|
"export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" |
|
|
|
|
+ "data_path=/data/iris.csv\n" |
|
|
|
|
+ "repo=dolphinscheduler-mlflow#Project-BasicAlgorithm\n" |
|
|
|
|
+ "git clone https://github.com/apache/dolphinscheduler-mlflow dolphinscheduler-mlflow\n" |
|
|
|
|
+ "mlflow run $repo " |
|
|
|
|
+ "-P algorithm=xgboost " |
|
|
|
|
+ "-P data_path=$data_path " |
|
|
|
|
+ "-P params=\"n_estimators=100\" " |
|
|
|
|
+ "-P search_params=\"\" " |
|
|
|
|
+ "-P model_name=\"BasicAlgorithm\" " |
|
|
|
|
+ "--experiment-name=\"BasicAlgorithm\""); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testInitAutoMLTask() { |
|
|
|
|
MlflowTask mlflowTask = initTask(createAutoMLParameters()); |
|
|
|
|
Assert.assertEquals(mlflowTask.buildCommand(), |
|
|
|
|
"export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" + |
|
|
|
|
"data_path=/data/iris.csv\n" + |
|
|
|
|
"repo=https://github.com/apache/dolphinscheduler-mlflow#Project-AutoML\n" + |
|
|
|
|
"mlflow run $repo " + |
|
|
|
|
"-P tool=autosklearn " + |
|
|
|
|
"-P data_path=$data_path " + |
|
|
|
|
"-P params=\"time_left_for_this_task=30\" " + |
|
|
|
|
"-P model_name=\"AutoML\" " + |
|
|
|
|
"--experiment-name=\"AutoML\" " + |
|
|
|
|
"--version=main "); |
|
|
|
|
"export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" |
|
|
|
|
+ "data_path=/data/iris.csv\n" |
|
|
|
|
+ "repo=dolphinscheduler-mlflow#Project-AutoML\n" |
|
|
|
|
+ "git clone https://github.com/apache/dolphinscheduler-mlflow dolphinscheduler-mlflow\n" |
|
|
|
|
+ "mlflow run $repo " |
|
|
|
|
+ "-P tool=autosklearn " |
|
|
|
|
+ "-P data_path=$data_path " |
|
|
|
|
+ "-P params=\"time_left_for_this_task=30\" " |
|
|
|
|
+ "-P model_name=\"AutoML\" " |
|
|
|
|
+ "--experiment-name=\"AutoML\""); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testInitCustomProjectTask() { |
|
|
|
|
MlflowTask mlflowTask = initTask(createCustomProjectParameters()); |
|
|
|
|
Assert.assertEquals(mlflowTask.buildCommand(), |
|
|
|
|
"export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" + |
|
|
|
|
"repo=https://github.com/mlflow/mlflow#examples/xgboost/xgboost_native\n" + |
|
|
|
|
"mlflow run $repo " + |
|
|
|
|
"-P learning_rate=0.2 " + |
|
|
|
|
"-P colsample_bytree=0.8 " + |
|
|
|
|
"-P subsample=0.9 " + |
|
|
|
|
"--experiment-name=\"custom_project\" " + |
|
|
|
|
"--version=\"master\" "); |
|
|
|
|
"export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" |
|
|
|
|
+ "repo=https://github.com/mlflow/mlflow#examples/xgboost/xgboost_native\n" |
|
|
|
|
+ "mlflow run $repo " |
|
|
|
|
+ "-P learning_rate=0.2 " |
|
|
|
|
+ "-P colsample_bytree=0.8 " |
|
|
|
|
+ "-P subsample=0.9 " |
|
|
|
|
+ "--experiment-name=\"custom_project\" " |
|
|
|
|
+ "--version=\"master\" "); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testModelsDeployMlflow() { |
|
|
|
|
MlflowTask mlflowTask = initTask(createModelDeplyMlflowParameters()); |
|
|
|
|
Assert.assertEquals(mlflowTask.buildCommand(), |
|
|
|
|
"export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" + |
|
|
|
|
"mlflow models serve -m models:/model/1 --port 7000 -h 0.0.0.0"); |
|
|
|
|
"export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" |
|
|
|
|
+ "mlflow models serve -m models:/model/1 --port 7000 -h 0.0.0.0"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testModelsDeployDocker() { |
|
|
|
|
MlflowTask mlflowTask = initTask(createModelDeplyDockerParameters()); |
|
|
|
|
Assert.assertEquals(mlflowTask.buildCommand(), |
|
|
|
|
"export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" + |
|
|
|
|
"mlflow models build-docker -m models:/model/1 -n mlflow/model:1 --enable-mlserver\n" + |
|
|
|
|
"docker rm -f ds-mlflow-model-1\n" + |
|
|
|
|
"docker run -d --name=ds-mlflow-model-1 -p=7000:8080 " + |
|
|
|
|
"--health-cmd \"curl --fail http://127.0.0.1:8080/ping || exit 1\" --health-interval 5s --health-retries 20 " + |
|
|
|
|
"mlflow/model:1"); |
|
|
|
|
"export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" |
|
|
|
|
+ "mlflow models build-docker -m models:/model/1 -n mlflow/model:1 --enable-mlserver\n" |
|
|
|
|
+ "docker rm -f ds-mlflow-model-1\n" |
|
|
|
|
+ "docker run -d --name=ds-mlflow-model-1 -p=7000:8080 " |
|
|
|
|
+ "--health-cmd \"curl --fail http://127.0.0.1:8080/ping || exit 1\" --health-interval 5s --health-retries 20 " |
|
|
|
|
+ "mlflow/model:1"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testModelsDeployDockerCompose() throws Exception{ |
|
|
|
|
public void testModelsDeployDockerCompose() throws Exception { |
|
|
|
|
MlflowTask mlflowTask = initTask(createModelDeplyDockerComposeParameters()); |
|
|
|
|
Assert.assertEquals(mlflowTask.buildCommand(), |
|
|
|
|
"export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" + |
|
|
|
|
"cp " + mlflowTask.getTemplatePath(MlflowConstants.TEMPLATE_DOCKER_COMPOSE) + |
|
|
|
|
" /tmp/dolphinscheduler_test\n" + |
|
|
|
|
"mlflow models build-docker -m models:/model/1 -n mlflow/model:1 --enable-mlserver\n" + |
|
|
|
|
"docker rm -f ds-mlflow-model-1\n" + |
|
|
|
|
"export DS_TASK_MLFLOW_IMAGE_NAME=mlflow/model:1\n" + |
|
|
|
|
"export DS_TASK_MLFLOW_CONTAINER_NAME=ds-mlflow-model-1\n" + |
|
|
|
|
"export DS_TASK_MLFLOW_DEPLOY_PORT=7000\n" + |
|
|
|
|
"export DS_TASK_MLFLOW_CPU_LIMIT=0.5\n" + |
|
|
|
|
"export DS_TASK_MLFLOW_MEMORY_LIMIT=200m\n" + |
|
|
|
|
"docker-compose up -d"); |
|
|
|
|
"export MLFLOW_TRACKING_URI=http://127.0.0.1:5000\n" |
|
|
|
|
+ "cp " |
|
|
|
|
+ mlflowTask.getTemplatePath(MlflowConstants.TEMPLATE_DOCKER_COMPOSE) |
|
|
|
|
+ " /tmp/dolphinscheduler_test\n" |
|
|
|
|
+ "mlflow models build-docker -m models:/model/1 -n mlflow/model:1 --enable-mlserver\n" |
|
|
|
|
+ "docker rm -f ds-mlflow-model-1\n" |
|
|
|
|
+ "export DS_TASK_MLFLOW_IMAGE_NAME=mlflow/model:1\n" |
|
|
|
|
+ "export DS_TASK_MLFLOW_CONTAINER_NAME=ds-mlflow-model-1\n" |
|
|
|
|
+ "export DS_TASK_MLFLOW_DEPLOY_PORT=7000\n" |
|
|
|
|
+ "export DS_TASK_MLFLOW_CPU_LIMIT=0.5\n" |
|
|
|
|
+ "export DS_TASK_MLFLOW_MEMORY_LIMIT=200m\n" |
|
|
|
|
+ "docker-compose up -d"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private MlflowTask initTask(MlflowParameters mlflowParameters) { |
|
|
|
|