use of com.alibaba.cobar.manager.dataobject.xml.CobarDO in project cobar by alibaba.
the class CobarDAOImple method write.
@SuppressWarnings({ "rawtypes", "unchecked" })
private boolean write() {
FileOutputStream os = null;
lock.lock();
try {
if (!backup(xmlPath)) {
logger.error("cobar backup fail!");
}
os = new FileOutputStream(xmlPath);
xsl.setOutput(os, "UTF-8");
xsl.startDocument("UTF-8", null);
xsl.text("\n");
xsl.startTag(null, "cobars");
xsl.text("\n");
Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Long, CobarDO> entry = (Entry<Long, CobarDO>) it.next();
CobarDO cobar = entry.getValue();
if (!write(cobar)) {
throw new IOException("Cobar write error!");
}
}
xsl.endTag(null, "cobars");
xsl.endDocument();
os.close();
return true;
} catch (IOException e) {
logger.error(e.getMessage(), e);
} finally {
lock.unlock();
}
if (null != os) {
try {
os.close();
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
return false;
}
use of com.alibaba.cobar.manager.dataobject.xml.CobarDO in project cobar by alibaba.
the class CobarDAOImple method getCobarList.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public List<CobarDO> getCobarList(long clusterId) {
List<CobarDO> list = new ArrayList<CobarDO>();
Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Long, CobarDO> entry = (Entry<Long, CobarDO>) it.next();
CobarDO cobar = entry.getValue();
if (clusterId == cobar.getClusterId()) {
list.add(cobar);
}
}
return list;
}
use of com.alibaba.cobar.manager.dataobject.xml.CobarDO 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.CobarDO 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.CobarDO in project cobar by alibaba.
the class ClusterInstantPerfValueAjax method getClusterInfo.
private AjaxResult getClusterInfo(AjaxParams params) {
JSONArray array = params.getArray();
long clusterId = params.getClusterId();
JSONObject json = null;
if (array.size() > 0) {
json = array.getJSONObject(0);
}
AjaxResult rs = new AjaxResult();
rs.setId(clusterId);
List<CobarDO> nodes = xmlAccesser.getCobarDAO().getCobarList(clusterId);
rs.setTotal(nodes.size());
for (CobarDO cobar : nodes) {
if (ConstantDefine.IN_ACTIVE.equals(cobar.getStatus())) {
continue;
}
CobarAdapterDAO perfAccesser = cobarAccesser.getAccesser(cobar.getId());
if (!perfAccesser.checkConnection()) {
rs.addError(1);
StringBuilder sb = new StringBuilder("getClusterInfo : cobar connect error for [ Name:");
sb.append(cobar.getName()).append(" Host:").append(cobar.getHost()).append(" ]");
logger.error(sb.toString());
continue;
}
rs.addActive(1);
rs.setSchema(perfAccesser.listDataBases().size());
List<ProcessorStatus> list = perfAccesser.listProccessorStatus();
rs.addNetIn(groupByPList(list, NET_IN));
rs.addNetOut(groupByPList(list, NET_OUT));
rs.addConnection(groupByPList(list, CONNECTION));
rs.setTimestamp(list.get(list.size() - 1).getSampleTimeStamp());
List<CommandStatus> commandList = perfAccesser.listCommandStatus();
rs.addRequest(groupByCList(commandList, REQUEST_COUNT));
}
if (json != null && json.getLong("netIn") != -1) {
long o_tiemstamp = json.getLong("timestamp");
rs.setNetIn_deriv(FormatUtil.formatNetwork(Math.round(MathUtil.getDerivate(rs.getNetIn(), json.getLong("netIn"), rs.getTimestamp(), o_tiemstamp, 1000.0))));
rs.setNetOut_deriv(FormatUtil.formatNetwork(Math.round(MathUtil.getDerivate(rs.getNetOut(), json.getLong("netOut"), rs.getTimestamp(), o_tiemstamp, 1000.0))));
rs.setRequest_deriv(FormatUtil.formatNumber(Math.round(MathUtil.getDerivate(rs.getRequest(), json.getLong("reCount"), rs.getTimestamp(), o_tiemstamp, 1000.0))));
}
return rs;
}
Aggregations