use of com.pamirs.attach.plugin.neo4j.operation.Operation in project LinkAgent by shulieTech.
the class Neo4jSessionOperationCutOffInterceptor method cutoff0.
@Override
public CutOffResult cutoff0(Advice advice) {
Object[] args = advice.getParameterArray();
String methodName = advice.getBehaviorName();
Object target = advice.getTarget();
/**
* 压测状态为关闭,如果当前为压测流量则直接报错
*/
if (!PradarSwitcher.isClusterTestEnabled()) {
if (Pradar.isClusterTest()) {
throw new PressureMeasureError(PradarSwitcher.PRADAR_SWITCHER_OFF + ":" + AppNameUtils.appName());
}
return CutOffResult.passed();
}
if (!Pradar.isClusterTest()) {
// 非压测流量
return CutOffResult.passed();
}
if (target instanceof Neo4JSessionExt) {
// 影子配置session回调
return CutOffResult.passed();
}
// 避免因配置重新生效而导致使用旧配置
Driver driver1 = Reflect.on(target).get(Neo4JConstants.DYNAMIC_FIELD_DRIVER);
DriverConfiguration configuration = driver1.getConfiguration();
String uri = configuration.getURI();
Credentials credentials = configuration.getCredentials();
String username = null;
if (credentials instanceof AuthTokenCredentials) {
username = ((AuthTokenCredentials) credentials).credentials();
} else if (credentials instanceof UsernamePasswordCredentials) {
username = ((UsernamePasswordCredentials) credentials).getUsername();
}
DataSourceMeta<Neo4jSession> neo4jSessionDataSourceMeta = new DataSourceMeta<Neo4jSession>(uri, username, (Neo4jSession) target);
DataSourceWrapUtil.wrap(neo4jSessionDataSourceMeta);
// 压测流量转发影子库
if (!DataSourceWrapUtil.pressureDataSources.containsKey(neo4jSessionDataSourceMeta) || null == DataSourceWrapUtil.pressureDataSources.get(neo4jSessionDataSourceMeta)) {
ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0002").setMessage("没有配置对应的影子库!").setDetail("Neo4J").closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS).report();
throw new PressureMeasureError("Neo4J-002:影子库配置不存在!");
}
DbMediatorDataSource<?> dbMediatorDataSource = DataSourceWrapUtil.pressureDataSources.get(neo4jSessionDataSourceMeta);
Neo4JSessionExt dataSourcePerformanceTest = (Neo4JSessionExt) dbMediatorDataSource.getDataSourcePerformanceTest();
Operation operation = Neo4JSessionOperation.of(methodName);
PradarSwitcher.httpPassPrefix.set(dataSourcePerformanceTest.getDriver().getConfiguration().getURI());
return CutOffResult.cutoff(operation.invoke(dataSourcePerformanceTest, args));
}
Aggregations