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;
}
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);
}
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);
}
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;
}
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);
}
Aggregations