Search in sources :

Example 1 with DbcpMediaDataSource

use of com.pamirs.attach.plugin.dbcp2.utils.DbcpMediaDataSource in project LinkAgent by shulieTech.

the class DataSourceGetConnectionCutoffInterceptor method cutoff0.

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

Example 2 with DbcpMediaDataSource

use of com.pamirs.attach.plugin.dbcp2.utils.DbcpMediaDataSource in project LinkAgent by shulieTech.

the class DataSourceGetConnectionCutoffArgsInterceptor method cutoff0.

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

Aggregations

DbcpMediaDataSource (com.pamirs.attach.plugin.dbcp2.utils.DbcpMediaDataSource)2 PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)2 DataSourceMeta (com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta)2 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 BasicDataSource (org.apache.commons.dbcp2.BasicDataSource)2