use of org.neo4j.ogm.MetaData in project LinkAgent by shulieTech.
the class Neo4jSessionConstructorInterceptor method afterLast.
@Override
public void afterLast(Advice advice) {
Object[] args = advice.getParameterArray();
Object target = advice.getTarget();
/**
* 压测状态判断
* 影子session回调
*/
if (!PradarSwitcher.isClusterTestEnabled() || target instanceof Neo4JSessionExt) {
return;
}
try {
// 业务库session
Neo4jSession sourceSession = (Neo4jSession) target;
DriverConfiguration driverConfiguration = ((HttpDriver) args[1]).getConfiguration();
String s = driverConfiguration.getURI();
Credentials credentials = driverConfiguration.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>(s, username, sourceSession);
if (DataSourceWrapUtil.pressureDataSources.containsKey(neo4jSessionDataSourceMeta) && DataSourceWrapUtil.pressureDataSources.get(neo4jSessionDataSourceMeta) != null) {
// 该业务库数据源已经初始化过影子库
return;
}
if (isPerformanceDataSource(driverConfiguration)) {
// 业务库配置是已初始化的影子库
return;
}
// 从应用的影子库配置中获取
String key = DbUrlUtils.getKey(neo4jSessionDataSourceMeta.getUrl(), neo4jSessionDataSourceMeta.getUsername());
if (!GlobalConfig.getInstance().containsShadowDatabaseConfig(key)) {
ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0002").setMessage("没有配置对应的影子表或影子库!").setDetail("业务库配置:::url: " + s + "; 中间件类型:other").closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS).report();
return;
}
MetaData metaData = (MetaData) args[0];
DataSourceWrapUtil.metaDataMap.put(sourceSession, metaData);
DataSourceWrapUtil.wrap(neo4jSessionDataSourceMeta);
} catch (Throwable e) {
ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0003").setMessage("影子库配置异常,无法由配置正确生成影子库!").setDetail("url: " + ((HttpDriver) args[1]).getConfiguration().getURI() + Throwables.getStackTraceAsString(e)).closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS).report();
throw new PressureMeasureError("Neo4J-002:影子库初始化失败:", e);
}
}
Aggregations