use of com.pamirs.attach.plugin.dynamic.Attachment in project LinkAgent by shulieTech.
the class ConnectionInterceptor method config.
void config(Advice advice) {
try {
if (Pradar.isClusterTest() || Version.workWithSpringLettuce) {
return;
}
Object t = advice.getTarget();
String nodes = null;
String password = null;
Integer db = null;
StringBuilder nodeBuilder = new StringBuilder();
// 版本问题 就不引用包了 全走反射
if ("io.lettuce.core.masterreplica.MasterReplica".equals(advice.getTarget().getClass().getName())) {
Boolean isSentinel = false;
RedisURI redisUri = (RedisURI) advice.getParameterArray()[1];
isSentinel = Reflect.on(advice.getTargetClass()).call("isSentinel", redisUri).get();
if (isSentinel) {
List<String> indexes = new ArrayList<String>();
String masterId = redisUri.getSentinelMasterId();
List<RedisURI> sentinels = redisUri.getSentinels();
StringBuilder builder = new StringBuilder();
for (RedisURI sentinel : sentinels) {
password = sentinel.getPassword() == null ? null : new String(sentinel.getPassword());
db = sentinel.getDatabase();
String node = sentinel.getHost().concat(":").concat(String.valueOf(sentinel.getPort()));
indexes.add(node);
builder.append(node).append(",");
}
nodes = builder.deleteCharAt(builder.length() - 1).toString();
ResourceManager.set(new Attachment(indexes, LettuceConstants.MODULE_NAME, new String[] { LettuceConstants.MIDDLEWARE_NAME }, new RedisTemplate.LettuceSentinelTemplate().setMaster(masterId).setDatabase(db).setNodes(nodes).setPassword(password)));
}
} else if (RedisClusterClient.class.isAssignableFrom(advice.getTarget().getClass())) {
/**
* 集群模式
*/
RedisClusterClient client = (RedisClusterClient) t;
Iterable<RedisURI> iterable = Reflect.on(client).get("initialUris");
Iterator iterator = iterable.iterator();
List<String> indexes = new ArrayList<String>();
while (iterator.hasNext()) {
RedisURI redisURI = (RedisURI) iterator.next();
String node = redisURI.getHost().concat(":").concat(String.valueOf(redisURI.getPort()));
indexes.add(node);
nodeBuilder.append(node).append(",");
password = redisURI.getPassword() == null ? null : new String(redisURI.getPassword());
db = redisURI.getDatabase();
}
nodes = nodeBuilder.deleteCharAt(nodeBuilder.length() - 1).toString();
Attachment attachment = new Attachment(indexes, "redis-lettuce", new String[] { "redis" }, new RedisTemplate.LettuceClusterTemplate().setDatabase(db).setNodes(nodes).setPassword(password));
ResourceManager.set(attachment);
} else if (RedisClient.class.isAssignableFrom(advice.getTarget().getClass())) {
RedisClient client = (RedisClient) t;
RedisURI redisURI = Reflect.on(client).get("redisURI");
nodes = redisURI.getHost().concat(":").concat(String.valueOf(redisURI.getPort()));
String index = redisURI.getHost().concat(":").concat(String.valueOf(redisURI.getPort()));
password = redisURI.getPassword() == null ? null : new String(redisURI.getPassword());
db = redisURI.getDatabase();
Attachment attachment = new Attachment(index, "redis-lettuce", new String[] { "redis" }, new RedisTemplate.LettuceSingleTemplate().setDatabase(db).setNodes(nodes).setPassword(password));
ResourceManager.set(attachment);
}
} catch (Throwable t) {
logger.error(t.getMessage());
}
}
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(), "dbcp2", 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 ConnectionShadowInterceptor method attachment.
void attachment(Advice advice) {
try {
Object[] args = advice.getParameterArray();
Configuration configuration = (Configuration) args[0];
String quorum = configuration.get(HConstants.ZOOKEEPER_QUORUM);
String port = configuration.get(HConstants.ZOOKEEPER_CLIENT_PORT);
String znode = configuration.get(HConstants.ZOOKEEPER_ZNODE_PARENT);
ResourceManager.set(new Attachment(null, "apache-hbase", new String[] { "hbase" }, new HbaseTemplate().setZookeeper_quorum(quorum).setZookeeper_client_port(port).setZookeeper_znode_parent(znode)));
} catch (Throwable t) {
}
}
use of com.pamirs.attach.plugin.dynamic.Attachment in project LinkAgent by shulieTech.
the class DataSourceGetConnectionCutoffInterceptor method attachment.
void attachment(Advice advice) {
try {
ProxoolDataSource target = (ProxoolDataSource) advice.getTarget();
ResourceManager.set(new Attachment(target.getDriverUrl(), "proxool", Type.DataBaseType.types(), new ProxoolTemplate().setUrl(target.getDriverUrl()).setUsername(target.getUser()).setPassword(target.getPassword()).setDriverClassName(target.getDriver()).setAlias(target.getAlias())));
} catch (Throwable t) {
logger.error(Throwables.getStackTraceAsString(t));
}
}
Aggregations