Search in sources :

Example 1 with GetPlanDetailResponse

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

the class GetPlanDetail method exec.

public GetPlanDetailResponse exec(GetPlanDetailRequest request) {
    GetPlanDetailResponse resp = new GetPlanDetailResponse();
    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;
    }
    JedisHelper helper = null;
    List<ServerInfo> serverList;
    int copy_num = 0;
    ArrayList<String> ip_port_list = new ArrayList<>();
    try {
        String sql;
        List<Object> params = new ArrayList<Object>();
        String plan_id = request.getPlan_id();
        if (request.getPlan_id() == null || request.getPlan_id().isEmpty()) {
            resp.setStatus(101);
            resp.setMessage("parameter error!");
            return resp;
        } else {
            sql = "select ip, port, set_id, group_id, memory, master, status from t_install_plan where plan_id=? and first_level_service_name=? and second_level_service_name=? order by set_id asc, group_id asc, master desc";
            params.clear();
            params.add(request.getPlan_id());
            params.add(request.getFirst_level_service_name());
            params.add(request.getSecond_level_service_name());
            try {
                serverList = util.findMoreRefResult(sql, params, ServerInfo.class);
            } catch (Exception e) {
                resp.setStatus(100);
                resp.setMessage("db query exception!");
                e.printStackTrace();
                return resp;
            }
        }
        if (serverList.size() == 0) {
            resp.setStatus(100);
            resp.setMessage("plan id error!");
            return resp;
        }
        boolean finished = true;
        for (ServerInfo server : serverList) {
            if (!server.getStatus().startsWith("Done")) {
                if (server.getStatus().startsWith("[ERROR]")) {
                    finished = true;
                    break;
                } else {
                    //in progress...
                    finished = false;
                }
            }
        }
        resp.setFinished(finished);
        resp.setServers((ArrayList<ServerInfo>) serverList);
        resp.setMessage("success");
        resp.setStatus(0);
        return resp;
    } finally {
        util.releaseConn();
    }
}
Also used : ServerInfo(beans.dbaccess.ServerInfo) ArrayList(java.util.ArrayList) GetPlanDetailResponse(beans.response.GetPlanDetailResponse) SQLException(java.sql.SQLException) DBUtil(msec.org.DBUtil)

Aggregations

ServerInfo (beans.dbaccess.ServerInfo)1 GetPlanDetailResponse (beans.response.GetPlanDetailResponse)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 DBUtil (msec.org.DBUtil)1