Search in sources :

Example 26 with UserDO

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

the class MCobarListScreen method handleRequestInternal.

@SuppressWarnings({ "unchecked" })
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    UserDO user = (UserDO) request.getSession().getAttribute("user");
    long clusterId = Long.parseLong(request.getParameter("clusterId"));
    ClusterDO cluster = xmlAccesser.getClusterDAO().getClusterById(clusterId);
    List<CobarDO> cobarList = xmlAccesser.getCobarDAO().getCobarList(clusterId);
    List<Map<String, Object>> cobarViewList = null;
    if (null != cobarList) {
        ListSortUtil.sortCobarByName(cobarList);
        cobarViewList = new ArrayList<Map<String, Object>>();
        PropertyUtilsBean util = new PropertyUtilsBean();
        for (CobarDO c : cobarList) {
            Map<String, Object> map = util.describe(c);
            map.remove("class");
            map.remove("name");
            map.put("name", CobarStringUtil.htmlEscapedString(c.getName()));
            cobarViewList.add(map);
        }
    }
    Map<String, Object> clusterView = new HashMap<String, Object>();
    clusterView.put("id", cluster.getId());
    clusterView.put("name", CobarStringUtil.htmlEscapedString(cluster.getName()));
    return new ModelAndView("m_cobarList", new FluenceHashMap<String, Object>().putKeyValue("cobarList", cobarViewList).putKeyValue("user", user).putKeyValue("cluster", clusterView));
}
Also used : PropertyUtilsBean(org.apache.commons.beanutils.PropertyUtilsBean) HashMap(java.util.HashMap) FluenceHashMap(com.alibaba.cobar.manager.util.FluenceHashMap) UserDO(com.alibaba.cobar.manager.dataobject.xml.UserDO) ModelAndView(org.springframework.web.servlet.ModelAndView) FluenceHashMap(com.alibaba.cobar.manager.util.FluenceHashMap) CobarDO(com.alibaba.cobar.manager.dataobject.xml.CobarDO) ClusterDO(com.alibaba.cobar.manager.dataobject.xml.ClusterDO) HashMap(java.util.HashMap) FluenceHashMap(com.alibaba.cobar.manager.util.FluenceHashMap) Map(java.util.Map)

Example 27 with UserDO

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

the class MUserListScreen method handleRequestInternal.

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    UserDO user = (UserDO) request.getSession().getAttribute("user");
    List<UserDO> uList = xmlAccesser.getUserDAO().getUserList();
    return new ModelAndView("m_userList", new FluenceHashMap<String, Object>().putKeyValue("user", user).putKeyValue("uList", uList));
}
Also used : UserDO(com.alibaba.cobar.manager.dataobject.xml.UserDO) ModelAndView(org.springframework.web.servlet.ModelAndView)

Example 28 with UserDO

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

the class ModifyPassword method onSubmit.

@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
    PasswordForm form = (PasswordForm) command;
    UserDO user = (UserDO) request.getSession().getAttribute("user");
    user.setPassword(EncryptUtil.encrypt(form.getNewPassword()));
    boolean flag = xmlAccesser.getUserDAO().modifyUser(user);
    if (flag) {
        return new ModelAndView("m_success", "info", "success");
    } else {
        return new ModelAndView("failure", "reason", "fail");
    }
}
Also used : UserDO(com.alibaba.cobar.manager.dataobject.xml.UserDO) ModelAndView(org.springframework.web.servlet.ModelAndView)

Example 29 with UserDO

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

the class PropertyReload method handleRequestInternal.

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    UserDO user = (UserDO) request.getSession().getAttribute("user");
    String types = request.getParameter("type");
    int type = typeMap.get(types);
    String list = request.getParameter("list");
    String[] temp = list.split(",");
    int[] index = new int[temp.length];
    for (int i = 0; i < temp.length; i++) {
        index[i] = Integer.parseInt(temp[i]);
    }
    if (logger.isWarnEnabled()) {
        StringBuilder log = new StringBuilder(user.getUsername()).append(" | do ").append(types).append(" | cobar:");
        for (int i = 0; i < index.length; i++) {
            log.append(xmlAccesser.getCobarDAO().getCobarById(index[i])).append(" ");
        }
        logger.warn(log.toString());
    }
    List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
    lock.lock();
    try {
        switch(type) {
            case CONFIG_RELOAD:
                for (int i = 0; i < index.length; i++) {
                    CobarDO c = xmlAccesser.getCobarDAO().getCobarById(index[i]);
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("name", CobarStringUtil.htmlEscapedString(c.getName()));
                    if (c.getStatus().equals(ConstantDefine.ACTIVE)) {
                        CobarAdapterDAO perf = cobarAccesser.getAccesser(index[i]);
                        if (perf.checkConnection()) {
                            if (perf.reloadConfig()) {
                                map.put("result", "success");
                            } else {
                                map.put("result", "config reload error");
                            }
                        } else {
                            map.put("result", "connection error");
                        }
                    } else {
                        map.put("result", "cobar InActive");
                    }
                    resultList.add(map);
                }
                break;
            case CONFIG_ROLLBACK:
                for (int i = 0; i < index.length; i++) {
                    CobarDO c = xmlAccesser.getCobarDAO().getCobarById(index[i]);
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("name", CobarStringUtil.htmlEscapedString(c.getName()));
                    if (c.getStatus().equals(ConstantDefine.ACTIVE)) {
                        CobarAdapterDAO perf = cobarAccesser.getAccesser(index[i]);
                        if (perf.checkConnection()) {
                            if (perf.rollbackConfig()) {
                                map.put("result", "success");
                            } else {
                                map.put("result", "config reload error");
                            }
                        } else {
                            map.put("result", "connection error");
                        }
                    } else {
                        map.put("result", "cobar InActive");
                    }
                    resultList.add(map);
                }
                break;
            default:
                logger.error("Wrong property control type!");
                break;
        }
    } 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 reloading");
        resultList.clear();
        resultList.add(map);
    } finally {
        lock.unlock();
    }
    return new ModelAndView("c_result", "resultList", resultList);
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) HashMap(java.util.HashMap) 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) HashMap(java.util.HashMap) Map(java.util.Map)

Example 30 with UserDO

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

the class UserDAOImple method write.

@SuppressWarnings({ "rawtypes", "unchecked" })
private boolean write() {
    FileOutputStream os = null;
    lock.lock();
    try {
        if (!backup(xmlPath)) {
            logger.error("user backup fail!");
        }
        os = new FileOutputStream(xmlPath);
        xsl.setOutput(os, "UTF-8");
        xsl.startDocument("UTF-8", null);
        xsl.text("\n");
        xsl.startTag(null, "users");
        xsl.text("\n");
        Iterator it = map.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<Long, UserDO> entry = (Entry<Long, UserDO>) it.next();
            UserDO user = entry.getValue();
            if (!write(user)) {
                throw new IOException("User write error!");
            }
        }
        xsl.endTag(null, "users");
        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;
}
Also used : Entry(java.util.Map.Entry) UserDO(com.alibaba.cobar.manager.dataobject.xml.UserDO) FileOutputStream(java.io.FileOutputStream) Iterator(java.util.Iterator) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

UserDO (com.alibaba.cobar.manager.dataobject.xml.UserDO)39 ModelAndView (org.springframework.web.servlet.ModelAndView)22 HashMap (java.util.HashMap)15 Map (java.util.Map)15 ClusterDO (com.alibaba.cobar.manager.dataobject.xml.ClusterDO)11 CobarDO (com.alibaba.cobar.manager.dataobject.xml.CobarDO)10 FluenceHashMap (com.alibaba.cobar.manager.util.FluenceHashMap)10 ArrayList (java.util.ArrayList)10 CobarAdapterDAO (com.alibaba.cobar.manager.dao.CobarAdapterDAO)7 PropertyUtilsBean (org.apache.commons.beanutils.PropertyUtilsBean)5 Test (org.junit.Test)5 Iterator (java.util.Iterator)4 Entry (java.util.Map.Entry)4 IOException (java.io.IOException)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 MockHttpSession (org.springframework.mock.web.MockHttpSession)3 UserDAOImple (com.alibaba.cobar.manager.dao.xml.UserDAOImple)1 ConnectionStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ConnectionStatus)1 DataNodesStatus (com.alibaba.cobar.manager.dataobject.cobarnode.DataNodesStatus)1