Search in sources :

Example 11 with CobarAdapterDAO

use of com.alibaba.cobar.manager.dao.CobarAdapterDAO in project cobar by alibaba.

the class AddCobar method onSubmit.

@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
    CobarForm form = (CobarForm) command;
    CobarDO cobar = new CobarDO();
    cobar.setClusterId(form.getClusterId());
    cobar.setHost(form.getHost().trim());
    cobar.setName(form.getCobarName().trim());
    cobar.setPassword(form.getPassword().trim());
    cobar.setServerPort(form.getServerPort());
    cobar.setPort(form.getPort());
    cobar.setUser(form.getUserName().trim());
    cobar.setStatus(form.getStatus().trim());
    cobar.setTime_diff("0");
    CobarAdapterDAO perf = cobarAccesser.getAccesser(cobar);
    boolean flag = false;
    String reason = null;
    if (ConstantDefine.ACTIVE.equals(cobar.getStatus())) {
        if (perf.checkConnection()) {
            flag = this.xmlAccesser.getCobarDAO().addCobar(cobar);
            if (!flag) {
                reason = form.getCobarName() + " exist";
            }
        } else {
            reason = "connect to cobar fail, please check parameters";
        }
    } else {
        flag = this.xmlAccesser.getCobarDAO().addCobar(cobar);
        if (!flag) {
            reason = form.getCobarName() + " exist";
        }
    }
    if (flag) {
        return new ModelAndView("m_success", "info", "add cobar success");
    } else {
        return new ModelAndView("failure", "reason", reason);
    }
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) ModelAndView(org.springframework.web.servlet.ModelAndView) CobarDO(com.alibaba.cobar.manager.dataobject.xml.CobarDO)

Example 12 with CobarAdapterDAO

use of com.alibaba.cobar.manager.dao.CobarAdapterDAO in project cobar by alibaba.

the class KillConnection method handleRequestInternal.

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    UserDO user = (UserDO) request.getSession().getAttribute("user");
    long cobarId = Long.parseLong(request.getParameter("cobarId"));
    long connecId = Long.parseLong(request.getParameter("connectionId"));
    CobarDO cobar = xmlAccesser.getCobarDAO().getCobarById(cobarId);
    if (logger.isWarnEnabled()) {
        logger.warn(new StringBuilder().append(user.getUsername()).append(" | kill connection | cobar: ").append(cobar.getName()).append(" | connection_id:").append(connecId).toString());
    }
    if (!cobar.getStatus().equals(ConstantDefine.ACTIVE)) {
        return new ModelAndView("c_failure", "reason", "cobar is inActive");
    }
    CobarAdapterDAO control = cobarAccesser.getAccesser(cobarId);
    if (control.checkConnection()) {
        control.killConnection(connecId);
        return new ModelAndView("c_success", "info", "success !");
    }
    return new ModelAndView("c_failure", "reason", "connect to cobar fail!");
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) UserDO(com.alibaba.cobar.manager.dataobject.xml.UserDO) ModelAndView(org.springframework.web.servlet.ModelAndView) CobarDO(com.alibaba.cobar.manager.dataobject.xml.CobarDO)

Example 13 with CobarAdapterDAO

use of com.alibaba.cobar.manager.dao.CobarAdapterDAO in project cobar by alibaba.

the class ModifyCobar method onSubmit.

@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
    CobarForm form = (CobarForm) command;
    CobarDO cobar = new CobarDO();
    cobar.setId(form.getCobarId());
    cobar.setClusterId(form.getClusterId());
    cobar.setHost(form.getHost().trim());
    cobar.setName(form.getCobarName().trim());
    cobar.setPassword(form.getPassword().trim());
    cobar.setServerPort(form.getServerPort());
    cobar.setPort(form.getPort());
    cobar.setUser(form.getUserName().trim());
    cobar.setStatus(form.getStatus().trim());
    cobar.setTime_diff("0");
    CobarAdapterDAO perf = null;
    try {
        perf = cobarAccesser.getAccesser(cobar);
    } catch (Exception e) {
    }
    boolean flag = false;
    String reason = null;
    if (ConstantDefine.ACTIVE.equals(cobar.getStatus())) {
        if (perf != null && perf.checkConnection()) {
            //                CobarDO cobarOld = xmlAccesser.getCobarDAO().getCobarById(cobar.getId());
            flag = this.xmlAccesser.getCobarDAO().modifyCobar(cobar);
            if (!flag) {
                reason = form.getCobarName() + "???????";
            }
        } else {
            reason = "connect to cobar fail ";
        }
    } else {
        flag = this.xmlAccesser.getCobarDAO().modifyCobar(cobar);
        if (!flag) {
            reason = form.getCobarName() + " exist";
        }
    /*
             * else { if (perf != null) perf.setCobarStatus(false); }
             */
    }
    if (flag) {
        return new ModelAndView("m_success", "info", "modify success");
    } else {
        return new ModelAndView("failure", "reason", reason);
    }
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) ModelAndView(org.springframework.web.servlet.ModelAndView) CobarDO(com.alibaba.cobar.manager.dataobject.xml.CobarDO) BindException(org.springframework.validation.BindException)

Example 14 with CobarAdapterDAO

use of com.alibaba.cobar.manager.dao.CobarAdapterDAO in project cobar by alibaba.

the class CobarNodeInstantPerfValueAjax method listDatanode.

@SuppressWarnings({ "unchecked" })
private List<Map<String, Object>> listDatanode(AjaxParams params) {
    CobarAdapterDAO perfAccesser = cobarAccesser.getAccesser(params.getCobarNodeId());
    if (!perfAccesser.checkConnection()) {
        return null;
    }
    PropertyUtilsBean util = new PropertyUtilsBean();
    List<DataNodesStatus> list = perfAccesser.listDataNodes();
    ;
    if (null != list) {
        ListSortUtil.sortDataNodesByPoolName(list);
    }
    List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();
    for (DataNodesStatus c : list) {
        Map<String, Object> map = null;
        try {
            map = util.describe(c);
        } catch (Exception e1) {
            throw new RuntimeException(e1);
        }
        map.remove("class");
        map.remove("executeCount");
        map.put("executeCount", FormatUtil.formatNumber(c.getExecuteCount()));
        map.remove("recoveryTime");
        if (-1 != c.getRecoveryTime()) {
            map.put("recoveryTime", FormatUtil.formatTime(c.getRecoveryTime() * 1000, 2));
        } else {
            map.put("recoveryTime", c.getRecoveryTime());
        }
        returnList.add(map);
    }
    return returnList;
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) DataNodesStatus(com.alibaba.cobar.manager.dataobject.cobarnode.DataNodesStatus) PropertyUtilsBean(org.apache.commons.beanutils.PropertyUtilsBean) ArrayList(java.util.ArrayList) JSONObject(net.sf.json.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 15 with CobarAdapterDAO

use of com.alibaba.cobar.manager.dao.CobarAdapterDAO in project cobar by alibaba.

the class CobarNodeInstantPerfValueAjax method handleRequest.

@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    AjaxParams params = new AjaxParams(request);
    CobarAdapterDAO perfAccesser = cobarAccesser.getAccesser(params.getCobarNodeId());
    JSONArray array = null;
    String jsonRst = null;
    String st = params.getValueType();
    if (null == st || st.equals("")) {
        throw new IllegalArgumentException("parameter 'cobarControlValueType' is unknown: " + st);
    }
    int type = typeMap.get(st);
    switch(type) {
        case TYPE_SERVER_STATUS:
            jsonRst = JSONObject.fromObject(getServerStatus(params)).toString(2);
            break;
        case TYPE_PROCESSOR_STATUS:
            List<Map<String, Object>> listProcessor = listProcessorStatus(params);
            array = JSONArray.fromObject(listProcessor);
            jsonRst = array.toString(2);
            break;
        case TYPE_THREAD_POOL:
            List<Map<String, Object>> listThreadpool = listThreadPool(params);
            array = JSONArray.fromObject(listThreadpool);
            jsonRst = array.toString(2);
            break;
        case TYPE_COMMAND:
            List<Map<String, Object>> listCommand = listCommand(params);
            array = JSONArray.fromObject(listCommand);
            jsonRst = array.toString(2);
            break;
        case TYPE_DATANODES:
            List<Map<String, Object>> listDatanode = listDatanode(params);
            array = JSONArray.fromObject(listDatanode);
            jsonRst = array.toString(2);
            break;
        case TYPE_DATABASES:
            List<String> listDatabase = null;
            if (perfAccesser.checkConnection()) {
                listDatabase = perfAccesser.listDataBases();
            }
            array = JSONArray.fromObject(listDatabase);
            jsonRst = array.toString(2);
            break;
        case TYPE_DATASOURCES:
            List<DataSources> listDatasource = null;
            if (perfAccesser.checkConnection()) {
                listDatasource = perfAccesser.listDataSources();
            }
            array = JSONArray.fromObject(listDatasource);
            jsonRst = array.toString(2);
            break;
        case TYPE_CONNECTION:
            List<Map<String, Object>> listConnection = listConnection(params);
            array = JSONArray.fromObject(listConnection);
            jsonRst = array.toString(2);
            break;
        default:
            throw new IllegalArgumentException("parameter 'cobarNodeInstantPerfValueType' is known: " + params.getValueType());
    }
    perfAccesser = null;
    response.setHeader("Content-Type", "text/json; charset=utf-8");
    OutputStream out = response.getOutputStream();
    out.write(jsonRst.getBytes("utf-8"));
    out.flush();
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) DataSources(com.alibaba.cobar.manager.dataobject.cobarnode.DataSources) OutputStream(java.io.OutputStream) JSONArray(net.sf.json.JSONArray) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

CobarAdapterDAO (com.alibaba.cobar.manager.dao.CobarAdapterDAO)24 CobarDO (com.alibaba.cobar.manager.dataobject.xml.CobarDO)16 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)15 Map (java.util.Map)14 JSONObject (net.sf.json.JSONObject)9 ModelAndView (org.springframework.web.servlet.ModelAndView)9 UserDO (com.alibaba.cobar.manager.dataobject.xml.UserDO)7 ClusterDO (com.alibaba.cobar.manager.dataobject.xml.ClusterDO)5 CommandStatus (com.alibaba.cobar.manager.dataobject.cobarnode.CommandStatus)4 ProcessorStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ProcessorStatus)4 ServerStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ServerStatus)4 JSONArray (net.sf.json.JSONArray)4 FluenceHashMap (com.alibaba.cobar.manager.util.FluenceHashMap)3 PropertyUtilsBean (org.apache.commons.beanutils.PropertyUtilsBean)3 ConnectionStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ConnectionStatus)2 DataNodesStatus (com.alibaba.cobar.manager.dataobject.cobarnode.DataNodesStatus)2 Pair (com.alibaba.cobar.manager.util.Pair)2 IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2