Search in sources :

Example 11 with CobarDO

use of com.alibaba.cobar.manager.dataobject.xml.CobarDO 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 CobarDO

use of com.alibaba.cobar.manager.dataobject.xml.CobarDO 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 CobarDO

use of com.alibaba.cobar.manager.dataobject.xml.CobarDO 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 CobarDO

use of com.alibaba.cobar.manager.dataobject.xml.CobarDO in project cobar by alibaba.

the class EditCobarPage method handleRequestInternal.

@SuppressWarnings("unchecked")
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    long cobarId = 0;
    try {
        cobarId = Long.parseLong(request.getParameter("cobarId").trim());
    } catch (Exception e) {
        throw new IllegalArgumentException("parameter 'cobarId' is invalid:" + request.getParameter("cobarId"));
    }
    CobarDO cobar = xmlAccesser.getCobarDAO().getCobarById(cobarId);
    Map<String, Object> cobarMap = new PropertyUtilsBean().describe(cobar);
    cobarMap.remove("class");
    cobarMap.remove("name");
    cobarMap.put("name", CobarStringUtil.htmlEscapedString(cobar.getName()));
    List<ClusterDO> cList = xmlAccesser.getClusterDAO().listAllCluster();
    List<Map<String, Object>> clusterList = new ArrayList<Map<String, Object>>();
    for (ClusterDO e : cList) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", e.getId());
        map.put("name", CobarStringUtil.htmlEscapedString(e.getName()));
        clusterList.add(map);
    }
    return new ModelAndView("m_editCobar", new FluenceHashMap<String, Object>().putKeyValue("cluList", clusterList).putKeyValue("cobar", cobarMap));
}
Also used : PropertyUtilsBean(org.apache.commons.beanutils.PropertyUtilsBean) HashMap(java.util.HashMap) FluenceHashMap(com.alibaba.cobar.manager.util.FluenceHashMap) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) CobarDO(com.alibaba.cobar.manager.dataobject.xml.CobarDO) ClusterDO(com.alibaba.cobar.manager.dataobject.xml.ClusterDO) HashMap(java.util.HashMap) FluenceHashMap(com.alibaba.cobar.manager.util.FluenceHashMap) Map(java.util.Map)

Example 15 with CobarDO

use of com.alibaba.cobar.manager.dataobject.xml.CobarDO in project cobar by alibaba.

the class XmlFile method initCobar.

private void initCobar() {
    String path = this.xmlPath + System.getProperty("file.separator") + "cobar.xml";
    init(path, "cobars");
    CobarDAOImple cobarDAO = new CobarDAOImple();
    cobarDAO.setXmlFileLoader(xmlFileLoader);
    try {
        cobarDAO.afterPropertiesSet();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        Assert.fail();
    }
    CobarDO cobar = new CobarDO();
    cobar.setClusterId(1);
    cobar.setHost("10.20.10.100");
    cobar.setName("cobar");
    cobar.setPassword("");
    cobar.setPort(9066);
    cobar.setStatus("Active");
    cobar.setTime_diff("no");
    cobar.setUser("test");
    cobarDAO.addCobar(cobar);
}
Also used : CobarDAOImple(com.alibaba.cobar.manager.dao.xml.CobarDAOImple) CobarDO(com.alibaba.cobar.manager.dataobject.xml.CobarDO) IOException(java.io.IOException)

Aggregations

CobarDO (com.alibaba.cobar.manager.dataobject.xml.CobarDO)35 CobarAdapterDAO (com.alibaba.cobar.manager.dao.CobarAdapterDAO)16 HashMap (java.util.HashMap)16 Map (java.util.Map)15 ArrayList (java.util.ArrayList)14 ModelAndView (org.springframework.web.servlet.ModelAndView)13 UserDO (com.alibaba.cobar.manager.dataobject.xml.UserDO)10 ClusterDO (com.alibaba.cobar.manager.dataobject.xml.ClusterDO)9 FluenceHashMap (com.alibaba.cobar.manager.util.FluenceHashMap)7 Test (org.junit.Test)7 PropertyUtilsBean (org.apache.commons.beanutils.PropertyUtilsBean)6 IOException (java.io.IOException)5 Iterator (java.util.Iterator)4 Entry (java.util.Map.Entry)4 JSONObject (net.sf.json.JSONObject)3 CommandStatus (com.alibaba.cobar.manager.dataobject.cobarnode.CommandStatus)2 ProcessorStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ProcessorStatus)2 ServerStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ServerStatus)2 Pair (com.alibaba.cobar.manager.util.Pair)2 JSONArray (net.sf.json.JSONArray)2