use of io.fabric8.gateway.loadbalancer.LoadBalancer in project fabric8 by jboss-fuse.
the class FabricMQGateway method addGateway.
protected TcpGateway addGateway(List<TcpGateway> gateways, Vertx vertx, ServiceMap serviceMap, String protocolName, boolean enabled, int listenPort, LoadBalancer pathLoadBalancer, LoadBalancer serviceLoadBalancer) {
if (enabled) {
TcpGatewayHandler handler = new TcpGatewayHandler(vertx, serviceMap, protocolName, pathLoadBalancer, serviceLoadBalancer);
TcpGateway gateway = new TcpGateway(vertx, serviceMap, listenPort, protocolName, handler);
if (Strings.isNotBlank(host)) {
gateway.setHost(host);
}
gateways.add(gateway);
return gateway;
} else {
return null;
}
}
use of io.fabric8.gateway.loadbalancer.LoadBalancer 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.gateway.loadbalancer.LoadBalancer in project fabric8 by jboss-fuse.
the class LoadBalancerTest method testRandomLoadBalancer.
@Test
public void testRandomLoadBalancer() throws Exception {
LoadBalancer loadBalancer = new RandomLoadBalancer();
assertLoadBalancerWorksOnEmptyOrSingletonServices(loadBalancer);
List<String> results = performRequests(loadBalancer);
Set<String> set = asSet(results);
assertTrue("Should have most of the values but was: " + set, set.size() > 1);
}
use of io.fabric8.gateway.loadbalancer.LoadBalancer in project fabric8 by jboss-fuse.
the class LoadBalancerTest method testStickyLoadBalancer.
@Test
public void testStickyLoadBalancer() throws Exception {
assertLoadBalancerWorksOnEmptyOrSingletonServices(new StickyLoadBalancer());
LoadBalancer loadBalancer = new StickyLoadBalancer();
Set<String> allRequests = new HashSet<String>();
int numberOfClients = 10;
for (int i = 0; i < numberOfClients; i++) {
clientRequestKey = "newClient:" + i;
List<String> results = performRequests(loadBalancer);
Set<String> set = asSet(results);
assertTrue("All values should be the same for client: " + clientRequestKey + " but got: " + set, set.size() == 1);
allRequests.addAll(set);
}
// now we should have a reasonable number of different overall answers.
assertTrue("Across " + numberOfClients + " we should have most of the values: " + allRequests, allRequests.size() > 1);
}
use of io.fabric8.gateway.loadbalancer.LoadBalancer in project fabric8 by jboss-fuse.
the class HttpMappingRuleBase method updateMappingRules.
/**
* Given a path being added or removed, update the services.
*
* @param remove whether to remove (if true) or add (if false) this mapping
* @param path the path that this mapping is bound
* @param services the HTTP URLs of the services to map to
* @param defaultParams the default parameters to use in the URI templates such as for version and container
* @param serviceDetails
*/
public void updateMappingRules(boolean remove, String path, List<String> services, Map<String, String> defaultParams, ServiceDetails serviceDetails) {
SimplePathTemplate pathTemplate = getUriTemplate();
if (pathTemplate != null) {
boolean versionSpecificUri = pathTemplate.getParameterNames().contains("version");
String versionId = defaultParams.get("version");
if (!remove && Strings.isNotBlank(versionId) && !versionSpecificUri && gatewayVersion != null) {
// lets ignore this mapping if the version does not match
if (!gatewayVersion.equals(versionId)) {
remove = true;
}
}
Map<String, String> params = new HashMap<String, String>();
if (defaultParams != null) {
params.putAll(defaultParams);
}
params.put("servicePath", path);
if (!versionSpecificUri && Strings.isNotBlank(this.enabledVersion)) {
if (!serviceDetails.getVersion().equals(this.enabledVersion)) {
remove = true;
}
}
for (String service : services) {
populateUrlParams(params, service);
String fullPath = pathTemplate.bindByNameNonStrict(params);
if (remove) {
MappedServices rule = mappingRules.get(fullPath);
if (rule != null) {
List<String> serviceUrls = rule.getServiceUrls();
serviceUrls.remove(service);
if (serviceUrls.isEmpty()) {
mappingRules.remove(fullPath);
}
}
} else {
MappedServices mappedServices = new MappedServices(service, serviceDetails, loadBalancer, reverseHeaders);
MappedServices oldRule = mappingRules.put(fullPath, mappedServices);
if (oldRule != null) {
mappedServices.getServiceUrls().addAll(oldRule.getServiceUrls());
}
}
}
}
fireMappingRulesChanged();
}
Aggregations