Search in sources :

Example 16 with DBUtil

use of ngse.org.DBUtil in project MSEC by Tencent.

the class DelMachine method exec.

public DelMachineResponse exec(DelMachineRequest request) {
    DelMachineResponse response = new DelMachineResponse();
    response.setMessage("unkown error.");
    response.setStatus(100);
    String result = checkIdentity();
    if (!result.equals("success")) {
        response.setStatus(99);
        response.setMessage(result);
        return response;
    }
    if (request.getMachine_name() == null || request.getMachine_name().equals("")) {
        response.setMessage("The name of machine to be deleted should NOT be empty.");
        response.setStatus(100);
        return response;
    }
    DBUtil util = new DBUtil();
    if (util.getConnection() == null) {
        response.setMessage("DB connect failed.");
        response.setStatus(100);
        return response;
    }
    String sql = "delete from t_machine where machine_name=?";
    List<Object> params = new ArrayList<Object>();
    params.add(request.getMachine_name());
    try {
        int delNum = util.updateByPreparedStatement(sql, params);
        if (delNum >= 0) {
            response.setMessage("success");
            response.setDeleteNumber(delNum);
            response.setStatus(0);
            return response;
        }
    } catch (SQLException e) {
        response.setMessage("Delete record failed:" + e.toString());
        response.setStatus(100);
        e.printStackTrace();
        return response;
    } finally {
        util.releaseConn();
    }
    return response;
}
Also used : DBUtil(ngse.org.DBUtil) SQLException(java.sql.SQLException) DelMachineResponse(beans.response.DelMachineResponse) ArrayList(java.util.ArrayList)

Example 17 with DBUtil

use of ngse.org.DBUtil in project MSEC by Tencent.

the class DelOddSecondLevelServiceIPInfo method exec.

public DelOddSecondLevelServiceIPInfoResponse exec(DelOddSecondLevelServiceIPInfoRequest request) {
    DelOddSecondLevelServiceIPInfoResponse response = new DelOddSecondLevelServiceIPInfoResponse();
    response.setMessage("unkown error.");
    response.setStatus(100);
    String result = checkIdentity();
    if (!result.equals("success")) {
        response.setStatus(99);
        response.setMessage(result);
        return response;
    }
    if (request.getIps() == null || request.getIps().length == 0) {
        response.setMessage("IP /port to be deleted should NOT be empty.");
        response.setStatus(100);
        return response;
    }
    DBUtil util = new DBUtil();
    if (util.getConnection() == null) {
        response.setMessage("DB connect failed.");
        response.setStatus(100);
        return response;
    }
    try {
        for (int i = 0; i < request.getIps().length; ++i) {
            String sql = "delete from t_second_level_service_ipinfo where ip=? and port=? and status='disabled'";
            List<Object> params = new ArrayList<Object>();
            params.add(request.getIps()[i].getIp());
            params.add(request.getIps()[i].getPort());
            try {
                int delNum = util.updateByPreparedStatement(sql, params);
                if (delNum <= 0) {
                    response.setMessage("delete record number is " + delNum);
                    response.setDelNumber(delNum);
                    response.setStatus(100);
                    return response;
                }
            } catch (SQLException e) {
                response.setMessage("Delete record failed:" + e.toString());
                response.setStatus(100);
                e.printStackTrace();
                return response;
            }
        }
        response.setMessage("success");
        response.setStatus(0);
        return response;
    } finally {
        util.releaseConn();
    }
}
Also used : DBUtil(ngse.org.DBUtil) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) DelOddSecondLevelServiceIPInfoResponse(beans.response.DelOddSecondLevelServiceIPInfoResponse)

Example 18 with DBUtil

use of ngse.org.DBUtil in project MSEC by Tencent.

the class QueryBusinessLog method getBusiLogSrvIPPort.

public static ArrayList<IPPortPair> getBusiLogSrvIPPort() {
    DBUtil util = new DBUtil();
    try {
        if (util.getConnection() == null) {
            return null;
        }
        String sql = sql = "select ip,port from t_second_level_service_ipinfo where second_level_service_name='log' " + "and first_level_service_name='RESERVED' and status='enabled'";
        ArrayList<IPPortPair> list = util.findMoreRefResult(sql, null, IPPortPair.class);
        return list;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    } finally {
        util.releaseConn();
    }
}
Also used : DBUtil(ngse.org.DBUtil) IPPortPair(beans.request.IPPortPair)

Example 19 with DBUtil

use of ngse.org.DBUtil in project MSEC by Tencent.

the class QueryCapacityDetail method exec.

public QueryCapacityDetailResponse exec(CapacityRequest request) {
    Logger logger = Logger.getLogger("QueryCapacityDetail");
    QueryCapacityDetailResponse resp = new QueryCapacityDetailResponse();
    String result = checkIdentity();
    if (!result.equals("success")) {
        resp.setStatus(99);
        resp.setMessage(result);
        return resp;
    }
    DBUtil util = new DBUtil();
    if (util.getConnection() == null) {
        resp.setStatus(100);
        resp.setMessage("db connect failed!");
        return resp;
    }
    ArrayList<CapacityDetailInfo> capacities = new ArrayList<CapacityDetailInfo>();
    AccessZooKeeper azk = new AccessZooKeeper();
    try {
        //该服务的所有ip
        ArrayList<IPPortPair> iplist = LoadBalance.getIPPortInfoByServiceName(request.getFirst_level_service_name(), request.getSecond_level_service_name(), util);
        if (iplist == null) {
            resp.setMessage("failed to get ip list for " + request.getFirst_level_service_name() + "." + request.getSecond_level_service_name());
            resp.setStatus(100);
            return resp;
        }
        //获取每一个ip的负载信息
        int j;
        for (j = 0; j < iplist.size(); j++) {
            IPPortPair ip = iplist.get(j);
            String svcname = request.getFirst_level_service_name() + "/" + request.getSecond_level_service_name();
            try {
                int load = LoadBalance.readOneServiceLoadInfo(azk, svcname, ip.getIp());
                if (load >= 0) {
                    CapacityDetailInfo c = new CapacityDetailInfo();
                    c.setIp(ip.getIp());
                    c.setLoad_level(load);
                    capacities.add(c);
                }
            } catch (Exception e) {
                e.printStackTrace();
                resp.setMessage(e.getMessage());
                resp.setStatus(100);
                return resp;
            }
        }
    } finally {
        util.releaseConn();
        azk.disconnect();
    }
    resp.setInfo(capacities);
    resp.setMessage("success");
    resp.setStatus(0);
    return resp;
}
Also used : DBUtil(ngse.org.DBUtil) IPPortPair(beans.request.IPPortPair) QueryCapacityDetailResponse(beans.response.QueryCapacityDetailResponse) ArrayList(java.util.ArrayList) CapacityDetailInfo(beans.dbaccess.CapacityDetailInfo) Logger(org.apache.log4j.Logger) AccessZooKeeper(ngse.org.AccessZooKeeper)

Example 20 with DBUtil

use of ngse.org.DBUtil in project MSEC by Tencent.

the class QueryCapacityList method exec.

public QueryCapacityListResponse exec(CapacityRequest request) {
    Logger logger = Logger.getLogger("QueryCapacityList");
    QueryCapacityListResponse resp = new QueryCapacityListResponse();
    String result = checkIdentity();
    if (!result.equals("success")) {
        resp.setStatus(99);
        resp.setMessage(result);
        return resp;
    }
    DBUtil util = new DBUtil();
    if (util.getConnection() == null) {
        resp.setStatus(100);
        resp.setMessage("db connect failed!");
        return resp;
    }
    List<CapacityBaseInfo> capacities = new ArrayList<CapacityBaseInfo>();
    AccessZooKeeper azk = new AccessZooKeeper();
    try {
        if (request.getFirst_level_service_name() == null || request.getFirst_level_service_name().length() < 1 || request.getSecond_level_service_name() == null || request.getSecond_level_service_name().length() < 1) {
            //所有服务
            ArrayList<SecondLevelService> svcList = LoadBalance.getAllService(util);
            if (svcList == null) {
                resp.setMessage("failed to get all service list");
                resp.setStatus(100);
                return resp;
            }
            for (int i = 0; i < svcList.size(); i++) {
                //每一个服务
                SecondLevelService svc = svcList.get(i);
                if (!svc.getType().equals("standard")) {
                    continue;
                }
                //用户可能指定了一级服务名进行过滤,即只查看该一级服务下所有二级服务的情况
                if (request.getFirst_level_service_name() != null && request.getFirst_level_service_name().length() > 0) {
                    if (!svc.getFirst_level_service_name().equals(request.getFirst_level_service_name())) {
                        continue;
                    }
                }
                CapacityBaseInfo c = new CapacityBaseInfo();
                //该服务的所有ip
                ArrayList<IPPortPair> iplist = LoadBalance.getIPPortInfoByServiceName(svc.getFirst_level_service_name(), svc.getSecond_level_service_name(), util);
                if (iplist == null) {
                    resp.setMessage("failed to get ip list for " + svc.getFirst_level_service_name() + "." + svc.getSecond_level_service_name());
                    resp.setStatus(100);
                    return resp;
                }
                c.setIp_count(iplist.size());
                c.setFirst_level_service_name(svc.getFirst_level_service_name());
                c.setSecond_level_service_name(svc.getSecond_level_service_name());
                //获取每一个ip的负载信息
                int sum = 0;
                int count = 0;
                int j;
                for (j = 0; j < iplist.size(); j++) {
                    IPPortPair ip = iplist.get(j);
                    String svcname = svc.getFirst_level_service_name() + "/" + svc.getSecond_level_service_name();
                    try {
                        int load = LoadBalance.readOneServiceLoadInfo(azk, svcname, ip.getIp());
                        if (load >= 0) {
                            sum += load;
                            count++;
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        resp.setMessage(e.getMessage());
                        resp.setStatus(100);
                        return resp;
                    }
                }
                c.setIp_report_num(count);
                if (count > 0) {
                    c.setLoad_level(sum / count);
                } else {
                    c.setLoad_level(0);
                }
                capacities.add(c);
            }
        } else {
            CapacityBaseInfo c = new CapacityBaseInfo();
            //该服务的所有ip
            ArrayList<IPPortPair> iplist = LoadBalance.getIPPortInfoByServiceName(request.getFirst_level_service_name(), request.getSecond_level_service_name(), util);
            if (iplist == null) {
                resp.setMessage("failed to get ip list for " + request.getFirst_level_service_name() + "." + request.getSecond_level_service_name());
                resp.setStatus(100);
                return resp;
            }
            c.setIp_count(iplist.size());
            c.setFirst_level_service_name(request.getFirst_level_service_name());
            c.setSecond_level_service_name(request.getSecond_level_service_name());
            //获取每一个ip的负载信息
            int sum = 0;
            int count = 0;
            int j;
            for (j = 0; j < iplist.size(); j++) {
                IPPortPair ip = iplist.get(j);
                String svcname = request.getFirst_level_service_name() + "/" + request.getSecond_level_service_name();
                try {
                    int load = LoadBalance.readOneServiceLoadInfo(azk, svcname, ip.getIp());
                    if (load > 0) {
                        sum += load;
                        count++;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    resp.setMessage(e.getMessage());
                    resp.setStatus(100);
                    return resp;
                }
            }
            c.setIp_report_num(count);
            if (count > 0) {
                c.setLoad_level(sum / count);
            } else {
                c.setLoad_level(0);
            }
            capacities.add(c);
        }
    } finally {
        util.releaseConn();
        azk.disconnect();
    }
    resp.setCapacity_list((ArrayList<CapacityBaseInfo>) capacities);
    resp.setMessage("success");
    resp.setStatus(0);
    return resp;
}
Also used : SecondLevelService(beans.dbaccess.SecondLevelService) ArrayList(java.util.ArrayList) Logger(org.apache.log4j.Logger) CapacityBaseInfo(beans.dbaccess.CapacityBaseInfo) DBUtil(ngse.org.DBUtil) IPPortPair(beans.request.IPPortPair) QueryCapacityListResponse(beans.response.QueryCapacityListResponse) AccessZooKeeper(ngse.org.AccessZooKeeper)

Aggregations

DBUtil (ngse.org.DBUtil)51 ArrayList (java.util.ArrayList)36 SQLException (java.sql.SQLException)23 Logger (org.apache.log4j.Logger)20 IPPortPair (beans.request.IPPortPair)12 OddSecondLevelServiceIPInfo (beans.dbaccess.OddSecondLevelServiceIPInfo)7 AccessZooKeeper (ngse.org.AccessZooKeeper)6 JsonRPCResponseBase (ngse.org.JsonRPCResponseBase)6 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)5 SecondLevelService (beans.dbaccess.SecondLevelService)4 OddSecondLevelService (beans.dbaccess.OddSecondLevelService)2 ReleasePlan (beans.request.ReleasePlan)2 IOException (java.io.IOException)2 HttpSession (javax.servlet.http.HttpSession)2 CapacityBaseInfo (beans.dbaccess.CapacityBaseInfo)1 CapacityDetailInfo (beans.dbaccess.CapacityDetailInfo)1 IDL (beans.dbaccess.IDL)1 LibraryFile (beans.dbaccess.LibraryFile)1 MachineInfo (beans.dbaccess.MachineInfo)1 OddFirstLevelService (beans.dbaccess.OddFirstLevelService)1