Search in sources :

Example 46 with DBUtil

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

the class RefreshOddCapacity method exec.

public JsonRPCResponseBase exec(CapacityRequest request) {
    JsonRPCResponseBase response = new JsonRPCResponseBase();
    String result = checkIdentity();
    if (!result.equals("success")) {
        response.setStatus(99);
        response.setMessage(result);
        return response;
    }
    Logger logger = Logger.getLogger(RefreshOddCapacity.class);
    //把ip列表刷新到LB的服务器里并下发给各个客户端
    AccessZooKeeper azk = new AccessZooKeeper();
    DBUtil util = new DBUtil();
    if (util.getConnection() == null) {
        response.setStatus(100);
        response.setMessage("db connect failed");
        return response;
    }
    try {
        //step2: 获得该服务下所有enabled的IP,写入LB系统
        ArrayList<IPPortPair> ips = LoadBalance.getIPPortInfoByServiceName(request.getFirst_level_service_name(), request.getSecond_level_service_name(), util);
        if (ips == null) {
            response.setStatus(100);
            response.setMessage("get ip info from db failed");
            return response;
        }
        logger.info("get enabled IP, they will be write to LB server, number:" + ips.size());
        result = LoadBalance.writeOneServiceConfigInfo(azk, request.getFirst_level_service_name() + "/" + request.getSecond_level_service_name(), false, ips);
        if (result == null || !result.equals("success")) {
            response.setStatus(100);
            response.setMessage(result);
            return response;
        }
        logger.info("write into LB server successfully.");
        response.setStatus(0);
        response.setMessage("success");
        return response;
    } catch (Exception e) {
        e.printStackTrace();
        response.setStatus(100);
        response.setMessage(e.getMessage());
        return response;
    } finally {
        azk.disconnect();
        util.releaseConn();
    }
}
Also used : DBUtil(ngse.org.DBUtil) JsonRPCResponseBase(ngse.org.JsonRPCResponseBase) IPPortPair(beans.request.IPPortPair) Logger(org.apache.log4j.Logger) AccessZooKeeper(ngse.org.AccessZooKeeper)

Example 47 with DBUtil

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

the class ReleaseOnlyConfig method CommitPlan.

private String CommitPlan(ReleasePlan plan) {
    //产生发布用的文件,并记录到数据库里
    DBUtil util = new DBUtil();
    if (util.getConnection() == null) {
        return "DB Connect Failed.";
    }
    String sql;
    List<Object> params = new ArrayList<Object>();
    try {
        ObjectMapper objectMapper = new ObjectMapper();
        String dest_ip_list_json_str = objectMapper.writeValueAsString(plan.getDest_ip_list());
        //System.out.println(dest_ip_list_json_str);
        sql = "insert into t_release_plan(plan_id, first_level_service_name,second_level_service_name," + "config_tag,idl_tag, sharedobject_tag, dest_ip_list,status,memo,release_type) values(?,?,?,?,?,?,?,'creating',?,?)";
        params.add(plan.getPlan_id());
        params.add(plan.getFirst_level_service_name());
        params.add(plan.getSecond_level_service_name());
        params.add(plan.getConfig_tag());
        params.add("");
        params.add("");
        params.add(dest_ip_list_json_str);
        params.add(plan.getMemo());
        params.add(plan.getRelease_type());
        int addNum = util.updateByPreparedStatement(sql, params);
        if (addNum != 1) {
            return "addNum is not 1:" + addNum;
        }
        //打包文件
        new Thread(new PackReleaseFile(plan, getServlet().getServletContext())).start();
        return "success";
    } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
    } finally {
        util.releaseConn();
        ;
    }
}
Also used : DBUtil(ngse.org.DBUtil) ArrayList(java.util.ArrayList) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 48 with DBUtil

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

the class QueryOddFirstLevelService method exec.

public QueryOddFirstLevelServiceResponse exec(OddSecondLevelService request) {
    QueryOddFirstLevelServiceResponse resp = new QueryOddFirstLevelServiceResponse();
    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<OddFirstLevelService> serviceList;
    String sql = "select first_level_service_name from t_first_level_service where type='odd' ";
    List<Object> params = new ArrayList<Object>();
    if (request.getSecond_level_service_name() != null && request.getSecond_level_service_name().length() > 0) {
        sql += " where first_level_service_name=? ";
        params.add(request.getSecond_level_service_name());
    }
    try {
        serviceList = util.findMoreRefResult(sql, params, OddFirstLevelService.class);
    } catch (Exception e) {
        resp.setStatus(100);
        resp.setMessage("db query exception!");
        e.printStackTrace();
        return resp;
    } finally {
        util.releaseConn();
    }
    resp.setService_list((ArrayList<OddFirstLevelService>) serviceList);
    resp.setMessage("success");
    resp.setStatus(0);
    return resp;
}
Also used : DBUtil(ngse.org.DBUtil) OddFirstLevelService(beans.dbaccess.OddFirstLevelService) ArrayList(java.util.ArrayList) QueryOddFirstLevelServiceResponse(beans.response.QueryOddFirstLevelServiceResponse)

Example 49 with DBUtil

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

the class ReleaseOnlySharedobject method CommitPlan.

private String CommitPlan(ReleasePlan plan) {
    //产生发布用的文件,并记录到数据库里
    DBUtil util = new DBUtil();
    if (util.getConnection() == null) {
        return "DB Connect Failed.";
    }
    String sql;
    List<Object> params = new ArrayList<Object>();
    try {
        ObjectMapper objectMapper = new ObjectMapper();
        String dest_ip_list_json_str = objectMapper.writeValueAsString(plan.getDest_ip_list());
        //System.out.println(dest_ip_list_json_str);
        sql = "insert into t_release_plan(plan_id, first_level_service_name,second_level_service_name," + "config_tag,idl_tag, sharedobject_tag, dest_ip_list,status,memo, release_type) values(?,?,?,?,?,?,?,'creating',?,?)";
        params.add(plan.getPlan_id());
        params.add(plan.getFirst_level_service_name());
        params.add(plan.getSecond_level_service_name());
        params.add("");
        params.add("");
        params.add(plan.getSharedobject_tag());
        params.add(dest_ip_list_json_str);
        params.add(plan.getMemo());
        params.add(plan.getRelease_type());
        int addNum = util.updateByPreparedStatement(sql, params);
        if (addNum != 1) {
            return "addNum is not 1:" + addNum;
        }
        //打包文件
        new Thread(new PackReleaseFile(plan, getServlet().getServletContext())).start();
        return "success";
    } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
    } finally {
        util.releaseConn();
        ;
    }
}
Also used : DBUtil(ngse.org.DBUtil) ArrayList(java.util.ArrayList) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 50 with DBUtil

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

the class ReleaseStepsGO method doStep1.

private ReleaseStepsGOResponse doStep1(ReleasePlan request) {
    ReleaseStepsGOResponse response = new ReleaseStepsGOResponse();
    if (request.getDest_ip_list() == null || request.getDest_ip_list().size() < 1) {
        response.setMessage("input is invalid");
        response.setStatus(100);
        return response;
    }
    DBUtil util = new DBUtil();
    try {
        util.getConnection();
        String sql = "select dev_lang from t_second_level_service where first_level_service_name=? and second_level_service_name=?";
        ArrayList<Object> params = new ArrayList<Object>();
        params.add(request.getFirst_level_service_name());
        params.add(request.getSecond_level_service_name());
        Map<String, Object> map = util.findSimpleResult(sql, params);
        request.setDev_lang((String) map.get("dev_lang"));
    } catch (Exception e) {
        request.setDev_lang("c++");
    } finally {
        util.releaseConn();
    }
    //把计划保存到session里
    HttpSession session = getHttpRequest().getSession();
    session.setAttribute("plan", request);
    Object ooo = session.getAttribute("plan");
    response.setMessage("success");
    response.setStatus(0);
    return response;
}
Also used : DBUtil(ngse.org.DBUtil) HttpSession(javax.servlet.http.HttpSession) ArrayList(java.util.ArrayList) ReleaseStepsGOResponse(beans.response.ReleaseStepsGOResponse)

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