use of io.fabric8.zookeeper.ZkPath in project fabric8 by jboss-fuse.
the class GatewayServiceTreeCache method treeCacheEvent.
protected void treeCacheEvent(PathChildrenCacheEvent event) {
ChildData childData = event.getData();
if (childData == null) {
return;
}
String path = childData.getPath();
LOG.trace("Event {} on path {}", event.getType().toString(), path);
PathChildrenCacheEvent.Type type = event.getType();
byte[] data = childData.getData();
if (data == null || data.length == 0 || path == null) {
return;
}
if (path.startsWith(zkPath)) {
path = path.substring(zkPath.length());
}
List<String> split = Strings.splitAndTrimAsList(path, "/");
// Lets just use the group name as the service path.
path = split.get(0);
String zNode = split.get(1);
boolean remove = false;
switch(type) {
case CHILD_ADDED:
case CHILD_UPDATED:
break;
case CHILD_REMOVED:
remove = true;
break;
default:
return;
}
ServiceDTO dto = null;
try {
dto = mapper.readValue(data, ServiceDTO.class);
expandPropertyResolvers(dto);
dto.setContainer(dto.getContainer() + "_zNode_" + zNode);
if (remove) {
LOG.info("Removed gateway service: " + path + ": " + dto);
serviceMap.serviceRemoved(path, dto);
} else {
LOG.info("Updated gateway service: " + path + ": " + dto);
serviceMap.serviceUpdated(path, dto);
}
} catch (IOException e) {
LOG.warn("Failed to parse the JSON: " + new String(data) + ". Reason: " + e, e);
} catch (URISyntaxException e) {
LOG.warn("Failed to update URI for dto: " + dto + ", .Reason: " + e, e);
}
}
use of io.fabric8.zookeeper.ZkPath in project fabric8 by jboss-fuse.
the class HttpMappingRuleConfiguration method updateConfiguration.
private void updateConfiguration(Map<String, ?> configuration) throws Exception {
LOG.info("activating http mapping rule " + configuration);
configurer.configure(configuration, this);
LOG.info("activating http mapping rule " + zooKeeperPath + " on " + gateway.get().getPort());
String zkPath = getZooKeeperPath();
Objects.notNull(zkPath, "zooKeeperPath");
Objects.notNull(getUriTemplate(), "uriTemplate");
LoadBalancer loadBalancer = LoadBalancers.createLoadBalancer(loadBalancerType, stickyLoadBalancerCacheSize);
LOG.info("activating http mapping ZooKeeper path: " + zkPath + " with URI template: " + uriTemplate + " enabledVersion: " + enabledVersion + " with load balancer: " + loadBalancer);
if (httpMappingRuleBase != null) {
gateway.get().removeMappingRuleConfiguration(httpMappingRuleBase);
}
httpMappingRuleBase = new HttpMappingRuleBase(new SimplePathTemplate(uriTemplate), gateway.get().getGatewayVersion(), enabledVersion, loadBalancer, reverseHeaders);
mappingTree = new HttpMappingZooKeeperTreeCache(curator.get(), httpMappingRuleBase, zooKeeperPath);
mappingTree.init();
gateway.get().addMappingRuleConfiguration(httpMappingRuleBase);
}
use of io.fabric8.zookeeper.ZkPath in project fabric8 by jboss-fuse.
the class FabricMQGateway method createListener.
protected GatewayServiceTreeCache createListener() {
String zkPath = getZooKeeperPath();
// TODO we should discover the broker group configuration here using the same
// mq-create / mq-client profiles so that we only listen to a subset of the available brokers here?
ServiceMap serviceMap = new ServiceMap();
VertxService vertxService = getVertxService();
Vertx vertx = vertxService.getVertx();
CuratorFramework curator = getCurator();
LoadBalancer pathLoadBalancer = LoadBalancers.createLoadBalancer(loadBalancerType, stickyLoadBalancerCacheSize);
LoadBalancer serviceLoadBalancer = LoadBalancers.createLoadBalancer(loadBalancerType, stickyLoadBalancerCacheSize);
LOG.info("activating MQ mapping ZooKeeper path: " + zkPath + " host: " + host + " with load balancer: " + pathLoadBalancer);
List<TcpGateway> gateways = new ArrayList<TcpGateway>();
addGateway(gateways, vertx, serviceMap, "tcp", isOpenWireEnabled(), getOpenWirePort(), pathLoadBalancer, serviceLoadBalancer);
addGateway(gateways, vertx, serviceMap, "stomp", isStompEnabled(), getStompPort(), pathLoadBalancer, serviceLoadBalancer);
addGateway(gateways, vertx, serviceMap, "amqp", isAmqpEnabled(), getAmqpPort(), pathLoadBalancer, serviceLoadBalancer);
addGateway(gateways, vertx, serviceMap, "mqtt", isMqttEnabled(), getMqttPort(), pathLoadBalancer, serviceLoadBalancer);
addGateway(gateways, vertx, serviceMap, "ws", isWebsocketEnabled(), getWebsocketPort(), pathLoadBalancer, serviceLoadBalancer);
if (gateways.isEmpty()) {
return null;
}
return new GatewayServiceTreeCache(curator, zkPath, serviceMap, gateways);
}
use of io.fabric8.zookeeper.ZkPath in project fabric8 by jboss-fuse.
the class GatewayServiceTreeCache method init.
public void init() throws Exception {
if (active.compareAndSet(false, true)) {
treeCache = new TreeCacheExtended(curator, zkPath, true, false, true, treeCacheExecutor);
treeCache.start(TreeCacheExtended.StartMode.NORMAL);
treeCache.getListenable().addListener(treeListener);
LOG.info("Started a group listener for " + zkPath);
for (TcpGateway gateway : gateways) {
gateway.init();
}
}
}
use of io.fabric8.zookeeper.ZkPath in project fabric8 by jboss-fuse.
the class GatewayServiceTreeCache method treeCacheEvent.
protected void treeCacheEvent(PathChildrenCacheEvent event) {
ChildData childData = event.getData();
if (childData == null) {
return;
}
String path = childData.getPath();
PathChildrenCacheEvent.Type type = event.getType();
byte[] data = childData.getData();
if (data == null || data.length == 0 || path == null) {
return;
}
if (path.startsWith(zkPath)) {
path = path.substring(zkPath.length());
}
boolean remove = false;
switch(type) {
case CHILD_ADDED:
case CHILD_UPDATED:
break;
case CHILD_REMOVED:
remove = true;
break;
default:
return;
}
ServiceDTO dto = null;
try {
dto = mapper.readValue(data, ServiceDTO.class);
expandPropertyResolvers(dto);
if (remove) {
serviceMap.serviceRemoved(path, dto);
} else {
serviceMap.serviceUpdated(path, dto);
}
} catch (IOException e) {
LOG.warn("Failed to parse the JSON: " + new String(data) + ". Reason: " + e, e);
} catch (URISyntaxException e) {
LOG.warn("Failed to update URI for dto: " + dto + ", .Reason: " + e, e);
}
}
Aggregations