use of com.pamirs.attach.plugin.dynamic.Attachment in project LinkAgent by shulieTech.
the class DataSourceWrapUtil method attachment.
public static void attachment(Advice advice) {
try {
BasicDataSource target = (BasicDataSource) advice.getTarget();
ResourceManager.set(new Attachment(target.getUrl(), "dbcp", Type.DataBaseType.types(), new DbcpTemplate().setUrl(target.getUrl()).setUsername(target.getUsername()).setPassword(target.getPassword()).setDriverClassName(target.getDriverClassName())));
} catch (Throwable t) {
logger.error(Throwables.getStackTraceAsString(t));
}
}
use of com.pamirs.attach.plugin.dynamic.Attachment in project LinkAgent by shulieTech.
the class JedisClusterConnectionInterceptor method attachment.
void attachment(Advice advice) {
try {
if (Pradar.isClusterTest()) {
return;
}
JedisSlotBasedConnectionHandler handler = (JedisSlotBasedConnectionHandler) advice.getTarget();
JedisClusterInfoCache cache = Reflect.on(handler).get("cache");
String password = Reflect.on(cache).get("password");
Map hashmap = Reflect.on(cache).get("nodes");
StringBuilder builder = new StringBuilder();
for (Object node : hashmap.keySet()) {
model.setClusterMode(String.valueOf(node));
builder.append(node).append(",");
}
builder.deleteCharAt(builder.length() - 1);
ResourceManager.set(new Attachment(new ArrayList(hashmap.keySet()), RedisConstants.PLUGIN_NAME, new String[] { RedisConstants.MIDDLEWARE_NAME }, new RedisTemplate.JedisClusterTemplate().setNodes(builder.toString()).setPassword(password)));
} catch (Throwable t) {
}
}
use of com.pamirs.attach.plugin.dynamic.Attachment in project LinkAgent by shulieTech.
the class JedisInterceptor method attachment.
void attachment(Advice advice, int stage) {
try {
if (Pradar.isClusterTest()) {
return;
}
Jedis jedis = (Jedis) advice.getTarget();
Client client = Reflect.on(jedis).get("client");
String node = client.getHost().concat(":").concat(String.valueOf(client.getPort()));
Object dataSource = null;
boolean isSentinel = false;
try {
/**
* 哨兵模式的端口会经过处理,不是配置的,所以这里判断一下
*/
dataSource = Reflect.on(jedis).get("dataSource");
if (dataSource != null && JedisSentinelPool.class.isAssignableFrom(dataSource.getClass())) {
isSentinel = true;
}
/**
* 判断下拦截的方法,如果是slaveOf,说明是主从模式,和哨兵模式有一定区别
*/
String method = advice.getBehavior().getName();
/**
* 这个实在难搞,加上对哨兵的过滤,因为哨兵也是基于主从做的
*/
if ("slaveof".equals(method.toLowerCase()) && !isSentinel) {
Object[] parameters = advice.getParameterArray();
String master = parameters[0] + ":" + parameters[1];
String slave = node;
model.setMasterSlaveMode(slave, master);
}
} catch (Throwable t) {
}
switch(stage) {
case 0:
{
/**
* 主从模式
*/
if (model.isMasterSlave(node)) {
String slave = node;
String master = model.getMasterBySlave(slave);
/* if (master == null) {
break;
}
Attachment ext = new Attachment(
null, RedisConstants.PLUGIN_NAME, new String[]{RedisConstants.MIDDLEWARE_NAME},
new RedisTemplate.JedisMasterSlaveTemplate()
.setMaster(master)
.setNodes(slave));
Pradar.getInvokeContext().setExt(ext);*/
break;
} else if (model.isClusterMode(node)) {
/**
* 集群模式
*/
Pradar.getInvokeContext().setIndex(node);
break;
} else if (isSentinel) {
/**
* 哨兵模式
*/
JedisSentinelPool jedisSentinelPool = (JedisSentinelPool) dataSource;
String password = Reflect.on(jedisSentinelPool).get("password");
Integer database = Reflect.on(jedisSentinelPool).get("database");
Set set = Reflect.on(jedisSentinelPool).get("masterListeners");
Iterator iterator = set.iterator();
StringBuilder nodeBuilder = new StringBuilder();
String masterName = null;
while (iterator.hasNext()) {
Object t = iterator.next();
Reflect ref = Reflect.on(t);
masterName = ref.get("masterName");
String host = ref.get("host");
String port = String.valueOf(ref.get("port"));
nodeBuilder.append(host.concat(":").concat(port)).append(",");
}
Attachment ext = new Attachment(null, RedisConstants.PLUGIN_NAME, new String[] { RedisConstants.MIDDLEWARE_NAME }, new RedisTemplate.JedisSentinelTemplate().setMaster(masterName).setNodes(nodeBuilder.deleteCharAt(nodeBuilder.length() - 1).toString()).setDatabase(database).setPassword(password));
Pradar.getInvokeContext().setExt(ext);
} else {
// 单机模式
String password = Reflect.on(client).get("password");
int db = Integer.parseInt(String.valueOf(Reflect.on(client).get("db")));
Attachment ext = new Attachment(node, RedisConstants.PLUGIN_NAME, new String[] { RedisConstants.MIDDLEWARE_NAME }, new RedisTemplate.JedisSingleTemplate().setNodes(node).setPassword(password).setDatabase(db));
Pradar.getInvokeContext().setExt(ext);
break;
}
}
case 1:
return;
}
} catch (Throwable t) {
}
}
use of com.pamirs.attach.plugin.dynamic.Attachment in project LinkAgent by shulieTech.
the class DataSourceGetConnectionArgsCutoffInterceptor method attachment.
void attachment(Advice advice) {
try {
ComboPooledDataSource target = (ComboPooledDataSource) advice.getTarget();
ResourceManager.set(new Attachment(target.getJdbcUrl(), "c3p0", Type.DataBaseType.types(), new C3p0Template().setUrl(target.getJdbcUrl()).setUsername(target.getUser()).setPassword(target.getPassword()).setDriverClassName(target.getDriverClass()).setInitialPoolSize(target.getInitialPoolSize()).setMaxIdleTime(target.getMaxIdleTime()).setMaxPoolSize(target.getMaxPoolSize())));
} catch (Throwable t) {
logger.error(t.getMessage());
}
}
use of com.pamirs.attach.plugin.dynamic.Attachment in project LinkAgent by shulieTech.
the class DataSourceGetConnectionCutoffInterceptor method attachment.
void attachment(Advice advice) {
try {
ComboPooledDataSource target = (ComboPooledDataSource) advice.getTarget();
ResourceManager.set(new Attachment(target.getJdbcUrl(), "c3p0", Type.DataBaseType.types(), new C3p0Template().setUrl(target.getJdbcUrl()).setUsername(target.getUser()).setPassword(target.getPassword()).setDriverClassName(target.getDriverClass()).setInitialPoolSize(target.getInitialPoolSize()).setMaxIdleTime(target.getMaxIdleTime()).setMaxPoolSize(target.getMaxPoolSize())));
} catch (Throwable t) {
logger.error(t.getMessage());
}
}
Aggregations