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);
}
}
}
}
}
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);
}
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;
}
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;
}
Aggregations