Search in sources :

Example 41 with DBUtil

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

the class DelSecondLevelServiceIPInfo method deleteAll.

public static String deleteAll(String flsn, String slsn) {
    DBUtil util = new DBUtil();
    if (util.getConnection() == null) {
        return "DB connect failed.";
    }
    String sql = "delete from t_second_level_service_ipinfo where " + "first_level_service_name=? and second_level_service_name=?";
    List<Object> params = new ArrayList<Object>();
    params.add(flsn);
    params.add(slsn);
    try {
        int delNum = util.updateByPreparedStatement(sql, params);
        return "success";
    } catch (SQLException e) {
        e.printStackTrace();
        return e.getMessage();
    } finally {
        util.releaseConn();
    }
}
Also used : DBUtil(ngse.org.DBUtil) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList)

Example 42 with DBUtil

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

the class DelSharedobject method deleteAll.

public static String deleteAll(String flsn, String slsn) {
    DBUtil util = new DBUtil();
    if (util.getConnection() == null) {
        return "DB connect failed.";
    }
    try {
        String sql = "select tag_name from t_sharedobject_tag where  first_level_service_name=? and second_level_service_name=?";
        List<Object> params = new ArrayList<Object>();
        params.add(flsn);
        params.add(slsn);
        ArrayList<SharedobjectTag> result = util.findMoreRefResult(sql, params, SharedobjectTag.class);
        for (int i = 0; i < result.size(); i++) {
            String tag_name = result.get(i).getTag_name();
            sql = "delete from t_sharedobject_tag where tag_name=? and first_level_service_name=? and second_level_service_name=?";
            params = new ArrayList<Object>();
            params.add(tag_name);
            params.add(flsn);
            params.add(slsn);
            //删除数据库记录
            int delNum = util.updateByPreparedStatement(sql, params);
            String filename = SharedobjectTag.getSharedobjectName(flsn, slsn, tag_name, "so");
            RemoveFile(filename);
        }
        return "success";
    } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
    } finally {
        util.releaseConn();
    }
}
Also used : DBUtil(ngse.org.DBUtil) ArrayList(java.util.ArrayList) SharedobjectTag(beans.dbaccess.SharedobjectTag) SQLException(java.sql.SQLException)

Example 43 with DBUtil

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

the class QueryAlarmSetting method initMonitorIPAndPort.

public static void initMonitorIPAndPort() throws Exception {
    DBUtil util = new DBUtil();
    Logger logger = Logger.getLogger(MonitorBySvcOrIP.class);
    try {
        if (util.getConnection() == null) {
            Exception e = new Exception("connect db failed.");
            throw e;
        }
        String sql = sql = "select ip,port from t_second_level_service_ipinfo where second_level_service_name='monitor' and first_level_service_name='RESERVED'";
        ArrayList<OddSecondLevelServiceIPInfo> list = util.findMoreRefResult(sql, null, OddSecondLevelServiceIPInfo.class);
        if (list == null || list.size() < 1) {
            throw new Exception("no db record exists.");
        }
        monitor_server_ip = list.get(0).getIp();
        //为什么加1,是个很长的故事,源于monitor的开发者将读写分离成两个端口
        monitor_server_port = list.get(0).getPort().intValue() + 1;
        logger.info(String.format("monitor server:%s:%d", monitor_server_ip, monitor_server_port));
    } finally {
        util.releaseConn();
    }
}
Also used : DBUtil(ngse.org.DBUtil) Logger(org.apache.log4j.Logger) OddSecondLevelServiceIPInfo(beans.dbaccess.OddSecondLevelServiceIPInfo)

Example 44 with DBUtil

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

the class QueryReleasePlan method exec.

public QueryReleasePlanResponse exec(ReleasePlan request) {
    QueryReleasePlanResponse resp = new QueryReleasePlanResponse();
    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<ReleasePlan> planList;
    String sql = "select plan_id, first_level_service_name,second_level_service_name," + "config_tag,idl_tag, sharedobject_tag, status,memo,backend_task_status from t_release_plan ";
    List<Object> params = new ArrayList<Object>();
    boolean hasWhere = false;
    if (request.getPlan_id() != null && request.getPlan_id().length() > 0) {
        sql += " where plan_id like ? ";
        params.add(request.getPlan_id());
        hasWhere = true;
    }
    String flsn = request.getFirst_level_service_name();
    String slsn = request.getSecond_level_service_name();
    if (flsn != null && flsn.length() > 0 && slsn != null && slsn.length() > 0) {
        if (hasWhere) {
            sql = sql + " and first_level_service_name=? and second_level_service_name=? ";
        } else {
            sql = sql + " where first_level_service_name=? and second_level_service_name=? ";
        }
        hasWhere = true;
        params.add(flsn);
        params.add(slsn);
    }
    sql = sql + " order by plan_id desc";
    try {
        planList = util.findMoreRefResult(sql, params, ReleasePlan.class);
    } catch (Exception e) {
        resp.setStatus(100);
        resp.setMessage("db query exception!");
        e.printStackTrace();
        return resp;
    } finally {
        util.releaseConn();
    }
    resp.setPlan_list((ArrayList<ReleasePlan>) planList);
    resp.setMessage("success");
    resp.setStatus(0);
    return resp;
}
Also used : DBUtil(ngse.org.DBUtil) QueryReleasePlanResponse(beans.response.QueryReleasePlanResponse) ArrayList(java.util.ArrayList) ReleasePlan(beans.request.ReleasePlan)

Example 45 with DBUtil

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

the class QueryReleasePlanDetail method exec.

public QueryReleasePlanDetailResponse exec(ReleasePlan request) {
    QueryReleasePlanDetailResponse resp = new QueryReleasePlanDetailResponse();
    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<ReleasePlan> planList;
    try {
        String sql = "select plan_id, first_level_service_name,second_level_service_name," + "config_tag,idl_tag, sharedobject_tag, status,memo,backend_task_status " + "from t_release_plan where plan_id=?";
        List<Object> params = new ArrayList<Object>();
        params.add(request.getPlan_id());
        planList = util.findMoreRefResult(sql, params, ReleasePlan.class);
        if (planList.size() != 1) {
            resp.setStatus(100);
            resp.setMessage("Plan does NOT exist.");
            return resp;
        }
        resp.setDetail(planList.get(0));
        ReleasePlan detail = resp.getDetail();
        sql = "select dest_ip_list from t_release_plan where plan_id=?";
        params = new ArrayList<Object>();
        params.add(request.getPlan_id());
        Map<String, Object> res = util.findSimpleResult(sql, params);
        if (res.get("dest_ip_list") == null) {
            resp.setStatus(100);
            resp.setMessage("query dest ip list failed.");
            return resp;
        }
        String dest_ip_list = (String) (res.get("dest_ip_list"));
        ObjectMapper objectMapper = new ObjectMapper();
        Object o = objectMapper.readValue(dest_ip_list, new ArrayList<IPPortPair>().getClass());
        detail.setDest_ip_list((ArrayList<IPPortPair>) o);
    } catch (Exception e) {
        resp.setStatus(100);
        resp.setMessage("db query exception!");
        e.printStackTrace();
        return resp;
    } finally {
        util.releaseConn();
    }
    resp.setMessage("success");
    resp.setStatus(0);
    return resp;
}
Also used : ArrayList(java.util.ArrayList) QueryReleasePlanDetailResponse(beans.response.QueryReleasePlanDetailResponse) ReleasePlan(beans.request.ReleasePlan) DBUtil(ngse.org.DBUtil) IPPortPair(beans.request.IPPortPair) JSONObject(org.json.JSONObject) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

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