Commit 22c99012 authored by ascrutae's avatar ascrutae
Browse files

1. 将页面加载改成ajax形式

parent 1b349b7f
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
package com.ai.cloud.skywalking.web.controller;

import com.ai.cloud.skywalking.web.common.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by xin on 16-4-10.
 */
@Controller
public class MainPageController extends BaseController{

    @RequestMapping("/mainPage")
    public String mainPage(String loadType, HttpServletRequest request){
        request.setAttribute("loadType", loadType);
        return "main";
    }
}
+41 −1
Original line number Diff line number Diff line
package com.ai.cloud.skywalking.web.controller;

import com.ai.cloud.skywalking.web.bo.LoginUserInfo;
import com.ai.cloud.skywalking.web.bo.TraceTreeInfo;
import com.ai.cloud.skywalking.web.common.BaseController;
import com.ai.cloud.skywalking.web.entity.CallChainTree;
import com.ai.cloud.skywalking.web.service.inter.ICallChainTreeService;
import com.ai.cloud.skywalking.web.service.inter.ITraceTreeService;
import com.ai.cloud.skywalking.web.util.StringUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
@@ -14,6 +20,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by xin on 16-3-29.
@@ -24,6 +32,11 @@ public class SearchController extends BaseController {
    @Autowired
    private ITraceTreeService iTraceTreeService;

    @Autowired
    private ICallChainTreeService callChainTreeService;
    private Logger logger = LogManager.getLogger(SearchController.class);


    @RequestMapping(value = "")
    public String showDefaultIndexPage(ModelMap root) throws Exception {
        return "index";
@@ -63,9 +76,36 @@ public class SearchController extends BaseController {

    @RequestMapping(value = "/{traceId:.+}")
    public String searchTrace(@PathVariable String traceId, HttpServletRequest request) {
        System.out.println("search Trace.....");
        request.setAttribute("key", traceId);
        request.setAttribute("searchType", "TRACE_ID");
        return "searchResult";
        request.setAttribute("loadType","showTraceInfo");
        return "main";
    }

    @RequestMapping(value = "/search/chainTree", produces = "application/json; charset=UTF-8")
    @ResponseBody
    public String searchCallChainTree(String key, HttpServletRequest request) {
        JSONObject jsonObject = new JSONObject();
        try {
            if (StringUtil.isBlank(key)) {
                jsonObject.put("code", "200");
                jsonObject.put("result", JSON.toJSONString(new ArrayList<CallChainTree>()));
                return jsonObject.toJSONString();
            }

            LoginUserInfo loginUserInfo = fetchLoginUserInfoFromSession(request);

            List<CallChainTree> callChainTreeList =
                    callChainTreeService.queryCurrentMonthCallChainTree(loginUserInfo.getUid(), key);
            jsonObject.put("code", "200");
            jsonObject.put("result", new Gson().toJson(callChainTreeList));
        } catch (Exception e) {
            logger.error("Failed to search chain tree:{}", key, e);
            jsonObject.put("code", "500");
            jsonObject.put("result", "Fatal error");
        }
        return jsonObject.toJSONString();
    }

}
+15 −0
Original line number Diff line number Diff line
@@ -106,4 +106,19 @@ public class UserMaintainController extends BaseController {
        }
        return result.toJSONString();
    }

    @RequestMapping(value = "/doLogout", produces = "application/json; charset=UTF-8")
    @ResponseBody
    public String doLogout(HttpServletRequest request) {
        JSONObject result = new JSONObject();
        try {
            request.getSession().removeAttribute(Constants.SESSION_LOGIN_INFO_KEY);
            result.put("code", "200");
            result.put("message", "register success");
        } catch (Exception e) {
            result.put("code", "500");
            result.put("message", "fatal error. please try it again.");
        }
        return result.toJSONString();
    }
}
+43 −0
Original line number Diff line number Diff line
package com.ai.cloud.skywalking.web.dao.impl;

import com.ai.cloud.skywalking.web.dao.inter.ICallChainTreeDao;
import com.ai.cloud.skywalking.web.entity.CallChainTree;
import com.ai.cloud.skywalking.web.util.HBaseUtils;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.io.IOException;

@Repository
public class CallChainTreeDao implements ICallChainTreeDao {

    @Autowired
    private HBaseUtils hBaseUtils;

    @Override
    public CallChainTree queryTreeId(String treeId) throws IOException {
        Table table = hBaseUtils.getConnection().getTable(TableName.valueOf("sw-chain-1day-summary"));
        Get get = new Get(treeId.getBytes());
        Result result = table.get(get);
        if (result.rawCells().length == 0) {
            return null;
        }
        CallChainTree chainTree = new CallChainTree(treeId);
        for (Cell cell : result.rawCells()) {
            if (cell.getValueArray().length > 0) {
                String qualifier = Bytes.toString(cell.getQualifierArray(),
                        cell.getQualifierOffset(), cell.getQualifierLength());
                String[] qualifierArr = qualifier.split("@");
                chainTree.addNode(qualifierArr[0],qualifierArr[1]);
            }

        }
        return null;
    }
}
+49 −0
Original line number Diff line number Diff line
package com.ai.cloud.skywalking.web.dao.impl;

import com.ai.cloud.skywalking.web.dao.inter.IChainDetailDao;
import com.ai.cloud.skywalking.web.util.DBConnectUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@Repository
public class ChainDetailDao implements IChainDetailDao {

    private Logger logger = LogManager.getLogger(SystemConfigMaintainDao.class);

    @Autowired
    private DBConnectUtil dbConnectUtil;

    @Override
    public List<String> queryChainTreeIds(String uid, String viewpoint) throws SQLException {
        List<String> treeIds = new ArrayList<String>();
        String sql = "SELECT treeId FROM sw_chain_detail WHERE uid = ? AND viewpoint like ? ";
        Connection connection = dbConnectUtil.getConnection();
        try {
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, uid);
            preparedStatement.setString(2, "%" + viewpoint + "%");

            ResultSet resultSet = preparedStatement.executeQuery();
            while (resultSet.next()) {
                treeIds.add(resultSet.getString("treeId"));
            }
        } catch (Exception e) {
            logger.error("Failed to query treeIds for Viewpoint[{}]", viewpoint);
            throw new RuntimeException("Failed to query treeIds for " + viewpoint, e);
        } finally {
            if (connection != null) {
                connection.close();
            }
        }
        return treeIds;
    }
}
Loading