Search in sources :

Example 1 with ServiceDTO

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

the class ExtendedBurnIn method startHttpGateway.

public HttpGatewayServer startHttpGateway() {
    if (restEndpointServer != null) {
        LoadBalancer loadBalancer = new RoundRobinLoadBalancer();
        ServiceDTO serviceDetails = new ServiceDTO();
        serviceDetails.setContainer("local");
        serviceDetails.setVersion("1");
        mappedServices.put("/hello/world", new MappedServices("http://localhost:8181", serviceDetails, loadBalancer, false));
    }
    DetectingGatewayWebSocketHandler websocketHandler = new DetectingGatewayWebSocketHandler();
    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) {
        }
    });
    websocketHandler.setPathPrefix("");
    httpGatewayServer = new HttpGatewayServer(vertx, handler, websocketHandler, 8080);
    httpGatewayServer.setHost("localhost");
    httpGatewayServer.init();
    return httpGatewayServer;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) RoundRobinLoadBalancer(io.fabric8.gateway.loadbalancer.RoundRobinLoadBalancer) LoadBalancer(io.fabric8.gateway.loadbalancer.LoadBalancer) RoundRobinLoadBalancer(io.fabric8.gateway.loadbalancer.RoundRobinLoadBalancer) DetectingGatewayWebSocketHandler(io.fabric8.gateway.handlers.detecting.DetectingGatewayWebSocketHandler)

Example 2 with ServiceDTO

use of io.fabric8.gateway.ServiceDTO 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);
    }
}
Also used : PathChildrenCacheEvent(org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent) ChildData(org.apache.curator.framework.recipes.cache.ChildData) ServiceDTO(io.fabric8.gateway.ServiceDTO) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException)

Example 3 with ServiceDTO

use of io.fabric8.gateway.ServiceDTO 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);
    }
}
Also used : PathChildrenCacheEvent(org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent) ChildData(org.apache.curator.framework.recipes.cache.ChildData) ServiceDTO(io.fabric8.gateway.ServiceDTO) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException)

Example 4 with ServiceDTO

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

the class MappingConfigurationTest method addService.

protected void addService(String path, String service, String version) {
    Map<String, String> params = new HashMap<String, String>();
    params.put("version", version);
    String container = path.contains("HelloWorld") ? "soapy" : "resty";
    params.put("container", container);
    ServiceDTO serviceDetails = new ServiceDTO();
    serviceDetails.setContainer(container);
    serviceDetails.setVersion(version);
    config.updateMappingRules(false, path, Arrays.asList(service), params, serviceDetails);
}
Also used : HashMap(java.util.HashMap) ServiceDTO(io.fabric8.gateway.ServiceDTO)

Example 5 with ServiceDTO

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

the class DetectingGatewayTest method startBrokers.

@Before
public void startBrokers() {
    for (int i = 0; i < 2; i++) {
        // create a broker..
        String name = "broker" + i;
        Broker broker = createBroker(name);
        ServiceControl.start(broker);
        brokers.add(broker);
        // Add a service map entry for the broker.
        ServiceDTO details = new ServiceDTO();
        details.setId(name);
        details.setVersion("1.0");
        details.setContainer("testing");
        details.setBundleName("none");
        details.setBundleVersion("1.0");
        List<String> services = Arrays.asList("stomp://localhost:" + portOfBroker(i), "mqtt://localhost:" + portOfBroker(i), "amqp://localhost:" + portOfBroker(i), "tcp://localhost:" + portOfBroker(i));
        details.setServices(services);
        serviceMap.serviceUpdated(name, details);
        println(String.format("Broker %s is exposing: %s", name, services));
    }
}
Also used : Broker(org.apache.activemq.apollo.broker.Broker) ServiceDTO(io.fabric8.gateway.ServiceDTO) Before(org.junit.Before)

Aggregations

ServiceDTO (io.fabric8.gateway.ServiceDTO)6 LoadBalancer (io.fabric8.gateway.loadbalancer.LoadBalancer)4 RoundRobinLoadBalancer (io.fabric8.gateway.loadbalancer.RoundRobinLoadBalancer)4 InetSocketAddress (java.net.InetSocketAddress)4 HttpGateway (io.fabric8.gateway.handlers.http.HttpGateway)3 HttpGatewayHandler (io.fabric8.gateway.handlers.http.HttpGatewayHandler)3 HttpGatewayServer (io.fabric8.gateway.handlers.http.HttpGatewayServer)3 HttpMappingRule (io.fabric8.gateway.handlers.http.HttpMappingRule)3 MappedServices (io.fabric8.gateway.handlers.http.MappedServices)3 IOException (java.io.IOException)3 URISyntaxException (java.net.URISyntaxException)3 Map (java.util.Map)3 ChildData (org.apache.curator.framework.recipes.cache.ChildData)3 HashMap (java.util.HashMap)2 Broker (org.apache.activemq.apollo.broker.Broker)2 PathChildrenCacheEvent (org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent)2 Before (org.junit.Before)2 DetectingGatewayWebSocketHandler (io.fabric8.gateway.handlers.detecting.DetectingGatewayWebSocketHandler)1 Type (org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent.Type)1 MultiMap (org.vertx.java.core.MultiMap)1