use of io.mycat.beans.MySQLDatasource in project Mycat2 by MyCATApache.
the class MySQLDatasourcePool method innerCreateCon.
private Future<MySQLClientSession> innerCreateCon() {
PromiseInternal<MySQLClientSession> promise = VertxUtil.newPromise();
new BackendConCreateHandler(this, promise);
return promise.flatMap(session -> {
synchronized (allSessions) {
allSessions.add(session);
}
MySQLDatasource datasource = session.getDatasource();
String sql = datasource.getInitSqlForProxy();
if (!StringUtil.isEmpty(sql)) {
PromiseInternal<MySQLClientSession> promiseInternal = VertxUtil.newPromise();
ResultSetHandler.DEFAULT.request(session, COM_QUERY, sql.getBytes(StandardCharsets.UTF_8), promiseInternal);
return promiseInternal.onFailure(event -> {
session.close(false, "initSql fail");
});
} else {
return Future.succeededFuture(session);
}
});
}
use of io.mycat.beans.MySQLDatasource in project Mycat2 by MyCATApache.
the class NativeMycatServer method showNativeDataSources.
@Override
public RowBaseIterator showNativeDataSources() {
MycatRouterConfig mycatRouterConfig = MetaClusterCurrent.wrapper(MycatRouterConfig.class);
Map<String, DatasourceConfig> datasourceConfigMap = mycatRouterConfig.getDatasources().stream().collect(Collectors.toMap(k -> k.getName(), v -> v));
ResultSetBuilder resultSetBuilder = ResultSetBuilder.create();
resultSetBuilder.addColumnInfo("NAME", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("USERNAME", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("PASSWORD", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("MAX_CON", JDBCType.BIGINT);
resultSetBuilder.addColumnInfo("MIN_CON", JDBCType.BIGINT);
resultSetBuilder.addColumnInfo("EXIST_CON", JDBCType.BIGINT);
resultSetBuilder.addColumnInfo("USE_CON", JDBCType.BIGINT);
resultSetBuilder.addColumnInfo("MAX_RETRY_COUNT", JDBCType.BIGINT);
resultSetBuilder.addColumnInfo("MAX_CONNECT_TIMEOUT", JDBCType.BIGINT);
resultSetBuilder.addColumnInfo("DB_TYPE", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("URL", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("WEIGHT", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("INIT_SQL", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("INIT_SQL_GET_CONNECTION", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("INSTANCE_TYPE", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("IDLE_TIMEOUT", JDBCType.BIGINT);
resultSetBuilder.addColumnInfo("DRIVER", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("TYPE", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("IS_MYSQL", JDBCType.VARCHAR);
Map<String, Integer> map = getDatasourceMap().values().stream().collect(Collectors.toMap(k -> k.getName(), v -> v.getAllSessions().size()));
for (MySQLDatasource value : getDatasourceMap().values()) {
String NAME = value.getName();
Optional<DatasourceConfig> e = Optional.ofNullable(datasourceConfigMap.get(NAME));
String IP = value.getIp();
int PORT = value.getPort();
String USERNAME = value.getUsername();
String PASSWORD = value.getPassword();
int MAX_CON = value.getSessionLimitCount();
int MIN_CON = value.getSessionMinCount();
long USED_CON = map.getOrDefault(NAME, -1);
int EXIST_CON = value.getConnectionCounter();
int MAX_RETRY_COUNT = value.gerMaxRetry();
long MAX_CONNECT_TIMEOUT = value.getMaxConnectTimeout();
String DB_TYPE = "mysql";
String URL = null;
int WEIGHT = e.map(i -> i.getWeight()).orElse(-1);
String INIT_SQL = value.getInitSqlForProxy();
boolean INIT_SQL_GET_CONNECTION = false;
ReplicaSelectorManager selectorRuntime = MetaClusterCurrent.wrapper(ReplicaSelectorManager.class);
String INSTANCE_TYPE = Optional.ofNullable(selectorRuntime.getPhysicsInstanceByName(NAME)).map(i -> i.getType().name()).orElse(e.map(i -> i.getInstanceType()).orElse(null));
long IDLE_TIMEOUT = value.getIdleTimeout();
// 保留属性
String DRIVER = "native";
String TYPE = e.map(i -> i.getType()).orElse(null);
boolean IS_MYSQL = true;
resultSetBuilder.addObjectRowPayload(Arrays.asList(NAME, IP, PORT, USERNAME, PASSWORD, MAX_CON, MIN_CON, EXIST_CON, USED_CON, MAX_RETRY_COUNT, MAX_CONNECT_TIMEOUT, DB_TYPE, URL, WEIGHT, INIT_SQL, INIT_SQL_GET_CONNECTION, INSTANCE_TYPE, IDLE_TIMEOUT, DRIVER, TYPE, IS_MYSQL));
}
return resultSetBuilder.build();
}
Aggregations