Search in sources :

Example 36 with DBUtil

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

the class DelLibraryFile method exec.

public DelLibraryFileResponse exec(LibraryFile request) {
    Logger logger = Logger.getLogger(this.getClass().getName());
    DelLibraryFileResponse response = new DelLibraryFileResponse();
    response.setMessage("unkown error.");
    response.setStatus(100);
    String result = checkIdentity();
    if (!result.equals("success")) {
        response.setStatus(99);
        response.setMessage(result);
        return response;
    }
    if (request.getFile_name() == null || request.getFile_name().equals("") || request.getSecond_level_service_name() == null || request.getSecond_level_service_name().equals("") || request.getFirst_level_service_name() == null || request.getFirst_level_service_name().equals("")) {
        response.setMessage("file name and service name  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_library_file where file_name=? and first_level_service_name=? and second_level_service_name=?";
    List<Object> params = new ArrayList<Object>();
    params.add(request.getFile_name());
    params.add(request.getFirst_level_service_name());
    params.add(request.getSecond_level_service_name());
    try {
        int delNum = util.updateByPreparedStatement(sql, params);
        String filename = LibraryFile.getLibraryFileName(request.getFirst_level_service_name(), request.getSecond_level_service_name(), request.getFile_name());
        logger.error("delte file:" + filename);
        RemoveFile(filename);
        if (delNum > 0) {
            response.setMessage("success");
            response.setDelNumber(delNum);
            response.setStatus(0);
            return response;
        } else {
            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;
    } finally {
        util.releaseConn();
    }
}
Also used : DelLibraryFileResponse(beans.response.DelLibraryFileResponse) DBUtil(ngse.org.DBUtil) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Logger(org.apache.log4j.Logger)

Example 37 with DBUtil

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

the class DelOddSecondLevelServiceIPInfo 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 38 with DBUtil

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

the class LibrarayFileUpload method insertTable.

private String insertTable(String firstName, String secondName, String baseFileName, String memo) {
    DBUtil util = new DBUtil();
    if (util.getConnection() == null) {
        return "DB connect failed.";
    }
    String sql;
    List<Object> params = new ArrayList<Object>();
    sql = "insert into t_library_file(first_level_service_name,  second_level_service_name,file_name, memo) values(?,?,?,?)";
    params.add(firstName);
    params.add(secondName);
    params.add(baseFileName);
    params.add(memo);
    try {
        int addNum = util.updateByPreparedStatement(sql, params);
        if (addNum >= 0) {
            return "success";
        }
        return "insert failed";
    } catch (SQLException e) {
        return "insert failed";
    } finally {
        util.releaseConn();
    }
}
Also used : DBUtil(ngse.org.DBUtil) SQLException(java.sql.SQLException)

Example 39 with DBUtil

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

the class AddAlarmSetting 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' and status='enabled'";
        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 40 with DBUtil

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

the class DelSecondLevelServiceConfigTag 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_config_tag where  first_level_service_name=? and second_level_service_name=?";
        List<Object> params = new ArrayList<Object>();
        params.add(flsn);
        params.add(slsn);
        ArrayList<SecondLevelServiceConfigTag> result = util.findMoreRefResult(sql, params, SecondLevelServiceConfigTag.class);
        for (int i = 0; i < result.size(); i++) {
            String tag_name = result.get(i).getTag_name();
            sql = "delete from t_config_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 = SecondLevelServiceConfigTag.getConfigFileName(flsn, slsn, tag_name);
            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) SQLException(java.sql.SQLException) SecondLevelServiceConfigTag(beans.dbaccess.SecondLevelServiceConfigTag)

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