Search in sources :

Example 96 with PressureMeasureError

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

the class AbstractRestClientShadowServerInterceptor method doShadowIndexInterceptor.

protected CutOffResult doShadowIndexInterceptor(Advice advice) {
    Object[] args = advice.getParameterArray();
    RequestIndexRename requestIndexRename = RequestIndexRenameProvider.get(args[0]);
    if (requestIndexRename == null) {
        throw new PressureMeasureError("elasticsearch " + args[0].getClass().getName() + " is not supported!");
    }
    if (requestIndexRename.supportedDirectReindex(args[0])) {
        requestIndexRename.reindex(args[0]);
    } else {
        Object index = requestIndexRename.indirectIndex(args[0]);
        advice.changeParameter(0, index);
    }
    return CutOffResult.PASSED;
}
Also used : PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) RequestIndexRename(com.pamirs.attach.plugin.es.common.RequestIndexRename)

Example 97 with PressureMeasureError

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

the class ShardUpgradeRequestIndexRename method reindex0.

@Override
public List<String> reindex0(Object target) {
    ShardUpgradeRequest req = (ShardUpgradeRequest) target;
    String[] indices = req.indices();
    for (int i = 0, len = indices.length; i < len; i++) {
        String index = indices[i];
        /**
         * 如果在白名单中则不允许写
         */
        if (GlobalConfig.getInstance().getSearchWhiteList().contains(index)) {
            throw new PressureMeasureError("Cluster Test request can't delete index template ! " + index);
        }
        if (!Pradar.isClusterTestPrefix(index)) {
            index = Pradar.addClusterTestPrefixLower(index);
            indices[i] = index;
        }
    }
    return Arrays.asList(indices);
}
Also used : PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) ShardUpgradeRequest(org.elasticsearch.action.admin.indices.upgrade.post.ShardUpgradeRequest)

Example 98 with PressureMeasureError

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

the class UpdateRequestIndexRename method reindex0.

@Override
public List<String> reindex0(Object target) {
    UpdateRequest req = (UpdateRequest) target;
    String index = req.index();
    /**
     * 如果在白名单中则不允许写
     */
    if (GlobalConfig.getInstance().getSearchWhiteList().contains(index)) {
        throw new PressureMeasureError("Cluster Test request can't write business index ! " + index);
    }
    if (!Pradar.isClusterTestPrefix(index)) {
        index = Pradar.addClusterTestPrefixLower(req.index());
    }
    req.index(index);
    return Arrays.asList(index);
}
Also used : UpdateRequest(org.elasticsearch.action.update.UpdateRequest) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError)

Example 99 with PressureMeasureError

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

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

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