Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix repl get task result bug #5036

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package org.apache.linkis.engineplugin.repl.executor;

import org.apache.linkis.common.io.MetaData;
import org.apache.linkis.common.io.Record;
import org.apache.linkis.common.io.resultset.ResultSetWriter;
import org.apache.linkis.common.log.LogUtils;
import org.apache.linkis.common.utils.OverloadUtils;
import org.apache.linkis.engineconn.computation.executor.entity.EngineConnTask;
Expand All @@ -36,15 +39,23 @@
import org.apache.linkis.manager.label.entity.engine.UserCreatorLabel;
import org.apache.linkis.protocol.engine.JobProgressInfo;
import org.apache.linkis.rpc.Sender;
import org.apache.linkis.scheduler.executer.ErrorExecuteResponse;
import org.apache.linkis.scheduler.executer.ExecuteResponse;
import org.apache.linkis.scheduler.executer.SuccessExecuteResponse;
import org.apache.linkis.storage.LineMetaData;
import org.apache.linkis.storage.LineRecord;
import org.apache.linkis.storage.resultset.ResultSetFactory;

import org.apache.commons.collections4.MapUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;

import org.springframework.util.CollectionUtils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -132,14 +143,33 @@ public ExecuteResponse executeLine(EngineExecutionContext engineExecutorContext,

threadCache.put(taskId, Thread.currentThread());

ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024);
PrintStream cacheStream = new PrintStream(outputStream);
PrintStream oldStream = System.out;
System.setOut(cacheStream);

try {
replAdapter.executorCode(realCode, classpathDir, methodName);
} catch (Exception e) {
String errorMessage = ExceptionUtils.getStackTrace(e);
logger.error("Repl engine execute failed : {}", errorMessage);
engineExecutorContext.appendStdout(LogUtils.generateERROR(errorMessage));
return new ErrorExecuteResponse(errorMessage, null);
}

String message = outputStream.toString();
System.setOut(oldStream);
engineExecutorContext.appendStdout(message);
ResultSetWriter<? extends MetaData, ? extends Record> resultSetWriter =
engineExecutorContext.createResultSetWriter(ResultSetFactory.TEXT_TYPE);
try {
resultSetWriter.addMetaData(new LineMetaData());
resultSetWriter.addRecord(new LineRecord(message));
} catch (IOException e) {
logger.error("Failed to get the task result");
} finally {
IOUtils.closeQuietly(resultSetWriter);
}
return new SuccessExecuteResponse();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class JavaReplCompiler {
Pattern.compile("\\s+implements\\s+([\\w\\.]+)\\s*\\{\n");

private static final Pattern METHODS_PATTERN =
Pattern.compile("\n(private|public|protected)\\s+");
Pattern.compile("(?<=\\})\\s+(private|public|protected)\\s+");

private static final Pattern FIELD_PATTERN = Pattern.compile("[^\n]+=[^\n]+;");

Expand Down
37 changes: 37 additions & 0 deletions linkis-engineconn-plugins/repl/src/main/resources/repl-ec.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,43 @@ import org.apache.commons.lang3.StringUtils;
}
```

#### 1.3. Multiple methods

```text
import org.apache.commons.lang3.StringUtils;

public void sayHello() {
System.out.println("hello");
System.out.println(StringUtils.isEmpty("hello"));
}
public void sayHi() {
System.out.println("hi");
System.out.println(StringUtils.isEmpty("hi"));
}
```

```json
{
"executionContent":{
"code":"import org.apache.commons.lang3.StringUtils;\n\n public void sayHello() {\n System.out.println(\"hello\");\n System.out.println(StringUtils.isEmpty(\"hello\"));\n }\n public void sayHi() {\n System.out.println(\"hi\");\n System.out.println(StringUtils.isEmpty(\"hi\"));\n }",
"runType":"repl"
},
"params":{
"configuration":{
"runtime":{
"linkis.repl.type":"java",
"linkis.repl.method.name":"sayHi"
}
}
},
"labels":{
"engineType":"repl-1",
"userCreator":"linkis-IDE"
}
}
```


### 2. Submitting scala tasks with Restful API

```text
Expand Down
Loading