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);
}
}
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!");
}
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);
}
}
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));
}
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);
}
Aggregations