use of com.alibaba.cobar.manager.dataobject.xml.UserDO in project cobar by alibaba.
the class ConnectionControlScreen method handleRequestInternal.
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
UserDO user = (UserDO) request.getSession().getAttribute("user");
String id = request.getParameter("clusterId");
long clusterId = -1;
if (null != id) {
clusterId = Long.parseLong(id);
}
String cobarNodeId = request.getParameter("cobarNodeId");
long cobarId = -1;
if (null != cobarNodeId) {
cobarId = Long.parseLong(cobarNodeId);
}
List<ClusterDO> cList = xmlAccesser.getClusterDAO().listAllCluster();
List<Map<String, Object>> clusterList = new ArrayList<Map<String, Object>>();
ListSortUtil.sortClusterByName(cList);
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);
}
List<CobarDO> cobarList = null;
if (null != cList && cList.size() > 0) {
if (-1 == clusterId) {
clusterId = cList.get(0).getId();
cobarList = xmlAccesser.getCobarDAO().getCobarList(clusterId, ConstantDefine.ACTIVE);
} else {
cobarList = xmlAccesser.getCobarDAO().getCobarList(clusterId, ConstantDefine.ACTIVE);
}
}
List<Map<String, Object>> cobarViewList = null;
if (null != cobarList && cobarList.size() > 0) {
ListSortUtil.sortCobarByName(cobarList);
cobarViewList = new ArrayList<Map<String, Object>>();
for (CobarDO c : cobarList) {
CobarAdapterDAO perf = cobarAccesser.getAccesser(c.getId());
if (perf.checkConnection()) {
Map<String, Object> cobarMap = new HashMap<String, Object>();
cobarMap.put("id", c.getId());
cobarMap.put("name", CobarStringUtil.htmlEscapedString(c.getName()));
cobarViewList.add(cobarMap);
}
}
}
/* cobarId=-2, cobar InActive; cobarId=-3, connection error */
List<ConnectionStatus> connecList = null;
if (cobarId > 0) {
CobarDO cobar = xmlAccesser.getCobarDAO().getCobarById(cobarId);
if (cobar.getStatus().equals(ConstantDefine.ACTIVE)) {
CobarAdapterDAO perf = cobarAccesser.getAccesser(cobarId);
if (!perf.checkConnection()) {
cobarId = -3;
} else {
connecList = perf.listConnectionStatus();
}
} else {
cobarId = -2;
}
}
List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();
if (null != connecList) {
ListSortUtil.sortConnections(connecList);
for (ConnectionStatus c : connecList) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("processor", c.getProcessor());
map.put("id", c.getId());
map.put("host", c.getHost());
map.put("port", c.getPort());
map.put("local_port", c.getLocal_port());
map.put("schema", c.getSchema());
map.put("charset", c.getCharset());
map.put("netIn", FormatUtil.formatStore(c.getNetIn()));
map.put("netOut", FormatUtil.formatStore(c.getNetOut()));
map.put("aliveTime", FormatUtil.formatTime(c.getAliveTime() * 1000, 2));
map.put("attempsCount", FormatUtil.formatNumber(c.getAttempsCount()));
map.put("recvBuffer", FormatUtil.formatStore(c.getRecvBuffer()));
map.put("sendQueue", c.getSendQueue());
map.put("channel", c.getChannel());
returnList.add(map);
}
}
return new ModelAndView("c_connection", new FluenceHashMap<String, Object>().putKeyValue("cList", clusterList).putKeyValue("cobarList", cobarViewList).putKeyValue("clusterId", clusterId).putKeyValue("cobarId", cobarId).putKeyValue("connecList", returnList).putKeyValue("user", user));
}
use of com.alibaba.cobar.manager.dataobject.xml.UserDO in project cobar by alibaba.
the class AddUser method onSubmit.
@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
UserForm form = (UserForm) command;
UserDO user = new UserDO();
user.setPassword(EncryptUtil.encrypt(form.getPassword().trim()));
user.setUser_role(form.getUser_role().trim());
user.setRealname(form.getRealname().trim());
user.setStatus(form.getStatus().trim());
user.setUsername(form.getUsername().trim());
boolean flag = xmlAccesser.getUserDAO().addUser(user);
if (flag) {
return new ModelAndView("m_success", "info", "add success");
} else {
String reason = form.getUsername() + " exist";
return new ModelAndView("failure", "reason", reason);
}
}
use of com.alibaba.cobar.manager.dataobject.xml.UserDO 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.UserDO in project cobar by alibaba.
the class LoginAction method onSubmit.
@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
Account form = (Account) command;
UserDO user = xmlAccesser.getUserDAO().validateUser(form.getUserName().trim(), form.getPassword().trim());
if (user != null) {
if (logger.isInfoEnabled()) {
StringBuilder sb = new StringBuilder("User '");
sb.append(user.getUsername());
sb.append("' login!");
logger.info(sb.toString());
}
request.getSession().setAttribute("user", user);
//request.getSession().setMaxInactiveInterval(30);
String to = (String) request.getSession().getAttribute("lastRequest");
if (null != to) {
request.getSession().removeAttribute("click");
request.getSession().removeAttribute("lastRequest");
response.sendRedirect(to);
} else {
response.sendRedirect(URLBroker.redirectClusterListScreen());
}
} else {
// ??????
boolean flag = (Boolean) request.getSession().getAttribute("click");
if (flag) {
response.sendRedirect(URLBroker.redirectIndexPage("false"));
} else {
response.sendRedirect(URLBroker.redirectLogInPage("false"));
}
}
return null;
}
use of com.alibaba.cobar.manager.dataobject.xml.UserDO in project cobar by alibaba.
the class ModifyUser method onSubmit.
@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
UserForm form = (UserForm) command;
UserDO user = new UserDO();
user.setId(form.getUserId());
user.setPassword(EncryptUtil.encrypt(form.getPassword().trim()));
user.setRealname(form.getRealname().trim());
user.setUser_role(form.getUser_role().trim());
user.setUsername(form.getUsername().trim());
user.setStatus(form.getStatus().trim());
boolean flag = xmlAccesser.getUserDAO().modifyUser(user);
if (flag) {
return new ModelAndView("m_success", "info", "success");
} else {
String reason = form.getUsername() + " exist";
return new ModelAndView("failure", "reason", reason);
}
}
Aggregations