Search in sources :

Example 1 with DelServiceResponse

use of beans.response.DelServiceResponse in project MSEC by Tencent.

the class DelOddService method exec.

public DelServiceResponse exec(DelServiceRequest request) {
    Logger logger = Logger.getLogger(this.getClass().getName());
    DelServiceResponse response = new DelServiceResponse();
    response.setMessage("unkown error.");
    response.setStatus(100);
    String result = checkIdentity();
    if (!result.equals("success")) {
        response.setStatus(99);
        response.setMessage(result);
        return response;
    }
    if (request.getService_name() == null || request.getService_name().equals("") || request.getService_level() == null || request.getService_level().equals("")) {
        response.setMessage("The name/level of service to be deled should NOT be empty.");
        response.setStatus(100);
        return response;
    }
    if (request.getService_parent().equals("RESERVED") && (request.getService_name().equals("log") || request.getService_name().equals("monitor"))) {
        response.setMessage("The reserved services can NOT be deleted.");
        response.setStatus(100);
        return response;
    }
    if (request.getService_level().equals("second_level") && (request.getService_parent() == null || request.getService_parent().equals(""))) {
        response.setMessage("The first level 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;
    List<Object> params = new ArrayList<Object>();
    if (request.getService_level().equals("first_level")) {
        //检查一下一级服务下还有没有二级服务,有的话不能删除
        if (checkIfHasSecondLevel(request.getService_name(), util) != false) {
            response.setMessage("还有二级服务挂靠在该一级服务下,不能删除该服务.");
            response.setStatus(100);
            return response;
        }
        sql = "delete from t_first_level_service where first_level_service_name=? ";
        logger.info(sql);
        params.add(request.getService_name());
    } else {
        sql = "delete from t_second_level_service where second_level_service_name=? and first_level_service_name=?";
        logger.info(sql);
        params.add(request.getService_name());
        params.add(request.getService_parent());
    }
    try {
        int delNum = util.updateByPreparedStatement(sql, params);
        if (delNum == 1) {
            if (request.getService_level().equals("second_level")) {
                DelOddSecondLevelServiceIPInfo.deleteAll(request.getService_parent(), request.getService_name());
            }
            response.setDelNum(delNum);
            response.setMessage("success");
            response.setStatus(0);
            return response;
        } else {
            response.setDelNum(delNum);
            response.setMessage("delete record number is " + delNum);
            response.setStatus(100);
            return response;
        }
    } catch (SQLException e) {
        response.setMessage("del record failed:" + e.toString());
        response.setStatus(100);
        e.printStackTrace();
        return response;
    } finally {
        util.releaseConn();
    }
}
Also used : DBUtil(ngse.org.DBUtil) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) DelServiceResponse(beans.response.DelServiceResponse) Logger(org.apache.log4j.Logger)

Example 2 with DelServiceResponse

use of beans.response.DelServiceResponse in project MSEC by Tencent.

the class DelService method exec.

public DelServiceResponse exec(DelServiceRequest request) {
    Logger logger = Logger.getLogger(this.getClass().getName());
    DelServiceResponse response = new DelServiceResponse();
    response.setMessage("unkown error.");
    response.setStatus(100);
    String result = checkIdentity();
    if (!result.equals("success")) {
        response.setStatus(99);
        response.setMessage(result);
        return response;
    }
    if (request.getService_name() == null || request.getService_name().equals("") || request.getService_level() == null || request.getService_level().equals("")) {
        response.setMessage("The name/level of service to be deled should NOT be empty.");
        response.setStatus(100);
        return response;
    }
    if (request.getService_level().equals("second_level") && (request.getService_parent() == null || request.getService_parent().equals(""))) {
        response.setMessage("The first level 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;
    List<Object> params = new ArrayList<Object>();
    if (request.getService_level().equals("first_level")) {
        //检查一下一级服务下还有没有二级服务,有的话不能删除
        if (checkIfHasSecondLevel(request.getService_name(), util) != false) {
            response.setMessage("还有二级服务挂靠在该一级服务下,不能删除该服务.");
            response.setStatus(100);
            return response;
        }
        sql = "delete from t_first_level_service where first_level_service_name=?";
        logger.info(sql);
        params.add(request.getService_name());
    } else {
        sql = "delete from t_service_info where second_level_service_name=? and first_level_service_name=?";
        params.add(request.getService_name());
        params.add(request.getService_parent());
        try {
            util.updateByPreparedStatement(sql, params);
        } catch (SQLException e) {
            response.setMessage("del record failed:" + e.toString());
            response.setStatus(100);
            e.printStackTrace();
            util.releaseConn();
            return response;
        }
        sql = "delete from t_second_level_service where second_level_service_name=? and first_level_service_name=?";
        params.clear();
        logger.info(sql);
        params.add(request.getService_name());
        params.add(request.getService_parent());
    }
    try {
        int delNum = util.updateByPreparedStatement(sql, params);
        if (delNum == 1) {
            //相关的一些信息也应该删除掉,例如IP、config、IDL等等
            if (request.getService_level().equals("second_level")) {
            }
            response.setDelNum(delNum);
            response.setMessage("success");
            response.setStatus(0);
            return response;
        } else {
            response.setDelNum(delNum);
            response.setMessage("delete record number is " + delNum);
            response.setStatus(100);
            return response;
        }
    } catch (SQLException e) {
        response.setMessage("del record failed:" + e.toString());
        response.setStatus(100);
        e.printStackTrace();
        return response;
    } finally {
        util.releaseConn();
    }
}
Also used : DBUtil(msec.org.DBUtil) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) DelServiceResponse(beans.response.DelServiceResponse) Logger(org.apache.log4j.Logger)

Aggregations

DelServiceResponse (beans.response.DelServiceResponse)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 Logger (org.apache.log4j.Logger)2 DBUtil (msec.org.DBUtil)1 DBUtil (ngse.org.DBUtil)1