Search in sources :

Example 1 with ShadowHbaseConfig

use of com.pamirs.pradar.internal.config.ShadowHbaseConfig in project LinkAgent by shulieTech.

the class MediatorConnection method dynamic.

public static void dynamic(ShadowHbaseConfig config) {
    for (Map.Entry<String, ShadowHbaseConfig> entry : GlobalConfig.getInstance().getShadowHbaseServerConfigs().entrySet()) {
        ShadowHbaseConfig hbaseConfig = entry.getValue();
        if (!hbaseConfig.equals(config)) {
            continue;
        }
        MediatorConnection mediator = mediatorMap.get(entry.getKey());
        if (null != mediator) {
            if (mediator.getPerformanceTestConnection() != null) {
                mediator.closeClusterTest();
            }
            Object ptConfig = mediator.matching(mediator.businessConfig);
            if (ptConfig != null) {
                try {
                    mediator.setPerformanceTestConnection(mediator.initConnection());
                } catch (Exception e) {
                    logger.error(e.getMessage(), e);
                }
            }
        }
    }
}
Also used : ShadowHbaseConfig(com.pamirs.pradar.internal.config.ShadowHbaseConfig) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with ShadowHbaseConfig

use of com.pamirs.pradar.internal.config.ShadowHbaseConfig in project LinkAgent by shulieTech.

the class ApacheHbasePlugin method initEventListener.

void initEventListener() {
    dynamicEventListener = new PradarEventListener() {

        @Override
        public EventResult onEvent(IEvent event) {
            if (!ShadowHbaseDynamicEvent.class.isAssignableFrom(event.getClass())) {
                return EventResult.IGNORE;
            }
            if (!GlobalConfig.getInstance().isShadowHbaseServer()) {
                return EventResult.IGNORE;
            }
            try {
                MediatorConnection.dynamic((ShadowHbaseConfig) event.getTarget());
            } catch (Exception e) {
            }
            return EventResult.success(event.getTarget());
        }

        @Override
        public int order() {
            return 10;
        }
    };
    EventRouter.router().addListener(dynamicEventListener);
    disableEventListener = new PradarEventListener() {

        @Override
        public EventResult onEvent(IEvent event) {
            if (!ShadowHbaseDisableEvent.class.isAssignableFrom(event.getClass())) {
                return EventResult.IGNORE;
            }
            try {
                MediatorConnection.disable((String) event.getTarget());
            } catch (Exception e) {
            }
            return EventResult.success(event.getTarget());
        }

        @Override
        public int order() {
            return 11;
        }
    };
    EventRouter.router().addListener(disableEventListener);
}
Also used : PradarEventListener(com.pamirs.pradar.pressurement.agent.listener.PradarEventListener) EventResult(com.pamirs.pradar.pressurement.agent.listener.EventResult) IEvent(com.pamirs.pradar.pressurement.agent.event.IEvent) ShadowHbaseConfig(com.pamirs.pradar.internal.config.ShadowHbaseConfig)

Example 3 with ShadowHbaseConfig

use of com.pamirs.pradar.internal.config.ShadowHbaseConfig in project LinkAgent by shulieTech.

the class HbaseMediatorConnection method matching.

@Override
public Object matching(Object arg1) {
    if (!(arg1 instanceof Configuration)) {
        return null;
    }
    Configuration configuration = (Configuration) arg1;
    String quorum = configuration.get(HConstants.ZOOKEEPER_QUORUM);
    String port = configuration.get(HConstants.ZOOKEEPER_CLIENT_PORT);
    String znode = configuration.get(HConstants.ZOOKEEPER_ZNODE_PARENT);
    Map<String, ShadowHbaseConfig> hbaseConfigMap = GlobalConfig.getInstance().getShadowHbaseServerConfigs();
    ShadowHbaseConfig ptConfig = null;
    SS: for (Map.Entry<String, ShadowHbaseConfig> entry : hbaseConfigMap.entrySet()) {
        String[] split = entry.getKey().split("\\|");
        if (split.length == 3) {
            if (logger.isInfoEnabled()) {
                logger.info("business config quorums:{}, port:{}, znode:{} ---------- " + "perfomanceTest config quorums:{}, port:{}, znode:{}", quorum, port, znode, split[0], split[1], split[2]);
            }
            if (!split[1].equals(port) || !split[2].equals(znode)) {
                continue;
            }
            List<String> quorums = Arrays.asList(split[0].split(","));
            String[] bquorums = quorum.split(",");
            for (String bquorum : bquorums) {
                if (!quorums.contains(bquorum)) {
                    continue SS;
                }
            }
            ptConfig = entry.getValue();
            break;
        } else {
            logger.error("business config key is error:{}", entry.getKey());
        }
    }
    if (ptConfig != null) {
        Configuration ptConfiguration = HBaseConfiguration.create();
        ptConfiguration.addResource(configuration);
        ptConfiguration.set(HConstants.ZOOKEEPER_CLIENT_PORT, ptConfig.getPort());
        ptConfiguration.set(HConstants.ZOOKEEPER_QUORUM, ptConfig.getQuorum());
        ptConfiguration.set(HConstants.ZOOKEEPER_ZNODE_PARENT, ptConfig.getZnode());
        if (null != ptConfig.getToken()) {
            ptConfiguration.set(sf_token, ptConfig.getToken());
        }
        if (null != ptConfig.getUsername()) {
            ptConfiguration.set(sf_username, ptConfig.getUsername());
        }
        if (null != ptConfig.getParams()) {
            for (Map.Entry<String, String> entry : ptConfig.getParams().entrySet()) {
                ptConfiguration.set(entry.getKey(), entry.getValue());
            }
        }
        return ptConfiguration;
    }
    return null;
}
Also used : HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Configuration(org.apache.hadoop.conf.Configuration) ShadowHbaseConfig(com.pamirs.pradar.internal.config.ShadowHbaseConfig) List(java.util.List) Map(java.util.Map)

Example 4 with ShadowHbaseConfig

use of com.pamirs.pradar.internal.config.ShadowHbaseConfig in project LinkAgent by shulieTech.

the class ShadowHbaseConfigs method compareIsChangeAndSet.

@Override
public Boolean compareIsChangeAndSet(ApplicationConfig currentValue, Map<String, ShadowHbaseConfig> newValue) {
    Map<String, ShadowHbaseConfig> old = GlobalConfig.getInstance().getShadowHbaseServerConfigs();
    boolean change = false;
    if (newValue.size() < 1) {
        GlobalConfig.getInstance().setShadowHbaseServer(false);
        for (Map.Entry<String, ShadowHbaseConfig> entry : old.entrySet()) {
            EventRouter.router().publish(new ShadowHbaseDisableEvent(entry.getKey()));
        }
        GlobalConfig.getInstance().getShadowHbaseServerConfigs().clear();
        return true;
    }
    for (Map.Entry<String, ShadowHbaseConfig> entry : old.entrySet()) {
        String key = entry.getKey();
        if (!newValue.containsKey(key)) {
            EventRouter.router().publish(new ShadowHbaseDisableEvent(key));
            change = true;
        } else {
            if (!newValue.get(key).equals(entry.getValue())) {
                EventRouter.router().publish(new ShadowHbaseDynamicEvent(entry.getValue()));
                change = true;
            }
        }
    }
    for (Map.Entry<String, ShadowHbaseConfig> entry : newValue.entrySet()) {
        String key = entry.getKey();
        if (old.containsKey(key)) {
            if (!old.get(key).equals(entry.getValue())) {
                EventRouter.router().publish(new ShadowHbaseDynamicEvent(entry.getValue()));
                change = true;
            }
        } else {
            change = true;
            EventRouter.router().publish(new ShadowHbaseDynamicEvent(entry.getValue()));
        }
    }
    GlobalConfig.getInstance().getShadowHbaseServerConfigs().clear();
    GlobalConfig.getInstance().setShadowHbaseServerConfigs(newValue);
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("publish shadow hbase config successful. config={}", newValue);
    }
    return change;
}
Also used : ShadowHbaseDynamicEvent(com.pamirs.pradar.pressurement.agent.event.impl.ShadowHbaseDynamicEvent) ShadowHbaseConfig(com.pamirs.pradar.internal.config.ShadowHbaseConfig) ShadowHbaseDisableEvent(com.pamirs.pradar.pressurement.agent.event.impl.ShadowHbaseDisableEvent) Map(java.util.Map)

Aggregations

ShadowHbaseConfig (com.pamirs.pradar.internal.config.ShadowHbaseConfig)4 Map (java.util.Map)3 IEvent (com.pamirs.pradar.pressurement.agent.event.IEvent)1 ShadowHbaseDisableEvent (com.pamirs.pradar.pressurement.agent.event.impl.ShadowHbaseDisableEvent)1 ShadowHbaseDynamicEvent (com.pamirs.pradar.pressurement.agent.event.impl.ShadowHbaseDynamicEvent)1 EventResult (com.pamirs.pradar.pressurement.agent.listener.EventResult)1 PradarEventListener (com.pamirs.pradar.pressurement.agent.listener.PradarEventListener)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Configuration (org.apache.hadoop.conf.Configuration)1 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)1