forked from opensci/piflow
add getProjectInfo API
This commit is contained in:
parent
7ee00efec5
commit
ac4e3043d6
|
@ -470,7 +470,7 @@ object H2Util {
|
|||
|
||||
statement.close()
|
||||
|
||||
Map[String, Any]("flowGroup" -> flowGroupInfoMap)
|
||||
Map[String, Any]("group" -> flowGroupInfoMap)
|
||||
}
|
||||
|
||||
//project related api
|
||||
|
@ -515,6 +515,56 @@ object H2Util {
|
|||
statement.close()
|
||||
}
|
||||
|
||||
def getProjectInfo(projectId:String) : String = {
|
||||
|
||||
val projectInfoMap = getProjectInfoMap(projectId)
|
||||
JsonUtil.format(JsonUtil.toJson(projectInfoMap))
|
||||
|
||||
}
|
||||
|
||||
def getProjectInfoMap(projectId:String) : Map[String, Any] = {
|
||||
val statement = getConnectionInstance().createStatement()
|
||||
statement.setQueryTimeout(QUERY_TIME)
|
||||
|
||||
|
||||
var projectInfoMap = Map[String, Any]()
|
||||
|
||||
val projectRS : ResultSet = statement.executeQuery("select * from project where id='" + projectId +"'")
|
||||
while (projectRS.next()){
|
||||
|
||||
projectInfoMap += ("id" -> projectRS.getString("id"))
|
||||
projectInfoMap += ("name" -> projectRS.getString("name"))
|
||||
projectInfoMap += ("state" -> projectRS.getString("state"))
|
||||
projectInfoMap += ("startTime" -> projectRS.getString("startTime"))
|
||||
projectInfoMap += ("endTime" -> projectRS.getString("endTime"))
|
||||
}
|
||||
projectRS.close()
|
||||
|
||||
//get flowGroups info
|
||||
var flowGroupList:List[Map[String, Any]] = List()
|
||||
val flowGroupRS : ResultSet = statement.executeQuery("select * from flowGroup where projectId='" + projectId +"'")
|
||||
while (flowGroupRS.next()){
|
||||
val flowGroupId = flowGroupRS.getString("id")
|
||||
flowGroupList = getFlowGroupInfoMap(flowGroupId) +: flowGroupList
|
||||
}
|
||||
flowGroupRS.close()
|
||||
projectInfoMap += ("groups" -> flowGroupList)
|
||||
|
||||
//get flow info
|
||||
var flowList:List[Map[String, Any]] = List()
|
||||
val flowRS : ResultSet = statement.executeQuery("select * from flow where projectId='" + projectId +"'")
|
||||
while (flowRS.next()){
|
||||
val appId = flowRS.getString("id")
|
||||
flowList = getFlowInfoMap(appId) +: flowList
|
||||
}
|
||||
flowRS.close()
|
||||
projectInfoMap += ("flows" -> flowList)
|
||||
|
||||
statement.close()
|
||||
|
||||
Map[String, Any]("flowGroup" -> projectInfoMap)
|
||||
}
|
||||
|
||||
|
||||
def main(args: Array[String]): Unit = {
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.util.concurrent.CountDownLatch
|
|||
|
||||
import org.apache.spark.sql.SparkSession
|
||||
import cn.piflow.conf.util.{ClassUtil, MapUtil, OptionUtil}
|
||||
import cn.piflow.{FlowGroupExecution, Process, Runner}
|
||||
import cn.piflow.{FlowGroupExecution, Process, ProjectExecution, Runner}
|
||||
import cn.piflow.api.util.{HdfsUtil, PropertyUtil}
|
||||
import cn.piflow.conf.bean.{FlowGroupBean, ProjectBean}
|
||||
import cn.piflow.util.{FlowState, H2Util, HadoopFileUtil}
|
||||
|
@ -45,6 +45,15 @@ object API {
|
|||
|
||||
}
|
||||
|
||||
def stopProject(projectExecution : ProjectExecution): Unit ={
|
||||
projectExecution.stop()
|
||||
}
|
||||
|
||||
def getProjectInfo(projectId : String) : String = {
|
||||
val projectInfo = H2Util.getProjectInfo(projectId)
|
||||
projectInfo
|
||||
}
|
||||
|
||||
def startFlowGroup(flowGroupJson : String) = {
|
||||
|
||||
println("StartFlowGroup API get json: \n" + flowGroupJson )
|
||||
|
|
|
@ -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 HTTPClientGetProjectInfo {
|
||||
|
||||
def main(args: Array[String]): Unit = {
|
||||
|
||||
val url = "http://10.0.86.98:8001/project/info?projectId=project_9ababcea-0e5c-4825-a005-4591c09ec9c4"
|
||||
val client = HttpClients.createDefault()
|
||||
val getFlowGroupInfoData:HttpGet = new HttpGet(url)
|
||||
|
||||
val response:CloseableHttpResponse = client.execute(getFlowGroupInfoData)
|
||||
val entity = response.getEntity
|
||||
val str = EntityUtils.toString(entity,"UTF-8")
|
||||
println("Code is " + str)
|
||||
}
|
||||
|
||||
}
|
|
@ -274,7 +274,7 @@ object HTTPService extends DefaultJsonProtocol with Directives with SprayJsonSup
|
|||
|
||||
Future.successful(HttpResponse(entity = result))
|
||||
}else{
|
||||
Future.successful(HttpResponse(entity = "groupId is null or flow run failed!"))
|
||||
Future.successful(HttpResponse(entity = "groupId is null or flowGroup run failed!"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -308,7 +308,7 @@ object HTTPService extends DefaultJsonProtocol with Directives with SprayJsonSup
|
|||
|
||||
projectMap.get(projectId) match {
|
||||
case Some(projectExecution) =>
|
||||
val result = projectExecution.stop()
|
||||
val result = API.stopProject(projectExecution)
|
||||
projectMap.-(projectId)
|
||||
Future.successful(HttpResponse(entity = "Stop project Ok!!!"))
|
||||
case ex =>{
|
||||
|
@ -321,6 +321,19 @@ object HTTPService extends DefaultJsonProtocol with Directives with SprayJsonSup
|
|||
}
|
||||
}
|
||||
|
||||
case HttpRequest(GET, Uri.Path("/project/info"), headers, entity, protocol) =>{
|
||||
|
||||
val projectId = req.getUri().query().getOrElse("projectId","")
|
||||
if(!projectId.equals("")){
|
||||
var result = API.getProjectInfo(projectId)
|
||||
println("getProjectInfo result: " + result)
|
||||
|
||||
Future.successful(HttpResponse(entity = result))
|
||||
}else{
|
||||
Future.successful(HttpResponse(entity = "projectId is null or project run failed!"))
|
||||
}
|
||||
}
|
||||
|
||||
case _: HttpRequest =>
|
||||
Future.successful(HttpResponse(404, entity = "Unknown resource!"))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue