Mlsql内部资源调度读取opentsdb数据信息代码

package com.redoop.mlsql
import java.net.URLEncoder
import java.nio.charset.Charset
import net.sf.json.JSONObject
import org.apache.http.client.fluent.{Form, Request}
import tech.mlsql.utils.PathFun
import com.google.gson.{JsonObject, JsonParser}
object RunScriptCommand {
var consoleUrl = s"http://192.168.72.128:9002"
var auth_secret = s"mlsql"
var owner = s"[email protected]"

def main(args: Array[String]): Unit = {
var scriptfile = args(0)
var start = args(1)
var end = args(2)

var id = getScriptId(scriptfile)

var scriptFileGetUrl = PathFun(consoleUrl).add(s"/api_v1/script_file/get?id=${id}").toPath
val script = Request.Get(scriptFileGetUrl)
.connectTimeout(60 * 1000)
.socketTimeout(10 * 60 * 1000).addHeader("access-token", auth_secret)
.execute().returnContent().asString()

val obj = JSONObject.fromObject(script)
val scriptContent = obj.getString("content")
//val owner = obj.getString("owner")
// 赋值
var newScriptContent = scriptContent.replace("&start",start).replace("&end",end)

var runScriptUrl = PathFun(consoleUrl).add(s"/api_v1/run/script").toPath
val res = Request.Post(runScriptUrl).
connectTimeout(60 * 1000).socketTimeout(12 * 60 * 60 * 1000).
addHeader("access-token", auth_secret).
bodyForm(Form.form().add("sql", newScriptContent).
add("owner", owner).build(), Charset.forName("utf8"))
.execute().returnContent().asString()
println(res)
val address = res
val str = address.replaceAll("\\["," ").replaceAll("\\]","")

println(str)
println(gson(str,"end"))

}

def getScriptId(path: String) = {
def encode(str: String) = {
URLEncoder.encode(str, "utf-8")
}

var url = PathFun(consoleUrl).add(s"/api_v1/script_file/path/id?path=${encode(path)}&owner=${encode(owner)}").toPath
println(url)
val script = Request.Get(url)
.connectTimeout(60 * 1000)
.socketTimeout(10 * 60 * 1000).addHeader("access-token", auth_secret)
.execute().returnContent().asString()
script.toInt
}
//
def gson(str: String,name:String) ={
val json = new JsonParser()
val obj = json.parse(str).asInstanceOf[JsonObject]
obj.get(name)

}



}




xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0

allwefantasy
mlsql-api-console
1.5.0-SNAPSHOT


UTF-8
2.11.8
2.11
2.11.0-M3
2.0.1




shade



org.apache.maven.plugins
maven-shade-plugin
2.4.3



*:*

META-INF/*.SF
META-INF/*.DSA
META-INF/*.RSA






package

shade











org.scala-lang
scala-compiler
${scala.version}



org.scala-lang
scala-library
${scala.version}


org.scalatest
scalatest_2.11
3.0.3
test



org.jooq
jooq
3.11.5


org.jooq
jooq-meta
3.11.5


org.jooq
jooq-codegen
3.11.5



tech.mlsql
streamingpro-api
1.2.0



commons-fileupload
commons-fileupload
1.4


org.apache.commons
commons-compress
1.18



net.liftweb
lift-json_2.11
3.3.0



net.liftweb
lift-json-ext_2.11
3.3.0



net.csdn
serviceframework-jetty-9-server_${scala.binary.version}
${serviceframework.version}


net.csdn
serviceframework-orm_${scala.binary.version}
${serviceframework.version}


commons-pool
commons-pool
1.6


org.json4s
json4s-jackson_2.11
3.6.1



net.java.dev.jna
jna-platform
5.3.1



net.csdn
serviceframework-web_2.11
${serviceframework.version}


org.slf4j
slf4j-api


org.slf4j
jcl-over-slf4j


org.slf4j
slf4j-log4j12


org.slf4j
jcl-over-slf4j


ch.qos.logback
logback-classic


ch.qos.logback
logback-core




org.apache.thrift
libthrift


com.101tec
zkclient


com.alibaba
dubbo


junit
junit


org.scala-lang
jline



com.google.guava
guava


org.apache.httpcomponents
httpclient





com.aliyun
aliyun-java-sdk-core
3.7.0


repository.com.google.code.gson
gson
2.2.4


com.aliyun
aliyun-java-sdk-ecs
4.11.0








org.apache.maven.plugins
maven-surefire-plugin
2.8.1


**/*.java
**/*.scala




org.apache.maven.plugins
maven-compiler-plugin
2.3.2

1.8
1.8
-g
true
UTF-8




org.scala-tools
maven-scala-plugin
2.15.2



-g:vars


true



scala-compile-first
process-resources

compile



scala-test-compile
process-test-resources

testCompile






maven-source-plugin
2.1

true



compile

jar










你可能感兴趣的:(Mlsql内部资源调度读取opentsdb数据信息代码)