feat: add joinInfo update logic

This commit is contained in:
haoeliu@foxmail.com 2023-02-14 20:57:55 +08:00
parent 6e25abbef0
commit 29f81e582a

View File

@ -15,6 +15,7 @@ import org.bdware.irp.exception.IrpClientException;
import org.bdware.irp.stateinfo.StateInfoBase;
import org.bdware.sc.ContractProcess;
import org.bdware.sc.bean.Contract;
import org.bdware.sc.bean.JoinInfo;
import org.bdware.sc.bean.RouteInfo;
import org.bdware.sc.handler.DOOPRequestHandler;
import org.bdware.sc.node.ContractNode;
@ -96,15 +97,19 @@ public class DoipClusterServer extends DoipServerImpl {
// doipOperationName和对应的routeFunctionName的对应关系存储方式为doipOperationName: routeFunctionName
JsonObject methodRouteInfoMap = new JsonObject();
// doipOperationName和对应的routeFunctionName的对应关系存储方式为doipOperationName: routeFunctionName
JsonObject methodJoinInfoMap = new JsonObject();
// 所有Router中用得到的函数例如Route函数和Route函数依赖的相关函数
JsonObject functions = new JsonObject();
// 维护RouteInfo将RouteInfo和doipOperationName的映射关系以及所有Router中用得到的函数都维护好
maintainRouteInfo(cn, methodRouteInfoMap, functions);
maintainRouteJoinInfo(cn, methodRouteInfoMap, methodJoinInfoMap, functions);
if(clusterInfo != null) repoHandleValues.add("clusterInfo", clusterInfo);
if(!functions.equals(new JsonObject())) repoHandleValues.add("functions", functions);
if(!methodRouteInfoMap.equals(new JsonObject())) repoHandleValues.add("routeInfo", methodRouteInfoMap);
if(!methodJoinInfoMap.equals(new JsonObject())) repoHandleValues.add("joinInfo", methodJoinInfoMap);
repoInfo.handleValues.addProperty("cluster", repoHandleValues.toString());
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
List<FunctionNode> allFunctions = cn.getFunctions();
// gson是Gson工具类昂
@ -128,20 +133,39 @@ public class DoipClusterServer extends DoipServerImpl {
String doipOperationName = doipFunctionNodes.getKey();
FunctionNode doipFunctionNode = doipFunctionNodes.getValue();
RouteInfo doipFunctionRouteInfo = doipFunctionNode.getRouteInfo();
JoinInfo doipFunctionJoinInfo = doipFunctionNode.getJoinInfo();
// 对于routerInfo进行处理对于routeInfo进行维护
// 对于RouterInfo进行维护
if(doipFunctionRouteInfo != null) {
// 建立method和RouteInfo的映射
methodRouteInfoMap.addProperty(doipOperationName, gson.toJson(doipFunctionRouteInfo));
if(doipFunctionRouteInfo.funcName != null) {
String routeFunctionName = doipFunctionRouteInfo.funcName;
packSourceFunctionAndDependentFunctions(allFunctions, routeFunctionName, functions);
}
}
// 对于JoinInfo进行维护
if(doipFunctionJoinInfo != null) {
// 建立method和RouteInfo的映射
methodJoinInfoMap.addProperty(doipOperationName, gson.toJson(doipFunctionJoinInfo));
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) {
// find Route Function
if(functionNode.functionName.equals(routeFunctionName)) {
// add sourceFunction
if(functionNode.functionName.equals(sourceFunctionName)) {
functions.addProperty(functionNode.functionName, functionNode.plainText());
// add all dependentFunction to the "functions" struct
// find all dependent functions to the "functions" struct
for (String dependentFunctionName : functionNode.getDependentFunctions()) {
for (FunctionNode f : cn.getFunctions()) {
for (FunctionNode f : allFunctions) {
if(f.functionName.equals(dependentFunctionName) && !functions.has(dependentFunctionName)) {
functions.addProperty(dependentFunctionName, f.plainText());
}
@ -150,7 +174,4 @@ public class DoipClusterServer extends DoipServerImpl {
}
}
}
}
}
}
}