in src/main/java/com/aliyun/openservices/log/Client.java [4850:4952]
public ListTopostoreNodeRelationResponse listTopostoreNodeRelations(ListTopostoreNodeRelationRequest request) throws LogException {
ListTopostoreNodeRelationResponse response = new ListTopostoreNodeRelationResponse();
// get all nodes
List<String> allNodeIds = new ArrayList<String>();
List<TopostoreNode> allTopoNodes = this.listTopostoreNodeWithAutoPage(request.getTopostoreName(), request.getNodeIds(),
request.getNodeTypes(), request.getNodeProperities(), request.GetParam());
for(TopostoreNode n: allTopoNodes){
allNodeIds.add(n.getNodeId());
}
if(request.getDepth()==0 || allNodeIds.size() == 0){
response.setRelations(new ArrayList<TopostoreRelation>());
response.setNodes(allTopoNodes);
return response;
}
// prepare relation maps
int relationOffset = 0;
int relationTotal = 100000;
Map<String, Map<String, List<TopostoreRelation>>> nodeRelationMap = new HashMap<String,Map<String,List<TopostoreRelation>>>();
nodeRelationMap.put(Consts.TOPOSTORE_RELATION_DIRECTION_IN, new HashMap<String,List<TopostoreRelation>>());
nodeRelationMap.put(Consts.TOPOSTORE_RELATION_DIRECTION_OUT, new HashMap<String,List<TopostoreRelation>>());
while( relationOffset < relationTotal ){
ListTopostoreRelationRequest listRelationReq = new ListTopostoreRelationRequest();
listRelationReq.setTopostoreName(request.getTopostoreName());
for(Map.Entry<String, String> kv: request.GetParam().entrySet()){
listRelationReq.SetParam(kv.getKey(), kv.getValue());
}
listRelationReq.setOffset(relationOffset);
ListTopostoreRelationResponse listRelationResp = this.listTopostoreRelation(listRelationReq);
relationTotal = listRelationResp.getTotal();
relationOffset += listRelationResp.getCount();
for(TopostoreRelation relation: listRelationResp.getTopostoreRelations()){
String srcNodeId = relation.getSrcNodeId();
String dstNodeId = relation.getDstNodeId();
if (!nodeRelationMap.get(Consts.TOPOSTORE_RELATION_DIRECTION_IN).containsKey(dstNodeId)){
nodeRelationMap.get(Consts.TOPOSTORE_RELATION_DIRECTION_IN).put(dstNodeId, new ArrayList<TopostoreRelation>());
}
nodeRelationMap.get(Consts.TOPOSTORE_RELATION_DIRECTION_IN).get(dstNodeId).add(relation);
if (!nodeRelationMap.get(Consts.TOPOSTORE_RELATION_DIRECTION_OUT).containsKey(srcNodeId)){
nodeRelationMap.get(Consts.TOPOSTORE_RELATION_DIRECTION_OUT).put(srcNodeId, new ArrayList<TopostoreRelation>());
}
nodeRelationMap.get(Consts.TOPOSTORE_RELATION_DIRECTION_OUT).get(srcNodeId).add(relation);
}
}
// traverse
Set<String> finalNodeIds = new HashSet<String>();
Set<String> finalRelationIds = new HashSet<String>();
for(String nodeId : allNodeIds){
for(Map.Entry<String, Map<String, List<TopostoreRelation>>> entry: nodeRelationMap.entrySet()){
if(request.getDirection().equals(entry.getKey())
||request.getDirection().equals(Consts.TOPOSTORE_RELATION_DIRECTION_BOTH)){
boolean depthMode=false;
if(request.getDepth()>0){
depthMode = true;
}
List<Set<String>> ret = traverseNodeRelations(entry.getValue(), entry.getKey(), nodeId,
request.getDepth(), depthMode, request.getRelationTypes());
if(ret.size() == 2){
for(String n: ret.get(0)){
finalNodeIds.add(n);
}
for(String r: ret.get(1)){
finalRelationIds.add(r);
}
}
}
}
}
// prepare results
List<String> reqNodeIds = new ArrayList<String>();
reqNodeIds.addAll(finalNodeIds);
if(reqNodeIds.size()>0){
response.setNodes(this.listTopostoreNodeWithAutoPage(request.getTopostoreName(), reqNodeIds, null, null, request.GetParam()));
} else {
response.setNodes(new ArrayList<TopostoreNode>());
}
List<String> reqRelationIds = new ArrayList<String>();
reqRelationIds.addAll(finalRelationIds);
if(reqRelationIds.size()>0){
response.setRelations(this.listTopostoreRelationWithAutoPage(request.getTopostoreName(), reqRelationIds, request.GetParam()));
} else {
response.setRelations(new ArrayList<TopostoreRelation>());
}
return response;
}