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