Search in sources :

Example 26 with ClusterDO

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;
}
Also used : Entry(java.util.Map.Entry) ClusterDO(com.alibaba.cobar.manager.dataobject.xml.ClusterDO) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 27 with ClusterDO

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));
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) HashMap(java.util.HashMap) FluenceHashMap(com.alibaba.cobar.manager.util.FluenceHashMap) PropertyUtilsBean(org.apache.commons.beanutils.PropertyUtilsBean) UserDO(com.alibaba.cobar.manager.dataobject.xml.UserDO) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) CobarDO(com.alibaba.cobar.manager.dataobject.xml.CobarDO) ClusterDO(com.alibaba.cobar.manager.dataobject.xml.ClusterDO) ServerStatus(com.alibaba.cobar.manager.dataobject.cobarnode.ServerStatus) HashMap(java.util.HashMap) FluenceHashMap(com.alibaba.cobar.manager.util.FluenceHashMap) Map(java.util.Map)

Example 28 with ClusterDO

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);
}
Also used : ClusterDO(com.alibaba.cobar.manager.dataobject.xml.ClusterDO) Test(org.junit.Test)

Example 29 with ClusterDO

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());
}
Also used : ClusterDO(com.alibaba.cobar.manager.dataobject.xml.ClusterDO) Test(org.junit.Test)

Example 30 with ClusterDO

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));
}
Also used : ClusterDO(com.alibaba.cobar.manager.dataobject.xml.ClusterDO) Test(org.junit.Test)

Aggregations

ClusterDO (com.alibaba.cobar.manager.dataobject.xml.ClusterDO)30 ModelAndView (org.springframework.web.servlet.ModelAndView)16 HashMap (java.util.HashMap)15 Map (java.util.Map)15 FluenceHashMap (com.alibaba.cobar.manager.util.FluenceHashMap)12 UserDO (com.alibaba.cobar.manager.dataobject.xml.UserDO)11 ArrayList (java.util.ArrayList)11 CobarDO (com.alibaba.cobar.manager.dataobject.xml.CobarDO)9 PropertyUtilsBean (org.apache.commons.beanutils.PropertyUtilsBean)7 Test (org.junit.Test)7 CobarAdapterDAO (com.alibaba.cobar.manager.dao.CobarAdapterDAO)5 IOException (java.io.IOException)5 Iterator (java.util.Iterator)3 Entry (java.util.Map.Entry)3 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)2 ClusterDAOImple (com.alibaba.cobar.manager.dao.xml.ClusterDAOImple)1 ConnectionStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ConnectionStatus)1 DataNodesStatus (com.alibaba.cobar.manager.dataobject.cobarnode.DataNodesStatus)1 ServerStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ServerStatus)1 FileInputStream (java.io.FileInputStream)1