diff --git a/piflow-configure/src/main/scala/cn/piflow/conf/util/ClassUtil.scala b/piflow-configure/src/main/scala/cn/piflow/conf/util/ClassUtil.scala index 673bf97..4dab2eb 100644 --- a/piflow-configure/src/main/scala/cn/piflow/conf/util/ClassUtil.scala +++ b/piflow-configure/src/main/scala/cn/piflow/conf/util/ClassUtil.scala @@ -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 = { diff --git a/piflow-server/src/main/scala/cn/piflow/api/API.scala b/piflow-server/src/main/scala/cn/piflow/api/API.scala index 44eab61..28809dd 100644 --- a/piflow-server/src/main/scala/cn/piflow/api/API.scala +++ b/piflow-server/src/main/scala/cn/piflow/api/API.scala @@ -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{ diff --git a/piflow-server/src/main/scala/cn/piflow/api/HTTPService.scala b/piflow-server/src/main/scala/cn/piflow/api/HTTPService.scala index 35eeaff..285fafc 100644 --- a/piflow-server/src/main/scala/cn/piflow/api/HTTPService.scala +++ b/piflow-server/src/main/scala/cn/piflow/api/HTTPService.scala @@ -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")) }