mirror of
https://gitee.com/BDWare/cp.git
synced 2025-01-10 09:54:07 +00:00
feat: add joinInfo update logic
This commit is contained in:
parent
6e25abbef0
commit
29f81e582a
@ -15,6 +15,7 @@ import org.bdware.irp.exception.IrpClientException;
|
|||||||
import org.bdware.irp.stateinfo.StateInfoBase;
|
import org.bdware.irp.stateinfo.StateInfoBase;
|
||||||
import org.bdware.sc.ContractProcess;
|
import org.bdware.sc.ContractProcess;
|
||||||
import org.bdware.sc.bean.Contract;
|
import org.bdware.sc.bean.Contract;
|
||||||
|
import org.bdware.sc.bean.JoinInfo;
|
||||||
import org.bdware.sc.bean.RouteInfo;
|
import org.bdware.sc.bean.RouteInfo;
|
||||||
import org.bdware.sc.handler.DOOPRequestHandler;
|
import org.bdware.sc.handler.DOOPRequestHandler;
|
||||||
import org.bdware.sc.node.ContractNode;
|
import org.bdware.sc.node.ContractNode;
|
||||||
@ -96,15 +97,19 @@ public class DoipClusterServer extends DoipServerImpl {
|
|||||||
|
|
||||||
// doipOperationName和对应的routeFunctionName的对应关系,存储方式为doipOperationName: routeFunctionName
|
// doipOperationName和对应的routeFunctionName的对应关系,存储方式为doipOperationName: routeFunctionName
|
||||||
JsonObject methodRouteInfoMap = new JsonObject();
|
JsonObject methodRouteInfoMap = new JsonObject();
|
||||||
|
// doipOperationName和对应的routeFunctionName的对应关系,存储方式为doipOperationName: routeFunctionName
|
||||||
|
JsonObject methodJoinInfoMap = new JsonObject();
|
||||||
|
|
||||||
// 所有Router中用得到的函数(例如Route函数和Route函数依赖的相关函数)
|
// 所有Router中用得到的函数(例如Route函数和Route函数依赖的相关函数)
|
||||||
JsonObject functions = new JsonObject();
|
JsonObject functions = new JsonObject();
|
||||||
|
|
||||||
// 维护RouteInfo,将RouteInfo和doipOperationName的映射关系,以及所有Router中用得到的函数都维护好
|
// 维护RouteInfo,将RouteInfo和doipOperationName的映射关系,以及所有Router中用得到的函数都维护好
|
||||||
maintainRouteInfo(cn, methodRouteInfoMap, functions);
|
maintainRouteJoinInfo(cn, methodRouteInfoMap, methodJoinInfoMap, functions);
|
||||||
|
|
||||||
if(clusterInfo != null) repoHandleValues.add("clusterInfo", clusterInfo);
|
if(clusterInfo != null) repoHandleValues.add("clusterInfo", clusterInfo);
|
||||||
if(!functions.equals(new JsonObject())) repoHandleValues.add("functions", functions);
|
if(!functions.equals(new JsonObject())) repoHandleValues.add("functions", functions);
|
||||||
if(!methodRouteInfoMap.equals(new JsonObject())) repoHandleValues.add("routeInfo", methodRouteInfoMap);
|
if(!methodRouteInfoMap.equals(new JsonObject())) repoHandleValues.add("routeInfo", methodRouteInfoMap);
|
||||||
|
if(!methodJoinInfoMap.equals(new JsonObject())) repoHandleValues.add("joinInfo", methodJoinInfoMap);
|
||||||
repoInfo.handleValues.addProperty("cluster", repoHandleValues.toString());
|
repoInfo.handleValues.addProperty("cluster", repoHandleValues.toString());
|
||||||
|
|
||||||
String updateRepoInfoRes = repoIrpClient.reRegister(repoInfo);
|
String updateRepoInfoRes = repoIrpClient.reRegister(repoInfo);
|
||||||
@ -117,7 +122,7 @@ public class DoipClusterServer extends DoipServerImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void maintainRouteInfo(ContractNode cn, JsonObject methodRouteInfoMap, JsonObject functions) {
|
public void maintainRouteJoinInfo(ContractNode cn, JsonObject methodRouteInfoMap, JsonObject methodJoinInfoMap, JsonObject functions) {
|
||||||
// all functions存了ContractNode中,所有的FunctionNode
|
// all functions存了ContractNode中,所有的FunctionNode
|
||||||
List<FunctionNode> allFunctions = cn.getFunctions();
|
List<FunctionNode> allFunctions = cn.getFunctions();
|
||||||
// gson是Gson工具类昂!!!
|
// gson是Gson工具类昂!!!
|
||||||
@ -128,25 +133,41 @@ public class DoipClusterServer extends DoipServerImpl {
|
|||||||
String doipOperationName = doipFunctionNodes.getKey();
|
String doipOperationName = doipFunctionNodes.getKey();
|
||||||
FunctionNode doipFunctionNode = doipFunctionNodes.getValue();
|
FunctionNode doipFunctionNode = doipFunctionNodes.getValue();
|
||||||
RouteInfo doipFunctionRouteInfo = doipFunctionNode.getRouteInfo();
|
RouteInfo doipFunctionRouteInfo = doipFunctionNode.getRouteInfo();
|
||||||
|
JoinInfo doipFunctionJoinInfo = doipFunctionNode.getJoinInfo();
|
||||||
|
|
||||||
// 对于routerInfo进行处理,对于routeInfo进行维护
|
// 对于RouterInfo进行维护
|
||||||
if(doipFunctionRouteInfo != null) {
|
if(doipFunctionRouteInfo != null) {
|
||||||
|
// 建立method和RouteInfo的映射
|
||||||
methodRouteInfoMap.addProperty(doipOperationName, gson.toJson(doipFunctionRouteInfo));
|
methodRouteInfoMap.addProperty(doipOperationName, gson.toJson(doipFunctionRouteInfo));
|
||||||
if(doipFunctionRouteInfo.funcName != null) {
|
if(doipFunctionRouteInfo.funcName != null) {
|
||||||
String routeFunctionName = doipFunctionRouteInfo.funcName;
|
String routeFunctionName = doipFunctionRouteInfo.funcName;
|
||||||
for(FunctionNode functionNode : allFunctions) {
|
packSourceFunctionAndDependentFunctions(allFunctions, routeFunctionName, functions);
|
||||||
// find Route Function
|
}
|
||||||
if(functionNode.functionName.equals(routeFunctionName)) {
|
}
|
||||||
functions.addProperty(functionNode.functionName, functionNode.plainText());
|
|
||||||
|
|
||||||
// add all dependentFunction to the "functions" struct
|
// 对于JoinInfo进行维护
|
||||||
for (String dependentFunctionName : functionNode.getDependentFunctions()) {
|
if(doipFunctionJoinInfo != null) {
|
||||||
for (FunctionNode f : cn.getFunctions()) {
|
// 建立method和RouteInfo的映射
|
||||||
if(f.functionName.equals(dependentFunctionName) && !functions.has(dependentFunctionName)) {
|
methodJoinInfoMap.addProperty(doipOperationName, gson.toJson(doipFunctionJoinInfo));
|
||||||
functions.addProperty(dependentFunctionName, f.plainText());
|
if(doipFunctionJoinInfo.joinFuncName != null) {
|
||||||
}
|
String joinFunctionName = doipFunctionJoinInfo.joinFuncName;
|
||||||
}
|
packSourceFunctionAndDependentFunctions(allFunctions, joinFunctionName, functions);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void packSourceFunctionAndDependentFunctions(List<FunctionNode> allFunctions, String sourceFunctionName, JsonObject functions) {
|
||||||
|
for(FunctionNode functionNode : allFunctions) {
|
||||||
|
// add sourceFunction
|
||||||
|
if(functionNode.functionName.equals(sourceFunctionName)) {
|
||||||
|
functions.addProperty(functionNode.functionName, functionNode.plainText());
|
||||||
|
|
||||||
|
// find all dependent functions to the "functions" struct
|
||||||
|
for (String dependentFunctionName : functionNode.getDependentFunctions()) {
|
||||||
|
for (FunctionNode f : allFunctions) {
|
||||||
|
if(f.functionName.equals(dependentFunctionName) && !functions.has(dependentFunctionName)) {
|
||||||
|
functions.addProperty(dependentFunctionName, f.plainText());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user