use of com.alibaba.cobar.manager.dataobject.xml.ClusterDO in project cobar by alibaba.
the class ClusterDAOImple method read.
private boolean read() {
FileInputStream is = null;
lock.lock();
try {
map.clear();
is = new FileInputStream(xmlPath);
xpp.setInput(is, "UTF-8");
while (!(xpp.getEventType() == XmlPullParser.END_TAG && "clusters".equals(xpp.getName()))) {
if (xpp.getEventType() == XmlPullParser.START_TAG && "cluster".equals(xpp.getName())) {
ClusterDO cluster = read(xpp);
if (null == cluster) {
throw new XmlPullParserException("Cluster read error");
}
maxId = (maxId < cluster.getId()) ? cluster.getId() : maxId;
map.put(cluster.getId(), cluster);
}
xpp.next();
}
is.close();
return true;
} catch (FileNotFoundException e) {
logger.error(e.getMessage(), e);
} catch (XmlPullParserException e) {
logger.error(e.getMessage(), e);
} catch (IOException e) {
logger.error(e.getMessage(), e);
} finally {
maxId = maxId < 0 ? 0 : maxId;
lock.unlock();
}
if (null != is) {
try {
is.close();
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
return false;
}
use of com.alibaba.cobar.manager.dataobject.xml.ClusterDO in project cobar by alibaba.
the class ClusterDAOImple method checkName.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public boolean checkName(String name, long id) {
Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Long, ClusterDO> entry = (Entry<Long, ClusterDO>) it.next();
ClusterDO cluster = entry.getValue();
if (cluster.getId() == id) {
continue;
}
if (name.equals(cluster.getName())) {
return false;
}
}
return true;
}
use of com.alibaba.cobar.manager.dataobject.xml.ClusterDO in project cobar by alibaba.
the class StopHeartbeat method handleRequestInternal.
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) {
UserDO user = (UserDO) request.getSession().getAttribute("user");
String datanodes = request.getParameter("datanodes");
int time = Integer.parseInt(request.getParameter("stoptime"));
long clusterId = Long.parseLong(request.getParameter("clusterIdK"));
ClusterDO cluster = xmlAccesser.getClusterDAO().getClusterById(clusterId);
List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
if (logger.isWarnEnabled()) {
StringBuilder log = new StringBuilder();
log.append(user.getUsername()).append(" | stop heartbeat | cluster:");
log.append(cluster.getName()).append(" | ");
log.append(datanodes).append(" | time:");
log.append(time);
logger.warn(log.toString());
}
List<CobarDO> cobarList = null;
lock.lock();
try {
cobarList = xmlAccesser.getCobarDAO().getCobarList(clusterId, ConstantDefine.ACTIVE);
for (CobarDO c : cobarList) {
CobarAdapterDAO control = cobarAccesser.getAccesser(c.getId());
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", CobarStringUtil.htmlEscapedString(c.getName()));
if (control.checkConnection()) {
int num = control.stopHeartbeat(datanodes, time);
map.put("result", num + " rows");
} else {
map.put("result", "connction error!");
}
resultList.add(map);
}
} 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 stopping heartbeat");
resultList.clear();
resultList.add(map);
} finally {
lock.unlock();
}
return new ModelAndView("c_result", "resultList", resultList);
}
use of com.alibaba.cobar.manager.dataobject.xml.ClusterDO in project cobar by alibaba.
the class SwitchDatanodes method handleRequestInternal.
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
String datanodes = request.getParameter("datanodes");
int index = Integer.parseInt(request.getParameter("index"));
long clusterId = Long.parseLong(request.getParameter("clusterIdK"));
UserDO user = (UserDO) request.getSession().getAttribute("user");
ClusterDO cluster = xmlAccesser.getClusterDAO().getClusterById(clusterId);
List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
List<CobarDO> cobarList = xmlAccesser.getCobarDAO().getCobarList(clusterId, ConstantDefine.ACTIVE);
if (logger.isWarnEnabled()) {
StringBuilder log = new StringBuilder();
log.append(user.getUsername()).append(" | switch datanodes | cluster:");
log.append(cluster.getName()).append(" | ");
log.append(datanodes).append(" | index:");
log.append(index);
logger.warn(log.toString());
}
lock.lock();
try {
for (CobarDO c : cobarList) {
CobarAdapterDAO control = cobarAccesser.getAccesser(c.getId());
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", CobarStringUtil.htmlEscapedString(c.getName()));
if (control.checkConnection()) {
int num = control.switchDataNode(datanodes, index);
map.put("result", num + " rows");
} else {
map.put("result", "connction error!");
}
resultList.add(map);
}
} 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 switching");
resultList.clear();
resultList.add(map);
} finally {
lock.unlock();
}
return new ModelAndView("c_result", "resultList", resultList);
}
use of com.alibaba.cobar.manager.dataobject.xml.ClusterDO in project cobar by alibaba.
the class ClusterListScreen method handleRequestInternal.
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
UserDO user = (UserDO) request.getSession().getAttribute("user");
List<ClusterDO> list = xmlAccesser.getClusterDAO().listAllCluster();
ListSortUtil.sortClusterBySortId(list);
List<Map<String, Object>> clusterList = new ArrayList<Map<String, Object>>();
for (ClusterDO e : list) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", e.getId());
map.put("name", CobarStringUtil.htmlEscapedString(e.getName()));
map.put("maintContact", e.getMaintContact());
map.put("onlineTime", e.getOnlineTime());
clusterList.add(map);
}
return new ModelAndView("v_clusterList", new FluenceHashMap<String, Object>().putKeyValue("clusterList", clusterList).putKeyValue("user", user));
}
Aggregations