|
@ -10,19 +10,15 @@ import com.yihu.hos.system.dao.AppDao;
|
|
|
import com.yihu.hos.system.dao.AppServiceDao;
|
|
|
import com.yihu.hos.system.dao.FlowProcessDao;
|
|
|
import com.yihu.hos.system.dao.ProcessorDao;
|
|
|
import com.yihu.hos.system.model.SystemApp;
|
|
|
import com.yihu.hos.system.model.SystemServiceEndpoint;
|
|
|
import com.yihu.hos.system.model.SystemServiceFlowProcess;
|
|
|
import com.yihu.hos.system.model.SystemServiceFlowProcessor;
|
|
|
import com.yihu.hos.system.model.*;
|
|
|
import com.yihu.hos.web.framework.model.Result;
|
|
|
import net.sf.json.JSONArray;
|
|
|
import net.sf.json.JSONObject;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.IOException;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.*;
|
|
|
|
|
|
@Service("ProcessManager")
|
|
|
public class ProcessManager {
|
|
@ -40,31 +36,54 @@ public class ProcessManager {
|
|
|
|
|
|
private ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
|
public Result getAllApp() throws Exception {
|
|
|
String hql = "from SystemApp";
|
|
|
List<SystemApp> appList = appDao.getEntityList(SystemApp.class, hql);
|
|
|
String result = objectMapper.writeValueAsString(appList);
|
|
|
return Result.success(result);
|
|
|
}
|
|
|
public Result getEndpoints(String endpointName) throws Exception {
|
|
|
|
|
|
public Result getAllAppService() throws Exception {
|
|
|
String hql = "from SystemServiceEndpoint";
|
|
|
List<SystemServiceEndpoint> serviceEndpointList = appServiceDao.getEntityList(SystemServiceEndpoint.class, hql);
|
|
|
String result = objectMapper.writeValueAsString(serviceEndpointList);
|
|
|
return Result.success(result);
|
|
|
}
|
|
|
List<SystemServiceEndpoint> serviceEndpointList = appServiceDao.getListByName(endpointName);
|
|
|
List<String> appIdList = new ArrayList<>();
|
|
|
Map<String, List<ProcessResultModel>> appServiceMap = new HashMap<>();
|
|
|
for (SystemServiceEndpoint endpoint : serviceEndpointList) {
|
|
|
ProcessResultModel resultModel = new ProcessResultModel();
|
|
|
resultModel.setName(endpoint.getName());
|
|
|
resultModel.setValue(endpoint.getEndpoint());
|
|
|
appIdList.add(endpoint.getAppId());
|
|
|
List<ProcessResultModel> endpointList;
|
|
|
if (appServiceMap.get(endpoint.getAppId()) != null) {
|
|
|
endpointList = appServiceMap.get(endpoint.getAppId());
|
|
|
} else {
|
|
|
endpointList = new ArrayList<>();
|
|
|
}
|
|
|
endpointList.add(resultModel);
|
|
|
appServiceMap.put(endpoint.getAppId(), endpointList);
|
|
|
}
|
|
|
List<SystemApp> appList = appDao.getAllByIdList(appIdList);
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
for (SystemApp app : appList) {
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("title", app.getName());
|
|
|
jsonObject.put("list", appServiceMap.get(app.getId()));
|
|
|
jsonArray.add(jsonObject);
|
|
|
}
|
|
|
|
|
|
public Result getAppServiceByAppId(String appId) throws Exception {
|
|
|
String hql = "from SystemServiceEndpoint where appId = "+appId+"";
|
|
|
List<SystemServiceEndpoint> serviceEndpointList = appServiceDao.getEntityList(SystemServiceEndpoint.class, hql);
|
|
|
String result = objectMapper.writeValueAsString(serviceEndpointList);
|
|
|
return Result.success(result);
|
|
|
return Result.success(jsonArray.toString());
|
|
|
}
|
|
|
|
|
|
public Result getAllProcessor() throws Exception {
|
|
|
String hql = "from SystemServiceFlowProcessor";
|
|
|
List<SystemServiceFlowProcessor> processorList = processorDao.getEntityList(SystemServiceFlowProcessor.class, hql);
|
|
|
String result = objectMapper.writeValueAsString(processorList);
|
|
|
// public Result getAppServiceByAppId(String appId) throws Exception {
|
|
|
// String hql = "from SystemServiceEndpoint where appId = "+appId+"";
|
|
|
// List<SystemServiceEndpoint> serviceEndpointList = appServiceDao.getEntityList(SystemServiceEndpoint.class, hql);
|
|
|
// String result = objectMapper.writeValueAsString(serviceEndpointList);
|
|
|
// return Result.success(result);
|
|
|
// }
|
|
|
|
|
|
public Result getAllProcessor(String processorName) throws Exception {
|
|
|
List<SystemServiceFlowProcessor> processorList = processorDao.getListByName(processorName);
|
|
|
List<ProcessResultModel> resultModelList = new ArrayList<>();
|
|
|
for (SystemServiceFlowProcessor processor : processorList) {
|
|
|
ProcessResultModel resultModel = new ProcessResultModel();
|
|
|
resultModel.setName(processor.getName());
|
|
|
resultModel.setValue(processor.getClassName());
|
|
|
resultModelList.add(resultModel);
|
|
|
}
|
|
|
String result = objectMapper.writeValueAsString(resultModelList);
|
|
|
return Result.success(result);
|
|
|
}
|
|
|
|
|
@ -79,7 +98,7 @@ public class ProcessManager {
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
String flowJsonStr = "{\n" +
|
|
|
" \"code\": \"cralwer\",\n" +
|
|
|
" \"code\": \"crawler\",\n" +
|
|
|
" \"nodes\": {\n" +
|
|
|
" \"node_1\": {\n" +
|
|
|
" \"name\": \"quartz\",\n" +
|
|
@ -87,23 +106,28 @@ public class ProcessManager {
|
|
|
" \"type\": \"service\"\n" +
|
|
|
" },\n" +
|
|
|
" \"node_2\": {\n" +
|
|
|
" \"name\": \"CrawlerProcessor0\",\n" +
|
|
|
" \"value\": \"crawler.processor.CrawlerProcessor0\",\n" +
|
|
|
" \"name\": \"Processor0\",\n" +
|
|
|
" \"value\": \"crawler.processor.Processor0\",\n" +
|
|
|
" \"type\": \"processor\"\n" +
|
|
|
" },\n" +
|
|
|
" \"node_3\": {\n" +
|
|
|
" \"name\": \"crawler\",\n" +
|
|
|
" \"value\": \"body().isEqualTo(false)\",\n" +
|
|
|
" \"type\": \"judgement\"\n" +
|
|
|
" \"name\": \"crawler0\",\n" +
|
|
|
" \"value\": \"http4://localhost:8088/crawler/patientList\",\n" +
|
|
|
" \"type\": \"service\"\n" +
|
|
|
" },\n" +
|
|
|
" \"node_4\": {\n" +
|
|
|
" \"name\": \"crawler\",\n" +
|
|
|
" \"value\": \"http4://localhost:8088/crawler/collect\",\n" +
|
|
|
" \"type\": \"service\"\n" +
|
|
|
" \"name\": \"multicast0\",\n" +
|
|
|
" \"value\": \"2\",\n" +
|
|
|
" \"type\": \"multicast\"\n" +
|
|
|
" },\n" +
|
|
|
" \"node_5\": {\n" +
|
|
|
" \"name\": \"crawler\",\n" +
|
|
|
" \"value\": \"http4://localhost:8088/crawler/patientList\",\n" +
|
|
|
" \"name\": \"crawle1r1\",\n" +
|
|
|
" \"value\": \"http4://localhost:8088/crawler/cralwer\",\n" +
|
|
|
" \"type\": \"service\"\n" +
|
|
|
" },\n" +
|
|
|
" \"node_6\": {\n" +
|
|
|
" \"name\": \"crawler2\",\n" +
|
|
|
" \"value\": \"http4://localhost:8088/crawler/collect\",\n" +
|
|
|
" \"type\": \"service\"\n" +
|
|
|
" }\n" +
|
|
|
" },\n" +
|
|
@ -116,19 +140,21 @@ public class ProcessManager {
|
|
|
" \"from\": \"node_2\",\n" +
|
|
|
" \"to\": \"node_3\"\n" +
|
|
|
" },\n" +
|
|
|
" \"line_3\": {\n" +
|
|
|
" \"line3\": {\n" +
|
|
|
" \"from\": \"node_3\",\n" +
|
|
|
" \"to\": \"node_4\",\n" +
|
|
|
" \"value\": \"correct\"\n" +
|
|
|
" \"to\": \"node_4\"\n" +
|
|
|
" },\n" +
|
|
|
" \"line_4\": {\n" +
|
|
|
" \"from\": \"node_3\",\n" +
|
|
|
" \"from\": \"node_4\",\n" +
|
|
|
" \"to\": \"node_5\"\n" +
|
|
|
" },\n" +
|
|
|
" \"line_5\": {\n" +
|
|
|
" \"from\": \"node_4\",\n" +
|
|
|
" \"to\": \"node_6\"\n" +
|
|
|
" }\n" +
|
|
|
" }\n" +
|
|
|
"}";
|
|
|
formatJson(flowJsonStr);
|
|
|
|
|
|
}
|
|
|
|
|
|
public static String formatJson(String flowJsonStr) throws Exception {
|
|
@ -171,22 +197,24 @@ public class ProcessManager {
|
|
|
public static String generate(String code, String root, Map<String, JsonNode> lineMap, Map<String, JsonNode> nodeMap, DGraph<String> mDG) throws IOException {
|
|
|
Boolean isFirstNodeFlg = true;
|
|
|
StringBuilder javaBuilder = new StringBuilder();
|
|
|
StringBuilder bodyBuilder = new StringBuilder();
|
|
|
StringBuilder packageBuilder = new StringBuilder();
|
|
|
String javaName = toUpperCaseFirstOne(code)+"Route";
|
|
|
|
|
|
javaBuilder.append("package "+code+".route;\n\n");
|
|
|
javaBuilder.append("import org.apache.camel.Exchange;\n");
|
|
|
javaBuilder.append("import org.apache.camel.builder.RouteBuilder;\n");
|
|
|
javaBuilder.append("import crawler.SplitUtil;\n");
|
|
|
packageBuilder.append("package "+code+".route;\n\n");
|
|
|
packageBuilder.append("import org.apache.camel.Exchange;\n");
|
|
|
packageBuilder.append("import org.apache.camel.builder.RouteBuilder;\n");
|
|
|
|
|
|
for (String key : nodeMap.keySet()) {
|
|
|
JsonNode node = nodeMap.get(key);
|
|
|
String type = node.get("type").asText();
|
|
|
if (type.equals("processor")) {
|
|
|
javaBuilder.append("import " + node.get("value").asText() + ";\n");
|
|
|
packageBuilder.append("import " + node.get("value").asText() + ";\n");
|
|
|
}
|
|
|
}
|
|
|
javaBuilder.append("public class "+javaName+" extends RouteBuilder {\n");
|
|
|
javaBuilder.append("public void configure() throws Exception {\n");
|
|
|
|
|
|
bodyBuilder.append("public class "+javaName+" extends RouteBuilder {\n");
|
|
|
bodyBuilder.append("public void configure() throws Exception {\n");
|
|
|
|
|
|
Iterator<String> it = mDG.iterator(root);
|
|
|
while(it.hasNext()) {
|
|
@ -196,15 +224,15 @@ public class ProcessManager {
|
|
|
String value = node.get("value").asText();
|
|
|
String name = node.get("name").asText();
|
|
|
if (isFirstNodeFlg) {
|
|
|
javaBuilder.append("from(\"");
|
|
|
javaBuilder.append(value + "\")");
|
|
|
javaBuilder.append(".routeId(\""+code+"\")");
|
|
|
bodyBuilder.append("from(\"");
|
|
|
bodyBuilder.append(value + "\")");
|
|
|
bodyBuilder.append(".routeId(\""+code+"\")");
|
|
|
isFirstNodeFlg = false;
|
|
|
} else {
|
|
|
if (type.equals("processor")) {
|
|
|
JsonNode args = node.get("args");
|
|
|
if (args == null) {
|
|
|
javaBuilder.append("\n.process(\"new "+name+"())");
|
|
|
bodyBuilder.append("\n.process(new "+name+"())");
|
|
|
} else {
|
|
|
String argStr = "";
|
|
|
String[] argArr = args.asText().split(",");
|
|
@ -212,26 +240,26 @@ public class ProcessManager {
|
|
|
argStr += "\"" + arg + "\",";
|
|
|
}
|
|
|
argStr = StringUtil.substring(argStr, 0, argStr.length() - 1);
|
|
|
javaBuilder.append("\n.process(\"new "+name+"("+argStr+"))");
|
|
|
bodyBuilder.append("\n.process(new "+name+"("+argStr+"))");
|
|
|
}
|
|
|
} else if (type.equals("judgement")) {
|
|
|
judgement(javaBuilder, value, nodeName, mDG, it, lineMap, nodeMap);
|
|
|
judgement(bodyBuilder, value, getEdgeList(nodeName, mDG), it, lineMap, nodeMap);
|
|
|
} else if (type.equals("circle")) {
|
|
|
split(javaBuilder, value);
|
|
|
split(bodyBuilder, packageBuilder, value);
|
|
|
} else if (type.equals("aggregate")) {
|
|
|
aggregate(javaBuilder);
|
|
|
aggregate(bodyBuilder, packageBuilder, value);
|
|
|
} else if (type.equals("multicast")) {
|
|
|
mulitcast(javaBuilder, value, nodeName, mDG, it, lineMap, nodeMap);
|
|
|
mulitcast(bodyBuilder, value, getEdgeList(nodeName, mDG), it, lineMap, nodeMap);
|
|
|
} else {
|
|
|
javaBuilder.append("\n.setHeader(Exchange.HTTP_METHOD, constant(\"POST\"))");
|
|
|
javaBuilder.append("\n.to(\"");
|
|
|
javaBuilder.append(value + "\")");
|
|
|
// bodyBuilder.append("\n.setHeader(Exchange.HTTP_METHOD, constant(\"POST\"))");
|
|
|
bodyBuilder.append("\n.to(\"");
|
|
|
bodyBuilder.append(value + "\")");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
javaBuilder.append("\n}\n}");
|
|
|
|
|
|
bodyBuilder.append(";");
|
|
|
bodyBuilder.append("\n}\n}");
|
|
|
javaBuilder.append(packageBuilder).append(bodyBuilder);
|
|
|
System.out.println(javaBuilder.toString());
|
|
|
// String packageFilePath = System.getProperty("user.dir");
|
|
|
//
|
|
@ -239,7 +267,7 @@ public class ProcessManager {
|
|
|
// File file = new File(filePath);
|
|
|
//
|
|
|
// FileWriter fw = new FileWriter(file);
|
|
|
// fw.write(javaBuilder.toString());
|
|
|
// fw.write(bodyBuilder.toString());
|
|
|
// fw.flush();
|
|
|
// fw.close();//这里只是产生一个JAVA文件,简单的IO操作
|
|
|
//
|
|
@ -264,10 +292,13 @@ public class ProcessManager {
|
|
|
return (new StringBuilder()).append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).toString();
|
|
|
}
|
|
|
|
|
|
public static void judgement(StringBuilder javaBuilder, String value, String nodeName, DGraph<String> mDG, Iterator<String> it, Map<String, JsonNode> lineMap, Map<String, JsonNode> nodeMap) {
|
|
|
public static List<Edge<String>> getEdgeList(String nodeName, DGraph<String> mDG) {
|
|
|
return mDG.getEdgeList(nodeName);
|
|
|
}
|
|
|
|
|
|
javaBuilder.append("\n.when("+value+")");
|
|
|
List<Edge<String>> edgeList = mDG.getEdgeList(nodeName);
|
|
|
public static void judgement(StringBuilder bodyBuilder, String value, List<Edge<String>> edgeList, Iterator<String> it, Map<String, JsonNode> lineMap, Map<String, JsonNode> nodeMap) {
|
|
|
bodyBuilder.append("\n.choice()");
|
|
|
bodyBuilder.append("\n.when("+value+")");
|
|
|
String trueNodeName = "";
|
|
|
String falseNodeName = "";
|
|
|
for (Edge<String> edge : edgeList) {
|
|
@ -275,7 +306,7 @@ public class ProcessManager {
|
|
|
String nextNodeName = edge.getDest();
|
|
|
String nextLineName = edge.getName();
|
|
|
JsonNode nextLine = lineMap.get(nextLineName);
|
|
|
if (nextLine.get("value") != null &&nextLine.get("value").asText().equals("correct")) {
|
|
|
if (nextLine.get("value") != null && nextLine.get("value").asText().equals("correct")) {
|
|
|
trueNodeName = nextNodeName;
|
|
|
} else {
|
|
|
falseNodeName = nextNodeName;
|
|
@ -286,34 +317,36 @@ public class ProcessManager {
|
|
|
JsonNode node2 = nodeMap.get(falseNodeName);
|
|
|
String firstValue = node1.get("value").asText();
|
|
|
String secondValue = node2.get("value").asText();
|
|
|
javaBuilder.append("\n.setHeader(Exchange.HTTP_METHOD, constant(\"POST\"))");
|
|
|
javaBuilder.append("\n.to(\"");
|
|
|
javaBuilder.append(firstValue + "\")");
|
|
|
javaBuilder.append(".otherwise()");
|
|
|
javaBuilder.append("\n.setHeader(Exchange.HTTP_METHOD, constant(\"POST\"))");
|
|
|
javaBuilder.append("\n.to(\"");
|
|
|
javaBuilder.append(secondValue + "\")");
|
|
|
bodyBuilder.append("\n.setHeader(Exchange.HTTP_METHOD, constant(\"POST\"))");
|
|
|
bodyBuilder.append("\n.to(\"");
|
|
|
bodyBuilder.append(firstValue + "\")");
|
|
|
bodyBuilder.append(".otherwise()");
|
|
|
bodyBuilder.append("\n.setHeader(Exchange.HTTP_METHOD, constant(\"POST\"))");
|
|
|
bodyBuilder.append("\n.to(\"");
|
|
|
bodyBuilder.append(secondValue + "\")");
|
|
|
bodyBuilder.append("\n.end()");
|
|
|
}
|
|
|
|
|
|
public static void split(StringBuilder javaBuilder, String value) {
|
|
|
javaBuilder.append("\n.split().method(Split.class, \""+value+"\")");
|
|
|
public static void split(StringBuilder bodyBuilder, StringBuilder packageBuilder, String value) {
|
|
|
packageBuilder.append("import crawler.Split;\n");
|
|
|
bodyBuilder.append("\n.split().method(Split.class, \""+value+"\")");
|
|
|
}
|
|
|
|
|
|
public static void aggregate(StringBuilder javaBuilder) {
|
|
|
javaBuilder.append("\n.aggregate(header(\"test_correlation_key\"), new Aggregate()).completionSize(3)");
|
|
|
public static void aggregate(StringBuilder bodyBuilder, StringBuilder packageBuilder, String value) {
|
|
|
packageBuilder.append("import crawler.Aggregate;\n");
|
|
|
bodyBuilder.append("\n.aggregate(header(\"test_correlation_key\"), new Aggregate()).completionSize(3)");
|
|
|
}
|
|
|
|
|
|
public static void mulitcast(StringBuilder javaBuilder, String value, String nodeName, DGraph<String> mDG, Iterator<String> it, Map<String, JsonNode> lineMap, Map<String, JsonNode> nodeMap) {
|
|
|
public static void mulitcast(StringBuilder bodyBuilder, String value, List<Edge<String>> edgeList, Iterator<String> it, Map<String, JsonNode> lineMap, Map<String, JsonNode> nodeMap) {
|
|
|
|
|
|
List<Edge<String>> edgeList = mDG.getEdgeList(nodeName);
|
|
|
String endpoints = "";
|
|
|
for (Edge<String> edge : edgeList) {
|
|
|
String nextNodeName = edge.getDest();
|
|
|
JsonNode node = nodeMap.get(nextNodeName);
|
|
|
endpoints += "\"" + node.get("value") + "\",";
|
|
|
endpoints += node.get("value") + ",";
|
|
|
it.next();
|
|
|
}
|
|
|
endpoints = StringUtil.substring(endpoints, 0, endpoints.length() - 1);
|
|
|
javaBuilder.append("\n.multicast().stopOnException().to("+endpoints+").end()");
|
|
|
bodyBuilder.append("\n.multicast().stopOnException().to("+endpoints+").end()");
|
|
|
}
|
|
|
}
|