Search in sources :

Example 1 with HikariMediaDataSource

use of com.pamirs.attach.plugin.hikariCP.utils.HikariMediaDataSource in project LinkAgent by shulieTech.

the class DataSourceConnectionInterceptor method cutoff0.

@Override
public CutOffResult cutoff0(Advice advice) {
    Object target = advice.getTarget();
    addListener();
    attachment(advice);
    ClusterTestUtils.validateClusterTest();
    HikariDataSource dataSource = (HikariDataSource) target;
    DataSourceMeta<HikariDataSource> dataSourceMeta = new DataSourceMeta<HikariDataSource>(dataSource.getJdbcUrl(), dataSource.getUsername(), dataSource);
    DataSourceWrapUtil.init(dataSourceMeta);
    Connection connection = null;
    /**
     * 所有的流量均切换到此逻辑上,防止业务有连接缓存后无法进入
     * 如果未找到配置情况下则当前流量为压测流量时返回null,非压测流量则执行业务连接池正常逻辑,此种情况可能由于数据源未配置的情况
     * 如果获取连接出错时如果流量为压测流量则返回null,非压测流量则执行业务连接池正常逻辑
     */
    HikariMediaDataSource mediatorDataSource = DataSourceWrapUtil.pressureDataSources.get(dataSourceMeta);
    if (mediatorDataSource != null) {
        try {
            connection = mediatorDataSource.getConnection();
        } catch (SQLException e) {
            throw new PressureMeasureError(e);
        }
        return CutOffResult.cutoff(connection);
    } else {
        if (!Pradar.isClusterTest()) {
            return CutOffResult.passed();
        }
        return CutOffResult.cutoff(null);
    }
}
Also used : HikariMediaDataSource(com.pamirs.attach.plugin.hikariCP.utils.HikariMediaDataSource) HikariDataSource(com.zaxxer.hikari.HikariDataSource) SQLException(java.sql.SQLException) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) Connection(java.sql.Connection) DataSourceMeta(com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta)

Aggregations

HikariMediaDataSource (com.pamirs.attach.plugin.hikariCP.utils.HikariMediaDataSource)1 PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)1 DataSourceMeta (com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1