forked from byzer-org/byzer-lang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46cf151
commit 471e45c
Showing
6 changed files
with
114 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# | ||
# 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. | ||
# | ||
# Set everything to be logged to the console | ||
log4j.rootCategory=INFO, console,file | ||
log4j.appender.console=org.apache.log4j.ConsoleAppender | ||
log4j.appender.console.target=System.err | ||
log4j.appender.console.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{1}: %m%n | ||
|
||
log4j.appender.file=org.apache.log4j.rolling.RollingFileAppender | ||
log4j.appender.file.File=/tmp/__mlsql__/logs/mlsql_engine.log | ||
log4j.appender.file.rollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicy | ||
log4j.appender.file.rollingPolicy.fileNamePattern=/tmp/__mlsql__/logs/mlsql_engine.%d.gz | ||
log4j.appender.file.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.file.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{1}: %m%n | ||
log4j.appender.file.MaxBackupIndex=5 | ||
# Set the default spark-shell log level to WARN. When running the spark-shell, the | ||
# log level for this class is used to overwrite the root logger's log level, so that | ||
# the user can have different defaults for the shell and regular Spark apps. | ||
log4j.logger.org.apache.spark.repl.Main=WARN | ||
#log4j.logger.org.apache.spark=WARN | ||
# Settings to quiet third party logs that are too verbose | ||
log4j.logger.org.spark_project.jetty=WARN | ||
log4j.logger.org.spark_project.jetty.util.component.AbstractLifeCycle=ERROR | ||
log4j.logger.org.apache.spark.repl.SparkIMain$exprTyper=INFO | ||
log4j.logger.org.apache.spark.repl.SparkILoop$SparkILoopInterpreter=INFO | ||
log4j.logger.org.apache.parquet=ERROR | ||
log4j.logger.parquet=ERROR | ||
# SPARK-9183: Settings to avoid annoying messages when looking up nonexistent UDFs in SparkSQL with Hive support | ||
log4j.logger.org.apache.hadoop.hive.metastore.RetryingHMSHandler=FATAL | ||
log4j.logger.org.apache.hadoop.hive.ql.exec.FunctionRegistry=ERROR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 27 additions & 48 deletions
75
streamingpro-mlsql/src/main/java/streaming/core/datasource/DataSourceRepository.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,59 @@ | ||
package streaming.core.datasource | ||
|
||
import java.io.File | ||
import java.net.{URL, URLClassLoader, URLEncoder} | ||
import java.net.{URL, URLClassLoader} | ||
import java.nio.file.Files | ||
|
||
import net.csdn.ServiceFramwork | ||
import net.csdn.common.path.Url | ||
import net.csdn.modules.http.RestRequest | ||
import net.csdn.modules.transport.HttpTransportService | ||
import net.sf.json.{JSONArray, JSONObject} | ||
import org.apache.http.client.fluent.Request | ||
import org.apache.http.client.fluent.{Form, Request} | ||
import streaming.common.{JSONTool, PathFun} | ||
import streaming.dsl.ScriptSQLExec | ||
|
||
import scala.collection.JavaConverters._ | ||
import streaming.log.{Logging, WowLog} | ||
|
||
/** | ||
* 2019-01-14 WilliamZhu([email protected]) | ||
*/ | ||
class DataSourceRepository(url: String) { | ||
def httpClient = ServiceFramwork.injector.getInstance[HttpTransportService](classOf[HttpTransportService]) | ||
class DataSourceRepository(url: String) extends Logging with WowLog { | ||
|
||
|
||
//"http://respository.datasource.mlsql.tech" | ||
def getOrDefaultUrl = { | ||
if (url == null || url.isEmpty) { | ||
val context = ScriptSQLExec.contextGetOrForTest() | ||
require(context.userDefinedParam.contains("__datasource_repository_url__"), "context.__datasource_repository_url__ should be configure if you want use connect DataSourceRepository") | ||
context.userDefinedParam.get("__datasource_repository_url__") | ||
context.userDefinedParam.getOrElse("__datasource_repository_url__", "http://datasource.repository.mlsql.tech") | ||
} else { | ||
url | ||
} | ||
} | ||
|
||
def listCommand = { | ||
val res = httpClient.http(new Url(s"${getOrDefaultUrl}/jar/manager/source/mapper"), "{}", RestRequest.Method.POST) | ||
|
||
JSONObject.fromObject(res.getContent).asScala.flatMap { kv => | ||
kv._2.asInstanceOf[JSONArray].asScala.map { _item => | ||
val item = _item.asInstanceOf[JSONObject] | ||
item.put("name", kv._1) | ||
val temp = new JSONArray() | ||
temp.add(item) | ||
val versionList = versionCommand(temp) | ||
val versionArray = new JSONArray | ||
versionList.foreach { v => versionArray.add(v) } | ||
item.put("versions", versionArray) | ||
item.toString | ||
} | ||
}.toSeq | ||
def versionCommand(name: String, sparkV: String) = { | ||
val res = Request.Post(s"${getOrDefaultUrl}/repo/versions").connectTimeout(60 * 1000) | ||
.socketTimeout(10 * 60 * 1000).bodyForm(Form.form().add("name", name). | ||
add("scalaV", "2.11").add("sparkV", sparkV).build() | ||
).execute().returnContent().asString() | ||
JSONTool.parseJson[List[String]](res) | ||
} | ||
|
||
def versionCommand(items: JSONArray) = { | ||
val request = new JSONArray | ||
items.asScala.map { _item => | ||
val item = _item.asInstanceOf[JSONObject] | ||
val json = new JSONObject() | ||
json.put("jarname", item.getString("groupid") + "/" + item.getString("artifactId")) | ||
request.add(json) | ||
} | ||
|
||
val res = httpClient.http(new Url(s"${getOrDefaultUrl}/jar/manager/versions"), request.toString(), RestRequest.Method.POST) | ||
JSONArray.fromObject(res.getContent).get(0).asInstanceOf[JSONObject].asScala.map { kv => | ||
val version = kv._1.asInstanceOf[String].split("/").last | ||
version | ||
}.toSeq | ||
def list() = { | ||
val res = Request.Get(s"${getOrDefaultUrl}/repo/list").connectTimeout(60 * 1000) | ||
.socketTimeout(10 * 60 * 1000).execute().returnContent().asString() | ||
JSONTool.parseJson[List[String]](res) | ||
} | ||
|
||
def addCommand(format: String, groupid: String, artifactId: String, version: String) = { | ||
val url = s"http://central.maven.org/maven2/${groupid.replaceAll("\\.", "/")}/${artifactId}/${version}" | ||
def addCommand(name: String, version: String, sparkV: String, scalaV: String = "2.11") = { | ||
|
||
// fileName format e.g es, mongodb | ||
val finalUrl = s"${getOrDefaultUrl}/jar/manager/http?fileName=${URLEncoder.encode(artifactId, "utf-8")}&url=${URLEncoder.encode(url, "utf-8")}" | ||
val inputStream = Request.Get(finalUrl).execute().returnContent().asStream() | ||
logInfo(s"downloading ${name} from ${getOrDefaultUrl}") | ||
val response = Request.Post(s"${getOrDefaultUrl}/repo/download").connectTimeout(60 * 1000) | ||
.socketTimeout(10 * 60 * 1000).bodyForm(Form.form().add("name", name). | ||
add("scalaV", scalaV).add("sparkV", sparkV).add("version", version).build()).execute().returnResponse() | ||
var fieldValue = response.getFirstHeader("Content-Disposition").getValue | ||
val inputStream = response.getEntity.getContent | ||
fieldValue = fieldValue.substring(fieldValue.indexOf("filename=\"") + 10, fieldValue.length() - 1); | ||
val tmpLocation = new File("./dataousrce_upjars") | ||
if (!tmpLocation.exists()) { | ||
tmpLocation.mkdirs() | ||
} | ||
val jarFile = new File(tmpLocation.getPath + s"/${artifactId}-${version}.jar") | ||
val jarFile = new File(PathFun(tmpLocation.getPath).add(fieldValue).toPath) | ||
if (!jarFile.exists()) { | ||
Files.copy(inputStream, jarFile.toPath) | ||
} else { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters