Search in sources :

Example 11 with Attachment

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());
    }
}
Also used : RedisTemplate(com.pamirs.attach.plugin.dynamic.template.RedisTemplate) RedisURI(io.lettuce.core.RedisURI) ArrayList(java.util.ArrayList) Attachment(com.pamirs.attach.plugin.dynamic.Attachment) RedisClient(io.lettuce.core.RedisClient) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) RedisClusterClient(io.lettuce.core.cluster.RedisClusterClient)

Example 12 with Attachment

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));
    }
}
Also used : Attachment(com.pamirs.attach.plugin.dynamic.Attachment) BasicDataSource(org.apache.commons.dbcp2.BasicDataSource) DbcpTemplate(com.pamirs.attach.plugin.dynamic.template.DbcpTemplate)

Example 13 with Attachment

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) {
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HbaseTemplate(com.pamirs.attach.plugin.dynamic.template.HbaseTemplate) Attachment(com.pamirs.attach.plugin.dynamic.Attachment)

Example 14 with Attachment

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));
    }
}
Also used : ProxoolTemplate(com.pamirs.attach.plugin.dynamic.template.ProxoolTemplate) ProxoolDataSource(org.logicalcobwebs.proxool.ProxoolDataSource) Attachment(com.pamirs.attach.plugin.dynamic.Attachment)

Aggregations

Attachment (com.pamirs.attach.plugin.dynamic.Attachment)14 RedisTemplate (com.pamirs.attach.plugin.dynamic.template.RedisTemplate)4 ArrayList (java.util.ArrayList)3 ComboPooledDataSource (com.mchange.v2.c3p0.ComboPooledDataSource)2 C3p0Template (com.pamirs.attach.plugin.dynamic.template.C3p0Template)2 DbcpTemplate (com.pamirs.attach.plugin.dynamic.template.DbcpTemplate)2 Reflect (com.shulie.instrument.simulator.api.reflect.Reflect)2 RedisURI (io.lettuce.core.RedisURI)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Set (java.util.Set)2 AbstractTemplate (com.pamirs.attach.plugin.dynamic.template.AbstractTemplate)1 HbaseTemplate (com.pamirs.attach.plugin.dynamic.template.HbaseTemplate)1 HikariTemplate (com.pamirs.attach.plugin.dynamic.template.HikariTemplate)1 ProxoolTemplate (com.pamirs.attach.plugin.dynamic.template.ProxoolTemplate)1 RedissionSentinelTemplate (com.pamirs.attach.plugin.dynamic.template.RedisTemplate.RedissionSentinelTemplate)1 RedissionSingleTemplate (com.pamirs.attach.plugin.dynamic.template.RedisTemplate.RedissionSingleTemplate)1 RedissonMasterSlaveTemplate (com.pamirs.attach.plugin.dynamic.template.RedisTemplate.RedissonMasterSlaveTemplate)1 RedissonReplicatedTemplate (com.pamirs.attach.plugin.dynamic.template.RedisTemplate.RedissonReplicatedTemplate)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1