Search in sources :

Example 6 with DataSourceMeta

use of com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta in project LinkAgent by shulieTech.

the class DataSourceGetConnectionCutoffInterceptor method cutoff0.

@Override
public CutOffResult cutoff0(Advice advice) {
    attachment(advice);
    Object target = advice.getTarget();
    ComboPooledDataSource dataSource = (ComboPooledDataSource) target;
    DataSourceMeta<ComboPooledDataSource> dataSourceMeta = new DataSourceMeta<ComboPooledDataSource>(dataSource.getJdbcUrl(), dataSource.getUser(), dataSource);
    ClusterTestUtils.validateClusterTest();
    DataSourceWrapUtil.init(dataSourceMeta);
    Connection connection = null;
    /**
     * 所有的流量均切换到此逻辑上,防止业务有连接缓存后无法进入
     * 如果未找到配置情况下则当前流量为压测流量时返回null,非压测流量则执行业务连接池正常逻辑,此种情况可能由于数据源未配置的情况
     * 如果获取连接出错时如果流量为压测流量则返回null,非压测流量则执行业务连接池正常逻辑
     *
     * 如果配置初始化异常或者没有对应配置
     */
    if (DataSourceWrapUtil.pressureDataSources.containsKey(dataSourceMeta)) {
        C3p0MediaDataSource 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 : ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) SQLException(java.sql.SQLException) C3p0MediaDataSource(com.pamirs.attach.plugin.c3p0.utils.C3p0MediaDataSource) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) Connection(java.sql.Connection) DataSourceMeta(com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta)

Example 7 with DataSourceMeta

use of com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta in project LinkAgent by shulieTech.

the class DataSourceGetConnectionCutoffInterceptor method wrapAtomikosNonXADataSourceBean.

private CutOffResult wrapAtomikosNonXADataSourceBean(AtomikosNonXADataSourceBean dataSourceBean) {
    DataSourceMeta<AtomikosNonXADataSourceBean> dataSourceMeta = new DataSourceMeta<AtomikosNonXADataSourceBean>(dataSourceBean.getUrl(), dataSourceBean.getUser(), dataSourceBean);
    AtomikosNonXADataSourceBeanWrapUtil.init(dataSourceMeta);
    Connection connection = null;
    /**
     * 所有的流量均切换到此逻辑上,防止业务有连接缓存后无法进入
     * 如果未找到配置情况下则当前流量为压测流量时返回null,非压测流量则执行业务连接池正常逻辑,此种情况可能由于数据源未配置的情况
     * 如果获取连接出错时如果流量为压测流量则返回null,非压测流量则执行业务连接池正常逻辑
     */
    if (AtomikosNonXADataSourceBeanWrapUtil.pressureDataSources.containsKey(dataSourceMeta)) {
        AtomikosNonXADataSourceBeanMediaDataSource mediatorDataSource = AtomikosNonXADataSourceBeanWrapUtil.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) Connection(java.sql.Connection) AtomikosNonXADataSourceBean(com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean) DataSourceMeta(com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta) AtomikosNonXADataSourceBeanMediaDataSource(com.pamirs.attach.plugin.atomikos.utils.AtomikosNonXADataSourceBeanMediaDataSource)

Example 8 with DataSourceMeta

use of com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta in project LinkAgent by shulieTech.

the class DataSourceGetConnectionCutoffInterceptor method wrapAtomikosDataSourceBean.

private CutOffResult wrapAtomikosDataSourceBean(AtomikosDataSourceBean dataSourceBean) {
    DataSourceMeta<AtomikosDataSourceBean> dataSourceMeta = new DataSourceMeta<AtomikosDataSourceBean>(getUrl(dataSourceBean), getUsername(dataSourceBean), dataSourceBean);
    AtomikosDataSourceBeanWrapUtil.init(dataSourceMeta);
    Connection connection = null;
    /**
     * 所有的流量均切换到此逻辑上,防止业务有连接缓存后无法进入
     * 如果未找到配置情况下则当前流量为压测流量时返回null,非压测流量则执行业务连接池正常逻辑,此种情况可能由于数据源未配置的情况
     * 如果获取连接出错时如果流量为压测流量则返回null,非压测流量则执行业务连接池正常逻辑
     */
    if (AtomikosDataSourceBeanWrapUtil.pressureDataSources.containsKey(dataSourceMeta)) {
        AtomikosDataSourceBeanMediaDataSource mediatorDataSource = AtomikosDataSourceBeanWrapUtil.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 : AtomikosDataSourceBeanMediaDataSource(com.pamirs.attach.plugin.atomikos.utils.AtomikosDataSourceBeanMediaDataSource) SQLException(java.sql.SQLException) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) Connection(java.sql.Connection) AtomikosDataSourceBean(com.atomikos.jdbc.AtomikosDataSourceBean) DataSourceMeta(com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta)

Example 9 with DataSourceMeta

use of com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta 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)

Example 10 with DataSourceMeta

use of com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta in project LinkAgent by shulieTech.

the class DataSourceConstructorInterceptor method doAfter.

@Override
public void doAfter(Advice advice) {
    Object target = advice.getTarget();
    if (target instanceof HikariDataSource) {
        HikariDataSource dataSource = (HikariDataSource) target;
        DataSourceMeta dataSourceMeta = DataSourceMeta.build(dataSource.getJdbcUrl(), dataSource.getUsername(), dataSource);
        DataSourceWrapUtil.init(dataSourceMeta);
    }
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) DataSourceMeta(com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta)

Aggregations

DataSourceMeta (com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta)16 PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)14 Connection (java.sql.Connection)12 SQLException (java.sql.SQLException)12 ComboPooledDataSource (com.mchange.v2.c3p0.ComboPooledDataSource)2 AtomikosDataSourceBeanMediaDataSource (com.pamirs.attach.plugin.atomikos.utils.AtomikosDataSourceBeanMediaDataSource)2 AtomikosNonXADataSourceBeanMediaDataSource (com.pamirs.attach.plugin.atomikos.utils.AtomikosNonXADataSourceBeanMediaDataSource)2 C3p0MediaDataSource (com.pamirs.attach.plugin.c3p0.utils.C3p0MediaDataSource)2 DbcpMediaDataSource (com.pamirs.attach.plugin.dbcp2.utils.DbcpMediaDataSource)2 Neo4JSessionExt (com.pamirs.attach.plugin.neo4j.config.Neo4JSessionExt)2 HikariDataSource (com.zaxxer.hikari.HikariDataSource)2 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)2 BasicDataSource (org.apache.commons.dbcp2.BasicDataSource)2 AuthTokenCredentials (org.neo4j.ogm.authentication.AuthTokenCredentials)2 Credentials (org.neo4j.ogm.authentication.Credentials)2 UsernamePasswordCredentials (org.neo4j.ogm.authentication.UsernamePasswordCredentials)2 DriverConfiguration (org.neo4j.ogm.config.DriverConfiguration)2 Neo4jSession (org.neo4j.ogm.session.Neo4jSession)2 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)1 AtomikosDataSourceBean (com.atomikos.jdbc.AtomikosDataSourceBean)1