use of com.pamirs.attach.plugin.common.datasource.pressure.PressureConnection in project LinkAgent by shulieTech.
the class TomcatJdbcMediatorDataSource method getConnection.
@Override
public Connection getConnection() throws SQLException {
if (Pradar.isClusterTest()) {
try {
init();
TomcatJdbcConstants.dbConnectionKey = dbConnectionKey;
TomcatJdbcConstants.dbType = dbType;
TomcatJdbcConstants.useTable = useTable;
if (useTable) {
// 影子表
if (dataSourceBusiness == null) {
throw new PressureMeasureError("Business dataSource is null.");
}
return new NormalConnection(dataSourceBusiness, dataSourceBusiness.getConnection(), dbConnectionKey, url, username, dbType, getMidType());
} else {
// 影子库
if (dataSourcePerformanceTest == null) {
throw new PressureMeasureError("Performance dataSource is null.");
}
return new PressureConnection(dataSourceBusiness, dataSourcePerformanceTest.getConnection(), dataSourcePerformanceTest.getUrl(), dataSourcePerformanceTest.getUsername(), dbConnectionKey, dbType);
}
} catch (Throwable e) {
ErrorReporter.Error error = ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0001").setMessage("数据源获取链接失败!" + ((Pradar.isClusterTest() ? "(压测流量)" : "") + ", url=" + (dataSourceBusiness == null ? null : dataSourceBusiness.getUrl()) + ", username=" + (dataSourceBusiness == null ? null : dataSourceBusiness.getUsername()))).setDetail("get connection failed by dbMediatorDataSource, url=" + (dataSourceBusiness == null ? null : dataSourceBusiness.getUrl()) + ", username=" + (dataSourceBusiness == null ? null : dataSourceBusiness.getUsername()) + "message: " + e.getMessage() + "\r\n" + printStackTrace(e));
// error.closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS);
error.report();
throw new PressureMeasureError("get connection failed by dbMediatorDataSource. url=" + (dataSourceBusiness == null ? null : dataSourceBusiness.getUrl()) + ", username=" + (dataSourceBusiness == null ? null : dataSourceBusiness.getUsername()), e);
}
} else {
String dbType = JdbcUtils.getDbType(dataSourceBusiness.getUrl(), JdbcUtils.getDriverClassName(dataSourceBusiness.getUrl()));
return new BizConnection(dataSourceBusiness.getConnection(), dataSourceBusiness.getUrl(), dataSourceBusiness.getUsername(), dbType);
}
}
use of com.pamirs.attach.plugin.common.datasource.pressure.PressureConnection in project LinkAgent by shulieTech.
the class ProxoolDriverConnectInterceptor method getResult0.
@Override
public Object getResult0(Advice advice) throws Throwable {
Object returnObj = advice.getReturnObj();
// 检查返回结果
if (!(returnObj instanceof Connection) || returnObj instanceof BizConnection || returnObj instanceof PressureConnection) {
return returnObj;
}
Connection conn = (Connection) returnObj;
String connectUrl = (String) advice.getParameterArray()[0];
if (!connectUrl.startsWith("proxool")) {
return returnObj;
}
String alias = getAlias(connectUrl);
// 说明url有问题
if (alias == null || alias.length() == 0) {
return returnObj;
}
if (Pradar.isClusterTestPrefix(alias)) {
return buildConnection(returnObj, conn, alias, true);
}
return buildConnection(returnObj, conn, alias, false);
}
use of com.pamirs.attach.plugin.common.datasource.pressure.PressureConnection in project LinkAgent by shulieTech.
the class TomcatJdbcMediatorDataSource method getConnection.
@Override
public Connection getConnection(String username, String password) throws SQLException {
if (Pradar.isClusterTest()) {
try {
init();
TomcatJdbcConstants.dbConnectionKey = dbConnectionKey;
TomcatJdbcConstants.dbType = dbType;
TomcatJdbcConstants.useTable = useTable;
if (useTable) {
// 影子表
if (dataSourceBusiness == null) {
throw new PressureMeasureError("Business dataSource is null.");
}
return new NormalConnection(dataSourceBusiness, dataSourceBusiness.getConnection(username, password), dbConnectionKey, url, username, dbType, "other");
} else {
// 影子库
if (dataSourcePerformanceTest == null) {
throw new PressureMeasureError("Performance dataSource is null.");
}
return new PressureConnection(dataSourceBusiness, dataSourcePerformanceTest.getConnection(username, password), url, username, dbConnectionKey, dbType);
}
} catch (Throwable e) {
ErrorReporter.Error error = ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0001").setMessage("数据源获取链接失败!" + (Pradar.isClusterTest() ? "(压测流量)" : "")).setDetail("get connection failed by dbMediatorDataSource, message: " + e.getMessage() + "\r\n" + printStackTrace(e));
// error.closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS);
error.report();
throw new PressureMeasureError("tomcat jdbc get connection failed by dbMediatorDataSource");
}
} else {
String dbType = JdbcUtils.getDbType(dataSourceBusiness.getUrl(), JdbcUtils.getDriverClassName(dataSourceBusiness.getUrl()));
return new BizConnection(dataSourceBusiness.getConnection(username, password), dataSourceBusiness.getUrl(), dataSourceBusiness.getUsername(), dbType);
}
}
Aggregations