Commit e024a329 authored by ascrutae's avatar ascrutae
Browse files

1.完成保存CallChainTree到HBase的方法

parent 38eb3b2f
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
package com.ai.cloud.skywalking.analysis.chainbuild;

import com.ai.cloud.skywalking.analysis.chainbuild.po.CallChainTreeNode;
import com.ai.cloud.skywalking.analysis.chainbuild.po.ChainInfo;
import com.ai.cloud.skywalking.analysis.chainbuild.po.ChainNode;
import com.ai.cloud.skywalking.analysis.chainbuild.po.CallChainTreeNode;
import com.ai.cloud.skywalking.analysis.chainbuild.util.HBaseUtil;
import com.google.gson.Gson;
import org.apache.hadoop.hbase.client.Put;

import java.io.IOException;
@@ -67,7 +68,7 @@ public class CallChainTree {
        }
    }

    public void saveToHbase() {
    public void saveToHbase() throws IOException {
        List<Put> chainInfoPuts = new ArrayList<Put>();
        for (Map.Entry<String, ChainInfo> entry : combineChains.entrySet()) {
            Put put = new Put(entry.getKey().getBytes());
@@ -75,7 +76,7 @@ public class CallChainTree {
            chainInfoPuts.add(put);
        }

        HBaseUtil.saveMergedCallChain(this);
        HBaseUtil.saveCallChainTree(this);
    }

    public String getCallEntrance() {
@@ -85,4 +86,12 @@ public class CallChainTree {
    public void addMergedChainNode(CallChainTreeNode chainNode) {
        nodes.put(chainNode.getTraceLevelId(), chainNode);
    }

    public Map<String, CallChainTreeNode> getNodes() {
        return nodes;
    }

    public String getHasBeenMergedChainIds() {
        return new Gson().toJson(hasBeenMergedChainIds);
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -43,4 +43,9 @@ public class CallChainTreeNode {
    public String getTraceLevelId() {
        return traceLevelId;
    }

    @Override
    public String toString() {
        return new Gson().toJson(this);
    }
}
+16 −4
Original line number Diff line number Diff line
@@ -2,8 +2,8 @@ package com.ai.cloud.skywalking.analysis.chainbuild.util;

import com.ai.cloud.skywalking.analysis.chain2summary.entity.*;
import com.ai.cloud.skywalking.analysis.chainbuild.CallChainTree;
import com.ai.cloud.skywalking.analysis.chainbuild.po.ChainInfo;
import com.ai.cloud.skywalking.analysis.chainbuild.po.CallChainTreeNode;
import com.ai.cloud.skywalking.analysis.chainbuild.po.ChainInfo;
import com.ai.cloud.skywalking.analysis.config.Config;
import com.ai.cloud.skywalking.analysis.config.HBaseTableMetaData;
import com.google.gson.Gson;
@@ -291,15 +291,27 @@ public class HBaseUtil {
        return result;
    }

    public static void saveMergedCallChain(CallChainTree callChainTree) {
    public static void saveCallChainTree(CallChainTree callChainTree) throws IOException {
        // save
        Put callChainTreePut = new Put(callChainTree.getCallEntrance().getBytes());
        for (Map.Entry<String, CallChainTreeNode> entry : callChainTree.getNodes().entrySet()) {
            callChainTreePut.addColumn(HBaseTableMetaData.TABLE_CALL_CHAIN_TREE_DETAIL.COLUMN_FAMILY_NAME.getBytes(),
                    entry.getKey().getBytes(), entry.getValue().toString().getBytes());
        }
        Table table = connection.getTable(TableName.valueOf(HBaseTableMetaData.TABLE_MERGED_CHAIN_DETAIL.TABLE_NAME));
        table.put(callChainTreePut);
        // save relationship
        Put treeIdCidMappingPut = new Put(callChainTree.getCallEntrance().getBytes());
        treeIdCidMappingPut.addColumn(HBaseTableMetaData.TABLE_CALL_CHAIN_TREE_ID_AND_CID_MAPPING.COLUMN_FAMILY_NAME.getBytes()
                , "HAS_BEEN_MERGED_CHAIN_ID".getBytes(), callChainTree.getHasBeenMergedChainIds().getBytes());
        Table relationshipTable = connection.getTable(TableName.valueOf(HBaseTableMetaData.TABLE_CALL_CHAIN_TREE_ID_AND_CID_MAPPING.TABLE_NAME));
        relationshipTable.put(treeIdCidMappingPut);
    }

    public static List<String> loadHasBeenMergeChainIds(String topoId) throws IOException {
    public static List<String> loadHasBeenMergeChainIds(String treeId) throws IOException {
        List<String> result = new ArrayList<String>();
        Table table = connection.getTable(TableName.valueOf(HBaseTableMetaData.TABLE_CALL_CHAIN_TREE_ID_AND_CID_MAPPING.TABLE_NAME));
        Get g = new Get(Bytes.toBytes(topoId));
        Get g = new Get(Bytes.toBytes(treeId));
        Result r = table.get(g);
        if (r.rawCells().length == 0) {
            return null;
+11 −1
Original line number Diff line number Diff line
@@ -111,10 +111,20 @@ public class HBaseTableMetaData {
        public static final String COLUMN_FAMILY_NAME = "chain_detail";
    }


    /**
     * 用于存放调用树和CID的映射关系
     *
     * @author zhangxin
     */
    public final static class TABLE_CALL_CHAIN_TREE_ID_AND_CID_MAPPING {
        public static final String TABLE_NAME = "sw-topologyId-cid-mapping";

        public static final String COLUMN_FAMILY_NAME = "sw-topologyId-cid-mapping";
    }

    public final static class TABLE_CALL_CHAIN_TREE_DETAIL {
        public static final String TABLE_NAME = "sw-call-chain-tree-detail";

        public static final String COLUMN_FAMILY_NAME = "tree-detail";
    }
}