This is an automated email from the ASF dual-hosted git repository.
peacewong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/linkis.git
The following commit(s) were added to refs/heads/master by this push:
new 5b60fbf08 [bugfix] Append code `val linkisVar=1` to prevent bugs that
do not exit tasks for a long time (#4760)
5b60fbf08 is described below
commit 5b60fbf08a623f206cdafc48d5505968c47661ee
Author: 人生有如两个橘子 <[email protected]>
AuthorDate: Wed Jul 12 21:44:36 2023 +0800
[bugfix] Append code `val linkisVar=1` to prevent bugs that do not exit
tasks for a long time (#4760)
---
.../linkis/governance/common/conf/GovernanceCommonConf.scala | 3 +++
.../apache/linkis/governance/common/paser/CodeParser.scala | 3 +++
.../linkis/governance/common/paser/ScalaCodeParserTest.scala | 11 +++++------
.../linkis/entrance/interceptor/impl/CommentInterceptor.scala | 2 ++
4 files changed, 13 insertions(+), 6 deletions(-)
diff --git
a/linkis-computation-governance/linkis-computation-governance-common/src/main/scala/org/apache/linkis/governance/common/conf/GovernanceCommonConf.scala
b/linkis-computation-governance/linkis-computation-governance-common/src/main/scala/org/apache/linkis/governance/common/conf/GovernanceCommonConf.scala
index ed18c34b1..fc7d1c890 100644
---
a/linkis-computation-governance/linkis-computation-governance-common/src/main/scala/org/apache/linkis/governance/common/conf/GovernanceCommonConf.scala
+++
b/linkis-computation-governance/linkis-computation-governance-common/src/main/scala/org/apache/linkis/governance/common/conf/GovernanceCommonConf.scala
@@ -86,4 +86,7 @@ object GovernanceCommonConf {
CommonVars(envKey, "").getValue
}
+ val SCALA_PARSE_APPEND_CODE_ENABLED =
+ CommonVars("linkis.scala.parse.append.code.enable", true).getValue
+
}
diff --git
a/linkis-computation-governance/linkis-computation-governance-common/src/main/scala/org/apache/linkis/governance/common/paser/CodeParser.scala
b/linkis-computation-governance/linkis-computation-governance-common/src/main/scala/org/apache/linkis/governance/common/paser/CodeParser.scala
index 19bd7f9cd..16f4ce097 100644
---
a/linkis-computation-governance/linkis-computation-governance-common/src/main/scala/org/apache/linkis/governance/common/paser/CodeParser.scala
+++
b/linkis-computation-governance/linkis-computation-governance-common/src/main/scala/org/apache/linkis/governance/common/paser/CodeParser.scala
@@ -109,6 +109,9 @@ class ScalaCodeParser extends SingleCodeParser with Logging
{
case _ =>
}
if (statementBuffer.nonEmpty)
codeBuffer.append(statementBuffer.mkString("\n"))
+
+ // Append code `val linkisVar=1` in ends to prevent bugs that do not exit
tasks for a long time
+ if (GovernanceCommonConf.SCALA_PARSE_APPEND_CODE_ENABLED)
codeBuffer.append("val linkisVar=1")
codeBuffer.toArray
}
diff --git
a/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/paser/ScalaCodeParserTest.scala
b/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/paser/ScalaCodeParserTest.scala
index 3cfe787f6..db7045bae 100644
---
a/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/paser/ScalaCodeParserTest.scala
+++
b/linkis-computation-governance/linkis-computation-governance-common/src/test/scala/org/apache/linkis/governance/common/paser/ScalaCodeParserTest.scala
@@ -29,8 +29,7 @@ class ScalaCodeParserTest {
"val codeBuffer = new ArrayBuffer[String]()\n val statementBuffer =
new ArrayBuffer[String]()"
val scalaCodeParser = new ScalaCodeParser
val array = scalaCodeParser.parse(scalaCode)
- Assertions.assertTrue(array.size == 1)
-
+ Assertions.assertTrue(array.length == 2)
}
@Test
@@ -41,7 +40,7 @@ class ScalaCodeParserTest {
" def addInt( a:Int, b:Int )\n var sum:Int = 0\n sum = a +
b\n return sum\n }"
val scalaCodeParser = new ScalaCodeParser
val array = scalaCodeParser.parse(abnormalCode)
- Assertions.assertTrue(array.length == 1)
+ Assertions.assertTrue(array.length == 2)
}
@@ -54,7 +53,7 @@ class ScalaCodeParserTest {
val scalaCodeParser = new ScalaCodeParser
val array = scalaCodeParser.parse(importCode)
- Assertions.assertTrue(array.length == 2)
+ Assertions.assertTrue(array.length == 3)
}
@@ -68,7 +67,7 @@ class ScalaCodeParserTest {
val scalaCodeParser = new ScalaCodeParser
val arrayResult1 = scalaCodeParser.parse(specialCodeExp1)
- Assertions.assertTrue(arrayResult1.length == 2)
+ Assertions.assertTrue(arrayResult1.length == 3)
val specialCodeExp2 =
" @BeanProperty\n var id: Long = _\n @BeanProperty\n var status: Int
= 0\n " +
@@ -79,7 +78,7 @@ class ScalaCodeParserTest {
".append(data, that.data)\n .isEquals\n }"
val arrayResult2 = scalaCodeParser.parse(specialCodeExp2)
- Assertions.assertTrue(arrayResult2.length == 1)
+ Assertions.assertTrue(arrayResult2.length == 2)
}
diff --git
a/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/CommentInterceptor.scala
b/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/CommentInterceptor.scala
index bbb904c6a..627ab82b8 100644
---
a/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/CommentInterceptor.scala
+++
b/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/CommentInterceptor.scala
@@ -18,6 +18,7 @@
package org.apache.linkis.entrance.interceptor.impl
import org.apache.linkis.common.utils.CodeAndRunTypeUtils
+import org.apache.linkis.entrance.conf.EntranceConfiguration
import org.apache.linkis.entrance.interceptor.EntranceInterceptor
import org.apache.linkis.governance.common.entity.job.JobRequest
import org.apache.linkis.manager.label.utils.LabelUtil
@@ -103,6 +104,7 @@ object ScalaCommentHelper extends CommentHelper {
private val scalaCommentPattern: String =
"(?ms)([\"'](?:|[^'])*['\"])|//.*?$|/\\*.*?\\*/"
override def dealComment(code: String): String = code
+
}
object CommentMain {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]