add stop groups api

This commit is contained in:
judy0131 2018-09-25 17:35:11 +08:00
parent e2b2df0418
commit 4c3385ea9f
3 changed files with 52 additions and 2 deletions

View File

@ -10,7 +10,7 @@ import cn.piflow.conf.util.ClassUtil.findConfigurableStopPropertyDescriptor
import org.apache.http.client.methods.{CloseableHttpResponse, HttpGet, HttpPost}
import org.apache.http.impl.client.HttpClients
import org.apache.http.util.EntityUtils
import org.apache.spark.launcher.SparkLauncher
import scala.util.parsing.json.JSON
@ -53,6 +53,20 @@ object API {
//spark.close();
new Thread( new WaitProcessTerminateRunnable(spark, process)).start()
(applicationId,process)
/*val launcher = new SparkLauncher
launcher.setMaster(PropertyUtil.getPropertyValue("spark.master"))
.setAppName("test")
.setDeployMode(PropertyUtil.getPropertyValue("spark.deploy.mode"))
.setConf("spark.hadoop.yarn.resourcemanager.hostname", PropertyUtil.getPropertyValue("yarn.resourcemanager.hostname"))
.setConf("spark.hadoop.yarn.resourcemanager.address", PropertyUtil.getPropertyValue("yarn.resourcemanager.address")).setConf("spark.yarn.access.namenode", PropertyUtil.getPropertyValue("yarn.access.namenode"))
.setConf("spark.yarn.stagingDir", PropertyUtil.getPropertyValue("yarn.stagingDir"))
.setConf("spark.yarn.jars", PropertyUtil.getPropertyValue("yarn.jars"))
.setConf("spark.jars", PropertyUtil.getPropertyValue("piflow.bundle"))
.setConf("hive.metastore.uris", PropertyUtil.getPropertyValue("hive.metastore.uris"))
.setMainClass("lalla")
.addAppArgs(flowJson)*/
}
def stopFlow(process : Process): String = {
@ -89,11 +103,16 @@ object API {
}
def getAllGroups() = {
val groups = ClassUtil.findAllGroups().mkString(",")
"""{"groups":"""" + groups + """"}"""
}
}
class WaitProcessTerminateRunnable(spark : SparkSession, process: Process) extends Runnable {
override def run(): Unit = {
process.awaitTermination()
spark.close()
//spark.close()
}
}

View File

@ -0,0 +1,21 @@
package cn.piflow.api
import org.apache.http.client.methods.{CloseableHttpResponse, HttpGet}
import org.apache.http.impl.client.HttpClients
import org.apache.http.util.EntityUtils
object HTTPClientGetGroups {
def main(args: Array[String]): Unit = {
val url = "http://10.0.86.98:8001/stop/groups"
val client = HttpClients.createDefault()
val getGroups:HttpGet = new HttpGet(url)
val response:CloseableHttpResponse = client.execute(getGroups)
val entity = response.getEntity
val str = EntityUtils.toString(entity,"UTF-8")
println("Groups is: " + str)
}
}

View File

@ -98,6 +98,16 @@ object HTTPService extends DefaultJsonProtocol with Directives with SprayJsonSup
case _ => Future.successful(HttpResponse(entity = "Can not found stop properties Error!"))
}
}
}
case HttpRequest(GET, Uri.Path("/stop/groups"), headers, entity, protocol) =>{
try{
val stopGroups = API.getAllGroups()
Future.successful(HttpResponse(entity = stopGroups))
}catch {
case _ => Future.successful(HttpResponse(entity = "Can not found stop properties Error!"))
}
}
case _: HttpRequest =>