Search in sources :

Example 1 with BizConnection

use of com.pamirs.attach.plugin.common.datasource.biz.BizConnection 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)

Example 2 with BizConnection

use of com.pamirs.attach.plugin.common.datasource.biz.BizConnection in project LinkAgent by shulieTech.

the class ProxoolDriverConnectInterceptor method getResult0.

@Override
public Object getResult0(Advice advice) throws Throwable {
    Object returnObj = advice.getReturnObj();
    // 检查返回结果
    if (!(returnObj instanceof Connection) || returnObj instanceof BizConnection || returnObj instanceof PressureConnection) {
        return returnObj;
    }
    Connection conn = (Connection) returnObj;
    String connectUrl = (String) advice.getParameterArray()[0];
    if (!connectUrl.startsWith("proxool")) {
        return returnObj;
    }
    String alias = getAlias(connectUrl);
    // 说明url有问题
    if (alias == null || alias.length() == 0) {
        return returnObj;
    }
    if (Pradar.isClusterTestPrefix(alias)) {
        return buildConnection(returnObj, conn, alias, true);
    }
    return buildConnection(returnObj, conn, alias, false);
}
Also used : Connection(java.sql.Connection) TraceConnection(com.pamirs.attach.plugin.common.datasource.TraceConnection) PressureConnection(com.pamirs.attach.plugin.common.datasource.pressure.PressureConnection) BizConnection(com.pamirs.attach.plugin.common.datasource.biz.BizConnection) BizConnection(com.pamirs.attach.plugin.common.datasource.biz.BizConnection) PressureConnection(com.pamirs.attach.plugin.common.datasource.pressure.PressureConnection)

Example 3 with BizConnection

use of com.pamirs.attach.plugin.common.datasource.biz.BizConnection in project LinkAgent by shulieTech.

the class TomcatJdbcMediatorDataSource method getConnection.

@Override
public Connection getConnection(String username, String password) 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(username, password), dbConnectionKey, url, username, dbType, "other");
            } else {
                // 影子库
                if (dataSourcePerformanceTest == null) {
                    throw new PressureMeasureError("Performance dataSource is null.");
                }
                return new PressureConnection(dataSourceBusiness, dataSourcePerformanceTest.getConnection(username, password), url, username, dbConnectionKey, dbType);
            }
        } catch (Throwable e) {
            ErrorReporter.Error error = ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0001").setMessage("数据源获取链接失败!" + (Pradar.isClusterTest() ? "(压测流量)" : "")).setDetail("get connection failed by dbMediatorDataSource, message: " + e.getMessage() + "\r\n" + printStackTrace(e));
            // error.closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS);
            error.report();
            throw new PressureMeasureError("tomcat jdbc get connection failed by dbMediatorDataSource");
        }
    } else {
        String dbType = JdbcUtils.getDbType(dataSourceBusiness.getUrl(), JdbcUtils.getDriverClassName(dataSourceBusiness.getUrl()));
        return new BizConnection(dataSourceBusiness.getConnection(username, password), 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

BizConnection (com.pamirs.attach.plugin.common.datasource.biz.BizConnection)3 PressureConnection (com.pamirs.attach.plugin.common.datasource.pressure.PressureConnection)3 NormalConnection (com.pamirs.attach.plugin.common.datasource.normal.NormalConnection)2 PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)2 TraceConnection (com.pamirs.attach.plugin.common.datasource.TraceConnection)1 Connection (java.sql.Connection)1