Skip to content

Commit

Permalink
default prefix services/
Browse files Browse the repository at this point in the history
  • Loading branch information
BartRobeyns committed Sep 24, 2018
1 parent 25ef868 commit e74ca45
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ parameters:
--spring.cloud.zookeeper.connect-string=<zookeeper-url> (defaults to localhost:2181)
--spring.cloud.zookeeper.discovery.register=<true|false> (default: true, makes zk-apache-bridge itself discoverable)
--zkapachebridge.healthcheck.interval=(default:20000, time in ms between healthchecks)
--zkapachebridge.urls.prefix=<prefix for the exposed endpoints> (defaults to 'services/')

--zkapachebridge.rewritemap.active=<true|false> (default: true)
--zkapachebridge.rewritemap.path=<path where to write the rewritemap> (default: /etc/apache2/maps/apimap.map)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Capture service-name into '$1' and the path that follows into 'path'
# and lookup that servicename in apimap
RewriteRule ^/([^\/]*)(.*)$ - [E=host:${apimap:$1|notfound},E=path:$2]
RewriteRule ^/(services/[^\/]*)(.*)$ - [E=host:${apimap:$1|notfound},E=path:$2]

# if the previous rule found the service in apimap, rewrite to the service
RewriteCond %{ENV:host} !notfound
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ public void getServiceInformation() {
public void getLoadBalancerConfiguration() {
assertThat(
this.restTemplate.getForObject("/api/info/loadbalancer", String.class),
new StringContains("ProxyPass /zk-apache-bridge"));
new StringContains("ProxyPass /services/zk-apache-bridge"));
}

@Test
public void getRewriteMapConfiguration() {
assertThat(
this.restTemplate.getForObject("/api/info/rewritemap", String.class),
new StringContains("zk-apache-bridge"));
new StringContains("services/zk-apache-bridge"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class LoadBalancerUpdater implements ApplicationListener<ServiceRegistryU
@Value("${zkapachebridge.loadbalancer.apache-reload}")
String apacheReload;

@Value("${zkapachebridge.urls.prefix:}")
String urlPrefix;

@Autowired
public LoadBalancerUpdater(Configuration freemarkerConfiguration, LoadBalancerWriter loadBalancerWriter, ServiceRegistry serviceRegistry) {
Expand Down Expand Up @@ -80,6 +82,7 @@ private String applyTemplate(Template template, Map<String, Object> model) throw
private Map<String, Object> buildServicesFreemarkerModel() {
Map<String, Object> model = new HashMap<>();
model.put("services", serviceRegistry.getServices());
model.put("prefix", urlPrefix);
return model;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class RewriteMapUpdater implements ApplicationListener<ServiceRegistryUpd
@Value("${zkapachebridge.rewritemap.active}")
boolean active;

@Value("${zkapachebridge.urls.prefix:}")
String urlPrefix;

@Autowired
public RewriteMapUpdater(Configuration freemarkerConfiguration, RewriteMapWriter rewriteMapWriter, ServiceRegistry serviceRegistry) {
this.freemarkerConfiguration = freemarkerConfiguration;
Expand All @@ -47,7 +50,10 @@ public String getConfiguration() {
private String buildRewriteMapContents() {
Map<String, EndpointCollection> services = serviceRegistry.getServices();
StringBuffer sb = new StringBuffer();
services.forEach((servicename, endpointCollection) -> sb.append(servicename)
services.forEach((servicename, endpointCollection) ->
sb
.append(urlPrefix)
.append(servicename)
.append("\t")
.append(String.join("|", endpointCollection.getActiveURIStrings()))
.append("\n"));
Expand Down
2 changes: 2 additions & 0 deletions zk-apache-bridge/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ spring:
zkapachebridge:
healthcheck:
interval: 20000
urls:
prefix: services/
rewritemap:
active: true
path: /etc/apache2/maps/apimap.map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
BalancerMember "${URI}"
</#list>
</Proxy>
ProxyPass /${key} balancer://${key}
ProxyPass /${prefix}${key} balancer://${key}
</#list>
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public void buildLoadBalancerContentsTest() throws Exception {
LoadBalancerUpdater loadBalancerUpdater = new LoadBalancerUpdater( freemarkerConfiguration,
rewriteMapWriter, serviceRegistry );
loadBalancerUpdater.loadBalancerConfigTemplate = "loadbalancer-config.ftl";
loadBalancerUpdater.urlPrefix="services/";
String content = loadBalancerUpdater.buildLoadBalancerContents();

final Pattern balancerOne = Pattern.compile("\\Q<Proxy \"balancer://one\">\\E(.*?)</Proxy>", Pattern.DOTALL);
Expand Down

0 comments on commit e74ca45

Please sign in to comment.