You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by pe...@apache.org on 2022/03/14 15:36:14 UTC

[incubator-linkis] 02/03: #1727 1. linkis-engineplugin-spark - replace old package header "com.webank.wedatasphere.linkis" to "org.apache.linkis"

This is an automated email from the ASF dual-hosted git repository.

peacewong pushed a commit to branch dev-1.1.1
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git

commit 119f8dd4eb00d334573beb4029176fd3ad9c14b2
Author: alexkun <xu...@qq.com>
AuthorDate: Mon Mar 14 22:38:40 2022 +0800

    #1727
    1. linkis-engineplugin-spark - replace old package header "com.webank.wedatasphere.linkis" to "org.apache.linkis"
---
 .../spark/args/SparkScalaPreExecutionHook.scala    | 63 ++++++++++++++++++++++
 .../spark/config/SparkConfiguration.scala          |  6 +++
 2 files changed, 69 insertions(+)

diff --git a/linkis-engineconn-plugins/engineconn-plugins/spark/src/main/scala/org/apache/linkis/engineplugin/spark/args/SparkScalaPreExecutionHook.scala b/linkis-engineconn-plugins/engineconn-plugins/spark/src/main/scala/org/apache/linkis/engineplugin/spark/args/SparkScalaPreExecutionHook.scala
new file mode 100644
index 0000000..e042a77
--- /dev/null
+++ b/linkis-engineconn-plugins/engineconn-plugins/spark/src/main/scala/org/apache/linkis/engineplugin/spark/args/SparkScalaPreExecutionHook.scala
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.engineplugin.spark.args
+
+import org.apache.commons.lang3.StringUtils
+import org.apache.linkis.common.utils.Logging
+import org.apache.linkis.engineconn.computation.executor.execute.EngineExecutionContext
+import org.apache.linkis.engineplugin.spark.common.SparkKind
+import org.apache.linkis.engineplugin.spark.config.SparkConfiguration
+import org.apache.linkis.engineplugin.spark.extension.SparkPreExecutionHook
+import org.apache.linkis.governance.common.paser.CodeType
+import org.apache.linkis.manager.label.entity.engine.RunType
+import org.apache.linkis.manager.label.utils.LabelUtil
+import org.springframework.stereotype.Component
+
+import javax.annotation.PostConstruct
+import scala.collection.JavaConverters.seqAsJavaListConverter
+
+@Component
+class SparkScalaPreExecutionHook extends SparkPreExecutionHook with Logging {
+
+  @PostConstruct
+  private def init(): Unit = {
+    SparkPreExecutionHook.register(this)
+  }
+
+  override def hookName: String = getClass.getSimpleName
+
+  override def callPreExecutionHook(engineExecutionContext: EngineExecutionContext, code: String): String = {
+    if (!SparkConfiguration.ENABLE_REPLACE_PACKAGE_NAME.getValue || StringUtils.isBlank(code)) {
+      return code
+    }
+    val codeTypeLabel = LabelUtil.getCodeTypeLabel(engineExecutionContext.getLabels.toList.asJava)
+    if (null != codeTypeLabel) {
+      codeTypeLabel.getCodeType.toLowerCase() match {
+        case SparkKind.SCALA_LAN | SparkKind.FUNCTION_MDQ_TYPE =>
+          if (!code.contains(SparkConfiguration.REPLACE_PACKAGE_HEADER.getValue)) {
+            return code
+          } else {
+            logger.info(s"Replaced ${SparkConfiguration.REPLACE_PACKAGE_HEADER.getValue} to ${SparkConfiguration.REPLACE_PACKAGE_TO_HEADER}")
+            return code.replaceAll(SparkConfiguration.REPLACE_PACKAGE_HEADER.getValue, SparkConfiguration.REPLACE_PACKAGE_TO_HEADER)
+          }
+        case _ =>
+      }
+    }
+    code
+  }
+}
diff --git a/linkis-engineconn-plugins/engineconn-plugins/spark/src/main/scala/org/apache/linkis/engineplugin/spark/config/SparkConfiguration.scala b/linkis-engineconn-plugins/engineconn-plugins/spark/src/main/scala/org/apache/linkis/engineplugin/spark/config/SparkConfiguration.scala
index 1f9d3dd..893f016 100644
--- a/linkis-engineconn-plugins/engineconn-plugins/spark/src/main/scala/org/apache/linkis/engineplugin/spark/config/SparkConfiguration.scala
+++ b/linkis-engineconn-plugins/engineconn-plugins/spark/src/main/scala/org/apache/linkis/engineplugin/spark/config/SparkConfiguration.scala
@@ -84,6 +84,12 @@ object SparkConfiguration extends Logging {
 
   val PYSPARK_PYTHON3_PATH = CommonVars[String]("pyspark.python3.path", "/appcom/Install/anaconda3/bin/python")
 
+  val ENABLE_REPLACE_PACKAGE_NAME = CommonVars("wds.linkis.spark.engine.scala.replace_package_header.enable", true)
+
+  val REPLACE_PACKAGE_HEADER = CommonVars("wds.linkis.spark.engine.scala.replace_package.header", "com.webank.wedatasphere.linkis")
+
+  val REPLACE_PACKAGE_TO_HEADER = "org.apache.linkis"
+
   private def getMainJarName(): String = {
     val somePath = ClassUtils.jarOfClass(classOf[SparkEngineConnFactory])
     if (somePath.isDefined) {

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org