Search in sources :

Example 1 with ServiceMap

use of io.fabric8.gateway.ServiceMap 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;
    }
}
Also used : TcpGateway(io.fabric8.gateway.handlers.tcp.TcpGateway) TcpGatewayHandler(io.fabric8.gateway.handlers.tcp.TcpGatewayHandler)

Example 2 with ServiceMap

use of io.fabric8.gateway.ServiceMap 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);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ServiceMap(io.fabric8.gateway.ServiceMap) TcpGateway(io.fabric8.gateway.handlers.tcp.TcpGateway) VertxService(io.fabric8.gateway.fabric.support.vertx.VertxService) ArrayList(java.util.ArrayList) LoadBalancer(io.fabric8.gateway.loadbalancer.LoadBalancer) Vertx(org.vertx.java.core.Vertx)

Example 3 with ServiceMap

use of io.fabric8.gateway.ServiceMap in project fabric8 by jboss-fuse.

the class GatewayServiceTreeCacheTest method treeCacheEvent.

@Test
public void treeCacheEvent() throws Exception {
    String zkPath = "/fabric/registry/clusters/test";
    ServiceMap serviceMap = new ServiceMap();
    CuratorFramework curator = mock(CuratorFramework.class);
    GatewayServiceTreeCache cache = new GatewayServiceTreeCache(curator, zkPath, serviceMap);
    String path = "/fabric/registry/clusters/test/default/0000001";
    // Add container1 - master
    // Add container2 - slave
    cache.treeCacheEvent(event(path, CHILD_ADDED, data("test", "container1", "service1", "service2")));
    cache.treeCacheEvent(event(path, CHILD_ADDED, data("test", "container2")));
    assertEquals(1, serviceMap.getServices("default").size());
    // Remove container1
    // Update container2 - master
    // Add container1 - slave
    cache.treeCacheEvent(event(path, CHILD_REMOVED, data("test", "container1", "service1", "service2")));
    cache.treeCacheEvent(event(path, CHILD_UPDATED, data("test", "container2", "service1", "service2")));
    cache.treeCacheEvent(event(path, CHILD_ADDED, data("test", "container1")));
    assertEquals(1, serviceMap.getServices("default").size());
    // Remove container2
    // Update container1 - master
    // Add container2 - slave
    cache.treeCacheEvent(event(path, CHILD_REMOVED, data("test", "container2", "service1", "service2")));
    cache.treeCacheEvent(event(path, CHILD_UPDATED, data("test", "container1", "service1", "service2")));
    cache.treeCacheEvent(event(path, CHILD_ADDED, data("test", "container2")));
    assertEquals(1, serviceMap.getServices("default").size());
    // Remove container2
    // Add container2 - slave
    cache.treeCacheEvent(event(path, CHILD_REMOVED, data("test", "container2")));
    cache.treeCacheEvent(event(path, CHILD_ADDED, data("test", "container2")));
    assertEquals(1, serviceMap.getServices("default").size());
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ServiceMap(io.fabric8.gateway.ServiceMap) Test(org.junit.Test)

Example 4 with ServiceMap

use of io.fabric8.gateway.ServiceMap in project fabric8 by jboss-fuse.

the class DetectingGatewayTest method createGateway.

public DetectingGateway createGateway() {
    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);
    gateway.init();
    gateways.add(gateway);
    return gateway;
}
Also used : SslProtocol(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol) ArrayList(java.util.ArrayList) LoadBalancer(io.fabric8.gateway.loadbalancer.LoadBalancer) MqttProtocol(io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol) OpenwireProtocol(io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol) SslConfig(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslConfig) HttpProtocol(io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol) StompProtocol(io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol) AmqpProtocol(io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol) MqttProtocol(io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol) SslProtocol(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol) StompProtocol(io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol) AmqpProtocol(io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol) HttpProtocol(io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol) OpenwireProtocol(io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol) File(java.io.File)

Example 5 with ServiceMap

use of io.fabric8.gateway.ServiceMap 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;
}
Also used : SslProtocol(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol) ArrayList(java.util.ArrayList) LoadBalancer(io.fabric8.gateway.loadbalancer.LoadBalancer) MqttProtocol(io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol) OpenwireProtocol(io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol) SslConfig(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslConfig) HttpProtocol(io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol) StompProtocol(io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol) AmqpProtocol(io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol) MqttProtocol(io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol) SslProtocol(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol) StompProtocol(io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol) AmqpProtocol(io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol) HttpProtocol(io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol) OpenwireProtocol(io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol) File(java.io.File)

Aggregations

LoadBalancer (io.fabric8.gateway.loadbalancer.LoadBalancer)5 AmqpProtocol (io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol)4 HttpProtocol (io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol)4 MqttProtocol (io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol)4 OpenwireProtocol (io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol)4 SslConfig (io.fabric8.gateway.handlers.detecting.protocol.ssl.SslConfig)4 SslProtocol (io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol)4 StompProtocol (io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol)4 ArrayList (java.util.ArrayList)4 File (java.io.File)3 ServiceMap (io.fabric8.gateway.ServiceMap)2 VertxService (io.fabric8.gateway.fabric.support.vertx.VertxService)2 DetectingGateway (io.fabric8.gateway.handlers.detecting.DetectingGateway)2 Protocol (io.fabric8.gateway.handlers.detecting.Protocol)2 TcpGateway (io.fabric8.gateway.handlers.tcp.TcpGateway)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 ShutdownException (io.fabric8.common.util.ShutdownTracker.ShutdownException)1 TcpGatewayHandler (io.fabric8.gateway.handlers.tcp.TcpGatewayHandler)1 RoundRobinLoadBalancer (io.fabric8.gateway.loadbalancer.RoundRobinLoadBalancer)1 InetSocketAddress (java.net.InetSocketAddress)1