Search in sources :

Example 16 with ClusterDO

use of com.alibaba.cobar.manager.dataobject.xml.ClusterDO in project cobar by alibaba.

the class ClusterDaoTest method testXmlFileNotFound.

@Ignore
@Test
public void testXmlFileNotFound() {
    String testXmlPath = "./src/resources/";
    xmlFileLoader.setXmlPath(testXmlPath);
    try {
        clusterDao.afterPropertiesSet();
    } catch (Exception e) {
        e.printStackTrace();
    }
    ClusterDO cluster = DOFactory.getCluster();
    clusterDao.addCluster(cluster);
    Assert.assertNull(clusterDao.getClusterById(1L));
    xmlFileLoader.setXmlPath(testXmlPath);
    try {
        clusterDao.afterPropertiesSet();
    } catch (Exception e) {
        e.printStackTrace();
    }
    Assert.assertNull(clusterDao.getClusterById(1L));
}
Also used : ClusterDO(com.alibaba.cobar.manager.dataobject.xml.ClusterDO) IOException(java.io.IOException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 17 with ClusterDO

use of com.alibaba.cobar.manager.dataobject.xml.ClusterDO in project cobar by alibaba.

the class ClusterDaoTest method testModifyClusterNameToExistName.

@Test
public void testModifyClusterNameToExistName() {
    int insertClusterNum = 3;
    for (int i = 0; i < insertClusterNum; i++) {
        ClusterDO cluster = DOFactory.getCluster();
        cluster.setName("test" + i);
        clusterDao.addCluster(cluster);
    }
    ClusterDO clusterTemp = clusterDao.getClusterById(1);
    clusterTemp.setName("test1");
    Assert.assertFalse(clusterDao.modifyCluster(clusterTemp));
    read();
    clusterTemp = clusterDao.getClusterById(1);
    Assert.assertEquals("test0", clusterTemp.getName());
}
Also used : ClusterDO(com.alibaba.cobar.manager.dataobject.xml.ClusterDO) Test(org.junit.Test)

Example 18 with ClusterDO

use of com.alibaba.cobar.manager.dataobject.xml.ClusterDO in project cobar by alibaba.

the class XmlFile method initCluster.

private void initCluster() {
    String path = this.xmlPath + System.getProperty("file.separator") + "cluster.xml";
    init(path, "clusters");
    ClusterDAOImple clusterDAO = new ClusterDAOImple();
    clusterDAO.setXmlFileLoader(xmlFileLoader);
    try {
        clusterDAO.afterPropertiesSet();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        Assert.fail();
    }
    ClusterDO cluster = new ClusterDO();
    cluster.setDeployContact("utest");
    cluster.setDeployDesc("utest");
    cluster.setMaintContact("utest");
    cluster.setName("cluster");
    cluster.setOnlineTime("2011-01-01");
    clusterDAO.addCluster(cluster);
}
Also used : ClusterDAOImple(com.alibaba.cobar.manager.dao.xml.ClusterDAOImple) ClusterDO(com.alibaba.cobar.manager.dataobject.xml.ClusterDO) IOException(java.io.IOException)

Example 19 with ClusterDO

use of com.alibaba.cobar.manager.dataobject.xml.ClusterDO in project cobar by alibaba.

the class DOFactory method getCluster.

public static ClusterDO getCluster() {
    ClusterDO cluster = new ClusterDO();
    cluster.setDeployContact("deployContact");
    cluster.setDeployDesc("deployDesc");
    cluster.setMaintContact("13456789123");
    cluster.setName("name");
    cluster.setOnlineTime("OnlineTime");
    return cluster;
}
Also used : ClusterDO(com.alibaba.cobar.manager.dataobject.xml.ClusterDO)

Example 20 with ClusterDO

use of com.alibaba.cobar.manager.dataobject.xml.ClusterDO in project cobar by alibaba.

the class AddCobarPage method handleRequestInternal.

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    UserDO user = (UserDO) request.getSession().getAttribute("user");
    long clusterId = Long.parseLong(request.getParameter("clusterId"));
    List<ClusterDO> cList;
    if (-1 == clusterId) {
        cList = this.xmlAccesser.getClusterDAO().listAllCluster();
    } else {
        ClusterDO cluster = xmlAccesser.getClusterDAO().getClusterById(clusterId);
        if (null == cluster) {
            logger.error("cluster doesn't exsit by id : " + clusterId);
        }
        cList = new ArrayList<ClusterDO>();
        cList.add(cluster);
    }
    ListSortUtil.sortClusterByName(cList);
    List<Map<String, Object>> clusterList = new ArrayList<Map<String, Object>>();
    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);
    }
    return new ModelAndView("m_addCobar", new FluenceHashMap<String, Object>().putKeyValue("cList", clusterList).putKeyValue("user", user));
}
Also used : HashMap(java.util.HashMap) FluenceHashMap(com.alibaba.cobar.manager.util.FluenceHashMap) UserDO(com.alibaba.cobar.manager.dataobject.xml.UserDO) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) ClusterDO(com.alibaba.cobar.manager.dataobject.xml.ClusterDO) HashMap(java.util.HashMap) FluenceHashMap(com.alibaba.cobar.manager.util.FluenceHashMap) Map(java.util.Map)

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