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) {
Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Long, ClusterDO> entry = (Entry<Long, ClusterDO>) it.next();
ClusterDO cluster = entry.getValue();
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 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.dataobject.xml.ClusterDO in project cobar by alibaba.
the class ClusterDaoTest method testModifyClusterWithoutId.
@Test
public void testModifyClusterWithoutId() {
ClusterDO cluster = DOFactory.getCluster();
clusterDao.addCluster(cluster);
long testId = 1L;
ClusterDO clusterTemp = clusterDao.getClusterById(testId);
Assert.assertNotNull(clusterTemp);
String destDeployContact = clusterTemp.getDeployContact() + "testModifyCluster";
String destDeployDesc = clusterTemp.getDeployDesc() + "testModifyCluster";
String destMainContact = clusterTemp.getMaintContact() + "11111";
String destName = clusterTemp.getName() + "testModifyCluster";
String destOnlineTime = clusterTemp.getOnlineTime() + "testModifyCluster";
clusterTemp.setDeployContact(destDeployContact);
clusterTemp.setDeployDesc(destDeployDesc);
clusterTemp.setMaintContact(destMainContact);
clusterTemp.setName(destName);
clusterTemp.setOnlineTime(destOnlineTime);
clusterDao.modifyCluster(clusterTemp);
read();
Assert.assertEquals(clusterDao.getClusterById(testId).getDeployContact(), destDeployContact);
Assert.assertEquals(clusterDao.getClusterById(testId).getDeployDesc(), destDeployDesc);
Assert.assertEquals(clusterDao.getClusterById(testId).getMaintContact(), destMainContact);
Assert.assertEquals(clusterDao.getClusterById(testId).getName(), destName);
Assert.assertEquals(clusterDao.getClusterById(testId).getOnlineTime(), destOnlineTime);
}
use of com.alibaba.cobar.manager.dataobject.xml.ClusterDO in project cobar by alibaba.
the class ClusterDaoTest method testAddDuplicatedCluster.
@Test
public void testAddDuplicatedCluster() {
ClusterDO cluster = DOFactory.getCluster();
clusterDao.addCluster(cluster);
int duplicatedClusterNum = 2;
for (int i = 0; i < duplicatedClusterNum; i++) {
ClusterDO clusterDuplicate = DOFactory.getCluster();
Assert.assertFalse(clusterDao.addCluster(clusterDuplicate));
}
read();
Assert.assertEquals(1, clusterDao.listAllCluster().size());
}
use of com.alibaba.cobar.manager.dataobject.xml.ClusterDO in project cobar by alibaba.
the class ClusterDaoTest method testCheckName.
@Test
public void testCheckName() {
int clusterNum = 10;
for (int i = 0; i < clusterNum; i++) {
ClusterDO cluster = DOFactory.getCluster();
cluster.setName("test" + i);
clusterDao.addCluster(cluster);
}
ClusterDO cluster = DOFactory.getCluster();
cluster.setName("test" + 0);
clusterDao.addCluster(cluster);
Assert.assertFalse(clusterDao.checkName("test1"));
Assert.assertTrue(clusterDao.checkName("test10"));
Assert.assertTrue(clusterDao.checkName("test2", 3));
Assert.assertFalse(clusterDao.checkName("test0", 3));
}
Aggregations