fix bug: Execute Python Stop
This commit is contained in:
parent
d2d0bdf67d
commit
5bb7d64efd
|
@ -5,13 +5,14 @@
|
||||||
"stops":[
|
"stops":[
|
||||||
{
|
{
|
||||||
"uuid":"1111",
|
"uuid":"1111",
|
||||||
"name":"CsvParser",
|
"name":"MysqlRead",
|
||||||
"bundle":"cn.piflow.bundle.csv.CsvParser",
|
"bundle":"cn.piflow.bundle.jdbc.MysqlRead",
|
||||||
"properties":{
|
"properties":{
|
||||||
"csvPath":"hdfs://10.0.88.13:9000/xjzhu/test.csv",
|
"sql":"select id,name from student",
|
||||||
"header":"false",
|
"url":"jdbc:mysql://10.0.88.24:3306/visualization?useUnicode=true&characterEncoding=utf-8",
|
||||||
"delimiter":",",
|
"driver":"com.mysql.jdbc.Driver",
|
||||||
"schema":"title,author"
|
"user":"root",
|
||||||
|
"password":"123456"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -19,14 +20,14 @@
|
||||||
"name":"ExecutePythonWithDataFrame",
|
"name":"ExecutePythonWithDataFrame",
|
||||||
"bundle":"cn.piflow.bundle.script.ExecutePythonWithDataFrame",
|
"bundle":"cn.piflow.bundle.script.ExecutePythonWithDataFrame",
|
||||||
"properties":{
|
"properties":{
|
||||||
"script":"import sys\nimport os\n\nimport numpy as np\nfrom scipy import linalg\nimport pandas as pd\n\nimport matplotlib\nmatplotlib.use('Agg')\n\n\ndef listFunction(dictInfo):\n\n return dictInfo",
|
"script":"import sys\nimport os\nimport numpy as np\ndef listFunction(dictInfo): \n newDict = {\"name\":\"hello new user!\", \"id\":11}\n secondDict = {\"name\":\"hello second user!\", \"id\":12}\n listInfo=[newDict, secondDict]\n return dictInfo + listInfo\n",
|
||||||
"execFunction": "listFunction"
|
"execFunction": "listFunction"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"paths":[
|
"paths":[
|
||||||
{
|
{
|
||||||
"from":"CsvParser",
|
"from":"MysqlRead",
|
||||||
"outport":"",
|
"outport":"",
|
||||||
"inport":"",
|
"inport":"",
|
||||||
"to":"ExecutePythonWithDataFrame"
|
"to":"ExecutePythonWithDataFrame"
|
||||||
|
|
|
@ -75,24 +75,35 @@ class ExecutePythonWithDataFrame extends ConfigurableStop{
|
||||||
val listInfo = df.toJSON.collectAsList()
|
val listInfo = df.toJSON.collectAsList()
|
||||||
jep.eval(s"result = $execFunction($listInfo)")
|
jep.eval(s"result = $execFunction($listInfo)")
|
||||||
val resultArrayList = jep.getValue("result",new util.ArrayList().getClass)
|
val resultArrayList = jep.getValue("result",new util.ArrayList().getClass)
|
||||||
println(resultArrayList)
|
println("Execute Python Result : " + resultArrayList + "!!!!!!!!!!!!!!!!!!!!!")
|
||||||
|
|
||||||
|
|
||||||
var resultList = List[Map[String, Any]]()
|
var resultList = List[Map[String, String]]()
|
||||||
val it = resultArrayList.iterator()
|
val it = resultArrayList.iterator()
|
||||||
while(it.hasNext){
|
while(it.hasNext){
|
||||||
val i = it.next().asInstanceOf[java.util.HashMap[String, Any]]
|
val i = it.next().asInstanceOf[java.util.HashMap[String, Any]]
|
||||||
val item = mapAsScalaMap(i).toMap[String, Any]
|
val item = mapAsScalaMap(i).toMap[String, Any]
|
||||||
resultList = item +: resultList
|
var new_item = Map[String, String]()
|
||||||
|
item.foreach(m => {
|
||||||
|
val key = m._1
|
||||||
|
val value = m._2
|
||||||
|
new_item += (key -> String.valueOf(value))
|
||||||
|
})
|
||||||
|
resultList = new_item +: resultList
|
||||||
}
|
}
|
||||||
|
println("Convert Python Result to Scala List: " + resultList + "!!!!!!!!!!!!!!!!!!!!!")
|
||||||
|
|
||||||
|
|
||||||
val rows = resultList.map( m => Row(m.values.toSeq:_*))
|
val rows = resultList.map( m => Row(m.values.toSeq:_*))
|
||||||
|
//println("rows: " + rows + "!!!!!!!!!!!!!!!!!!!!!")
|
||||||
val header = resultList.head.keys.toList
|
val header = resultList.head.keys.toList
|
||||||
|
//println("header: " + header + "!!!!!!!!!!!!!!!!!!!!!")
|
||||||
val schema = StructType(header.map(fieldName => new StructField(fieldName, StringType, true)))
|
val schema = StructType(header.map(fieldName => new StructField(fieldName, StringType, true)))
|
||||||
|
println("schema: " + schema + "!!!!!!!!!!!!!!!!!!!!!")
|
||||||
|
|
||||||
val rdd = spark.sparkContext.parallelize(rows)
|
val rdd = spark.sparkContext.parallelize(rows)
|
||||||
val resultDF = spark.createDataFrame(rdd, schema)
|
val resultDF = spark.createDataFrame(rdd, schema)
|
||||||
|
resultDF.show()
|
||||||
|
|
||||||
out.write(resultDF)
|
out.write(resultDF)
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ class ExecuteScala extends ConfigurableStop{
|
||||||
val pluginName = new PropertyDescriptor()
|
val pluginName = new PropertyDescriptor()
|
||||||
.name("plugin")
|
.name("plugin")
|
||||||
.displayName("Plugin")
|
.displayName("Plugin")
|
||||||
.description("The class name of scala code. This field is generated automaticly.")
|
.description("The class name of scala code.")
|
||||||
.defaultValue("")
|
.defaultValue("")
|
||||||
.required(true)
|
.required(true)
|
||||||
descriptor = pluginName :: descriptor
|
descriptor = pluginName :: descriptor
|
||||||
|
|
|
@ -31,6 +31,8 @@ import org.flywaydb.core.api.FlywayException
|
||||||
import org.h2.tools.Server
|
import org.h2.tools.Server
|
||||||
import spray.json.DefaultJsonProtocol
|
import spray.json.DefaultJsonProtocol
|
||||||
|
|
||||||
|
import scala.io.Source
|
||||||
|
|
||||||
|
|
||||||
object HTTPService extends DefaultJsonProtocol with Directives with SprayJsonSupport{
|
object HTTPService extends DefaultJsonProtocol with Directives with SprayJsonSupport{
|
||||||
implicit val config = ConfigFactory.load()
|
implicit val config = ConfigFactory.load()
|
||||||
|
@ -295,28 +297,28 @@ object HTTPService extends DefaultJsonProtocol with Directives with SprayJsonSup
|
||||||
|
|
||||||
case HttpRequest(POST, Uri.Path("/group/start"), headers, entity, protocol) =>{
|
case HttpRequest(POST, Uri.Path("/group/start"), headers, entity, protocol) =>{
|
||||||
|
|
||||||
try{
|
/*try{
|
||||||
/*entity match {
|
|
||||||
case HttpEntity.Strict(_, data) =>{
|
val bodyFeature = Unmarshal(entity.withoutSizeLimit())
|
||||||
var flowGroupJson = data.utf8String
|
val flowGroupJson = ""//Await.result(bodyFeature,scala.concurrent.duration.Duration(5,"second"))
|
||||||
val flowGroupExecution = API.startGroup(flowGroupJson)
|
|
||||||
flowGroupMap += (flowGroupExecution.getGroupId() -> flowGroupExecution)
|
val flowGroupExecution = API.startGroup(flowGroupJson)
|
||||||
val result = "{\"group\":{\"id\":\"" + flowGroupExecution.getGroupId() + "\"}}"
|
flowGroupMap += (flowGroupExecution.getGroupId() -> flowGroupExecution)
|
||||||
Future.successful(HttpResponse(SUCCESS_CODE, entity = result))
|
val result = "{\"group\":{\"id\":\"" + flowGroupExecution.getGroupId() + "\"}}"
|
||||||
}
|
Future.successful(HttpResponse(SUCCESS_CODE, entity = result))
|
||||||
case otherType => {
|
}catch {
|
||||||
println(otherType)
|
case ex => {
|
||||||
|
println(ex)
|
||||||
|
Future.successful(HttpResponse(FAIL_CODE, entity = "Can not start group!"))
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
try{
|
||||||
|
|
||||||
val bodyFeature = Unmarshal(entity).to [String]
|
|
||||||
val flowGroupJson = Await.result(bodyFeature,scala.concurrent.duration.Duration(1,"second"))
|
|
||||||
val flowGroupExecution = API.startGroup(flowGroupJson)
|
|
||||||
flowGroupMap += (flowGroupExecution.getGroupId() -> flowGroupExecution)
|
|
||||||
val result = "{\"group\":{\"id\":\"" + flowGroupExecution.getGroupId() + "\"}}"
|
|
||||||
Future.successful(HttpResponse(SUCCESS_CODE, entity = result))
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
val bodyFeature = Unmarshal(entity).to [String]
|
val bodyFeature = Unmarshal(entity).to [String]
|
||||||
val flowGroupJson = Await.result(bodyFeature,scala.concurrent.duration.Duration(1,"second"))
|
val flowGroupJson = Await.result(bodyFeature,scala.concurrent.duration.Duration(1,"second"))
|
||||||
|
//use file to run large group
|
||||||
|
//val flowGroupJsonPath = Await.result(bodyFeature,scala.concurrent.duration.Duration(1,"second"))
|
||||||
|
//val flowGroupJson = Source.fromFile(flowGroupJsonPath).getLines().toArray.mkString("\n")*/
|
||||||
val flowGroupExecution = API.startGroup(flowGroupJson)
|
val flowGroupExecution = API.startGroup(flowGroupJson)
|
||||||
flowGroupMap += (flowGroupExecution.getGroupId() -> flowGroupExecution)
|
flowGroupMap += (flowGroupExecution.getGroupId() -> flowGroupExecution)
|
||||||
val result = "{\"group\":{\"id\":\"" + flowGroupExecution.getGroupId() + "\"}}"
|
val result = "{\"group\":{\"id\":\"" + flowGroupExecution.getGroupId() + "\"}}"
|
||||||
|
@ -328,6 +330,7 @@ object HTTPService extends DefaultJsonProtocol with Directives with SprayJsonSup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue