|
@@ -20,6 +20,7 @@ package org.apache.dolphinscheduler.plugin.task.spark;
|
|
|
import java.util.Collections;
|
|
|
|
|
|
import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
|
|
|
+import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo;
|
|
|
import org.apache.dolphinscheduler.spi.utils.JSONUtils;
|
|
|
|
|
|
import org.junit.Assert;
|
|
@@ -42,8 +43,8 @@ import static org.powermock.api.mockito.PowerMockito.when;
|
|
|
public class SparkTaskTest {
|
|
|
|
|
|
@Test
|
|
|
- public void testBuildCommandWithSparkSql() throws Exception {
|
|
|
- String parameters = buildSparkParametersWithSparkSql();
|
|
|
+ public void testBuildCommandWithSpark2Sql() throws Exception {
|
|
|
+ String parameters = buildSparkParametersWithSparkSql(ProgramType.SQL, "SPARK2");
|
|
|
TaskExecutionContext taskExecutionContext = PowerMockito.mock(TaskExecutionContext.class);
|
|
|
when(taskExecutionContext.getTaskParams()).thenReturn(parameters);
|
|
|
when(taskExecutionContext.getExecutePath()).thenReturn("/tmp");
|
|
@@ -63,22 +64,108 @@ public class SparkTaskTest {
|
|
|
"--name sparksql " +
|
|
|
"-f /tmp/5536_node.sql");
|
|
|
}
|
|
|
+ @Test
|
|
|
+ public void testBuildCommandWithSpark1Sql() throws Exception {
|
|
|
+ String parameters = buildSparkParametersWithSparkSql(ProgramType.SQL, "SPARK1");
|
|
|
+ TaskExecutionContext taskExecutionContext = PowerMockito.mock(TaskExecutionContext.class);
|
|
|
+ when(taskExecutionContext.getTaskParams()).thenReturn(parameters);
|
|
|
+ when(taskExecutionContext.getExecutePath()).thenReturn("/tmp");
|
|
|
+ when(taskExecutionContext.getTaskAppId()).thenReturn("5536");
|
|
|
+ SparkTask sparkTask = spy(new SparkTask(taskExecutionContext));
|
|
|
+ sparkTask.init();
|
|
|
+ Assert.assertEquals(sparkTask.buildCommand(),
|
|
|
+ "${SPARK_HOME1}/bin/spark-sql " +
|
|
|
+ "--master yarn " +
|
|
|
+ "--deploy-mode client " +
|
|
|
+ "--driver-cores 1 " +
|
|
|
+ "--driver-memory 512M " +
|
|
|
+ "--num-executors 2 " +
|
|
|
+ "--executor-cores 2 " +
|
|
|
+ "--executor-memory 1G " +
|
|
|
+ "--name sparksql " +
|
|
|
+ "-f /tmp/5536_node.sql");
|
|
|
+ }
|
|
|
|
|
|
- private String buildSparkParametersWithSparkSql() {
|
|
|
+ @Test
|
|
|
+ public void testBuildCommandWithSpark2Submit() throws Exception {
|
|
|
+ String parameters = buildSparkParametersWithSparkSubmit(ProgramType.SCALA, "SPARK2");
|
|
|
+ TaskExecutionContext taskExecutionContext = PowerMockito.mock(TaskExecutionContext.class);
|
|
|
+ when(taskExecutionContext.getTaskParams()).thenReturn(parameters);
|
|
|
+ when(taskExecutionContext.getExecutePath()).thenReturn("/tmp");
|
|
|
+ when(taskExecutionContext.getTaskAppId()).thenReturn("5536");
|
|
|
+ SparkTask sparkTask = spy(new SparkTask(taskExecutionContext));
|
|
|
+ sparkTask.init();
|
|
|
+ Assert.assertEquals(sparkTask.buildCommand(),
|
|
|
+ "${SPARK_HOME2}/bin/spark-submit " +
|
|
|
+ "--master yarn " +
|
|
|
+ "--deploy-mode client " +
|
|
|
+ "--class org.apache.dolphinscheduler.plugin.task.spark.SparkTaskTest " +
|
|
|
+ "--driver-cores 1 " +
|
|
|
+ "--driver-memory 512M " +
|
|
|
+ "--num-executors 2 " +
|
|
|
+ "--executor-cores 2 " +
|
|
|
+ "--executor-memory 1G " +
|
|
|
+ "--name spark " +
|
|
|
+ "lib/dolphinscheduler-task-spark.jar");
|
|
|
+ }
|
|
|
+ @Test
|
|
|
+ public void testBuildCommandWithSpark1Submit() throws Exception {
|
|
|
+ String parameters = buildSparkParametersWithSparkSubmit(ProgramType.SCALA, "SPARK1");
|
|
|
+ TaskExecutionContext taskExecutionContext = PowerMockito.mock(TaskExecutionContext.class);
|
|
|
+ when(taskExecutionContext.getTaskParams()).thenReturn(parameters);
|
|
|
+ when(taskExecutionContext.getExecutePath()).thenReturn("/tmp");
|
|
|
+ when(taskExecutionContext.getTaskAppId()).thenReturn("5536");
|
|
|
+ SparkTask sparkTask = spy(new SparkTask(taskExecutionContext));
|
|
|
+ sparkTask.init();
|
|
|
+ Assert.assertEquals(sparkTask.buildCommand(),
|
|
|
+ "${SPARK_HOME1}/bin/spark-submit " +
|
|
|
+ "--master yarn " +
|
|
|
+ "--deploy-mode client " +
|
|
|
+ "--class org.apache.dolphinscheduler.plugin.task.spark.SparkTaskTest " +
|
|
|
+ "--driver-cores 1 " +
|
|
|
+ "--driver-memory 512M " +
|
|
|
+ "--num-executors 2 " +
|
|
|
+ "--executor-cores 2 " +
|
|
|
+ "--executor-memory 1G " +
|
|
|
+ "--name spark " +
|
|
|
+ "lib/dolphinscheduler-task-spark.jar");
|
|
|
+ }
|
|
|
+ private String buildSparkParametersWithSparkSql(ProgramType programType, String sparkVersion) {
|
|
|
SparkParameters sparkParameters = new SparkParameters();
|
|
|
sparkParameters.setLocalParams(Collections.emptyList());
|
|
|
sparkParameters.setRawScript("selcet 11111;");
|
|
|
- sparkParameters.setProgramType(ProgramType.SQL);
|
|
|
+ sparkParameters.setProgramType(programType);
|
|
|
sparkParameters.setMainClass("");
|
|
|
sparkParameters.setDeployMode("client");
|
|
|
sparkParameters.setAppName("sparksql");
|
|
|
sparkParameters.setOthers("");
|
|
|
- sparkParameters.setSparkVersion("SPARK2");
|
|
|
+ sparkParameters.setSparkVersion(sparkVersion);
|
|
|
+ sparkParameters.setDriverCores(1);
|
|
|
+ sparkParameters.setDriverMemory("512M");
|
|
|
+ sparkParameters.setNumExecutors(2);
|
|
|
+ sparkParameters.setExecutorMemory("1G");
|
|
|
+ sparkParameters.setExecutorCores(2);
|
|
|
+ return JSONUtils.toJsonString(sparkParameters);
|
|
|
+ }
|
|
|
+ private String buildSparkParametersWithSparkSubmit(ProgramType programType, String sparkVersion) {
|
|
|
+ SparkParameters sparkParameters = new SparkParameters();
|
|
|
+ sparkParameters.setLocalParams(Collections.emptyList());
|
|
|
+ sparkParameters.setProgramType(programType);
|
|
|
+ sparkParameters.setMainClass("org.apache.dolphinscheduler.plugin.task.spark.SparkTaskTest");
|
|
|
+ sparkParameters.setDeployMode("client");
|
|
|
+ sparkParameters.setAppName("spark");
|
|
|
+ sparkParameters.setOthers("");
|
|
|
+ sparkParameters.setSparkVersion(sparkVersion);
|
|
|
sparkParameters.setDriverCores(1);
|
|
|
sparkParameters.setDriverMemory("512M");
|
|
|
sparkParameters.setNumExecutors(2);
|
|
|
sparkParameters.setExecutorMemory("1G");
|
|
|
sparkParameters.setExecutorCores(2);
|
|
|
+ ResourceInfo resourceInfo = new ResourceInfo();
|
|
|
+ resourceInfo.setId(1);
|
|
|
+ resourceInfo.setRes("dolphinscheduler-task-spark.jar");
|
|
|
+ resourceInfo.setResourceName("/lib/dolphinscheduler-task-spark.jar");
|
|
|
+ sparkParameters.setMainJar(resourceInfo);
|
|
|
return JSONUtils.toJsonString(sparkParameters);
|
|
|
}
|
|
|
|