use of org.cloudfoundry.client.v2.routemappings.RouteMappingResource 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;
}
}
use of org.cloudfoundry.client.v2.routemappings.RouteMappingResource in project promregator by promregator.
the class CFAccessorMock method retrieveRouteMapping.
@Override
public Mono<ListRouteMappingsResponse> retrieveRouteMapping(String appId) {
RouteMappingEntity entity = null;
if (appId.equals(UNITTEST_APP1_UUID)) {
entity = RouteMappingEntity.builder().applicationId(appId).routeId(UNITTEST_APP1_ROUTE_UUID).build();
} else if (appId.equals(UNITTEST_APP2_UUID)) {
entity = RouteMappingEntity.builder().applicationId(appId).routeId(UNITTEST_APP2_ROUTE_UUID).build();
}
if (entity == null) {
Assert.fail("Invalid route mapping request");
return null;
}
RouteMappingResource rmr = null;
rmr = RouteMappingResource.builder().entity(entity).build();
List<RouteMappingResource> list = new LinkedList<>();
list.add(rmr);
ListRouteMappingsResponse resp = ListRouteMappingsResponse.builder().addAllResources(list).build();
return Mono.just(resp);
}
Aggregations