Search in sources :

Example 31 with UserConfig

use of io.mycat.config.model.UserConfig in project Mycat-Server by MyCATApache.

the class ReloadConfig method reload.

public static boolean reload() {
    /**
     *  1、载入新的配置, ConfigInitializer 内部完成自检工作, 由于不更新数据源信息,此处不自检 dataHost  dataNode
     */
    ConfigInitializer loader = new ConfigInitializer(false);
    Map<String, UserConfig> users = loader.getUsers();
    Map<String, SchemaConfig> schemas = loader.getSchemas();
    Map<String, PhysicalDBNode> dataNodes = loader.getDataNodes();
    Map<String, PhysicalDBPool> dataHosts = loader.getDataHosts();
    MycatCluster cluster = loader.getCluster();
    FirewallConfig firewall = loader.getFirewall();
    /**
     * 2、在老的配置上,应用新的配置
     */
    MycatServer.getInstance().getConfig().reload(users, schemas, dataNodes, dataHosts, cluster, firewall, false);
    /**
     * 3、清理缓存
     */
    MycatServer.getInstance().getCacheService().clearCache();
    MycatServer.getInstance().initRuleData();
    return true;
}
Also used : PhysicalDBNode(io.mycat.backend.datasource.PhysicalDBNode) SchemaConfig(io.mycat.config.model.SchemaConfig) ConfigInitializer(io.mycat.config.ConfigInitializer) MycatCluster(io.mycat.config.MycatCluster) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool) UserConfig(io.mycat.config.model.UserConfig) FirewallConfig(io.mycat.config.model.FirewallConfig)

Example 32 with UserConfig

use of io.mycat.config.model.UserConfig in project Mycat-Server by MyCATApache.

the class ShowWhiteHost method execute.

public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c, true);
    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = eof.write(buffer, c, true);
    // write rows
    byte packetId = eof.packetId;
    Map<String, List<UserConfig>> map = MycatServer.getInstance().getConfig().getFirewall().getWhitehost();
    for (String key : map.keySet()) {
        List<UserConfig> userConfigs = map.get(key);
        String users = "";
        for (int i = 0; i < userConfigs.size(); i++) {
            if (i > 0) {
                users += "," + userConfigs.get(i).getName();
            } else {
                users += userConfigs.get(i).getName();
            }
        }
        RowDataPacket row = getRow(key, users, c.getCharset());
        row.packetId = ++packetId;
        buffer = row.write(buffer, c, true);
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) ArrayList(java.util.ArrayList) List(java.util.List) UserConfig(io.mycat.config.model.UserConfig) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 33 with UserConfig

use of io.mycat.config.model.UserConfig in project Mycat-Server by MyCATApache.

the class ConfigTest method testReadUserBenchmark.

/**
 * 测试 用户服务降级 拒连 配置
 */
@Test
public void testReadUserBenchmark() {
    UserConfig userConfig = this.users.get("test");
    int benchmark = userConfig.getBenchmark();
    Assert.assertTrue(benchmark == 11111);
}
Also used : UserConfig(io.mycat.config.model.UserConfig) Test(org.junit.Test)

Example 34 with UserConfig

use of io.mycat.config.model.UserConfig in project Mycat-Server by MyCATApache.

the class ShowFullTables method getTableSet.

private static Set<String> getTableSet(ServerConnection c, Map<String, String> parm) {
    TreeSet<String> tableSet = new TreeSet<String>();
    MycatConfig conf = MycatServer.getInstance().getConfig();
    Map<String, UserConfig> users = conf.getUsers();
    UserConfig user = users == null ? null : users.get(c.getUser());
    if (user != null) {
        Map<String, SchemaConfig> schemas = conf.getSchemas();
        for (String name : schemas.keySet()) {
            if (null != parm.get(SCHEMA_KEY) && parm.get(SCHEMA_KEY).toUpperCase().equals(name.toUpperCase())) {
                if (null == parm.get("LIKE_KEY")) {
                    tableSet.addAll(schemas.get(name).getTables().keySet());
                } else {
                    String p = "^" + parm.get("LIKE_KEY").replaceAll("%", ".*");
                    Pattern pattern = Pattern.compile(p, Pattern.CASE_INSENSITIVE);
                    Matcher ma;
                    for (String tname : schemas.get(name).getTables().keySet()) {
                        ma = pattern.matcher(tname);
                        if (ma.matches()) {
                            tableSet.add(tname);
                        }
                    }
                }
            }
        }
        ;
    }
    return tableSet;
}
Also used : Pattern(java.util.regex.Pattern) SchemaConfig(io.mycat.config.model.SchemaConfig) Matcher(java.util.regex.Matcher) TreeSet(java.util.TreeSet) MycatConfig(io.mycat.config.MycatConfig) UserConfig(io.mycat.config.model.UserConfig)

Example 35 with UserConfig

use of io.mycat.config.model.UserConfig in project Mycat-Server by MyCATApache.

the class ShowDatabases method response.

public static void response(ServerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c, true);
    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = eof.write(buffer, c, true);
    // write rows
    byte packetId = eof.packetId;
    MycatConfig conf = MycatServer.getInstance().getConfig();
    Map<String, UserConfig> users = conf.getUsers();
    UserConfig user = users == null ? null : users.get(c.getUser());
    if (user != null) {
        TreeSet<String> schemaSet = new TreeSet<String>();
        Set<String> schemaList = user.getSchemas();
        if (schemaList == null || schemaList.size() == 0) {
            schemaSet.addAll(conf.getSchemas().keySet());
        } else {
            for (String schema : schemaList) {
                schemaSet.add(schema);
            }
        }
        for (String name : schemaSet) {
            RowDataPacket row = new RowDataPacket(FIELD_COUNT);
            row.add(StringUtil.encode(name, c.getCharset()));
            row.packetId = ++packetId;
            buffer = row.write(buffer, c, true);
        }
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // post write
    c.write(buffer);
}
Also used : TreeSet(java.util.TreeSet) RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) MycatConfig(io.mycat.config.MycatConfig) UserConfig(io.mycat.config.model.UserConfig) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Aggregations

UserConfig (io.mycat.config.model.UserConfig)36 MycatConfig (io.mycat.config.MycatConfig)10 SchemaConfig (io.mycat.config.model.SchemaConfig)10 FirewallConfig (io.mycat.config.model.FirewallConfig)8 ArrayList (java.util.ArrayList)8 Pattern (java.util.regex.Pattern)8 PhysicalDBNode (io.mycat.backend.datasource.PhysicalDBNode)6 PhysicalDBPool (io.mycat.backend.datasource.PhysicalDBPool)6 MycatCluster (io.mycat.config.MycatCluster)6 ConfigException (io.mycat.config.util.ConfigException)6 List (java.util.List)6 TreeSet (java.util.TreeSet)6 ConfigInitializer (io.mycat.config.ConfigInitializer)4 EOFPacket (io.mycat.net.mysql.EOFPacket)4 FieldPacket (io.mycat.net.mysql.FieldPacket)4 RowDataPacket (io.mycat.net.mysql.RowDataPacket)4 ByteBuffer (java.nio.ByteBuffer)4 Matcher (java.util.regex.Matcher)4 Element (org.w3c.dom.Element)4 Node (org.w3c.dom.Node)4