Search in sources :

Example 1 with DbMediatorDataSource

use of com.pamirs.pradar.pressurement.datasource.DbMediatorDataSource in project LinkAgent by shulieTech.

the class DataSourceWrapUtil method init.

// static AtomicBoolean inited = new AtomicBoolean(false);
public static void init(DataSourceMeta<BasicDataSource> dataSourceMeta) {
    if (pressureDataSources.containsKey(dataSourceMeta) && pressureDataSources.get(dataSourceMeta) != null) {
        return;
    }
    BasicDataSource target = dataSourceMeta.getDataSource();
    if (isPerformanceDataSource(target)) {
        return;
    }
    if (!validate(target)) {
        // 没有配置对应的影子表或影子库
        ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0002").setMessage("没有配置对应的影子表或影子库!").setDetail("dbcp:DataSourceWrapUtil:业务库配置:::url: " + target.getUrl() + "; username:" + dataSourceMeta.getUsername() + "; 中间件类型:dbcp").report();
        DbcpMediaDataSource dbMediatorDataSource = new DbcpMediaDataSource();
        dbMediatorDataSource.setDataSourceBusiness(target);
        DbMediatorDataSource old = pressureDataSources.put(dataSourceMeta, dbMediatorDataSource);
        if (old != null) {
            if (logger.isInfoEnabled()) {
                logger.info("[dbcp] destroyed shadow table datasource success. url:{} ,username:{}", target.getUrl(), target.getUsername());
            }
            old.close();
        }
        return;
    }
    if (shadowTable(target)) {
        // 影子表
        try {
            DbcpMediaDataSource dbMediatorDataSource = new DbcpMediaDataSource();
            dbMediatorDataSource.setDataSourceBusiness(target);
            DbMediatorDataSource old = pressureDataSources.put(dataSourceMeta, dbMediatorDataSource);
            if (old != null) {
                if (logger.isInfoEnabled()) {
                    logger.info("[dbcp] destroyed shadow table datasource success. url:{} ,username:{}", target.getUrl(), target.getUsername());
                }
                old.close();
            }
        } catch (Throwable e) {
            ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0003").setMessage("影子表设置初始化异常!").setDetail("dbcp:DataSourceWrapUtil:业务库配置:::url: " + target.getUrl() + "|||" + Throwables.getStackTraceAsString(e)).closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS).report();
            logger.error("init datasource err!", e);
        }
    } else {
        // 影子库
        try {
            DbcpMediaDataSource dataSource = new DbcpMediaDataSource();
            BasicDataSource ptDataSource = copy(target);
            dataSource.setDataSourcePerformanceTest(ptDataSource);
            dataSource.setDataSourceBusiness(target);
            DbMediatorDataSource old = pressureDataSources.put(dataSourceMeta, dataSource);
            if (old != null) {
                if (logger.isInfoEnabled()) {
                    logger.info("[dbcp] destroyed shadow table datasource success. url:{} ,username:{}", target.getUrl(), target.getUsername());
                }
                old.close();
            }
            if (logger.isInfoEnabled()) {
                logger.info("[dbcp] create shadow datasource success. target:{} url:{} ,username:{} shadow-url:{},shadow-username:{}", target.hashCode(), target.getUrl(), target.getUsername(), ptDataSource.getUrl(), ptDataSource.getUsername());
            }
        } catch (Throwable t) {
            logger.error("[dbcp] init datasource err!", t);
            ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0003").setMessage("影子库设置初始化异常!").setDetail("dbcp:DataSourceWrapUtil:业务库配置:::url: " + target.getUrl() + "|||" + Throwables.getStackTraceAsString(t)).closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS).report();
        }
    }
}
Also used : DbMediatorDataSource(com.pamirs.pradar.pressurement.datasource.DbMediatorDataSource) BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 2 with DbMediatorDataSource

use of com.pamirs.pradar.pressurement.datasource.DbMediatorDataSource in project LinkAgent by shulieTech.

the class AtomikosNonXADataSourceBeanWrapUtil method init.

// static AtomicBoolean inited = new AtomicBoolean(false);
public static void init(DataSourceMeta<AtomikosNonXADataSourceBean> dataSourceMeta) {
    if (pressureDataSources.containsKey(dataSourceMeta) && pressureDataSources.get(dataSourceMeta) != null) {
        return;
    }
    AtomikosNonXADataSourceBean target = dataSourceMeta.getDataSource();
    if (isPerformanceDataSource(target)) {
        return;
    }
    if (!validate(target)) {
        // 没有配置对应的影子表或影子库
        ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0002").setMessage("没有配置对应的影子表或影子库!").setDetail("[atomikos] DataSourceWrapUtil:业务库配置::url: " + target.getUrl() + "; username:" + dataSourceMeta.getUsername() + "; 中间件类型:other").report();
        AtomikosNonXADataSourceBeanMediaDataSource dbMediatorDataSource = new AtomikosNonXADataSourceBeanMediaDataSource();
        dbMediatorDataSource.setDataSourceBusiness(target);
        DbMediatorDataSource old = pressureDataSources.put(dataSourceMeta, dbMediatorDataSource);
        if (old != null) {
            if (isInfoEnabled) {
                logger.info("[atomikos] destroyed shadow table datasource success. url:{} ,username:{}", target.getUrl(), target.getUser());
            }
            old.close();
        }
        return;
    }
    if (shadowTable(target)) {
        // 影子表
        try {
            AtomikosNonXADataSourceBeanMediaDataSource dbMediatorDataSource = new AtomikosNonXADataSourceBeanMediaDataSource();
            dbMediatorDataSource.setDataSourceBusiness(target);
            DbMediatorDataSource old = pressureDataSources.put(dataSourceMeta, dbMediatorDataSource);
            if (old != null) {
                if (isInfoEnabled) {
                    logger.info("[atomikos] destroyed shadow table datasource success. url:{} ,username:{}", target.getUrl(), target.getUser());
                }
                old.close();
            }
        } catch (Throwable e) {
            ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0003").setMessage("影子表设置初始化异常!").setDetail("[atomikos] DataSourceWrapUtil:业务库配置:::url: " + target.getUrl() + "|||" + Throwables.getStackTraceAsString(e)).closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS).report();
            logger.error("[atomikos] init datasource err!", e);
        }
    } else {
        // 影子库
        try {
            AtomikosNonXADataSourceBeanMediaDataSource dataSource = new AtomikosNonXADataSourceBeanMediaDataSource();
            AtomikosNonXADataSourceBean ptDataSource = copy(target);
            dataSource.setDataSourcePerformanceTest(ptDataSource);
            dataSource.setDataSourceBusiness(target);
            DbMediatorDataSource old = pressureDataSources.put(dataSourceMeta, dataSource);
            if (old != null) {
                if (isInfoEnabled) {
                    logger.info("[atomikos] destroyed shadow table datasource success. url:{} ,username:{}", target.getUrl(), target.getUser());
                }
                old.close();
            }
            if (isInfoEnabled) {
                logger.info("[atomikos] create shadow datasource success. target:{} url:{} ,username:{} shadow-url:{},shadow-username:{}", target.hashCode(), target.getUrl(), target.getUser(), ptDataSource.getUrl(), ptDataSource.getUser());
            }
        } catch (Throwable t) {
            logger.error("[atomikos] init datasource err!", t);
            ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0003").setMessage("影子库设置初始化异常!").setDetail("[atomikos] DataSourceWrapUtil:业务库配置:::url: " + target.getUrl() + "|||" + Throwables.getStackTraceAsString(t)).closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS).report();
        }
    }
}
Also used : DbMediatorDataSource(com.pamirs.pradar.pressurement.datasource.DbMediatorDataSource) AtomikosNonXADataSourceBean(com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean)

Example 3 with DbMediatorDataSource

use of com.pamirs.pradar.pressurement.datasource.DbMediatorDataSource in project LinkAgent by shulieTech.

the class DataSourceWrapUtil method doWrap.

public static void doWrap(DataSourceMeta<DataSource> dataSourceMeta) {
    DataSource target = dataSourceMeta.getDataSource();
    if (pressureDataSources.containsKey(dataSourceMeta) && pressureDataSources.get(dataSourceMeta) != null) {
        return;
    }
    if (isPerformanceDataSource(target)) {
        return;
    }
    if (!TomcatJdbcDatasourceUtils.configured(target)) {
        // 没有配置对应的影子表或影子库
        LOGGER.error("[tomcat-jdbc] No configuration found for datasource, url:{} username:{}", target.getUrl(), target.getUsername());
        ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0002").setMessage("没有配置对应的影子表或影子库!").setDetail("业务库配置:::url: " + target.getUrl() + " ; username: " + target.getUsername() + "; 中间件类型:other").report();
        TomcatJdbcMediatorDataSource dbMediatorDataSource = new TomcatJdbcMediatorDataSource();
        dbMediatorDataSource.setDataSourceBusiness(target);
        DbMediatorDataSource old = pressureDataSources.put(dataSourceMeta, dbMediatorDataSource);
        if (old != null) {
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("[tomcat-jdbc] destroyed shadow table datasource success. url:{} ,username:{}", target.getUrl(), target.getUsername());
            }
            old.close();
        }
        return;
    }
    if (TomcatJdbcDatasourceUtils.shadowTable(target)) {
        // 影子表
        TomcatJdbcMediatorDataSource dbMediatorDataSource = new TomcatJdbcMediatorDataSource();
        dbMediatorDataSource.setDataSourceBusiness(target);
        DbMediatorDataSource old = pressureDataSources.put(dataSourceMeta, dbMediatorDataSource);
        if (old != null) {
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("[tomcat-jdbc] destroyed shadow table datasource success. url:{} ,username:{}", target.getUrl(), target.getUsername());
            }
            old.close();
        }
    } else {
        // 影子库
        // 初始化影子数据源配置
        TomcatJdbcMediatorDataSource dbMediatorDataSource = new TomcatJdbcMediatorDataSource();
        dbMediatorDataSource.setDataSourceBusiness(target);
        DataSource ptDataSource = TomcatJdbcDatasourceUtils.generateDatasourceFromConfiguration(target, GlobalConfig.getInstance().getShadowDatasourceConfigs());
        if (ptDataSource == null) {
            LOGGER.error("[tomcat-jdbc] Configuration error for datasource, url: {} username:{} configurations:{}", target.getUrl(), target.getUsername(), GlobalConfig.getInstance().getShadowDatasourceConfigs());
            ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0002").setMessage("没有配置对应的影子表或影子库!").setDetail("TomcatJdbcDataSourceWrapUtil:业务库配置:::url: " + target.getUrl() + "; username: " + target.getUsername() + "; 中间件类型:other").report();
            return;
        }
        dbMediatorDataSource.setDataSourcePerformanceTest(ptDataSource);
        DbMediatorDataSource old = pressureDataSources.put(dataSourceMeta, dbMediatorDataSource);
        if (old != null) {
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("[tomcat-jdbc] destroyed shadow table datasource success. url:{} ,username:{}", target.getUrl(), target.getUsername());
            }
            old.close();
        }
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("[tomcat-jdbc] create shadow datasource success. target:{} url:{} ,username:{} shadow-url:{},shadow-username:{}", target.hashCode(), target.getUrl(), target.getUsername(), ptDataSource.getUrl(), ptDataSource.getUsername());
        }
    }
}
Also used : DbMediatorDataSource(com.pamirs.pradar.pressurement.datasource.DbMediatorDataSource) TomcatJdbcMediatorDataSource(com.pamirs.attach.plugin.apache.tomcatjdbc.obj.TomcatJdbcMediatorDataSource) DbMediatorDataSource(com.pamirs.pradar.pressurement.datasource.DbMediatorDataSource) DataSource(org.apache.tomcat.jdbc.pool.DataSource) TomcatJdbcMediatorDataSource(com.pamirs.attach.plugin.apache.tomcatjdbc.obj.TomcatJdbcMediatorDataSource)

Example 4 with DbMediatorDataSource

use of com.pamirs.pradar.pressurement.datasource.DbMediatorDataSource in project LinkAgent by shulieTech.

the class DataSourceWrapUtil method init.

// static AtomicBoolean inited = new AtomicBoolean(false);
public static void init(DataSourceMeta<ProxoolDataSource> dataSourceMeta) {
    if (pressureDataSources.containsKey(dataSourceMeta) && pressureDataSources.get(dataSourceMeta) != null) {
        return;
    }
    ProxoolDataSource target = dataSourceMeta.getDataSource();
    if (isPerformanceDataSource(target)) {
        return;
    }
    if (!validate(target)) {
        logger.error("[proxool] No configuration found for datasource, url: " + target.getDriverUrl());
        // 没有配置对应的影子表或影子库
        ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0002").setMessage("没有配置对应的影子表或影子库!").setDetail("proxool:DataSourceWrapUtil:业务库配置:::url: " + target.getDriverUrl() + "; username: " + target.getUser()).report();
        ProxoolMediaDataSource dbMediatorDataSource = new ProxoolMediaDataSource();
        dbMediatorDataSource.setDataSourceBusiness(target);
        DbMediatorDataSource old = pressureDataSources.put(dataSourceMeta, dbMediatorDataSource);
        if (old != null) {
            if (logger.isInfoEnabled()) {
                logger.info("[proxool] destroyed shadow table datasource success. url:{} ,username:{}", target.getDriverUrl(), target.getUser());
            }
            old.close();
        }
        return;
    }
    if (shadowTable(target)) {
        // 影子表
        try {
            ProxoolMediaDataSource dbMediatorDataSource = new ProxoolMediaDataSource();
            dbMediatorDataSource.setDataSourceBusiness(target);
            DbMediatorDataSource old = pressureDataSources.put(dataSourceMeta, dbMediatorDataSource);
            if (old != null) {
                if (logger.isInfoEnabled()) {
                    logger.info("[proxool] destroyed shadow table datasource success. url:{} ,username:{}", target.getDriverUrl(), target.getUser());
                }
                old.close();
            }
        } catch (Throwable e) {
            ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0002").setMessage("没有配置对应的影子表或影子库!").setDetail("proxool:DataSourceWrapUtil:业务库配置:::url: " + target.getDriverUrl() + "; username: " + target.getUser()).closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS).report();
            logger.error("[proxool] init datasource err!", e);
        }
    } else {
        // 影子库
        try {
            ProxoolMediaDataSource dataSource = new ProxoolMediaDataSource();
            /**
             * 如果没有配置则为null
             */
            ProxoolDataSource ptDataSource = copy(target);
            dataSource.setDataSourcePerformanceTest(ptDataSource);
            dataSource.setDataSourceBusiness(target);
            DbMediatorDataSource old = pressureDataSources.put(dataSourceMeta, dataSource);
            if (old != null) {
                if (logger.isInfoEnabled()) {
                    logger.info("[proxool] destroyed shadow table datasource success. url:{} ,username:{}", target.getDriverUrl(), target.getUser());
                }
                old.close();
            }
            if (logger.isInfoEnabled()) {
                logger.info("[proxool] create shadow datasource success. target:{} url:{} ,username:{} shadow-url:{}," + "shadow-username:{}", target.hashCode(), target.getDriverUrl(), target.getUser(), ptDataSource.getDriverUrl(), ptDataSource.getUser());
            }
        } catch (Throwable t) {
            logger.error("[proxool] init datasource err!", t);
            ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0003").setMessage("影子库初始化失败!").setDetail("proxool:DataSourceWrapUtil:业务库配置:::url: " + target.getDriverUrl() + "; username: " + target.getUser()).closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS).report();
        }
    }
}
Also used : DbMediatorDataSource(com.pamirs.pradar.pressurement.datasource.DbMediatorDataSource) ProxoolDataSource(org.logicalcobwebs.proxool.ProxoolDataSource)

Example 5 with DbMediatorDataSource

use of com.pamirs.pradar.pressurement.datasource.DbMediatorDataSource in project LinkAgent by shulieTech.

the class AtomikosDataSourceBeanWrapUtil method init.

// static AtomicBoolean inited = new AtomicBoolean(false);
public static void init(DataSourceMeta<AtomikosDataSourceBean> dataSourceMeta) {
    if (pressureDataSources.containsKey(dataSourceMeta) && pressureDataSources.get(dataSourceMeta) != null) {
        return;
    }
    AtomikosDataSourceBean target = dataSourceMeta.getDataSource();
    if (isPerformanceDataSource(target)) {
        return;
    }
    if (!validate(target)) {
        // 没有配置对应的影子表或影子库
        ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0002").setMessage("没有配置对应的影子表或影子库!").setDetail("[atomikos] DataSourceWrapUtil:业务库配置:::url: " + target.getXaProperties().getProperty("URL") + "; username:" + dataSourceMeta.getUsername() + "; 中间件类型:other").report();
        AtomikosDataSourceBeanMediaDataSource dbMediatorDataSource = new AtomikosDataSourceBeanMediaDataSource();
        dbMediatorDataSource.setDataSourceBusiness(target);
        DbMediatorDataSource old = pressureDataSources.put(dataSourceMeta, dbMediatorDataSource);
        if (old != null) {
            if (isInfoEnabled) {
                logger.info("[atomikos] destroyed shadow table datasource success. url:{} ,username:{}", target.getXaProperties().getProperty("URL"), target.getXaProperties().getProperty("user"));
            }
            old.close();
        }
        return;
    }
    if (shadowTable(target)) {
        // 影子表
        try {
            AtomikosDataSourceBeanMediaDataSource dbMediatorDataSource = new AtomikosDataSourceBeanMediaDataSource();
            dbMediatorDataSource.setDataSourceBusiness(target);
            DbMediatorDataSource old = pressureDataSources.put(dataSourceMeta, dbMediatorDataSource);
            if (old != null) {
                if (isInfoEnabled) {
                    logger.info("[atomikos] destroyed shadow table datasource success. url:{} ,username:{}", target.getXaProperties().getProperty("URL"), target.getXaProperties().getProperty("user"));
                }
                old.close();
            }
        } catch (Throwable e) {
            ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0003").setMessage("影子表设置初始化异常!").setDetail("dbcp:DataSourceWrapUtil:业务库配置:::url: " + target.getXaProperties().getProperty("URL") + "|||" + Throwables.getStackTraceAsString(e)).closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS).report();
            logger.error("[atomikos] init datasource err!", e);
        }
    } else {
        // 影子库
        try {
            AtomikosDataSourceBeanMediaDataSource dataSource = new AtomikosDataSourceBeanMediaDataSource();
            AtomikosDataSourceBean ptDataSource = copy(target);
            dataSource.setDataSourcePerformanceTest(ptDataSource);
            dataSource.setDataSourceBusiness(target);
            DbMediatorDataSource old = pressureDataSources.put(dataSourceMeta, dataSource);
            if (old != null) {
                if (isInfoEnabled) {
                    logger.info("[atomikos] destroyed shadow table datasource success. url:{} ,username:{}", getUrl(target), getUsername(target));
                }
                old.close();
            }
            if (isInfoEnabled) {
                logger.info("[atomikos] create shadow datasource success. target:{} url:{} ,username:{} shadow-url:{},shadow-username:{}", target.hashCode(), getUrl(target), getUsername(target), getUrl(ptDataSource), getUsername(ptDataSource));
            }
        } catch (Throwable t) {
            logger.error("[atomikos] init datasource err!", t);
            ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0003").setMessage("影子库设置初始化异常!").setDetail("[atomikos] DataSourceWrapUtil:业务库配置:::url: " + getUrl(target) + "|||" + Throwables.getStackTraceAsString(t)).closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS).report();
        }
    }
}
Also used : DbMediatorDataSource(com.pamirs.pradar.pressurement.datasource.DbMediatorDataSource) AtomikosDataSourceBean(com.atomikos.jdbc.AtomikosDataSourceBean)

Aggregations

DbMediatorDataSource (com.pamirs.pradar.pressurement.datasource.DbMediatorDataSource)9 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)1 AtomikosDataSourceBean (com.atomikos.jdbc.AtomikosDataSourceBean)1 AtomikosNonXADataSourceBean (com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean)1 ComboPooledDataSource (com.mchange.v2.c3p0.ComboPooledDataSource)1 DbDruidMediatorDataSource (com.pamirs.attach.plugin.alibaba.druid.obj.DbDruidMediatorDataSource)1 TomcatJdbcMediatorDataSource (com.pamirs.attach.plugin.apache.tomcatjdbc.obj.TomcatJdbcMediatorDataSource)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)1 BasicDataSource (org.apache.commons.dbcp2.BasicDataSource)1 DataSource (org.apache.tomcat.jdbc.pool.DataSource)1 ProxoolDataSource (org.logicalcobwebs.proxool.ProxoolDataSource)1