use of io.fabric8.gateway.loadbalancer.LoadBalancer in project fabric8 by jboss-fuse.
the class DetectingGatewayVirtualHostTest method createGateway.
public DetectingGateway createGateway() {
String loadBalancerType = LoadBalancers.ROUND_ROBIN_LOAD_BALANCER;
int stickyLoadBalancerCacheSize = LoadBalancers.STICKY_LOAD_BALANCER_DEFAULT_CACHE_SIZE;
LoadBalancer serviceLoadBalancer = LoadBalancers.createLoadBalancer(loadBalancerType, stickyLoadBalancerCacheSize);
ArrayList<Protocol> protocols = new ArrayList<Protocol>();
protocols.add(new StompProtocol());
protocols.add(new MqttProtocol());
protocols.add(new AmqpProtocol());
protocols.add(new OpenwireProtocol());
protocols.add(new HttpProtocol());
protocols.add(new SslProtocol());
DetectingGateway gateway = new DetectingGateway();
gateway.setPort(0);
gateway.setVertx(vertx);
SslConfig sslConfig = new SslConfig(new File(basedir(), "src/test/resources/server.ks"), "password");
sslConfig.setKeyPassword("password");
gateway.setSslConfig(sslConfig);
gateway.setServiceMap(serviceMap);
gateway.setProtocols(protocols);
gateway.setServiceLoadBalancer(serviceLoadBalancer);
gateway.setDefaultVirtualHost("broker");
gateway.setConnectionTimeout(500000);
gateway.init();
gateways.add(gateway);
return gateway;
}
use of io.fabric8.gateway.loadbalancer.LoadBalancer in project fabric8 by jboss-fuse.
the class LoadBalancerTest method testRoundRobbinLoadBalancer.
@Test
public void testRoundRobbinLoadBalancer() throws Exception {
LoadBalancer loadBalancer = new RoundRobinLoadBalancer();
assertLoadBalancerWorksOnEmptyOrSingletonServices(loadBalancer);
List<String> results = performRequests(loadBalancer);
Set<String> set = asSet(results);
assertEquals("Should have all of the values: " + set, services.size(), set.size());
for (String service : services) {
assertTrue("Should have found service: " + service, set.contains(service));
}
}
use of io.fabric8.gateway.loadbalancer.LoadBalancer in project fabric8 by jboss-fuse.
the class FabricDetectingGateway method createDetectingGateway.
protected DetectingGateway createDetectingGateway() {
DetectingGateway gateway = new DetectingGateway();
VertxService vertxService = getVertxService();
LoadBalancer serviceLoadBalancer = LoadBalancers.createLoadBalancer(loadBalancerType, stickyLoadBalancerCacheSize);
gateway.setVertx(vertxService.getVertx());
gateway.setPort(port);
gateway.setServiceMap(serviceMap);
gateway.setShutdownTacker(shutdownTacker);
gateway.setServiceLoadBalancer(serviceLoadBalancer);
gateway.setDefaultVirtualHost(defaultVirtualHost);
ArrayList<Protocol> protocols = new ArrayList<Protocol>();
if (isStompEnabled()) {
protocols.add(new StompProtocol());
}
if (isMqttEnabled()) {
protocols.add(new MqttProtocol());
}
if (isAmqpEnabled()) {
protocols.add(new AmqpProtocol());
}
if (isOpenWireEnabled()) {
protocols.add(new OpenwireProtocol());
}
if (isHttpEnabled()) {
protocols.add(new HttpProtocol());
}
if (isSslEnabled()) {
SslConfig sslConfig = new SslConfig();
if (Strings.isNotBlank(sslAlgorithm)) {
sslConfig.setAlgorithm(sslAlgorithm);
}
if (Strings.isNotBlank(keyAlias)) {
sslConfig.setKeyAlias(keyAlias);
}
if (Strings.isNotBlank(keyPassword)) {
sslConfig.setKeyPassword(keyPassword);
}
if (Strings.isNotBlank(keyStorePassword)) {
sslConfig.setKeyStorePassword(keyStorePassword);
}
if (keyStoreURL != null) {
sslConfig.setKeyStoreURL(keyStoreURL);
}
if (Strings.isNotBlank(sslProtocol)) {
sslConfig.setProtocol(sslProtocol);
}
if (Strings.isNotBlank(sslStoreType)) {
sslConfig.setStoreType(sslStoreType);
}
if (Strings.isNotBlank(trustStorePassword)) {
sslConfig.setTrustStorePassword(trustStorePassword);
}
if (trustStoreURL != null) {
sslConfig.setTrustStoreURL(trustStoreURL);
}
if (Strings.isNotBlank(enabledCipherSuites)) {
sslConfig.setEnabledCipherSuites(enabledCipherSuites);
}
if (Strings.isNotBlank(disabledCypherSuites)) {
sslConfig.setDisabledCypherSuites(disabledCypherSuites);
}
gateway.setSslConfig(sslConfig);
// validating configuration
try {
SSLContext sslContext = SSLContext.getInstance(sslConfig.getProtocol());
sslContext.init(sslConfig.getKeyManagers(), sslConfig.getTrustManagers(), null);
} catch (Exception e) {
throw new ComponentException(e);
}
protocols.add(new SslProtocol());
}
if (protocols.isEmpty()) {
return null;
}
gateway.setProtocols(protocols);
return gateway;
}
use of io.fabric8.gateway.loadbalancer.LoadBalancer in project fabric8 by jboss-fuse.
the class ExtendedBurnIn method startDetectingGateway.
public DetectingGateway startDetectingGateway() {
String loadBalancerType = LoadBalancers.STICKY_LOAD_BALANCER;
int stickyLoadBalancerCacheSize = LoadBalancers.STICKY_LOAD_BALANCER_DEFAULT_CACHE_SIZE;
LoadBalancer serviceLoadBalancer = LoadBalancers.createLoadBalancer(loadBalancerType, stickyLoadBalancerCacheSize);
ArrayList<Protocol> protocols = new ArrayList<Protocol>();
protocols.add(new StompProtocol());
protocols.add(new MqttProtocol());
protocols.add(new AmqpProtocol());
protocols.add(new OpenwireProtocol());
protocols.add(new HttpProtocol());
protocols.add(new SslProtocol());
DetectingGateway gateway = new DetectingGateway();
gateway.setPort(0);
gateway.setVertx(vertx);
SslConfig sslConfig = new SslConfig(new File(basedir(), "src/test/resources/server.ks"), "password");
sslConfig.setKeyPassword("password");
gateway.setSslConfig(sslConfig);
gateway.setServiceMap(serviceMap);
gateway.setProtocols(protocols);
gateway.setServiceLoadBalancer(serviceLoadBalancer);
gateway.setDefaultVirtualHost("broker1");
gateway.setConnectionTimeout(5000);
if (httpGatewayServer != null) {
gateway.setHttpGateway(new InetSocketAddress("localhost", httpGatewayServer.getPort()));
}
gateway.init();
gateways.add(gateway);
return gateway;
}
use of io.fabric8.gateway.loadbalancer.LoadBalancer in project fabric8 by jboss-fuse.
the class HttpGatewayConnectionTimeoutTest method startHttpGateway.
@Override
public HttpGatewayServer startHttpGateway() {
if (restEndpointServer != null) {
LoadBalancer loadBalancer = new RoundRobinLoadBalancer();
ServiceDTO serviceDetails = new ServiceDTO();
serviceDetails.setContainer("local");
serviceDetails.setVersion("1");
// XXX: pick a non routable address to simulate connection refused (in this case 10.0.0.0 )
mappedServices.put("/hello/world", new MappedServices("http://10.0.0.0:8181", serviceDetails, loadBalancer, false));
}
HttpGatewayHandler handler = new HttpGatewayHandler(vertx, new HttpGateway() {
@Override
public void addMappingRuleConfiguration(HttpMappingRule mappingRule) {
}
@Override
public void removeMappingRuleConfiguration(HttpMappingRule mappingRule) {
}
@Override
public Map<String, MappedServices> getMappedServices() {
return mappedServices;
}
@Override
public boolean isEnableIndex() {
return true;
}
@Override
public InetSocketAddress getLocalAddress() {
return new InetSocketAddress("0.0.0.0", 8080);
}
@Override
public void addCallDetailRecord(CallDetailRecord cdr) {
}
});
handler.setConnectionTimeout(1000);
httpGatewayServer = new HttpGatewayServer(vertx, handler, null, 8080);
httpGatewayServer.setHost("localhost");
httpGatewayServer.init();
return httpGatewayServer;
}
Aggregations