Skip to content

Commit

Permalink
Merge pull request #923 from FireFoxAhri/dev-1.1.0-917
Browse files Browse the repository at this point in the history
fix jdbc url is not configured
  • Loading branch information
leeebai authored Nov 10, 2021
2 parents 8fadfa8 + 049871d commit 5a7802d
Showing 1 changed file with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ import org.apache.linkis.manager.engineplugin.jdbc.ConnectionManager
import org.apache.linkis.manager.engineplugin.jdbc.conf.JDBCConfiguration
import org.apache.linkis.manager.label.entity.Label
import org.apache.linkis.protocol.engine.JobProgressInfo
import org.apache.linkis.rpc.Sender
import org.apache.linkis.rpc.{RPCMapCache, Sender}
import org.apache.linkis.scheduler.executer.{AliasOutputExecuteResponse, ErrorExecuteResponse, ExecuteResponse, SuccessExecuteResponse}
import org.apache.linkis.storage.domain.{Column, DataType}
import org.apache.linkis.storage.resultset.ResultSetFactory
import org.apache.linkis.storage.resultset.table.{TableMetaData, TableRecord}
import org.apache.commons.io.IOUtils
import org.apache.linkis.common.conf.Configuration
import org.apache.linkis.governance.common.protocol.conf.{RequestQueryEngineConfig, ResponseQueryConfig}
import org.apache.linkis.manager.label.entity.engine.{EngineTypeLabel, UserCreatorLabel}
import org.apache.linkis.protocol.CacheableProtocol
import org.springframework.util.CollectionUtils

import scala.collection.JavaConversions._
Expand All @@ -51,6 +55,15 @@ class JDBCEngineConnExecutor(override val outputPrintLimit: Int, val id: Int) ex
override def executeLine(engineExecutorContext: EngineExecutionContext, code: String): ExecuteResponse = {
val realCode = code.trim()
val properties = engineExecutorContext.getProperties.asInstanceOf[util.Map[String, String]]

if (properties.get("jdbc.url") == null) {
info(s"jdbc url is empty, adding now...")
val globalConfig = Utils.tryAndWarn(JDBCEngineConfig.getCacheMap(engineExecutorContext.getLabels))
properties.put("jdbc.url", globalConfig.get("wds.linkis.jdbc.connect.url"))
properties.put("jdbc.username", globalConfig.get("wds.linkis.jdbc.username"))
properties.put("jdbc.password", globalConfig.get("wds.linkis.jdbc.password"))
}

info(s"jdbc client begins to run jdbc code:\n ${realCode.trim}")
connection = connectionManager.getConnection(properties)
statement = connection.createStatement()
Expand Down Expand Up @@ -177,3 +190,16 @@ class JDBCEngineConnExecutor(override val outputPrintLimit: Int, val id: Int) ex
}
}


object JDBCEngineConfig extends RPCMapCache[Array[Label[_]], String, String](Configuration.CLOUD_CONSOLE_CONFIGURATION_SPRING_APPLICATION_NAME.getValue) {

override protected def createRequest(labels: Array[Label[_]]): CacheableProtocol = {
val userCreatorLabel = labels.find(_.isInstanceOf[UserCreatorLabel]).get.asInstanceOf[UserCreatorLabel]
val engineTypeLabel = labels.find(_.isInstanceOf[EngineTypeLabel]).get.asInstanceOf[EngineTypeLabel]
RequestQueryEngineConfig(userCreatorLabel, engineTypeLabel)
}

override protected def createMap(any: Any): util.Map[String, String] = any match {
case response: ResponseQueryConfig => response.getKeyAndValue
}
}

0 comments on commit 5a7802d

Please sign in to comment.