Skip to content

Commit

Permalink
Remove wrapper class and resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
EricGao888 committed Sep 19, 2022
1 parent 6eafdd2 commit c968f2f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.dolphinscheduler.plugin.task.api.parser.ParameterUtils;
import org.apache.dolphinscheduler.spi.utils.DateUtils;
import org.apache.dolphinscheduler.spi.utils.JSONUtils;
import org.apache.dolphinscheduler.spi.utils.PropertyUtils;
import org.apache.dolphinscheduler.spi.utils.StringUtils;

import java.io.IOException;
Expand All @@ -48,8 +49,6 @@ public class JupyterTask extends AbstractRemoteTask {

private ShellCommandExecutor shellCommandExecutor;

private JupyterPropertyReader jupyterPropertyReader;

public JupyterTask(TaskExecutionContext taskExecutionContext) {
super(taskExecutionContext);
this.taskExecutionContext = taskExecutionContext;
Expand All @@ -58,19 +57,13 @@ public JupyterTask(TaskExecutionContext taskExecutionContext) {
logger);
}

protected JupyterPropertyReader proxyJupyterPropertyReaderCreator() {
return new JupyterPropertyReader();
}

@Override
public List<String> getApplicationIds() throws TaskException {
return Collections.emptyList();
}

@Override
public void init() {
this.jupyterPropertyReader = proxyJupyterPropertyReaderCreator();

logger.info("jupyter task params {}", taskExecutionContext.getTaskParams());

jupyterParameters = JSONUtils.parseObject(taskExecutionContext.getTaskParams(), JupyterParameters.class);
Expand Down Expand Up @@ -121,7 +114,7 @@ public void trackApplicationStatus() throws TaskException {
protected String buildCommand() throws IOException {

List<String> args = new ArrayList<>();
final String condaPath = jupyterPropertyReader.readProperty(TaskConstants.CONDA_PATH);
final String condaPath = readCondaPath();
final String timestamp = DateUtils.getTimestampString();
String condaEnvName = jupyterParameters.getCondaEnvName();
if (condaEnvName.endsWith(JupyterConstants.TXT_SUFFIX)) {
Expand Down Expand Up @@ -164,6 +157,10 @@ protected String buildCommand() throws IOException {
return command;
}

protected String readCondaPath() {
return PropertyUtils.getString(TaskConstants.CONDA_PATH);
}

protected List<String> populateJupyterParameterization() throws IOException {
List<String> args = new ArrayList<>();
String parameters = jupyterParameters.getParameters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.dolphinscheduler.plugin.task.jupyter;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -118,10 +117,8 @@ public void jupyterTaskUsePipRequirements() throws Exception {
private JupyterTask prepareJupyterTaskForTest(final String jupyterTaskParameters) {
TaskExecutionContext taskExecutionContext = Mockito.mock(TaskExecutionContext.class);
when(taskExecutionContext.getTaskParams()).thenReturn(jupyterTaskParameters);
JupyterPropertyReader mockedJupyterPropertyReader = Mockito.mock(JupyterPropertyReader.class);
JupyterTask jupyterTask = spy(new JupyterTask(taskExecutionContext));
doReturn(mockedJupyterPropertyReader).when(jupyterTask).proxyJupyterPropertyReaderCreator();
doReturn("/opt/anaconda3/etc/profile.d/conda.sh").when(mockedJupyterPropertyReader).readProperty(any());
doReturn("/opt/anaconda3/etc/profile.d/conda.sh").when(jupyterTask).readCondaPath();
return jupyterTask;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

import com.fasterxml.jackson.databind.ObjectMapper;

import org.apache.dolphinscheduler.plugin.task.api.TaskCallBack;
import org.apache.dolphinscheduler.plugin.task.api.TaskException;
import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
Expand Down Expand Up @@ -123,8 +121,8 @@ public void testHandleWithParagraphExecutionError() throws Exception {

@Test(expected = TaskException.class)
public void testHandleWithParagraphExecutionException() throws Exception {
when(this.zClient.executeParagraph(any(), any(), any(Map.class))).
thenThrow(new TaskException("Something wrong happens from zeppelin side"));
when(this.zClient.executeParagraph(any(), any(), any(Map.class)))
.thenThrow(new TaskException("Something wrong happens from zeppelin side"));
this.zeppelinTask.handle(taskCallBack);

Mockito.verify(this.zClient).executeParagraph(MOCK_NOTE_ID,
Expand All @@ -148,7 +146,6 @@ public void testHandleWithNoteExecutionSuccess() throws Exception {
doReturn(this.zClient).when(this.zeppelinTask).getZeppelinClient();
when(this.zClient.executeNote(any(), any(Map.class))).thenReturn(this.noteResult);
this.zeppelinTask.init();
when(this.paragraphResult.getStatus()).thenReturn(Status.FINISHED);
this.zeppelinTask.handle(taskCallBack);

Mockito.verify(this.zClient).executeNote(MOCK_NOTE_ID,
Expand Down
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
<spring.boot.version>2.6.1</spring.boot.version>
<java.version>1.8</java.version>
<junit.version>4.13.1</junit.version>
<mockito.version>3.9.0</mockito.version>
<spotbugs.version>3.1.12</spotbugs.version>
<maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
<maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version>
Expand Down

0 comments on commit c968f2f

Please sign in to comment.