use of org.cloudfoundry.client.v2.routes.GetRouteResponse in project promregator by promregator.
the class CFAccessorMock method retrieveRoute.
@Override
public Mono<GetRouteResponse> retrieveRoute(String routeId) {
RouteEntity entity = null;
if (routeId.equals(UNITTEST_APP1_ROUTE_UUID)) {
entity = RouteEntity.builder().domainId(UNITTEST_SHARED_DOMAIN_UUID).host(UNITTEST_APP1_HOST).build();
} else if (routeId.equals(UNITTEST_APP2_ROUTE_UUID)) {
entity = RouteEntity.builder().domainId(UNITTEST_SHARED_DOMAIN_UUID).host(UNITTEST_APP2_HOST).path("additionalPath").build();
}
if (entity == null) {
Assert.fail("Invalid route request");
return null;
}
GetRouteResponse resp = GetRouteResponse.builder().entity(entity).build();
return Mono.just(resp);
}
use of org.cloudfoundry.client.v2.routes.GetRouteResponse in project promregator by promregator.
the class ReactiveAppInstanceScanner method getApplicationUrl.
private Mono<String> getApplicationUrl(Mono<String> applicationIdMono, String protocol) {
String key = String.format("%d", applicationIdMono.hashCode());
synchronized (key.intern()) {
Mono<String> cached = this.hostnameMap.get(key);
if (cached != null) {
this.internalMetrics.countHit("appinstancescanner.route");
return cached;
}
this.internalMetrics.countMiss("appinstancescanner.route");
ReactiveTimer reactiveTimer = new ReactiveTimer(this.internalMetrics, "route");
Mono<RouteEntity> routeMono = applicationIdMono.zipWith(Mono.just(reactiveTimer)).map(tuple -> {
tuple.getT2().start();
return tuple.getT1();
}).flatMap(appId -> {
return this.cfAccessor.retrieveRouteMapping(appId);
}).flatMap(mappingResponse -> {
List<RouteMappingResource> resourceList = mappingResponse.getResources();
if (resourceList.isEmpty())
return Mono.empty();
String routeId = resourceList.get(0).getEntity().getRouteId();
if (routeId == null)
return Mono.empty();
return this.cfAccessor.retrieveRoute(routeId);
}).flatMap(GetRouteResponse -> {
RouteEntity route = GetRouteResponse.getEntity();
if (route == null)
return Mono.empty();
// and not the URL which points to the endpoint of the cell!
return Mono.just(route);
});
Mono<String> domainMono = routeMono.map(route -> route.getDomainId()).flatMap(domainId -> {
return this.getDomain(domainId);
});
Mono<String> applicationUrlMono = Mono.zip(domainMono, routeMono).map(tuple -> {
String domain = tuple.getT1();
RouteEntity route = tuple.getT2();
String url = String.format("%s://%s.%s", protocol, route.getHost(), domain);
if (route.getPath() != null) {
url += "/" + route.getPath();
}
return url;
}).zipWith(Mono.just(reactiveTimer)).map(tuple -> {
tuple.getT2().stop();
return tuple.getT1();
}).cache();
this.hostnameMap.put(key, applicationUrlMono);
return applicationUrlMono;
}
}
Aggregations