Search in sources :

Example 11 with DataSourceMeta

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

the class TomcatJdbcDataSourceProxyGetConnectionInterceptor method cutoff0.

@Override
public CutOffResult cutoff0(Advice advice) {
    Object target = advice.getTarget();
    DataSource dataSource = (DataSource) target;
    DataSourceMeta<DataSource> dataSourceMeta = new DataSourceMeta<DataSource>(dataSource.getUrl(), dataSource.getUsername(), dataSource);
    /**
     * 压测状态为关闭,如果当前为压测流量则直接报错
     */
    ClusterTestUtils.validateClusterTest();
    DataSourceWrapUtil.doWrap(dataSourceMeta);
    Connection connection = null;
    /**
     * 所有的流量均切换到此逻辑上,防止业务有连接缓存后无法进入
     * 如果未找到配置情况下则当前流量为压测流量时返回null,非压测流量则执行业务连接池正常逻辑,此种情况可能由于数据源未配置的情况
     * 如果获取连接出错时如果流量为压测流量则返回null,非压测流量则执行业务连接池正常逻辑
     */
    if (DataSourceWrapUtil.pressureDataSources.containsKey(dataSourceMeta)) {
        TomcatJdbcMediatorDataSource 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 : TomcatJdbcMediatorDataSource(com.pamirs.attach.plugin.apache.tomcatjdbc.obj.TomcatJdbcMediatorDataSource) SQLException(java.sql.SQLException) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) Connection(java.sql.Connection) DataSourceMeta(com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta) DataSource(org.apache.tomcat.jdbc.pool.DataSource) TomcatJdbcMediatorDataSource(com.pamirs.attach.plugin.apache.tomcatjdbc.obj.TomcatJdbcMediatorDataSource)

Example 12 with DataSourceMeta

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

Example 13 with DataSourceMeta

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

the class DataSourceGetConnectionCutoffArgsInterceptor method cutoff0.

@Override
public CutOffResult cutoff0(Advice advice) {
    DataSourceWrapUtil.attachment(advice);
    Object target = advice.getTarget();
    BasicDataSource dataSource = (BasicDataSource) target;
    DataSourceMeta<BasicDataSource> dataSourceMeta = new DataSourceMeta<BasicDataSource>(dataSource.getUrl(), dataSource.getUsername(), dataSource);
    ClusterTestUtils.validateClusterTest();
    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.dbcp.utils.DbcpMediaDataSource) Connection(java.sql.Connection) BasicDataSource(org.apache.commons.dbcp.BasicDataSource) DataSourceMeta(com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta)

Example 14 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) {
    DataSourceWrapUtil.attachment(advice);
    Object target = advice.getTarget();
    BasicDataSource dataSource = (BasicDataSource) target;
    DataSourceMeta<BasicDataSource> dataSourceMeta = new DataSourceMeta<BasicDataSource>(dataSource.getUrl(), dataSource.getUsername(), dataSource);
    ClusterTestUtils.validateClusterTest();
    DataSourceWrapUtil.init(dataSourceMeta);
    Connection connection = null;
    /**
     * 所有的流量均切换到此逻辑上,防止业务有连接缓存后无法进入
     * 如果未找到配置情况下则当前流量为压测流量时返回null,非压测流量则执行业务连接池正常逻辑,此种情况可能由于数据源未配置的情况
     * 如果获取连接出错时如果流量为压测流量则返回null,非压测流量则执行业务连接池正常逻辑
     */
    if (DataSourceWrapUtil.pressureDataSources.containsKey(dataSourceMeta)) {
        DbMediatorDataSource<?> 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) Connection(java.sql.Connection) BasicDataSource(org.apache.commons.dbcp.BasicDataSource) DataSourceMeta(com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta)

Example 15 with DataSourceMeta

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

the class DataSourceGetConnectionCutoffInterceptor method addListener.

private void addListener() {
    EventRouter.router().addListener(new PradarEventListener() {

        @Override
        public EventResult onEvent(IEvent event) {
            if (!(event instanceof ClusterTestSwitchOffEvent)) {
                return EventResult.IGNORE;
            }
            // 关闭压测数据源
            AtomikosDataSourceBeanWrapUtil.destroy();
            AtomikosNonXADataSourceBeanWrapUtil.destroy();
            return EventResult.success("tomcat-jdbc-plugin");
        }

        @Override
        public int order() {
            return 8;
        }
    }).addListener(new PradarEventListener() {

        @Override
        public EventResult onEvent(IEvent event) {
            if (!(event instanceof ShadowDataSourceConfigModifyEvent)) {
                return EventResult.IGNORE;
            }
            ShadowDataSourceConfigModifyEvent shadowDataSourceConfigModifyEvent = (ShadowDataSourceConfigModifyEvent) event;
            Set<ShadowDatabaseConfig> target = shadowDataSourceConfigModifyEvent.getTarget();
            if (null == target || target.size() == 0) {
                return EventResult.IGNORE;
            }
            for (ShadowDatabaseConfig config : target) {
                Iterator<Map.Entry<DataSourceMeta, AtomikosDataSourceBeanMediaDataSource>> it = AtomikosDataSourceBeanWrapUtil.pressureDataSources.entrySet().iterator();
                while (it.hasNext()) {
                    Map.Entry<DataSourceMeta, AtomikosDataSourceBeanMediaDataSource> entry = it.next();
                    if (StringUtils.equalsIgnoreCase(DbUrlUtils.getKey(config.getUrl(), config.getUsername()), DbUrlUtils.getKey(entry.getKey().getUrl(), entry.getKey().getUsername()))) {
                        AtomikosDataSourceBeanMediaDataSource value = entry.getValue();
                        it.remove();
                        try {
                            value.close();
                            if (logger.isInfoEnabled()) {
                                logger.info("module-atomikos-datasource: destroyed shadow table datasource success. url:{} ,username:{}", entry.getKey().getUrl(), entry.getKey().getUsername());
                            }
                        } catch (Throwable e) {
                            logger.error("module-atomikos-datasource: closed datasource err! target:{}, url:{} username:{}", entry.getKey().getDataSource().hashCode(), entry.getKey().getUrl(), entry.getKey().getUsername(), e);
                        }
                        break;
                    }
                }
                Iterator<Map.Entry<DataSourceMeta, AtomikosNonXADataSourceBeanMediaDataSource>> nonIt = AtomikosNonXADataSourceBeanWrapUtil.pressureDataSources.entrySet().iterator();
                while (nonIt.hasNext()) {
                    Map.Entry<DataSourceMeta, AtomikosNonXADataSourceBeanMediaDataSource> entry = nonIt.next();
                    if (StringUtils.equalsIgnoreCase(config.getUrl(), entry.getKey().getUrl()) && StringUtils.equalsIgnoreCase(config.getUsername(), entry.getKey().getUsername())) {
                        AtomikosNonXADataSourceBeanMediaDataSource value = entry.getValue();
                        nonIt.remove();
                        try {
                            value.close();
                            if (logger.isInfoEnabled()) {
                                logger.info("module-atomikos-datasource: destroyed shadow table datasource success. url:{} ,username:{}", entry.getKey().getUrl(), entry.getKey().getUsername());
                            }
                        } catch (Throwable e) {
                            logger.error("module-atomikos-datasource: closed datasource err! target:{}, url:{} username:{}", entry.getKey().getDataSource().hashCode(), entry.getKey().getUrl(), entry.getKey().getUsername(), e);
                        }
                        break;
                    }
                }
            }
            return EventResult.success("module-atomikos-datasource: destroyed shadow table datasource success.");
        }

        @Override
        public int order() {
            return 2;
        }
    });
}
Also used : AtomikosDataSourceBeanMediaDataSource(com.pamirs.attach.plugin.atomikos.utils.AtomikosDataSourceBeanMediaDataSource) Set(java.util.Set) IEvent(com.pamirs.pradar.pressurement.agent.event.IEvent) ShadowDataSourceConfigModifyEvent(com.pamirs.pradar.pressurement.agent.event.impl.ShadowDataSourceConfigModifyEvent) ShadowDatabaseConfig(com.pamirs.pradar.internal.config.ShadowDatabaseConfig) DataSourceMeta(com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta) AtomikosNonXADataSourceBeanMediaDataSource(com.pamirs.attach.plugin.atomikos.utils.AtomikosNonXADataSourceBeanMediaDataSource) PradarEventListener(com.pamirs.pradar.pressurement.agent.listener.PradarEventListener) EventResult(com.pamirs.pradar.pressurement.agent.listener.EventResult) Iterator(java.util.Iterator) Map(java.util.Map) ClusterTestSwitchOffEvent(com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOffEvent)

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