use of com.alibaba.cobar.manager.dao.CobarAdapterDAO in project cobar by alibaba.
the class CobarAccesser method getAccesser.
public CobarAdapterDAO getAccesser(long cobarId) {
final CobarDO cobar = xmlAccesser.getCobarDAO().getCobarById(cobarId);
if (cobar == null) {
logger.error(new StringBuilder("Fail to get cobar information which id = ").append(cobarId).toString());
}
CobarAdapterDAO accesser = cobarAdapterDelegate.getCobarNodeAccesser(cobar.getHost(), cobar.getPort(), cobar.getUser(), cobar.getPassword());
return accesser;
}
use of com.alibaba.cobar.manager.dao.CobarAdapterDAO in project cobar by alibaba.
the class PropertyReload method handleRequestInternal.
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
UserDO user = (UserDO) request.getSession().getAttribute("user");
String types = request.getParameter("type");
int type = typeMap.get(types);
String list = request.getParameter("list");
String[] temp = list.split(",");
int[] index = new int[temp.length];
for (int i = 0; i < temp.length; i++) {
index[i] = Integer.parseInt(temp[i]);
}
if (logger.isWarnEnabled()) {
StringBuilder log = new StringBuilder(user.getUsername()).append(" | do ").append(types).append(" | cobar:");
for (int i = 0; i < index.length; i++) {
log.append(xmlAccesser.getCobarDAO().getCobarById(index[i])).append(" ");
}
logger.warn(log.toString());
}
List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
lock.lock();
try {
switch(type) {
case CONFIG_RELOAD:
for (int i = 0; i < index.length; i++) {
CobarDO c = xmlAccesser.getCobarDAO().getCobarById(index[i]);
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", CobarStringUtil.htmlEscapedString(c.getName()));
if (c.getStatus().equals(ConstantDefine.ACTIVE)) {
CobarAdapterDAO perf = cobarAccesser.getAccesser(index[i]);
if (perf.checkConnection()) {
if (perf.reloadConfig()) {
map.put("result", "success");
} else {
map.put("result", "config reload error");
}
} else {
map.put("result", "connection error");
}
} else {
map.put("result", "cobar InActive");
}
resultList.add(map);
}
break;
case CONFIG_ROLLBACK:
for (int i = 0; i < index.length; i++) {
CobarDO c = xmlAccesser.getCobarDAO().getCobarById(index[i]);
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", CobarStringUtil.htmlEscapedString(c.getName()));
if (c.getStatus().equals(ConstantDefine.ACTIVE)) {
CobarAdapterDAO perf = cobarAccesser.getAccesser(index[i]);
if (perf.checkConnection()) {
if (perf.rollbackConfig()) {
map.put("result", "success");
} else {
map.put("result", "config reload error");
}
} else {
map.put("result", "connection error");
}
} else {
map.put("result", "cobar InActive");
}
resultList.add(map);
}
break;
default:
logger.error("Wrong property control type!");
break;
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", "UNKNOWN ERROR");
map.put("result", "unknown exception occurs when reloading");
resultList.clear();
resultList.add(map);
} finally {
lock.unlock();
}
return new ModelAndView("c_result", "resultList", resultList);
}
use of com.alibaba.cobar.manager.dao.CobarAdapterDAO in project cobar by alibaba.
the class PropertyReloadScreen method handleRequestInternal.
@SuppressWarnings("unchecked")
@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);
}
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);
} else {
cobarList = xmlAccesser.getCobarDAO().getCobarList(clusterId);
}
}
List<Map<String, Object>> cobarListMap = new ArrayList<Map<String, Object>>();
PropertyUtilsBean util = new PropertyUtilsBean();
if (null != cobarList) {
ListSortUtil.sortCobarByName(cobarList);
for (CobarDO c : cobarList) {
CobarAdapterDAO perf = cobarAccesser.getAccesser(c.getId());
Map<String, Object> map;
try {
map = util.describe(c);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
map.remove("class");
map.remove("name");
map.put("name", CobarStringUtil.htmlEscapedString(c.getName()));
if (ConstantDefine.ACTIVE.equals(c.getStatus())) {
if (!perf.checkConnection()) {
map.remove("status");
map.put("status", ConstantDefine.ERROR);
map.put("reloadTime", "");
map.put("rollbackTime", "");
} else {
ServerStatus ss = perf.getServerStatus();
String rollbackTime = "NO";
String reloadTime = FormatUtil.fromMilliseconds2String(ss.getReloadTime());
if (ss.getRollbackTime() != -1) {
rollbackTime = FormatUtil.fromMilliseconds2String(ss.getRollbackTime());
}
map.put("reloadTime", reloadTime);
map.put("rollbackTime", rollbackTime);
}
} else {
map.put("reloadTime", "");
map.put("rollbackTime", "");
}
cobarListMap.add(map);
}
}
return new ModelAndView("c_propertyReload", new FluenceHashMap<String, Object>().putKeyValue("cList", clusterList).putKeyValue("cobarList", cobarListMap).putKeyValue("clusterId", clusterId).putKeyValue("user", user));
}
use of com.alibaba.cobar.manager.dao.CobarAdapterDAO in project cobar by alibaba.
the class CobarAccessTest method main.
public static void main(String[] args) throws Exception {
String xmlpath = "./src/main/resources/";
CobarAccesser accesser = new CobarAccesser();
XmlAccesser xmlAccesser = new XmlAccesser();
XMLFileLoaderPath xmlFileLoader = new XMLFileLoaderPath();
xmlFileLoader.setXmlPath(xmlpath);
ClusterDAOImple cluster = new ClusterDAOImple();
cluster.setXmlFileLoader(xmlFileLoader);
cluster.afterPropertiesSet();
CobarDAOImple cobar = new CobarDAOImple();
cobar.setXmlFileLoader(xmlFileLoader);
cobar.afterPropertiesSet();
xmlAccesser.setClusterDAO(cluster);
xmlAccesser.setCobarDAO(cobar);
accesser.setXmlAccesser(xmlAccesser);
AdapterDelegate res = new AdapterDelegate();
accesser.setCobarAdapterDelegate(res);
CobarAdapterDAO perf = accesser.getAccesser(1L);
String version = perf.getVersion();
System.out.println(version);
ServerStatus ss = perf.getServerStatus();
System.out.println(ss.getMaxMemory());
System.out.println(ss.getStatus());
System.out.println(ss.getTotalMemory());
System.out.println(ss.getUptime());
System.out.println(ss.getUsedMemory());
System.out.println(ss.getReloadTime());
System.out.println(ss.getRollbackTime());
List<String> databases = perf.listDataBases();
for (String s : databases) {
System.out.println(s);
}
// perf.reloadConfig();
// perf.rollbackConfig();
// int num = perf.switchDataNode("circe,cndb,dubbo,napoli", 0);
// System.out.println("num: " + num);
// int num = perf.stopHeartbeat("circe,cndb,dubbo,napoli", -10);
// System.out.println("num: " + num);
}
Aggregations