Search in sources :

Example 21 with PressureMeasureError

use of com.pamirs.pradar.exception.PressureMeasureError 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 22 with PressureMeasureError

use of com.pamirs.pradar.exception.PressureMeasureError 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 23 with PressureMeasureError

use of com.pamirs.pradar.exception.PressureMeasureError 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 24 with PressureMeasureError

use of com.pamirs.pradar.exception.PressureMeasureError in project LinkAgent by shulieTech.

the class AtomikosDataSourceBeanMediaDataSource method getConnection.

@Override
public Connection getConnection() throws SQLException {
    if (Pradar.isClusterTest()) {
        try {
            init();
            if (useTable) {
                // 影子表
                if (dataSourceBusiness == null) {
                    throw new PressureMeasureError("[atomikos] Business dataSource is null.");
                }
                Connection connection = dataSourceBusiness.getConnection();
                return new AtomikosNormalConnection(dataSourceBusiness, connection, dbConnectionKey, url, username, dbType);
            } else {
                if (dataSourcePerformanceTest == null) {
                    throw new PressureMeasureError("[atomikos] pressure dataSource is null.");
                }
                return new AtomikosPressureConnection(dataSourcePerformanceTest, dataSourcePerformanceTest.getConnection(), getUrl(dataSourcePerformanceTest), getUsername(dataSourcePerformanceTest), dbConnectionKey, dbType);
            }
        } catch (Throwable e) {
            ErrorReporter.Error error = ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0001").setMessage("数据源获取链接失败!" + (Pradar.isClusterTest() ? "(压测流量)" : "")).setDetail("[atomikos] get connection failed by dbMediatorDataSource, message: " + e.getMessage() + "\r\n" + printStackTrace(e));
            // error.closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS);
            logger.error("ATOMIKOS: pressure test flow get connection fail.", e);
            error.report();
            throw new PressureMeasureError("pressure test flow get connection fail " + e.getMessage());
        }
    } else {
        final String url = getUrl(dataSourceBusiness);
        final String username = getUsername(dataSourceBusiness);
        String dbType = JdbcUtils.getDbType(url, JdbcUtils.getDriverClassName(url));
        return new AtomikosBizConnection(dataSourceBusiness.getConnection(), url, username, dbType);
    }
}
Also used : AtomikosBizConnection(com.pamirs.attach.plugin.atomikos.connection.AtomikosBizConnection) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) AtomikosNormalConnection(com.pamirs.attach.plugin.atomikos.connection.AtomikosNormalConnection) Connection(java.sql.Connection) AtomikosBizConnection(com.pamirs.attach.plugin.atomikos.connection.AtomikosBizConnection) AtomikosPressureConnection(com.pamirs.attach.plugin.atomikos.connection.AtomikosPressureConnection) AtomikosPressureConnection(com.pamirs.attach.plugin.atomikos.connection.AtomikosPressureConnection) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) AtomikosNormalConnection(com.pamirs.attach.plugin.atomikos.connection.AtomikosNormalConnection)

Example 25 with PressureMeasureError

use of com.pamirs.pradar.exception.PressureMeasureError 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);
    }
}
Also used : PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) NormalConnection(com.pamirs.attach.plugin.common.datasource.normal.NormalConnection) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) BizConnection(com.pamirs.attach.plugin.common.datasource.biz.BizConnection) PressureConnection(com.pamirs.attach.plugin.common.datasource.pressure.PressureConnection)

Aggregations

PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)150 PradarException (com.pamirs.pradar.exception.PradarException)34 DataSourceMeta (com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta)14 Connection (java.sql.Connection)14 SQLException (java.sql.SQLException)13 ArrayList (java.util.ArrayList)13 Map (java.util.Map)11 MatchConfig (com.pamirs.pradar.internal.config.MatchConfig)8 ShadowDatabaseConfig (com.pamirs.pradar.internal.config.ShadowDatabaseConfig)8 HashMap (java.util.HashMap)8 MongoNamespace (com.mongodb.MongoNamespace)7 RequestIndexRename (com.pamirs.attach.plugin.es.common.RequestIndexRename)7 ProcessControlException (com.shulie.instrument.simulator.api.ProcessControlException)7 MQTraceContext (com.pamirs.attach.plugin.alibaba.rocketmq.common.MQTraceContext)6 SpanRecord (com.pamirs.pradar.interceptor.SpanRecord)6 ReflectException (com.shulie.instrument.simulator.api.reflect.ReflectException)6 List (java.util.List)6 ConsumeMessageContext (org.apache.rocketmq.client.hook.ConsumeMessageContext)6 ConsumeMessageContext (com.alibaba.rocketmq.client.hook.ConsumeMessageContext)5 WrapperRequest (com.pamirs.attach.plugin.hessian.common.WrapperRequest)5