use of io.mycat.config.DatasourceConfig in project Mycat2 by MyCATApache.
the class TestMySQLManagerImpl method getWriteableConnectionMap.
@Override
@SneakyThrows
public Map<String, java.sql.Connection> getWriteableConnectionMap() {
ConcurrentHashMap.KeySetView<String, DruidDataSource> strings = nameMap.keySet();
JdbcConnectionManager jdbcConnectionManager = MetaClusterCurrent.wrapper(JdbcConnectionManager.class);
Map<String, JdbcDataSource> datasourceInfo = jdbcConnectionManager.getDatasourceInfo();
HashMap<String, Connection> map = new HashMap<>();
for (String string : strings) {
JdbcDataSource jdbcDataSource = datasourceInfo.get(string);
DatasourceConfig config = jdbcDataSource.getConfig();
if (jdbcDataSource.isMySQLType()) {
if (InstanceType.valueOf(Optional.ofNullable(config.getInstanceType()).orElse("READ_WRITE").toUpperCase()).isWriteType()) {
Connection connection = jdbcDataSource.getDataSource().getConnection();
map.put(string, connection);
}
}
}
return map;
}
use of io.mycat.config.DatasourceConfig in project Mycat2 by MyCATApache.
the class SpmTest method init.
@BeforeClass
public static void init() throws Exception {
HashMap<Class, Object> context = new HashMap<>();
context.put(Vertx.class, Vertx.vertx());
context.put(ServerConfig.class, new ServerConfig());
context.put(IOExecutor.class, IOExecutor.DEFAULT);
context.put(DrdsSqlCompiler.class, new DrdsSqlCompiler(new DrdsConst() {
@Override
public NameMap<SchemaHandler> schemas() {
return new NameMap<>();
}
}));
MetaClusterCurrent.register(context);
String customerDatasourceProvider = DruidDatasourceProvider.class.getName();
DatasourceConfig datasourceConfig = new DatasourceConfig();
datasourceConfig.setDbType("mysql");
datasourceConfig.setUser("root");
datasourceConfig.setPassword("123456");
datasourceConfig.setName("prototypeDs");
datasourceConfig.setUrl("jdbc:mysql://localhost:3306/mysql");
Map<String, DatasourceConfig> datasources = Maps.of("prototypeDs", datasourceConfig);
ClusterConfig clusterConfig = new ClusterConfig();
clusterConfig.setName("prototype");
clusterConfig.setMasters(Arrays.asList("prototypeDs"));
Map<String, ClusterConfig> clusterConfigs = Maps.of("prototype", clusterConfig);
LinkedList<Runnable> runnables = new LinkedList<>();
ReplicaSelectorManager manager = ReplicaSelectorRuntime.create(new ArrayList<>(clusterConfigs.values()), datasources, new LoadBalanceManager(), name -> 0, (command, initialDelay, period, unit) -> {
runnables.add(command);
return () -> {
};
});
context.put(ReplicaSelectorManager.class, manager);
context.put(JdbcConnectionManager.class, jdbcManager = new JdbcConnectionManager(DruidDatasourceProvider.class.getName(), datasources));
MetaClusterCurrent.register(context);
}
use of io.mycat.config.DatasourceConfig in project Mycat2 by MyCATApache.
the class JdbcConnectionManager method getConfigAsMap.
@Override
public Map<String, DatasourceConfig> getConfigAsMap() {
HashMap<String, DatasourceConfig> res = new HashMap<>();
for (Map.Entry<String, JdbcDataSource> entry : dataSourceMap.entrySet()) {
DatasourceConfig config = entry.getValue().getConfig();
String key = config.getName();
res.put(key, config);
}
return res;
}
use of io.mycat.config.DatasourceConfig in project Mycat2 by MyCATApache.
the class DbKVImpl method values.
@Override
public List<T> values() {
Config config = DbStorageManagerImpl.readConfig(datasourceConfig);
Map<String, String> stringStringMap = config.config.getOrDefault(this.path, Collections.emptyMap());
return (List) stringStringMap.values().stream().map(i -> JsonUtil.from(i, aClass)).collect(Collectors.toList());
}
use of io.mycat.config.DatasourceConfig in project Mycat2 by MyCATApache.
the class DbKVImpl method removeKey.
@Override
public void removeKey(String key) {
Config config = DbStorageManagerImpl.readConfig(datasourceConfig);
Map<String, String> stringStringMap = new HashMap<>(config.config.getOrDefault(this.path, Collections.emptyMap()));
stringStringMap.remove(key);
config.config.put(this.path, stringStringMap);
DbStorageManagerImpl.removeBy(datasourceConfig, config.version);
DbStorageManagerImpl.writeString(datasourceConfig, config.config);
}
Aggregations