Search in sources :

Example 1 with SimplePathTemplate

use of io.fabric8.zookeeper.internal.SimplePathTemplate 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);
}
Also used : HttpMappingZooKeeperTreeCache(io.fabric8.gateway.fabric.support.http.HttpMappingZooKeeperTreeCache) HttpMappingRuleBase(io.fabric8.gateway.fabric.support.http.HttpMappingRuleBase) SimplePathTemplate(io.fabric8.zookeeper.internal.SimplePathTemplate) LoadBalancer(io.fabric8.gateway.loadbalancer.LoadBalancer)

Example 2 with SimplePathTemplate

use of io.fabric8.zookeeper.internal.SimplePathTemplate 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();
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MappedServices(io.fabric8.gateway.handlers.http.MappedServices) SimplePathTemplate(io.fabric8.zookeeper.internal.SimplePathTemplate)

Example 3 with SimplePathTemplate

use of io.fabric8.zookeeper.internal.SimplePathTemplate in project fabric8 by jboss-fuse.

the class MappingConfigurationTest method setUriTemplate.

protected void setUriTemplate(String uriTemplate, String version) {
    config = new HttpMappingRuleBase(new SimplePathTemplate(uriTemplate), version, enabledVersion, loadBalancer, reverseHeaders);
    httpGateway.addMappingRuleConfiguration(config);
}
Also used : HttpMappingRuleBase(io.fabric8.gateway.fabric.support.http.HttpMappingRuleBase) SimplePathTemplate(io.fabric8.zookeeper.internal.SimplePathTemplate)

Aggregations

SimplePathTemplate (io.fabric8.zookeeper.internal.SimplePathTemplate)3 HttpMappingRuleBase (io.fabric8.gateway.fabric.support.http.HttpMappingRuleBase)2 HttpMappingZooKeeperTreeCache (io.fabric8.gateway.fabric.support.http.HttpMappingZooKeeperTreeCache)1 MappedServices (io.fabric8.gateway.handlers.http.MappedServices)1 LoadBalancer (io.fabric8.gateway.loadbalancer.LoadBalancer)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1