return stop's info when mount or unmount plugin

This commit is contained in:
judy0131 2020-07-30 05:32:25 -04:00
parent 3c444e5685
commit ccff706c04
3 changed files with 44 additions and 13 deletions

View File

@ -5,7 +5,7 @@ import java.net.URLClassLoader
import cn.piflow.conf.ConfigurableStop
import cn.piflow.conf.bean.PropertyDescriptor
import net.liftweb.json.compactRender
import net.liftweb.json.{JValue, compactRender}
import org.clapper.classutil.ClassFinder
import org.reflections.Reflections
import net.liftweb.json.JsonDSL._
@ -187,17 +187,16 @@ object ClassUtil {
stopPropertyDesc.getPropertyDescriptor()
}
def findConfigurableStopInfo(bundle : String) : String = {
val stop = ClassUtil.findConfigurableStop(bundle)
def constructStopInfoJValue(bundle: String, stop:ConfigurableStop) : JValue ={
val stopName = bundle.split("\\.").last
val propertyDescriptorList:List[PropertyDescriptor] = stop.getPropertyDescriptor()
propertyDescriptorList.foreach(p=> if (p.allowableValues == null || p.allowableValues == None) p.allowableValues = List(""))
val stopName = bundle.split("\\.").last
val base64Encoder = new BASE64Encoder()
val json =
val jsonValue =
("StopInfo" ->
("name" -> stopName)~
("bundle" -> bundle) ~
("owner" -> stop.authorEmail) ~
("bundle" -> bundle) ~
("owner" -> stop.authorEmail) ~
("inports" -> stop.inportList.mkString(",")) ~
("outports" -> stop.outportList.mkString(",")) ~
("groups" -> stop.getGroup().mkString(",")) ~
@ -214,9 +213,27 @@ object ClassUtil {
("required" -> property.required.toString) ~
("sensitive" -> property.sensitive.toString) ~
("example" -> property.example)) }) )
val jsonString = compactRender(json)
jsonString
jsonValue
}
def findConfigurableStopInfo(bundle : String) : String = {
val stop = ClassUtil.findConfigurableStop(bundle)
val jvalue = constructStopInfoJValue(bundle,stop)
val jsonString = compactRender(jvalue)
jsonString
}
def findConfigurableStopListInfo(bundleList : List[String]) : String = {
var stopInfoJValueList = List[JValue]()
bundleList.foreach(bundle =>{
val stop = ClassUtil.findConfigurableStop(bundle)
val stopJValue = constructStopInfoJValue(bundle,stop)
stopInfoJValueList = stopJValue +: stopInfoJValueList
})
val stopInfoJValue = (stopInfoJValueList)
val jsonString = compactRender(stopInfoJValue)
jsonString
}
def main(args: Array[String]): Unit = {

View File

@ -78,6 +78,16 @@ object API {
"""{"bundles":"""" + bundleList.mkString(",") + """"}"""
}
def getConfigurableStopInfoInPlugin(pluginManager:PluginManager, pluginName : String) : String = {
var bundleList = List[String]()
val stops = pluginManager.getPluginConfigurableStops(pluginName)
stops.foreach(s => {
bundleList = s.getClass.getName +: bundleList
})
val jsonString = ClassUtil.findConfigurableStopListInfo(bundleList)
jsonString
}
def getResourceInfo() : String = {
try{

View File

@ -426,8 +426,8 @@ object HTTPService extends DefaultJsonProtocol with Directives with SprayJsonSup
val pluginName = data.get("plugin").getOrElse("").asInstanceOf[String]
val pluginID = API.addPlugin(pluginManager, pluginName)
if(pluginID != ""){
//val bundles = API.getConfigurableStopInPlugin(pluginManager, pluginName)
val result = "{\"plugin\":{\"id\":\"" + pluginID + "\"}}"
val stopsInfo = API.getConfigurableStopInfoInPlugin(pluginManager,pluginName)
val result = "{\"plugin\":{\"id\":\"" + pluginID + "\"},\"stopsInfo\":" + stopsInfo +"}"
Future.successful(HttpResponse(SUCCESS_CODE, entity = result))
}else{
Future.successful(HttpResponse(FAIL_CODE, entity = "Fail"))
@ -447,10 +447,14 @@ object HTTPService extends DefaultJsonProtocol with Directives with SprayJsonSup
case HttpEntity.Strict(_, data) =>{
val data = toJson(entity)
val pluginId = data.get("pluginId").getOrElse("").asInstanceOf[String]
val isOk = API.removePlugin(pluginManager, pluginId)
val pluginName = H2Util.getPluginInfoMap(pluginId).getOrElse("name","")
val stopsInfo = API.getConfigurableStopInfoInPlugin(pluginManager,pluginName)
val isOk = API.removePlugin(pluginManager, pluginId)
if(isOk == true){
Future.successful(HttpResponse(SUCCESS_CODE, entity = "OK"))
val result = "{\"plugin\":{\"id\":\"" + pluginId + "\"},\"stopsInfo\":" + stopsInfo +"}"
Future.successful(HttpResponse(SUCCESS_CODE, entity = result))
}else{
Future.successful(HttpResponse(FAIL_CODE, entity = "Fail"))
}